Initial commit
This commit is contained in:
62
app/plugins/todo/controllers/api/lists.php
Normal file
62
app/plugins/todo/controllers/api/lists.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/todo/controllers/tasts.php
|
||||
*
|
||||
* This is the task lists' API controller.
|
||||
*
|
||||
* @package TP ToDo
|
||||
* @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\Tasklists as ListModel;
|
||||
use TheTempusProject\Classes\ApiController;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
|
||||
class Lists extends ApiController {
|
||||
protected static $lists;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$lists = new ListModel;
|
||||
}
|
||||
|
||||
public function hide( $id = null ) {
|
||||
$list = self::$lists->get( $id );
|
||||
if ( ! $list ) {
|
||||
$responseType = 'error';
|
||||
$response = 'No list found.';
|
||||
} else {
|
||||
$responseType = 'data';
|
||||
$response = self::$lists->hide( $id );
|
||||
}
|
||||
Views::view( 'api.response', ['response' => json_encode( [ $responseType => $response ], true )]);
|
||||
}
|
||||
|
||||
public function delete( $id = null ) {
|
||||
$list = self::$lists->get( $id );
|
||||
if ( ! $list ) {
|
||||
$responseType = 'error';
|
||||
$response = 'No list found.';
|
||||
} else {
|
||||
$responseType = 'data';
|
||||
$response = self::$lists->delete( $id );
|
||||
}
|
||||
Views::view( 'api.response', ['response' => json_encode( [ $responseType => $response ], true )]);
|
||||
}
|
||||
|
||||
public function home( $id = null ) {
|
||||
$list = self::$lists->get( $id );
|
||||
if ( ! $list ) {
|
||||
$responseType = 'error';
|
||||
$response = 'No list found.';
|
||||
} else {
|
||||
$responseType = 'data';
|
||||
$response = $list;
|
||||
}
|
||||
Views::view( 'api.response', ['response' => json_encode( [ $responseType => $response ], true )]);
|
||||
}
|
||||
}
|
62
app/plugins/todo/controllers/api/tasks.php
Normal file
62
app/plugins/todo/controllers/api/tasks.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/todo/controllers/tasts.php
|
||||
*
|
||||
* This is the tasks' API controller.
|
||||
*
|
||||
* @package TP ToDo
|
||||
* @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\Tasks as TaskModel;
|
||||
use TheTempusProject\Classes\ApiController;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
|
||||
class Tasks extends ApiController {
|
||||
protected static $tasks;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$tasks = new TaskModel;
|
||||
}
|
||||
|
||||
public function complete( $id = null ) {
|
||||
$task = self::$tasks->get( $id );
|
||||
if ( ! $task ) {
|
||||
$responseType = 'error';
|
||||
$response = 'No task found.';
|
||||
} else {
|
||||
$responseType = 'data';
|
||||
$response = self::$tasks->complete( $id );
|
||||
}
|
||||
Views::view( 'api.response', ['response' => json_encode( [ $responseType => $response ], true )]);
|
||||
}
|
||||
|
||||
public function delete( $id = null ) {
|
||||
$task = self::$tasks->get( $id );
|
||||
if ( ! $task ) {
|
||||
$responseType = 'error';
|
||||
$response = 'No task found.';
|
||||
} else {
|
||||
$responseType = 'data';
|
||||
$response = self::$tasks->delete( $id );
|
||||
}
|
||||
Views::view( 'api.response', ['response' => json_encode( [ $responseType => $response ], true )]);
|
||||
}
|
||||
|
||||
public function home( $id = null ) {
|
||||
$task = self::$tasks->get( $id );
|
||||
if ( ! $task ) {
|
||||
$responseType = 'error';
|
||||
$response = 'No task found.';
|
||||
} else {
|
||||
$responseType = 'data';
|
||||
$response = $task;
|
||||
}
|
||||
Views::view( 'api.response', ['response' => json_encode( [ $responseType => $response ], true )]);
|
||||
}
|
||||
}
|
371
app/plugins/todo/controllers/todo.php
Normal file
371
app/plugins/todo/controllers/todo.php
Normal file
@ -0,0 +1,371 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/todo/controllers/todo.php
|
||||
*
|
||||
* This is the todo controller.
|
||||
*
|
||||
* @package TP ToDo
|
||||
* @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\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Hermes\Functions\Redirect;
|
||||
use TheTempusProject\Bedrock\Functions\Session;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Classes\Controller;
|
||||
use TheTempusProject\Classes\Forms;
|
||||
use TheTempusProject\Houdini\Classes\Forms as FormBuilder;
|
||||
use TheTempusProject\Models\Tasks;
|
||||
use TheTempusProject\Models\Tasklists;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Classes\Config;
|
||||
use TheTempusProject\Houdini\Classes\Navigation;
|
||||
use TheTempusProject\Houdini\Classes\Template;
|
||||
|
||||
class Todo extends Controller {
|
||||
protected static $tasks;
|
||||
protected static $lists;
|
||||
protected static $showHidden;
|
||||
protected static $listView;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
if ( !App::$isLoggedIn ) {
|
||||
Session::flash( 'notice', 'You must be logged in to use this feature.' );
|
||||
return Redirect::home();
|
||||
}
|
||||
self::$tasks = new Tasks;
|
||||
self::$lists = new Tasklists;
|
||||
self::$title = 'To-Do - {SITENAME}';
|
||||
self::$pageDescription = 'On this page you can create and manage tasks and lists.';
|
||||
|
||||
|
||||
if ( Input::exists('includeCompleted') && 'true' == Input::get('includeCompleted') ) {
|
||||
self::$showHidden = true;
|
||||
Components::set( 'completedToggleText', 'Hide' );
|
||||
Components::set( 'completedToggle', 'false' );
|
||||
} else {
|
||||
self::$showHidden = false;
|
||||
Components::set( 'completedToggleText', 'Show' );
|
||||
Components::set( 'completedToggle', 'true' );
|
||||
}
|
||||
|
||||
$taskTabs = Views::simpleView( 'todo.nav.listTabs' );
|
||||
if ( stripos( Input::get('url'), 'todo/list' ) !== false ) {
|
||||
$tabsView = Navigation::activePageSelect( $taskTabs, '/todo/list/', false, true );
|
||||
$userListTabs = Views::simpleView('todo.nav.userListTabs', self::$lists->simpleObjectByUser(true) );
|
||||
$userListTabsView = Navigation::activePageSelect( $userListTabs, Input::get( 'url' ), false, true );
|
||||
} else {
|
||||
$tabsView = Navigation::activePageSelect( $taskTabs, Input::get( 'url' ), false, true );
|
||||
$userListTabsView = '';
|
||||
}
|
||||
Components::set( 'userListTabs', $userListTabsView );
|
||||
Views::raw( $tabsView );
|
||||
}
|
||||
public function index() {
|
||||
Components::set( 'listName', 'All' );
|
||||
Components::set( 'listID', '' );
|
||||
|
||||
$recentlyCompleted = Views::simpleView( 'todo.tasks.list', self::$tasks->recentlyCompleted( 10 ) );
|
||||
Components::set( 'recentlyCompleted', $recentlyCompleted );
|
||||
|
||||
$dailyTasks = Views::simpleView( 'todo.tasks.daily', self::$tasks->dailyTasks( 10 ) );
|
||||
Components::set( 'dailyTasks', $dailyTasks );
|
||||
|
||||
$weeklyTasks = Views::simpleView( 'todo.tasks.weekly', self::$tasks->weeklyTasks( 10 ) );
|
||||
Components::set( 'weeklyTasks', $weeklyTasks );
|
||||
|
||||
$monthlyTasks = Views::simpleView( 'todo.tasks.monthly', self::$tasks->monthlyTasks( 10 ) );
|
||||
Components::set( 'monthlyTasks', $monthlyTasks );
|
||||
|
||||
$yearlyTasks = Views::simpleView( 'todo.tasks.yearly', self::$tasks->yearlyTasks( 10 ) );
|
||||
Components::set( 'yearlyTasks', $yearlyTasks );
|
||||
|
||||
$tasks = Views::simpleView( 'todo.tasks.list', self::$tasks->recent( 10 ) );
|
||||
Components::set( 'taskList', $tasks );
|
||||
|
||||
$lists = Views::simpleView( 'todo.lists.list', self::$lists->recent() );
|
||||
Components::set( 'listList', $lists );
|
||||
|
||||
Views::view( 'todo.dashboard' );
|
||||
}
|
||||
public function daily() {
|
||||
Views::view( 'todo.tasks.daily', self::$tasks->dailyTasks( 10, self::$showHidden ) );
|
||||
}
|
||||
public function weekly() {
|
||||
Views::view( 'todo.tasks.weekly', self::$tasks->weeklyTasks( 10, self::$showHidden ) );
|
||||
}
|
||||
public function monthly() {
|
||||
Views::view( 'todo.tasks.monthly', self::$tasks->monthlyTasks( 10, self::$showHidden ) );
|
||||
}
|
||||
public function yearly() {
|
||||
Views::view( 'todo.tasks.yearly', self::$tasks->yearlyTasks( 10, self::$showHidden ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists
|
||||
*/
|
||||
public function list( $id = 0 ) {
|
||||
$list = self::$lists->findById( $id );
|
||||
if ( $list == false ) {
|
||||
$lists = self::$lists->recent();
|
||||
return Views::view( 'todo.lists.list', $lists );
|
||||
}
|
||||
Components::set( 'listID', $id );
|
||||
if ( Input::exists('includeCompleted') && 'true' == Input::get('includeCompleted') ) {
|
||||
$include_completed = true;
|
||||
} else {
|
||||
$include_completed = false;
|
||||
}
|
||||
$tasks = self::$tasks->findByListId( $id, $include_completed );
|
||||
Components::set( 'listName', $list->title );
|
||||
Components::set( 'CONTENT_ID', $id );
|
||||
Components::set( 'COMMENT_TYPE', 'tasklist' );
|
||||
Views::view( 'todo.tasks.list', $tasks );
|
||||
}
|
||||
public function createList() {
|
||||
if ( !Input::exists() ) {
|
||||
return Views::view( 'todo.lists.create' );
|
||||
}
|
||||
if ( !Forms::check( 'createTaskList' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error creating your task list.' => Check::userErrors() ] );
|
||||
return Views::view( 'todo.lists.create' );
|
||||
}
|
||||
if ( !self::$lists->create( Input::post( 'listName' )) ) {
|
||||
Issues::add( 'error', [ 'There was an error creating your task list.' => Check::userErrors() ] );
|
||||
return Views::view( 'todo.lists.create' );
|
||||
}
|
||||
Session::flash( 'success', 'Your Task List has been created.' );
|
||||
Redirect::to( 'todo/index' );
|
||||
}
|
||||
public function editList( $id = null ) {
|
||||
$list = self::$lists->findById( $id );
|
||||
if ( $list == false ) {
|
||||
Issues::add( 'error', 'TaskList not found.' );
|
||||
return $this->index();
|
||||
}
|
||||
if ( !Input::exists() ) {
|
||||
return Views::view( 'todo.lists.edit', $list );
|
||||
}
|
||||
if ( !Forms::check( 'editTaskList' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your todo task.' => Check::userErrors() ] );
|
||||
return Views::view( 'todo.lists.edit', $list );
|
||||
}
|
||||
if ( !self::$lists->update( $id, Input::post( 'listName' ) ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your todo task.' => Check::userErrors() ] );
|
||||
return Views::view( 'todo.lists.edit', $list );
|
||||
}
|
||||
Session::flash( 'success', 'Your Task List has been saved.' );
|
||||
Redirect::to( 'todo/list/' . $id );
|
||||
}
|
||||
public function deleteList( $id = null ) {
|
||||
$list = self::$lists->findById( $id );
|
||||
if ( $list == false ) {
|
||||
Issues::add( 'error', 'TaskList not found.' );
|
||||
return $this->index();
|
||||
}
|
||||
if ( $list->createdBy != App::$activeUser->ID ) {
|
||||
Issues::add( 'error', 'You do not have permission to modify this calendar.' );
|
||||
return $this->index();
|
||||
}
|
||||
$result = self::$lists->delete( $id );
|
||||
if ( !$result ) {
|
||||
Issues::add( 'error', 'There was an error deleting the list(s)' );
|
||||
} else {
|
||||
Issues::add( 'success', 'List deleted' );
|
||||
}
|
||||
return $this->index();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tasks
|
||||
*/
|
||||
public function task( $id = null ) {
|
||||
$task = self::$tasks->findById( $id );
|
||||
if ( $task == false ) {
|
||||
$tasks = self::$tasks->recent();
|
||||
return Views::view( 'todo.tasks.list', $tasks );
|
||||
}
|
||||
Components::set( 'CONTENT_ID', $id );
|
||||
Components::set( 'COMMENT_TYPE', 'task' );
|
||||
Views::view( 'todo.tasks.view', $task );
|
||||
}
|
||||
public function createTask( $id = null ) {
|
||||
if ( in_array( $id, self::$tasks->repeatOptions ) ) {
|
||||
$repeat = $id;
|
||||
$id = 'non';
|
||||
} else {
|
||||
$repeat = 'none';
|
||||
$id = $id;
|
||||
}
|
||||
|
||||
// @todo need to make this change if it 'id' is actually a repeats value
|
||||
$select = FormBuilder::getFormFieldHtml(
|
||||
'listID',
|
||||
'Task List',
|
||||
'select',
|
||||
$id,
|
||||
self::$lists->getSimpleList(true),
|
||||
);
|
||||
Components::set( 'listSelect', $select );
|
||||
|
||||
$repeatSelect = FormBuilder::getFormFieldHtml( 'repeats', 'Frequency', 'select', $repeat, self::$tasks->repeatOptions );
|
||||
Components::set( 'repeatSelect', $repeatSelect );
|
||||
if ( !Input::exists() ) {
|
||||
return Views::view( 'todo.tasks.create' );
|
||||
}
|
||||
if ( !Forms::check( 'createTask' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your form.' => Check::userErrors() ] );
|
||||
return Views::view( 'todo.tasks.create' );
|
||||
}
|
||||
if ( !self::$tasks->create( Input::post( 'task' ), 'false', Input::post( 'dueDate' ), Input::post( 'listID' ), Input::post( 'repeats' ) ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your todo task.' => Check::userErrors() ] );
|
||||
return Views::view( 'todo.tasks.create' );
|
||||
}
|
||||
Session::flash( 'success', 'Your Task has been created.' );
|
||||
if ( Input::exists( 'listID' ) ) {
|
||||
Redirect::to( 'todo/list/' . Input::post( 'listID' ) );
|
||||
} else {
|
||||
Redirect::to( 'todo/index' );
|
||||
}
|
||||
}
|
||||
public function editTask( $id = null ) {
|
||||
$task = self::$tasks->findById( $id );
|
||||
if ( $task == false ) {
|
||||
Issues::add( 'error', 'Task not found.' );
|
||||
return $this->index();
|
||||
}
|
||||
if ( $task->createdBy != App::$activeUser->ID ) {
|
||||
Issues::add( 'error', 'You do not have permission to modify this task.' );
|
||||
return $this->index();
|
||||
}
|
||||
|
||||
$select = FormBuilder::getFormFieldHtml(
|
||||
'listID',
|
||||
'Task List',
|
||||
'select',
|
||||
$task->listID,
|
||||
self::$lists->getSimpleList(true),
|
||||
);
|
||||
Components::set( 'listSelect', $select );
|
||||
|
||||
$repeatSelect = FormBuilder::getFormFieldHtml( 'repeats', 'Frequency', 'select', $task->repeats, self::$tasks->repeatOptions );
|
||||
Components::set( 'repeatSelect', $repeatSelect );
|
||||
|
||||
if ( !Input::exists( 'submit' ) ) {
|
||||
return Views::view( 'todo.tasks.edit', $task );
|
||||
}
|
||||
if ( !Forms::check( 'editTask' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
|
||||
return Views::view( 'todo.tasks.edit', $task );
|
||||
}
|
||||
if ( self::$tasks->update( $id, Input::post( 'task' ), $task->completed, Input::post( 'dueDate' ), Input::post( 'listID' ), Input::post( 'repeats' ) ) ) {
|
||||
Session::flash( 'success', 'Task updated' );
|
||||
} else {
|
||||
return Views::view( 'todo.tasks.edit', self::$tasks->findById( $data ) );
|
||||
}
|
||||
if ( !empty( $task->listID ) ) {
|
||||
Redirect::to( 'todo/list/' . $task->listID );
|
||||
} else {
|
||||
Redirect::to( 'todo/index' );
|
||||
}
|
||||
}
|
||||
public function deleteTask( $id = null ) {
|
||||
$task = self::$tasks->findById( $id );
|
||||
if ( $task == false ) {
|
||||
Issues::add( 'error', 'Task not found.' );
|
||||
return $this->index();
|
||||
}
|
||||
if ( $task->createdBy != App::$activeUser->ID ) {
|
||||
Issues::add( 'error', 'You do not have permission to modify this task.' );
|
||||
return $this->index();
|
||||
}
|
||||
$result = self::$tasks->delete( $id );
|
||||
if ( !$result ) {
|
||||
Session::flash( 'error', 'There was an error deleting the task(s)' );
|
||||
} else {
|
||||
Session::flash( 'success', 'Task deleted' );
|
||||
}
|
||||
if ( !empty( $task->listID ) ) {
|
||||
Redirect::to( 'todo/list/' . $task->listID );
|
||||
} else {
|
||||
Redirect::to( 'todo/index' );
|
||||
}
|
||||
}
|
||||
public function duplicateTask( $id = null ) {
|
||||
$task = self::$tasks->findById( $id );
|
||||
if ( $task == false ) {
|
||||
Issues::add( 'error', 'Task not found.' );
|
||||
return $this->index();
|
||||
}
|
||||
if ( $task->createdBy != App::$activeUser->ID ) {
|
||||
Issues::add( 'error', 'You do not have permission to modify this task.' );
|
||||
return $this->index();
|
||||
}
|
||||
if ( $task->repeats != 'none' ) {
|
||||
Issues::add( 'error', 'You cannot duplicate a repeating task.' );
|
||||
return $this->index();
|
||||
}
|
||||
if ( ! self::$tasks->duplicate( $id ) ) {
|
||||
Session::flash( 'error', [ 'There was an error duplicating your todo task.'] );
|
||||
} else {
|
||||
Session::flash( 'success', 'Your Task has been duplicated.' );
|
||||
}
|
||||
if ( !empty( $task->listID ) ) {
|
||||
Redirect::to( 'todo/list/' . $task->listID );
|
||||
} else {
|
||||
Redirect::to( 'todo/index' );
|
||||
}
|
||||
}
|
||||
public function completeTask( $id = null ) {
|
||||
$task = self::$tasks->findById( $id );
|
||||
if ( $task == false ) {
|
||||
Issues::add( 'error', 'Task not found.' );
|
||||
return $this->index();
|
||||
}
|
||||
if ( $task->createdBy != App::$activeUser->ID ) {
|
||||
Issues::add( 'error', 'You do not have permission to modify this task.' );
|
||||
return $this->index();
|
||||
}
|
||||
$result = self::$tasks->complete( $id );
|
||||
if ( !$result ) {
|
||||
Session::flash( 'error', 'There was an error completing the task(s)' );
|
||||
} else {
|
||||
Session::flash( 'success', 'Task completed' );
|
||||
}
|
||||
if ( !empty( $task->listID ) ) {
|
||||
Redirect::to( 'todo/list/' . $task->listID );
|
||||
} else {
|
||||
Redirect::to( 'todo/index' );
|
||||
}
|
||||
}
|
||||
public function incompleteTask( $id = null ) {
|
||||
$task = self::$tasks->findById( $id );
|
||||
if ( $task == false ) {
|
||||
Issues::add( 'error', 'Task not found.' );
|
||||
return $this->index();
|
||||
}
|
||||
if ( $task->createdBy != App::$activeUser->ID ) {
|
||||
Issues::add( 'error', 'You do not have permission to modify this task.' );
|
||||
return $this->index();
|
||||
}
|
||||
$result = self::$tasks->incomplete( $id );
|
||||
if ( ! $result ) {
|
||||
Session::flash( 'error', 'There was an error un-completing the task(s)' );
|
||||
} else {
|
||||
Session::flash( 'success', 'Task un-completed' );
|
||||
}
|
||||
if ( !empty( $task->listID ) ) {
|
||||
Redirect::to( 'todo/list/' . $task->listID );
|
||||
} else {
|
||||
Redirect::to( 'todo/index' );
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user