2012-02-05 18:37:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Ctrl_AllTasks
|
|
|
|
extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
public function handle( Page $page )
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$mode = $this->getParameter( 'mode' , 'GET' );
|
|
|
|
} catch ( ParameterException $e ) {
|
|
|
|
$mode = 'active';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $mode == 'active' ) {
|
|
|
|
$tasks = Loader::DAO( 'tasks' )->getAllActiveTasks( );
|
|
|
|
$title = 'Active tasks';
|
2012-02-05 22:22:16 +01:00
|
|
|
$bTitle = 'Display active tasks';
|
|
|
|
$bMode = 'blocked';
|
|
|
|
} elseif ( $mode == 'blocked' ) {
|
|
|
|
$tasks = Loader::DAO( 'tasks' )->getAllBlockedTasks( );
|
|
|
|
$title = 'Blocked tasks';
|
2012-02-05 18:37:25 +01:00
|
|
|
$bTitle = 'Display all tasks';
|
|
|
|
$bMode = 'all';
|
|
|
|
} else {
|
|
|
|
$mode = 'all';
|
|
|
|
$tasks = Loader::DAO( 'tasks' )->getAllTasks( );
|
|
|
|
$title = 'All tasks';
|
|
|
|
$bTitle = 'Display active tasks only';
|
|
|
|
$bMode = 'active';
|
|
|
|
}
|
|
|
|
|
|
|
|
$tree = Loader::DAO( 'items' )->getTree( );
|
2012-02-06 17:57:56 +01:00
|
|
|
$box = Loader::View( 'box' , $title , Loader::View( 'tasks_list' , $tasks ) )
|
2012-02-05 18:37:25 +01:00
|
|
|
->addButton( BoxButton::create( $bTitle , 'tasks?mode=' . $bMode )
|
|
|
|
->setClass( 'icon refresh' ) );
|
|
|
|
if ( !empty( $tree ) ) {
|
|
|
|
$box ->addButton( BoxButton::create( 'New task' , 'tasks/add' )
|
|
|
|
->setClass( 'list-add' ) );
|
|
|
|
}
|
|
|
|
return $box;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
abstract class Ctrl_TaskFormBase
|
|
|
|
extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
protected final function createPrioritySelector( )
|
|
|
|
{
|
|
|
|
$select = Loader::Create( 'Field' , 'priority' , 'select' )
|
|
|
|
->setDescription( 'Priority:' )
|
|
|
|
->setValidator( Loader::Create( 'Validator_IntValue' , 'Priorité invalide' )
|
|
|
|
->setMinValue( 1 )->setMaxValue( 5 ) );
|
|
|
|
$tasks = Loader::DAO( 'tasks' );
|
|
|
|
|
|
|
|
for ( $i = 5 ; $i >= 1 ; $i -- ) {
|
|
|
|
$select->addOption( $i , $tasks->translatePriority( $i ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $select;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Ctrl_AddTaskForm
|
|
|
|
extends Ctrl_TaskFormBase
|
|
|
|
{
|
|
|
|
|
|
|
|
public function handle( Page $page )
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$target = (int) $this->getParameter( 'to' );
|
2012-02-09 18:50:54 +01:00
|
|
|
$targetIsItem = true;
|
2012-02-05 18:37:25 +01:00
|
|
|
} catch ( ParameterException $e ) {
|
2012-02-09 18:50:54 +01:00
|
|
|
try {
|
|
|
|
$target = (int) $this->getParameter( 'parent' );
|
|
|
|
$targetIsItem = false;
|
|
|
|
} catch ( ParameterException $e ) {
|
|
|
|
$target = null;
|
|
|
|
$targetIsItem = null;
|
|
|
|
}
|
2012-02-05 18:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$form = Loader::Create( 'Form' , 'Add this task' , 'create-task' );
|
|
|
|
|
|
|
|
if ( $target === null ) {
|
|
|
|
$returnURL = 'tasks';
|
|
|
|
if ( ! $this->addItemSelector( $form ) ) {
|
|
|
|
return 'items';
|
|
|
|
}
|
2012-02-09 18:50:54 +01:00
|
|
|
$form->addField( Loader::Create( 'Field' , 'nested' , 'hidden' )
|
|
|
|
->setDefaultValue( 0 ) );
|
|
|
|
} elseif ( $targetIsItem ) {
|
2012-02-05 18:37:25 +01:00
|
|
|
$item = Loader::DAO( 'items' )->get( $target );
|
|
|
|
if ( $item === null ) {
|
2012-02-09 18:50:54 +01:00
|
|
|
return 'tasks';
|
2012-02-05 18:37:25 +01:00
|
|
|
}
|
|
|
|
$returnURL = 'items/view?id=' . $target;
|
|
|
|
|
|
|
|
$form->addField( Loader::Create( 'Field' , 'to' , 'hidden' )
|
|
|
|
->setDefaultValue( $target ) )
|
2012-02-09 18:50:54 +01:00
|
|
|
->addField( Loader::Create( 'Field' , 'nested' , 'hidden' )
|
|
|
|
->setDefaultValue( 0 ) )
|
2012-02-05 18:37:25 +01:00
|
|
|
->addField( Loader::Create( 'Field' , 'item' , 'hidden' )
|
2012-02-07 09:29:20 +01:00
|
|
|
->setDefaultValue( $target ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'item-name' , 'label' )
|
2012-02-09 18:50:54 +01:00
|
|
|
->setMandatory( false )
|
2012-02-07 09:29:20 +01:00
|
|
|
->setDescription( 'Item:' )
|
|
|
|
->setDefaultValue( $item->name ) );
|
2012-02-09 18:50:54 +01:00
|
|
|
} else {
|
|
|
|
$parent = Loader::DAO( 'tasks' )->get( $target );
|
|
|
|
if ( $parent === null ) {
|
|
|
|
return 'tasks';
|
|
|
|
}
|
|
|
|
$returnURL = 'tasks/view?id=' . $target;
|
|
|
|
if ( $parent->completed_by !== null ) {
|
|
|
|
return $returnURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
$form->addField( Loader::Create( 'Field' , 'parent' , 'hidden' )
|
|
|
|
->setDefaultValue( $target ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'nested' , 'hidden' )
|
|
|
|
->setDefaultValue( 1 ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'item-name' , 'label' )
|
|
|
|
->setMandatory( false )
|
|
|
|
->setDescription( 'Sub-task of:' )
|
|
|
|
->setDefaultValue( $parent->title ) );
|
2012-02-05 18:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$page->setTitle( 'New task' );
|
|
|
|
|
|
|
|
return $form->addField( Loader::Create( 'Field' , 'title' , 'text' )
|
|
|
|
->setDescription( 'Task title:' )
|
|
|
|
->setModifier( Loader::Create( 'Modifier_TrimString' ) )
|
|
|
|
->setValidator( Loader::Create( 'Validator_StringLength' , 'This title' , 5 , 256 ) ) )
|
|
|
|
->addField( $this->createPrioritySelector( )
|
|
|
|
->setDefaultValue( 3 ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'description' , 'textarea' )
|
|
|
|
->setDescription( 'Description:' )
|
|
|
|
->setMandatory( false ) )
|
|
|
|
->setURL( $returnURL )
|
|
|
|
->addController( Loader::Ctrl( 'add_task' ) )
|
|
|
|
->controller( );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function addItemSelector( $form )
|
|
|
|
{
|
|
|
|
$form->addField( $select = Loader::Create( 'Field' , 'item' , 'select' )
|
|
|
|
->setDescription( 'Item:' )
|
|
|
|
->addOption( '' , '(please select an item)' ) );
|
|
|
|
|
|
|
|
$items = Loader::DAO( 'items' )->getTreeList( );
|
|
|
|
if ( empty( $items ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
foreach ( $items as $item ) {
|
|
|
|
$name = '-' . str_repeat( '--' , $item->depth ) . ' ' . $item->name;
|
|
|
|
$select->addOption( $item->id , $name );
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Ctrl_ViewTask
|
|
|
|
extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
public function handle( Page $page )
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$id = (int) $this->getParameter( 'id' , 'GET' );
|
|
|
|
} catch ( ParameterException $e ) {
|
|
|
|
return 'tasks';
|
|
|
|
}
|
|
|
|
|
|
|
|
$task = Loader::DAO( 'tasks' )->get( $id );
|
|
|
|
if ( $task === null ) {
|
|
|
|
return 'tasks';
|
|
|
|
}
|
|
|
|
$page->setTitle( $task->title . ' (task)' );
|
|
|
|
|
2012-02-05 19:59:51 +01:00
|
|
|
$result = array(
|
2012-02-09 18:50:54 +01:00
|
|
|
Loader::Ctrl( 'task_details' , $task )
|
2012-02-05 19:59:51 +01:00
|
|
|
);
|
2012-02-05 18:37:25 +01:00
|
|
|
|
2012-02-09 18:50:54 +01:00
|
|
|
if ( $task->completed_by === null || ! empty( $task->subtasks ) ) {
|
|
|
|
$result[] = Loader::Ctrl( 'task_list_subtasks' , $task );
|
|
|
|
}
|
|
|
|
$result[] = Loader::Ctrl( 'task_dependencies' , $task );
|
2012-02-05 18:37:25 +01:00
|
|
|
if ( $task->completed_by === null ) {
|
|
|
|
array_push( $result , Loader::Ctrl( 'add_task_note_form' , $task ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
array_push( $result , Loader::Ctrl( 'task_notes' , $task ) );
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Ctrl_DeleteTaskForm
|
|
|
|
extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
public function handle( Page $page )
|
|
|
|
{
|
|
|
|
// Check selected task
|
|
|
|
try {
|
|
|
|
$id = (int) $this->getParameter( 'id' );
|
|
|
|
} catch ( ParameterException $e ) {
|
|
|
|
return 'tasks';
|
|
|
|
}
|
|
|
|
|
|
|
|
$tasks = Loader::DAO( 'tasks' );
|
|
|
|
$task = $tasks->get( $id );
|
|
|
|
if ( $task === null ) {
|
|
|
|
return 'tasks';
|
|
|
|
}
|
|
|
|
if ( ! $tasks->canDelete( $task ) ) {
|
|
|
|
return 'tasks/view?id=' . $id;
|
|
|
|
}
|
|
|
|
$page->setTitle( $task->title . ' (task)' );
|
|
|
|
|
2012-02-09 18:50:54 +01:00
|
|
|
// Create parent URL from either the item or parent task
|
|
|
|
if ( $task->parent_task === null ) {
|
|
|
|
$parentURL = 'items/view?id=' . $task->item;
|
|
|
|
} else {
|
|
|
|
$parentURL = 'tasks/view?id=' . $task->parent_task;
|
|
|
|
}
|
|
|
|
|
2012-02-05 18:37:25 +01:00
|
|
|
// Generate confirmation text
|
|
|
|
$confText = HTML::make( 'div' )
|
|
|
|
->appendElement( HTML::make( 'p' )
|
|
|
|
->appendText( "You are about to delete this task, and any comment attached to it." ) )
|
|
|
|
->appendElement( HTML::make( 'p' )
|
|
|
|
->appendText( "This operation cannot be undone." ) );
|
|
|
|
|
|
|
|
// Generate form
|
|
|
|
return Loader::Create( 'Form' , 'Delete the task' , 'delete-task' , 'Task deletion' )
|
|
|
|
->addField( Loader::Create( 'Field' , 'id' , 'hidden' )
|
|
|
|
->setDefaultValue( $task->id ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'confirm' , 'html' )->setDefaultValue( $confText ) )
|
|
|
|
->setCancelURL( 'tasks/view?id=' . $task->id )
|
2012-02-09 18:50:54 +01:00
|
|
|
->setSuccessURL( $parentURL )
|
2012-02-05 18:37:25 +01:00
|
|
|
->addController( Loader::Ctrl( 'delete_task' ) )
|
|
|
|
->controller( );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Ctrl_EditTaskForm
|
|
|
|
extends Ctrl_TaskFormBase
|
|
|
|
{
|
|
|
|
|
|
|
|
public function handle( Page $page )
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$id = (int) $this->getParameter( 'id' );
|
|
|
|
} catch ( ParameterException $e ) {
|
|
|
|
return 'tasks';
|
|
|
|
}
|
|
|
|
|
|
|
|
$task = Loader::DAO( 'tasks' )->get( $id );
|
|
|
|
if ( $task === null ) {
|
|
|
|
return 'tasks';
|
|
|
|
}
|
2012-02-06 16:38:11 +01:00
|
|
|
if ( $task->completed_at !== null ) {
|
|
|
|
return 'tasks/view?id=' . $id;
|
|
|
|
}
|
2012-02-05 18:37:25 +01:00
|
|
|
$page->setTitle( $task->title . ' (task)' );
|
|
|
|
|
|
|
|
|
2012-02-09 18:50:54 +01:00
|
|
|
$form = Loader::Create( 'Form' , 'Update task' , 'edit-task' , 'Editing task' )
|
2012-02-05 18:37:25 +01:00
|
|
|
->setURL( 'tasks/view?id=' . $task->id )
|
|
|
|
->addField( Loader::Create( 'Field' , 'id' , 'hidden' )
|
|
|
|
->setDefaultValue( $task->id ) )
|
2012-02-09 18:50:54 +01:00
|
|
|
->addField( Loader::Create( 'Field' , 'nested' , 'hidden' )
|
2012-02-15 10:04:11 +01:00
|
|
|
->setDefaultValue( $task->parent_task === null ? 0 : 1 ) );
|
2012-02-09 18:50:54 +01:00
|
|
|
|
2012-02-15 10:04:11 +01:00
|
|
|
if ( $task->parent_task === null ) {
|
2012-02-09 18:50:54 +01:00
|
|
|
$form->addField( $this->createItemSelector( )
|
|
|
|
->setDefaultValue( $task->item ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $form->addField( Loader::Create( 'Field' , 'title' , 'text' )
|
2012-02-05 18:37:25 +01:00
|
|
|
->setDescription( 'Title:' )
|
|
|
|
->setModifier( Loader::Create( 'Modifier_TrimString' ) )
|
|
|
|
->setValidator( Loader::Create( 'Validator_StringLength' , 'This title' , 5 , 256 ) )
|
|
|
|
->setDefaultValue( $task->title ) )
|
|
|
|
->addField( $this->createPrioritySelector( )
|
|
|
|
->setDefaultValue( $task->priority ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'description' , 'textarea' )
|
|
|
|
->setDescription( 'Description:' )
|
|
|
|
->setMandatory( false )
|
|
|
|
->setDefaultValue( $task->description ) )
|
2012-02-06 16:38:11 +01:00
|
|
|
->addField( $this->createAssigneeSelector( )
|
|
|
|
->setDefaultValue( $task->assigned_id ) )
|
2012-02-05 18:37:25 +01:00
|
|
|
->addController( Loader::Ctrl( 'edit_task' ) )
|
|
|
|
->controller( );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function createItemSelector( )
|
|
|
|
{
|
|
|
|
$select = Loader::Create( 'Field' , 'item' , 'select' )
|
|
|
|
->setDescription( 'On item:' );
|
|
|
|
|
2012-02-06 16:38:11 +01:00
|
|
|
$items = Loader::DAO( 'items' )->getTreeList( );
|
2012-02-05 18:37:25 +01:00
|
|
|
foreach ( $items as $item ) {
|
|
|
|
$name = '-' . str_repeat( '--' , $item->depth ) . ' ' . $item->name;
|
|
|
|
$select->addOption( $item->id , $name );
|
|
|
|
}
|
|
|
|
return $select;
|
|
|
|
|
|
|
|
}
|
2012-02-06 16:38:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
private function createAssigneeSelector( )
|
|
|
|
{
|
|
|
|
$select = Loader::Create( 'Field' , 'assigned-to' , 'select' )
|
|
|
|
->setDescription( 'Assigned to:' )
|
|
|
|
->setMandatory( false );
|
|
|
|
$select->addOption( '' , '(unassigned task)' );
|
|
|
|
|
|
|
|
$users = Loader::DAO( 'users' )->getUsers( );
|
|
|
|
foreach ( $users as $user ) {
|
|
|
|
$select->addOption( $user->user_id , $user->user_view_name );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $select;
|
|
|
|
}
|
2012-02-05 18:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Ctrl_DeleteNoteForm
|
|
|
|
extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
public function handle( Page $page )
|
|
|
|
{
|
|
|
|
// Check selected note
|
|
|
|
try {
|
|
|
|
$id = (int) $this->getParameter( 'id' );
|
|
|
|
} catch ( ParameterException $e ) {
|
|
|
|
return 'tasks';
|
|
|
|
}
|
|
|
|
|
|
|
|
$tasks = Loader::DAO( 'tasks' );
|
|
|
|
$note = $tasks->getNote( $id );
|
|
|
|
if ( $note === null ) {
|
|
|
|
return 'tasks';
|
|
|
|
}
|
|
|
|
if ( !$note->editable ) {
|
|
|
|
return 'tasks/view?id=' . $note->task;
|
|
|
|
}
|
|
|
|
$task = $tasks->get( $note->task );
|
|
|
|
$page->setTitle( $task->title . ' (task)' );
|
|
|
|
|
|
|
|
// Generate confirmation text
|
|
|
|
$confText = HTML::make( 'div' )
|
|
|
|
->appendElement( HTML::make( 'p' )
|
|
|
|
->appendText( 'You are about to delete a comment attached to this task.' ) )
|
|
|
|
->appendElement( HTML::make( 'p' )
|
|
|
|
->appendText( 'This operation cannot be undone.' ) );
|
|
|
|
|
|
|
|
// Generate form
|
|
|
|
return Loader::Create( 'Form' , 'Delete this comment' , 'delete-note' , 'Comment deletion' )
|
|
|
|
->addField( Loader::Create( 'Field' , 'id' , 'hidden' )
|
|
|
|
->setDefaultValue( $note->id ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'confirm' , 'html' )->setDefaultValue( $confText ) )
|
|
|
|
->setURL( 'tasks/view?id=' . $note->task )
|
|
|
|
->addController( Loader::Ctrl( 'delete_note' ) )
|
|
|
|
->controller( );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Ctrl_EditNoteForm
|
|
|
|
extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
public function handle( Page $page )
|
|
|
|
{
|
|
|
|
// Check selected note
|
|
|
|
try {
|
|
|
|
$id = (int) $this->getParameter( 'id' );
|
|
|
|
} catch ( ParameterException $e ) {
|
|
|
|
return 'tasks';
|
|
|
|
}
|
|
|
|
|
|
|
|
$tasks = Loader::DAO( 'tasks' );
|
|
|
|
$note = $tasks->getNote( $id );
|
|
|
|
if ( $note === null ) {
|
|
|
|
return 'tasks';
|
|
|
|
}
|
|
|
|
if ( !$note->editable ) {
|
|
|
|
return 'tasks/view?id=' . $note->task;
|
|
|
|
}
|
|
|
|
$task = $tasks->get( $note->task );
|
|
|
|
$page->setTitle( $task->title . ' (task)' );
|
|
|
|
|
|
|
|
// Generate form
|
|
|
|
return Loader::Create( 'Form' , 'Update comment' , 'edit-note' )
|
|
|
|
->addField( Loader::Create( 'Field' , 'id' , 'hidden' )
|
|
|
|
->setDefaultValue( $note->id ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'text' , 'textarea' )
|
|
|
|
->setDescription( 'Comment:' )
|
2016-01-16 21:08:14 +01:00
|
|
|
->setValidator( Loader::Create( 'Validator_StringLength' , 'This comment' , 5 ) )
|
2012-02-05 18:37:25 +01:00
|
|
|
->setDefaultValue( $note->text ) )
|
|
|
|
->setURL( 'tasks/view?id=' . $note->task )
|
|
|
|
->addController( Loader::Ctrl( 'edit_note' ) )
|
|
|
|
->controller( );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2012-02-05 20:55:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Ctrl_DependencyAddForm
|
|
|
|
extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
public function handle( Page $page )
|
|
|
|
{
|
|
|
|
// Check selected note
|
|
|
|
try {
|
|
|
|
$id = (int) $this->getParameter( 'to' );
|
|
|
|
} catch ( ParameterException $e ) {
|
|
|
|
return 'tasks';
|
|
|
|
}
|
|
|
|
|
|
|
|
$tasks = Loader::DAO( 'tasks' );
|
|
|
|
$task = $tasks->get( $id );
|
|
|
|
if ( $task === null ) {
|
|
|
|
return 'tasks';
|
|
|
|
}
|
|
|
|
if ( $task->completed_at !== null || empty( $task->possibleDependencies ) ) {
|
|
|
|
return 'tasks/view?id=' . $id;
|
|
|
|
}
|
|
|
|
$page->setTitle( $task->title . ' (task)' );
|
|
|
|
|
|
|
|
// Generate form
|
2016-01-16 23:55:24 +01:00
|
|
|
$form = Loader::Create( 'Form' , 'Add dependency' , 'add-dep' , 'Select dependency' )
|
2012-02-05 20:55:09 +01:00
|
|
|
->addField( Loader::Create( 'Field' , 'to' , 'hidden' )
|
2016-01-16 23:55:24 +01:00
|
|
|
->setDefaultValue( $id ) )
|
|
|
|
->setURL( 'tasks/view?id=' . $id )
|
|
|
|
->addController( Loader::Ctrl( 'dependency_add' ) );
|
|
|
|
|
|
|
|
$filters = $this->handleFiltering( $page , $form , $task );
|
2012-02-05 20:55:09 +01:00
|
|
|
|
2016-01-16 23:55:24 +01:00
|
|
|
return array( $form->controller( ) , $filters );
|
2012-02-05 20:55:09 +01:00
|
|
|
}
|
|
|
|
|
2016-01-16 23:55:24 +01:00
|
|
|
private function handleFiltering( Page $page , Form $form , $task )
|
2012-02-05 20:55:09 +01:00
|
|
|
{
|
2016-01-16 23:55:24 +01:00
|
|
|
$fCtrl = Loader::Ctrl( 'dependency_add_filtering' , $form , $task );
|
|
|
|
$filters = $this->makeFilteringForm( $form , $fCtrl , $task );
|
|
|
|
|
|
|
|
// Was the filters form submitted?
|
|
|
|
try {
|
|
|
|
$submitted = $this->getParameter( 'filter-deps-submit' , 'POST' );
|
|
|
|
} catch ( ParameterException $e ) {
|
|
|
|
$submitted = null;
|
|
|
|
}
|
|
|
|
if ( $submitted !== null ) {
|
|
|
|
return $filters->controller( )->handle( $page );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Was the main form submitted?
|
|
|
|
try {
|
|
|
|
$submitted = $this->getParameter( 'to' , 'POST' );
|
|
|
|
} catch ( ParameterException $e ) {
|
|
|
|
$submitted = null;
|
|
|
|
}
|
|
|
|
if ( $submitted !== null ) {
|
|
|
|
$fCtrl->getFiltersFromSelector( );
|
2016-01-17 00:23:13 +01:00
|
|
|
} else {
|
|
|
|
$fCtrl->getFiltersFromSession( );
|
2012-02-05 20:55:09 +01:00
|
|
|
}
|
|
|
|
|
2016-01-16 23:55:24 +01:00
|
|
|
// Fake handling the form
|
|
|
|
$fCtrl->handle( $page );
|
|
|
|
return $filters->view( );
|
2012-02-05 20:55:09 +01:00
|
|
|
}
|
|
|
|
|
2016-01-16 23:55:24 +01:00
|
|
|
private function makeFilteringForm( Form $form , Controller $ctrl , $task )
|
2012-02-05 20:55:09 +01:00
|
|
|
{
|
2016-01-16 23:55:24 +01:00
|
|
|
// Generate filtering form, and handle it immediately
|
|
|
|
$filters = Loader::Create( 'Form' , 'Apply' , 'filter-deps' , 'Filter dependencies' )
|
|
|
|
->addController( $ctrl )
|
|
|
|
->setAction( '?' )
|
|
|
|
->addField( Loader::Create( 'Field' , 'to' , 'hidden' )
|
|
|
|
->setDefaultValue( $task->id ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'text' , 'text' )
|
|
|
|
->setDescription( 'Name must contain:' )
|
|
|
|
->setMandatory( false ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'state' , 'select' )
|
|
|
|
->setDescription( 'Task state:' )
|
|
|
|
->setMandatory( false )
|
|
|
|
->addOption( 'abc' , 'Indifferent' )
|
|
|
|
->addOption( 'ab' , 'Active or blocked' )
|
|
|
|
->addOption( 'a' , 'Active' )
|
|
|
|
->addOption( 'b' , 'Blocked' )
|
|
|
|
->addOption( 'c' , 'Completed' ) );
|
|
|
|
if ( $task->parent_task === null ) {
|
|
|
|
$itemSelect = Loader::Create( 'Field' , 'items' , 'select' )
|
|
|
|
->setDescription( 'Limit to items:' )
|
|
|
|
->setMandatory( false )
|
|
|
|
->addOption( '' , '(Any item)' );
|
|
|
|
$this->addItemSelector( $itemSelect );
|
|
|
|
$filters->addField( $itemSelect )
|
|
|
|
->addField( Loader::Create( 'Field' , 'item-children' , 'select' )
|
|
|
|
->setDescription( 'Include child items:' )
|
|
|
|
->setMandatory( false )
|
|
|
|
->addOption( '1' , 'Yes' )
|
|
|
|
->addOption( '0' , 'No' ) );
|
2012-02-05 20:55:09 +01:00
|
|
|
}
|
2016-01-17 00:23:13 +01:00
|
|
|
$filters->addField( Loader::Create( 'Field' , 'keep' , 'select' )
|
|
|
|
->setMandatory( false )
|
|
|
|
->setDescription( 'Keep these filters for next time' )
|
|
|
|
->addOption( '0' , 'No' )
|
|
|
|
->addOption( '1' , 'Yes' ) );
|
2016-01-16 23:55:24 +01:00
|
|
|
return $filters;
|
2012-02-05 20:55:09 +01:00
|
|
|
}
|
|
|
|
|
2016-01-16 23:55:24 +01:00
|
|
|
// FIXME: duplicate code
|
|
|
|
private function addItemSelector( $select )
|
2012-02-05 20:55:09 +01:00
|
|
|
{
|
2016-01-16 23:55:24 +01:00
|
|
|
$items = Loader::DAO( 'items' )->getTreeList( );
|
|
|
|
foreach ( $items as $item ) {
|
|
|
|
$name = '-' . str_repeat( '--' , $item->depth ) . ' ' . $item->name;
|
|
|
|
$select->addOption( $item->id , $name );
|
2012-02-05 20:55:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-05 21:22:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Ctrl_DependencyDeleteForm
|
|
|
|
extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
public function handle( Page $page )
|
|
|
|
{
|
|
|
|
$tasks = Loader::DAO( 'tasks' );
|
|
|
|
|
|
|
|
// Get the task a dependency is being removed from
|
|
|
|
try {
|
|
|
|
$from = (int) $this->getParameter( 'from' );
|
|
|
|
} catch ( ParameterException $e ) {
|
|
|
|
return 'tasks';
|
|
|
|
}
|
|
|
|
$task = $tasks->get( $from );
|
|
|
|
if ( $task === null ) {
|
|
|
|
return 'tasks';
|
|
|
|
}
|
|
|
|
$page->setTitle( $task->title . ' (task)' );
|
|
|
|
if ( $task->completed_at !== null ) {
|
|
|
|
return 'tasks/view?id=' . $from;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the dependency being deleted
|
|
|
|
try {
|
|
|
|
$to = (int) $this->getParameter( 'to' );
|
|
|
|
} catch ( ParameterException $e ) {
|
|
|
|
return 'tasks/view?id=' . $from;
|
|
|
|
}
|
|
|
|
$dependency = $tasks->get( $to );
|
|
|
|
if ( $dependency === null || ! $this->checkDependency( $task , $to ) ) {
|
|
|
|
return 'tasks/view?id=' . $from;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate confirmation text
|
|
|
|
$confText = HTML::make( 'div' )
|
|
|
|
->appendElement( HTML::make( 'p' )
|
|
|
|
->appendText( 'The selected task will no longer depend on ' )
|
|
|
|
->appendElement( HTML::make( 'strong' )
|
|
|
|
->appendText( $dependency->title ) )
|
|
|
|
->appendText( '.' ) );
|
|
|
|
|
|
|
|
// Generate form
|
|
|
|
return Loader::Create( 'Form' , 'Delete dependency' , 'delete-dep' )
|
|
|
|
->addField( Loader::Create( 'Field' , 'from' , 'hidden' )
|
|
|
|
->setDefaultValue( $from ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'to' , 'hidden' )
|
|
|
|
->setDefaultValue( $to ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'confirm' , 'html' )->setDefaultValue( $confText ) )
|
|
|
|
->setURL( 'tasks/view?id=' . $from )
|
|
|
|
->addController( Loader::Ctrl( 'dependency_delete' ) )
|
|
|
|
->controller( );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function checkDependency( $task , $to )
|
|
|
|
{
|
|
|
|
foreach ( $task->dependencies as $dep ) {
|
|
|
|
if ( $dep->id == $to ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-09 18:50:54 +01:00
|
|
|
|
|
|
|
class Ctrl_TaskMoveDown
|
|
|
|
extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
public function __construct( )
|
|
|
|
{
|
|
|
|
$this->dao = Loader::DAO( 'tasks' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handle( Page $page )
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$id = (int) $this->getParameter( 'id' );
|
|
|
|
} catch ( ParameterException $e ) {
|
|
|
|
return 'tasks';
|
|
|
|
}
|
|
|
|
|
|
|
|
$task = $this->dao->get( $id );
|
|
|
|
if ( $task === null ) {
|
|
|
|
return 'tasks';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( empty( $task->moveDownTargets ) ) {
|
|
|
|
return 'tasks/view?id=' . $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
$page->setTitle( $task->title . ' (task)' );
|
|
|
|
$sibling = $this->getSibling( $task );
|
|
|
|
if ( $sibling != null ) {
|
|
|
|
if ( $this->handleSelectedSibling( $task , $sibling ) ) {
|
|
|
|
return 'tasks/view?id=' . $id;
|
|
|
|
} else {
|
|
|
|
return $this->confirmationForm( $task , $sibling );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->siblingSelectionForm( $task );
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getSibling( $task )
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$sibling = (int) $this->getParameter( 'sibling' );
|
|
|
|
$okSiblings = array_map( function( $item ) { return $item->target_id; } , $task->moveDownTargets );
|
|
|
|
if ( ! in_array( $sibling , $okSiblings ) ) {
|
|
|
|
$sibling = null;
|
|
|
|
}
|
|
|
|
} catch ( ParameterException $e ) {
|
|
|
|
$sibling = null;
|
|
|
|
}
|
|
|
|
return $sibling;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function handleSelectedSibling( $task , $sibling )
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$force = (bool) $this->getParameter( 'force' );
|
|
|
|
} catch ( ParameterException $e ) {
|
|
|
|
$force = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->dao->moveDown( $task , $sibling , $force );
|
|
|
|
}
|
|
|
|
|
|
|
|
private function confirmationForm( $task , $sibling )
|
|
|
|
{
|
|
|
|
$sibling = $this->dao->get( $sibling );
|
|
|
|
$confText = HTML::make( 'div' )
|
|
|
|
->appendElement( HTML::make( 'p' )
|
|
|
|
->appendText( 'All dependencies and reverse dependencies of the '
|
|
|
|
. 'selected task will be lost when it is moved into ' )
|
|
|
|
->appendElement( HTML::make( 'strong' )->appendText( $sibling->title ) )
|
|
|
|
->appendText( '.' ) )
|
|
|
|
->appendElement( HTML::make( 'p' )
|
|
|
|
->appendText( 'Please confirm.' ) );
|
|
|
|
|
|
|
|
return Loader::Create( 'Form' , 'Move task' , 'move-down' )
|
|
|
|
->addField( Loader::Create( 'Field' , 'id' , 'hidden' )
|
|
|
|
->setDefaultValue( $task->id ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'sibling' , 'hidden' )
|
|
|
|
->setDefaultValue( $sibling->id ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'force' , 'hidden' )
|
|
|
|
->setDefaultValue( 1 ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'confirm' , 'html' )->setDefaultValue( $confText ) )
|
|
|
|
->setURL( 'tasks/view?id=' . $task->id )
|
|
|
|
->controller( );
|
|
|
|
}
|
|
|
|
|
|
|
|
private function siblingSelectionForm( $task )
|
|
|
|
{
|
|
|
|
$selector = Loader::Create( 'Field' , 'sibling' , 'select' )
|
|
|
|
->setDescription( 'Move task into: ' );
|
|
|
|
foreach ( $task->moveDownTargets as $target ) {
|
|
|
|
$selector->addOption( $target->target_id , $target->target_title );
|
|
|
|
}
|
|
|
|
return Loader::Create( 'Form' , 'Move task' , 'move-down' , 'Move task to sibling' )
|
|
|
|
->addField( Loader::Create( 'Field' , 'id' , 'hidden' )
|
|
|
|
->setDefaultValue( $task->id ) )
|
|
|
|
->addField( $selector )
|
|
|
|
->setURL( 'tasks/view?id=' . $task->id )
|
|
|
|
->controller( );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Ctrl_TaskMoveUp
|
|
|
|
extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
public function handle( Page $page )
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$id = (int) $this->getParameter( 'id' );
|
|
|
|
} catch ( ParameterException $e ) {
|
|
|
|
return 'tasks';
|
|
|
|
}
|
|
|
|
|
|
|
|
$dao = Loader::DAO( 'tasks' );
|
|
|
|
$task = $dao->get( $id );
|
|
|
|
if ( $task === null ) {
|
|
|
|
return 'tasks';
|
|
|
|
}
|
2012-02-10 09:41:49 +01:00
|
|
|
if ( ! $task->can_move_up ) {
|
|
|
|
return 'tasks/view?id=' . $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
$page->setTitle( $task->title . ' (task)' );
|
|
|
|
try {
|
|
|
|
$confirmed = (bool) $this->getParameter( 'confirmed' );
|
|
|
|
} catch ( ParameterException $e ) {
|
|
|
|
$confirmed = false;
|
|
|
|
}
|
|
|
|
if ( ! $confirmed ) {
|
|
|
|
return $this->showConfirmationForm( $task );
|
|
|
|
}
|
2012-02-09 18:50:54 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
$force = (bool) $this->getParameter( 'force' );
|
|
|
|
} catch ( ParameterException $e ) {
|
|
|
|
$force = false;
|
|
|
|
}
|
2012-02-10 09:41:49 +01:00
|
|
|
if ( $dao->moveUp( $task , $force ) ) {
|
2012-02-09 18:50:54 +01:00
|
|
|
return 'tasks/view?id=' . $id;
|
|
|
|
}
|
2012-02-10 09:41:49 +01:00
|
|
|
return $this->showForceForm( $task );
|
|
|
|
}
|
|
|
|
|
|
|
|
private function showConfirmationForm( $task )
|
|
|
|
{
|
|
|
|
$confText = HTML::make( 'div' )
|
|
|
|
->appendElement( HTML::make( 'p' )
|
|
|
|
->appendText( 'You are about to move this sub-task into its '
|
|
|
|
. 'grand-parent.' ) )
|
|
|
|
->appendElement( HTML::make( 'p' )
|
|
|
|
->appendText( 'Please confirm.' ) );
|
2012-02-09 18:50:54 +01:00
|
|
|
|
2012-02-10 09:41:49 +01:00
|
|
|
return Loader::Create( 'Form' , 'Move task' , 'move-up' )
|
|
|
|
->addField( Loader::Create( 'Field' , 'id' , 'hidden' )
|
|
|
|
->setDefaultValue( $task->id ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'confirmed' , 'hidden' )
|
|
|
|
->setDefaultValue( 1 ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'confirm' , 'html' )->setDefaultValue( $confText ) )
|
|
|
|
->setURL( 'tasks/view?id=' . $task->id )
|
|
|
|
->controller( );
|
|
|
|
}
|
|
|
|
|
|
|
|
private function showForceForm( $task )
|
|
|
|
{
|
2012-02-09 18:50:54 +01:00
|
|
|
$confText = HTML::make( 'div' )
|
|
|
|
->appendElement( HTML::make( 'p' )
|
|
|
|
->appendText( 'All dependencies and reverse dependencies of the '
|
|
|
|
. 'selected task will be lost when it is moved.' ) )
|
|
|
|
->appendElement( HTML::make( 'p' )
|
|
|
|
->appendText( 'Please confirm.' ) );
|
|
|
|
|
|
|
|
return Loader::Create( 'Form' , 'Move task' , 'move-up' )
|
|
|
|
->addField( Loader::Create( 'Field' , 'id' , 'hidden' )
|
2012-02-10 09:41:49 +01:00
|
|
|
->setDefaultValue( $task->id ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'confirmed' , 'hidden' )
|
|
|
|
->setDefaultValue( 1 ) )
|
2012-02-09 18:50:54 +01:00
|
|
|
->addField( Loader::Create( 'Field' , 'force' , 'hidden' )
|
|
|
|
->setDefaultValue( 1 ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'confirm' , 'html' )->setDefaultValue( $confText ) )
|
2012-02-10 09:41:49 +01:00
|
|
|
->setURL( 'tasks/view?id=' . $task->id )
|
2012-02-09 18:50:54 +01:00
|
|
|
->controller( );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2016-01-03 09:54:47 +01:00
|
|
|
|
|
|
|
|
2016-01-04 11:01:28 +01:00
|
|
|
class Ctrl_TaskMoveForm
|
2016-01-03 09:54:47 +01:00
|
|
|
extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
public function __construct( )
|
|
|
|
{
|
|
|
|
$this->dTasks = Loader::DAO( 'tasks' );
|
|
|
|
$this->dItems = Loader::DAO( 'items' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handle( Page $page )
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$id = (int) $this->getParameter( 'id' );
|
|
|
|
$type = $this->getParameter( 'type' );
|
|
|
|
} catch ( ParameterException $e ) {
|
|
|
|
return 'tasks';
|
|
|
|
}
|
|
|
|
|
|
|
|
$subtasks = ( $type === 's' );
|
|
|
|
$failure = $subtasks ? 'tasks' : 'items';
|
|
|
|
|
|
|
|
// Get the parent
|
|
|
|
if ( $subtasks ) {
|
|
|
|
$parent = $this->dTasks->get( $id );
|
|
|
|
} else {
|
|
|
|
$parent = $this->dItems->get( $id );
|
|
|
|
}
|
|
|
|
if ( $parent === null ) {
|
|
|
|
return $failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the parent's empty, go back to displaying it
|
|
|
|
$failure .= '/view?id=' . $id;
|
|
|
|
if ( $subtasks ) {
|
|
|
|
$tasks = $parent->subtasks;
|
|
|
|
$name = $parent->title;
|
|
|
|
} else {
|
|
|
|
$tasks = $this->dTasks->getTasksAt( $parent );
|
|
|
|
$name = $parent->name;
|
|
|
|
}
|
|
|
|
if ( empty( $tasks ) ) {
|
|
|
|
return $failure;
|
|
|
|
}
|
|
|
|
|
2016-01-04 11:01:28 +01:00
|
|
|
// Form header
|
2016-01-03 09:54:47 +01:00
|
|
|
$page->setTitle( $name . ': move tasks' );
|
|
|
|
$form = Loader::Create( 'Form' , 'Move tasks' , 'move-tasks' )
|
2016-01-04 11:01:28 +01:00
|
|
|
->setURL( $failure )
|
|
|
|
->addController( Loader::Ctrl( 'task_move' ) )
|
2016-01-03 09:54:47 +01:00
|
|
|
->addField( Loader::Create( 'Field' , 'type' , 'hidden' )
|
|
|
|
->setDefaultValue( $subtasks ? 's' : 'i' ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'id' , 'hidden' )
|
2016-01-04 11:01:28 +01:00
|
|
|
->setDefaultValue( $id ) );
|
|
|
|
|
|
|
|
// List of targets
|
|
|
|
$tSel = Loader::Create( 'Field' , 'target' , 'select' )
|
|
|
|
->setDescription( 'Move to:' )
|
|
|
|
->addOption( '' , '(please select a target)' );
|
|
|
|
$this->addTargets( $tSel , $subtasks , $id );
|
|
|
|
$form->addField( $tSel );
|
|
|
|
|
|
|
|
// List of tasks
|
|
|
|
$tSel = Loader::Create( 'Field' , 'tasks[]' , 'select' , array( 'multiple' ) )
|
|
|
|
->setDescription( 'Tasks to move:' );
|
|
|
|
foreach ( $tasks as $t ) {
|
|
|
|
$tSel->addOption( $t->id , $t->title );
|
|
|
|
}
|
|
|
|
$form->addField( $tSel );
|
|
|
|
|
|
|
|
return $form->controller( );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function addTargets( Field $field , $isTask , $id )
|
|
|
|
{
|
|
|
|
$items = $this->dItems->getTreeList( );
|
|
|
|
$tasks = $this->dTasks->getActiveTasksAssoc( );
|
|
|
|
|
|
|
|
foreach ( $items as $item ) {
|
|
|
|
$title = str_repeat( '--' , $item->depth ) . ' ' . strtoupper( $item->name );
|
|
|
|
$disabled = !$isTask && $item->id == $id;
|
|
|
|
$iid = 'I' . $item->id;
|
|
|
|
$field->addOption( $iid , $title , $disabled );
|
|
|
|
$this->addTargetTasks( $field , $iid , $tasks , $isTask , $id , $item->depth + 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function addTargetTasks( Field $field , $iid , $tasks , $isTask , $id , $depth )
|
|
|
|
{
|
|
|
|
if ( !array_key_exists( $iid , $tasks ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ( $tasks[ $iid ] as $task ) {
|
|
|
|
$title = str_repeat( '--' , $depth ) . '> ' . $task->title;
|
|
|
|
$disabled = $isTask && $task->id == $id;
|
|
|
|
$tid = 'T' . $task->id;
|
|
|
|
$field->addOption( $tid , $title , $disabled );
|
|
|
|
$this->addTargetTasks( $field , $tid , $tasks , $isTask , $id , $depth + 1 );
|
|
|
|
}
|
2016-01-03 09:54:47 +01:00
|
|
|
}
|
2016-01-04 11:01:28 +01:00
|
|
|
|
2016-01-03 09:54:47 +01:00
|
|
|
}
|