Emmanuel BENOîT
9677ad4dd3
This initial import is a heavily modified version of the code I had here, as Arse was modified for other purposes in the meantime and the application no longer worked with it. In addition: * I did not import the user management part yet, * task dependencies are supported in-base, but there is no interface for that yet.
282 lines
5.1 KiB
PHP
282 lines
5.1 KiB
PHP
<?php
|
|
|
|
|
|
class Ctrl_ItemsTree
|
|
extends Controller
|
|
implements TitleProvider
|
|
{
|
|
private $useParameter;
|
|
|
|
public function __construct( $useParameter = false )
|
|
{
|
|
$this->useParameter = $useParameter;
|
|
}
|
|
|
|
public function handle( Page $page )
|
|
{
|
|
$items = Loader::DAO( 'items' );
|
|
$tree = $items->getTree( );
|
|
$items->countActiveTasks( );
|
|
|
|
if ( $this->useParameter ) {
|
|
$root = (int) $this->getParameter( $this->useParameter , 'GET' );
|
|
} else {
|
|
$root = null;
|
|
}
|
|
|
|
$buttonURL = 'items/add';
|
|
if ( $root != null ) {
|
|
$rootObj = $items->get( $root );
|
|
$tree = $items->getAll( $rootObj->children );
|
|
$boxTitle = 'Child items';
|
|
$buttonURL .= "?from=$root";
|
|
} else {
|
|
$boxTitle = null;
|
|
}
|
|
|
|
return Loader::View( 'box' , $boxTitle , Loader::View( 'items_tree' , $tree ) )
|
|
->setClass( 'list' )
|
|
->addButton( BoxButton::create( 'Add item' , $buttonURL )
|
|
->setClass( 'list-add' ) );
|
|
}
|
|
|
|
|
|
public function getTitle( )
|
|
{
|
|
return 'Items';
|
|
}
|
|
}
|
|
|
|
|
|
class Ctrl_ItemDetails
|
|
extends Controller
|
|
{
|
|
private $item;
|
|
|
|
public function __construct( Data_Item $item )
|
|
{
|
|
$this->item = $item;
|
|
}
|
|
|
|
public function handle( Page $page )
|
|
{
|
|
$items = Loader::DAO( 'items');
|
|
$items->getTree( );
|
|
|
|
$box = Loader::View( 'box' , 'Details' , Loader::View( 'item_details' , $this->item ) )
|
|
->addButton( BoxButton::create( 'Edit item' , 'items/edit?id=' . $this->item->id )
|
|
->setClass( 'icon edit' ) );
|
|
|
|
if ( $items->canMove( $this->item ) ) {
|
|
$box->addButton( BoxButton::create( 'Move item' , 'items/move?id=' . $this->item->id )
|
|
->setClass( 'icon move' ) );
|
|
}
|
|
|
|
if ( $items->canDelete( $this->item ) ) {
|
|
$box->addButton( BoxButton::create( 'Delete item' , 'items/delete?id=' . $this->item->id )
|
|
->setClass( 'icon delete' ) );
|
|
}
|
|
|
|
return $box;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
class Ctrl_AddItem
|
|
extends Controller
|
|
implements FormAware
|
|
{
|
|
private $form;
|
|
|
|
public function setForm( Form $form )
|
|
{
|
|
$this->form = $form;
|
|
}
|
|
|
|
public function handle( Page $page )
|
|
{
|
|
$name = $this->form->field( 'name' );
|
|
$before = $this->form->field( 'before' );
|
|
list( $after , $id ) = explode( ':' , $before->value( ) );
|
|
|
|
$items = Loader::DAO( 'items' );
|
|
if ( $id === '' ) {
|
|
$error = $items->createLast( $name->value( ) );
|
|
} elseif ( $after == 1 ) {
|
|
$error = $items->createUnder( $name->value( ) , $id );
|
|
} else {
|
|
$error = $items->createBefore( $name->value( ) , $id );
|
|
}
|
|
|
|
switch ( $error ) {
|
|
|
|
case 0:
|
|
return true;
|
|
|
|
case 1:
|
|
$name->putError( 'This name is not unique' );
|
|
break;
|
|
|
|
case 2:
|
|
$before->putError( 'The item you selected no longer exists' );
|
|
break;
|
|
|
|
default:
|
|
$name->putError( 'An unknown error occurred (' . $error . ')' );
|
|
break;
|
|
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
class Ctrl_MoveItem
|
|
extends Controller
|
|
implements FormAware
|
|
{
|
|
private $form;
|
|
|
|
|
|
public function setForm( Form $form )
|
|
{
|
|
$this->form = $form;
|
|
}
|
|
|
|
|
|
public function handle( Page $page )
|
|
{
|
|
$srcId = (int) $this->form->field( 'id' )->value( );
|
|
$dest = $this->form->field( 'destination' );
|
|
list( $after , $id ) = explode( ':' , $dest->value( ) );
|
|
|
|
$items = Loader::DAO( 'items' );
|
|
if ( $id === '' ) {
|
|
$error = $items->moveLast( $srcId );
|
|
} elseif ( $after == 1 ) {
|
|
$error = $items->moveUnder( $srcId , $id );
|
|
} else {
|
|
$error = $items->moveBefore( $srcId , $id );
|
|
}
|
|
|
|
switch ( $error ) {
|
|
|
|
case 0:
|
|
return true;
|
|
|
|
case 1:
|
|
$dest->putError( 'Invalid destination' );
|
|
break;
|
|
|
|
case 2:
|
|
$before->putError( 'The place you selected no longer exists.' );
|
|
break;
|
|
|
|
default:
|
|
$name->putError( 'An unknown error occurred (' . $error . ')' );
|
|
break;
|
|
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
class Ctrl_DeleteItem
|
|
extends Controller
|
|
implements FormAware
|
|
{
|
|
private $form;
|
|
|
|
|
|
public function setForm( Form $form )
|
|
{
|
|
$this->form = $form;
|
|
}
|
|
|
|
|
|
public function handle( Page $page )
|
|
{
|
|
$id = (int) $this->form->field( 'id' )->value( );
|
|
|
|
$items = Loader::DAO( 'items' );
|
|
if ( ! $items->canDelete( $items->get( $id ) ) ) {
|
|
return false;
|
|
}
|
|
$items->destroy( $id );
|
|
return true;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
class Ctrl_EditItem
|
|
extends Controller
|
|
implements FormAware
|
|
{
|
|
private $form;
|
|
|
|
|
|
public function setForm( Form $form )
|
|
{
|
|
$this->form = $form;
|
|
}
|
|
|
|
|
|
public function handle( Page $page )
|
|
{
|
|
$id = (int) $this->form->field( 'id' )->value( );
|
|
$items = Loader::DAO( 'items' );
|
|
$item = $items->get( $id );
|
|
|
|
$name = $this->form->field( 'name' );
|
|
if ( $name->value( ) === $item->name ) {
|
|
return true;
|
|
}
|
|
|
|
$error = $items->rename( $id , $name->value( ) );
|
|
switch ( $error ) {
|
|
|
|
case 0:
|
|
return true;
|
|
|
|
case 1:
|
|
$name->putError( 'Ce nom n\'est pas unique' );
|
|
break;
|
|
|
|
default:
|
|
$name->putError( 'Une erreur inconnue s\'est produite (' . $error . ')' );
|
|
break;
|
|
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
class Ctrl_ItemTasks
|
|
extends Controller
|
|
{
|
|
private $item;
|
|
|
|
public function __construct( Data_Item $item )
|
|
{
|
|
$this->item = $item;
|
|
}
|
|
|
|
|
|
public function handle( Page $page )
|
|
{
|
|
$tasks = Loader::DAO( 'tasks' )->getTasksAt( $this->item );
|
|
|
|
return Loader::View( 'box' , 'Tasks' , Loader::View( 'tasks' , $tasks ) )
|
|
->addButton( BoxButton::create( 'Add task' , 'tasks/add?to=' . $this->item->id )
|
|
->setClass( 'list-add' ) );
|
|
}
|
|
}
|