Initial commit
This commit is contained in:
113
app/plugins/timers/controllers/timers.php
Normal file
113
app/plugins/timers/controllers/timers.php
Normal 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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user