Initial commit

This commit is contained in:
Joey Kimsey
2024-08-04 21:15:59 -04:00
parent c9d1fb983f
commit 0d469501ee
695 changed files with 70184 additions and 71 deletions

View File

@ -0,0 +1,42 @@
<?php
/**
* app/controllers/api/users.php
*
* This is the users' api controller.
*
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Controllers\Api;
use TheTempusProject\Models\User;
use TheTempusProject\Classes\ApiController;
use TheTempusProject\Houdini\Classes\Views;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Classes\Forms;
use TheTempusProject\Houdini\Classes\Template;
use TheTempusProject\Models\Timers as Timer;
class Timers extends ApiController {
public static $timers;
public function __construct() {
parent::__construct();
self::$timers = new Timer;
Template::setTemplate( 'api' );
}
public function create() {
$name = Input::exists('name') ? Input::post('name') : '';
$type = Input::exists('type') ? Input::post('type') : 'stopwatch';
$currentSeconds = Input::exists('currentSeconds') ? Input::post('currentSeconds') : 0;
$pausedAt = 0;
$hours = Input::exists('hours') ? Input::post('hour') : '00';
$minutes = Input::exists('minutes') ? Input::post('minute') : '00';
$seconds = Input::exists('seconds') ? Input::post('seconds') : '00';
$response = self::$timers->create( $name, $currentSeconds, $type, $pausedAt, $hours, $minutes, $seconds);
Views::view( 'api.response', ['response' => json_encode( [ 'data' => $response ], true )]);
}
}

View File

@ -0,0 +1,113 @@
<?php
/**
* app/plugins/timers/controllers/timers.php
*
* This is the home controller for the timers plugin.
*
* @package TP Timers
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Controllers;
use TheTempusProject\Houdini\Classes\Views;
use TheTempusProject\Classes\Controller;
use TheTempusProject\Models\Timers as Timer;
use TheTempusProject\Houdini\Classes\Components;
use TheTempusProject\TheTempusProject as App;
use TheTempusProject\Bedrock\Functions\Session;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Houdini\Classes\Issues;
use TheTempusProject\Classes\Forms;
use TheTempusProject\Houdini\Classes\Template;
use TheTempusProject\Bedrock\Bedrock;
class Timers extends Controller {
protected static $timers;
public function __construct() {
self::$title = 'Timers - {SITENAME}';
self::$pageDescription = 'This is for tracking any number of things using timers.';
self::$timers = new Timer;
if ( ! App::$isLoggedIn ) {
Issues::add( 'info', 'If you register an account and log in, you can save your timers for reuse.' );
Components::set( 'timers', '' );
Components::set( 'stopWatches', '' );
} else {
$timers = self::$timers->userTimers();
$timerView = Views::simpleView( 'timers.timerElement', $timers );
Components::set( 'timers', $timerView );
$stopwatches = self::$timers->userStopWatches();
$stopWatcheView = Views::simpleView( 'timers.stopwatchElement', $stopwatches );
Components::set( 'stopWatches', $stopWatcheView );
}
parent::__construct();
}
public function index() {
Views::view( 'timers.index' );
}
public function save() {
Template::setTemplate( 'api' );
$name = Input::post('name') ? Input::post('name') : 'unnamed';
$type = Input::post('type') ? Input::post('type') : 'stopwatch';
$currentSeconds = Input::post('currentSeconds') ? Input::post('currentSeconds') : 0;
$pausedAt = 0;
$hours = Input::post('hours') ? Input::post('hours') : '00';
$minutes = Input::post('minutes') ? Input::post('minutes') : '00';
$seconds = Input::post('seconds') ? Input::post('seconds') : '00';
$response = self::$timers->create( $name, $currentSeconds, $type, $pausedAt, $hours, $minutes, $seconds );
$out = [
'id' => $response,
];
Views::view( 'api.response', ['response' => json_encode( [ 'data' => $out ], true )]);
}
public function update( $id = null ) {
if ( empty( $id ) ) {
$id = Input::postNull('id');
}
Template::setTemplate( 'api' );
$timer = self::$timers->findById( $id );
if ( $timer == false || $timer->createdBy != App::$activeUser->ID ) {
$response = $id;
} else {
if ( Input::post('paused') ) {
$pausedAt = time();
} else {
$pausedAt = 0;
}
$response = self::$timers->update( $id, Input::post('currentSeconds'), $pausedAt );
}
Views::view( 'api.response', ['response' => json_encode( [ 'data' => $response ], true )]);
}
public function remove( $id = null ) {
if ( empty( $id ) ) {
$id = Input::postNull('id');
}
Template::setTemplate( 'api' );
$timer = self::$timers->findById( $id );
if ( $timer == false || $timer->createdBy != App::$activeUser->ID ) {
$response = $id;
} else {
$response = self::$timers->delete( $id );
}
Views::view( 'api.response', ['response' => json_encode( [ 'data' => $response ], true )]);
}
public function resume() {
$this->index();
}
public function pause() {
$this->index();
}
public function archive() {
$this->index();
}
}