2012-02-05 18:37:25 +01:00
|
|
|
<?php
|
|
|
|
|
2012-02-06 17:57:56 +01:00
|
|
|
class View_TasksList
|
2012-02-05 18:37:25 +01:00
|
|
|
extends BaseURLAwareView
|
|
|
|
{
|
|
|
|
protected $tasks;
|
|
|
|
protected $dao;
|
|
|
|
|
|
|
|
|
2012-02-06 17:57:56 +01:00
|
|
|
public function __construct( $tasks , $features = array( 'item' , 'assigned' , 'deps' , 'completed' ) )
|
2012-02-05 18:37:25 +01:00
|
|
|
{
|
2012-02-06 17:57:56 +01:00
|
|
|
$this->tasks = $tasks;
|
|
|
|
$this->features = array_combine( $features , array_fill( 0 , count( $features ) , 1 ) );
|
2012-02-05 18:37:25 +01:00
|
|
|
$this->dao = Loader::DAO( 'tasks' );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public final function render( )
|
|
|
|
{
|
|
|
|
if ( empty( $this->tasks ) ) {
|
|
|
|
return HTML::make( 'div' )
|
|
|
|
->setAttribute( 'class' , 'no-table' )
|
|
|
|
->appendText( 'No tasks to display.' );
|
|
|
|
}
|
|
|
|
return HTML::make( 'dl' )
|
|
|
|
->append( $this->generateList( ) )
|
|
|
|
->setAttribute( 'class' , 'tasks' );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function generateList( )
|
|
|
|
{
|
|
|
|
$result = array( );
|
|
|
|
$prevPriority = 6;
|
|
|
|
foreach ( $this->tasks as $task ) {
|
|
|
|
$priority = ( $task->completed_by === null ) ? $task->priority : -1;
|
|
|
|
if ( $priority !== $prevPriority ) {
|
|
|
|
if ( $priority == -1 ) {
|
|
|
|
$text = 'Completed tasks';
|
|
|
|
$extraClass = ' completed';
|
|
|
|
} else {
|
|
|
|
$text = $this->dao->translatePriority( $priority ) . ' priority';
|
|
|
|
$extraClass = '';
|
|
|
|
}
|
|
|
|
$prevPriority = $priority;
|
|
|
|
|
|
|
|
array_push( $result , HTML::make( 'dt' )
|
|
|
|
->setAttribute( 'class' , 'sub-title' . $extraClass )
|
|
|
|
->appendText( $text ) );
|
|
|
|
}
|
|
|
|
$result = array_merge( $result , $this->generateItem( $task ) );
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function generateItem( $task )
|
|
|
|
{
|
|
|
|
$cell = array( );
|
|
|
|
array_push( $cell , HTML::make( 'dt' )
|
|
|
|
->appendElement( HTML::make( 'a' )
|
|
|
|
->setAttribute( 'href' , $this->base . '/tasks/view?id=' . $task->id )
|
|
|
|
->appendText( $task->title ) ) );
|
2012-02-06 17:57:56 +01:00
|
|
|
$this->addItem( $cell , $task );
|
|
|
|
$classes = array( );
|
2012-02-05 18:37:25 +01:00
|
|
|
|
|
|
|
$addedAt = strtotime( $task->added_at );
|
|
|
|
$addedAtDate = date( 'd/m/o' , $addedAt );
|
|
|
|
$addedAtTime = date( 'H:i:s' , $addedAt );
|
|
|
|
array_push( $cell ,
|
|
|
|
HTML::make( 'dd' )->appendText( "Added $addedAtDate at $addedAtTime by {$task->added_by}" ) );
|
|
|
|
|
2012-02-06 17:57:56 +01:00
|
|
|
if ( $task->completed_by !== null ) {
|
|
|
|
$this->generateCompletedTask( $cell , $classes , $task );
|
|
|
|
} else {
|
|
|
|
if ( $task->missing_dependencies !== null ) {
|
|
|
|
$this->generateMissingDependencies( $cell , $classes , $task );
|
2012-02-05 22:22:16 +01:00
|
|
|
}
|
2012-02-06 17:57:56 +01:00
|
|
|
if ( $task->assigned_to !== null ) {
|
|
|
|
$this->generateAssignedTask( $cell , $classes , $task );
|
2012-02-06 16:38:11 +01:00
|
|
|
}
|
2012-02-06 17:57:56 +01:00
|
|
|
}
|
2012-02-05 18:37:25 +01:00
|
|
|
|
2012-02-06 17:57:56 +01:00
|
|
|
if ( ! empty( $classes ) ) {
|
2012-02-05 18:37:25 +01:00
|
|
|
foreach ( $cell as $entry ) {
|
2012-02-06 17:57:56 +01:00
|
|
|
$entry->setAttribute( 'class' , join( ' ' , $classes ) );
|
2012-02-05 18:37:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $cell;
|
|
|
|
}
|
|
|
|
|
2012-02-06 17:57:56 +01:00
|
|
|
protected function addItem( &$cell , $task )
|
2012-02-06 16:38:11 +01:00
|
|
|
{
|
2012-02-06 17:57:56 +01:00
|
|
|
if ( ! array_key_exists( 'item' , $this->features ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2012-02-06 16:38:11 +01:00
|
|
|
|
2012-02-06 17:57:56 +01:00
|
|
|
$item = Loader::DAO( 'items' )->get( $task->item );
|
2012-02-05 18:37:25 +01:00
|
|
|
$lineage = $item->lineage;
|
|
|
|
array_push( $lineage , $item->id );
|
|
|
|
|
|
|
|
$contents = array( );
|
|
|
|
foreach ( Loader::DAO( 'items' )->getAll( $lineage ) as $ancestor ) {
|
|
|
|
if ( ! empty( $contents ) ) {
|
|
|
|
array_push( $contents , ' » ' );
|
|
|
|
}
|
|
|
|
array_push( $contents , HTML::make( 'a' )
|
|
|
|
->setAttribute( 'href' , $this->base . '/items/view?id=' . $ancestor->id )
|
|
|
|
->appendText( $ancestor->name ) );
|
|
|
|
}
|
|
|
|
array_unshift( $contents, 'On ' );
|
|
|
|
|
2012-02-06 17:57:56 +01:00
|
|
|
array_push( $cell , HTML::make( 'dd' )->append( $contents ) );
|
2012-02-05 18:37:25 +01:00
|
|
|
}
|
|
|
|
|
2012-02-06 17:57:56 +01:00
|
|
|
protected function generateMissingDependencies( &$cell , &$classes , $task )
|
2012-02-05 18:37:25 +01:00
|
|
|
{
|
2012-02-06 17:57:56 +01:00
|
|
|
if ( ! array_key_exists( 'deps' , $this->features ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2012-02-05 18:37:25 +01:00
|
|
|
|
2012-02-06 17:57:56 +01:00
|
|
|
if ( $task->missing_dependencies > 1 ) {
|
|
|
|
$end = 'ies';
|
|
|
|
} else {
|
|
|
|
$end = 'y';
|
|
|
|
}
|
|
|
|
array_push( $cell ,
|
|
|
|
$md = HTML::make( 'dd' )->appendText( "{$task->missing_dependencies} missing dependenc$end" ) );
|
|
|
|
if ( $task->total_missing_dependencies != $task->missing_dependencies ) {
|
|
|
|
$md->appendText( " ({$task->total_missing_dependencies} when counting transitive dependencies)" );
|
|
|
|
}
|
2012-02-05 18:37:25 +01:00
|
|
|
|
2012-02-06 17:57:56 +01:00
|
|
|
array_push( $classes , 'missing-deps' );
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function generateAssignedTask( &$cell , &$classes , $task )
|
2012-02-05 18:37:25 +01:00
|
|
|
{
|
2012-02-06 17:57:56 +01:00
|
|
|
if ( ! array_key_exists( 'assigned' , $this->features ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
array_push( $cell , HTML::make( 'dd' )->appendText( 'Assigned to ' . $task->assigned_to ) );
|
|
|
|
array_push( $classes , 'assigned' );
|
2012-02-05 18:37:25 +01:00
|
|
|
}
|
|
|
|
|
2012-02-06 17:57:56 +01:00
|
|
|
protected function generateCompletedTask( &$cell , &$classes , $task )
|
|
|
|
{
|
|
|
|
if ( ! array_key_exists( 'completed' , $this->features ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$completedAt = strtotime( $task->completed_at );
|
|
|
|
$completedAtDate = date( 'd/m/o' , $completedAt );
|
|
|
|
$completedAtTime = date( 'H:i:s' , $completedAt );
|
|
|
|
array_push( $cell , HTML::make( 'dd' )->appendText(
|
|
|
|
"Completed $completedAtDate at $completedAtTime by {$task->completed_by}" ) );
|
|
|
|
array_push( $classes , 'completed' );
|
|
|
|
}
|
2012-02-05 18:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class View_TaskDetails
|
|
|
|
extends BaseURLAwareView
|
|
|
|
{
|
|
|
|
private $task;
|
|
|
|
|
|
|
|
public function __construct( $task )
|
|
|
|
{
|
|
|
|
$this->task = $task;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render( )
|
|
|
|
{
|
|
|
|
$list = HTML::make( 'dl' )
|
|
|
|
->setAttribute( 'class' , 'tasks' )
|
|
|
|
->appendElement( HTML::make( 'dt' )
|
|
|
|
->appendText( 'On item:' ) )
|
|
|
|
->appendElement( HTML::make( 'dd' )
|
|
|
|
->append( $this->formatPlaceLineage( $this->task->item ) ) );
|
|
|
|
|
|
|
|
if ( $this->task->description != '' ) {
|
|
|
|
$list->appendElement( HTML::make( 'dt' )
|
|
|
|
->appendText( 'Description:' ) )
|
|
|
|
->appendElement( HTML::make( 'dd' )
|
|
|
|
->appendRaw( $this->formatDescription( ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
$list->appendElement( HTML::make( 'dt' )
|
|
|
|
->appendText( 'Added:' ) )
|
|
|
|
->appendElement( HTML::make( 'dd' )
|
|
|
|
->appendText( $this->formatAction( $this->task->added_at , $this->task->added_by ) ) );
|
|
|
|
|
|
|
|
if ( $this->task->completed_by === null ) {
|
|
|
|
$list->appendElement( HTML::make( 'dt' )
|
|
|
|
->appendText( 'Priority:' ) )
|
|
|
|
->appendElement( HTML::make( 'dd' )
|
|
|
|
->appendText( Loader::DAO( 'tasks' )
|
|
|
|
->translatePriority( $this->task->priority ) ) );
|
2012-02-06 16:38:11 +01:00
|
|
|
|
|
|
|
if ( $this->task->assigned_to === null ) {
|
|
|
|
$list->appendElement( HTML::make( 'dt' )
|
|
|
|
->setAttribute( 'class' , 'unassigned-task' )
|
|
|
|
->appendText( 'Unassigned!' ) );
|
|
|
|
} else {
|
|
|
|
$list->appendElement( HTML::make( 'dt' )
|
|
|
|
->appendText( 'Assigned to:' ) )
|
|
|
|
->appendElement( HTML::make( 'dd' )
|
|
|
|
->appendText( $this->task->assigned_to ) );
|
|
|
|
}
|
2012-02-05 18:37:25 +01:00
|
|
|
} else {
|
|
|
|
$list->appendElement( HTML::make( 'dt' )
|
|
|
|
->appendText( 'Completed:' ) )
|
|
|
|
->appendElement( HTML::make( 'dd' )
|
|
|
|
->appendText( $this->formatAction(
|
|
|
|
$this->task->completed_at , $this->task->completed_by ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function formatPlaceLineage( $item )
|
|
|
|
{
|
|
|
|
$lineage = $item->lineage;
|
|
|
|
array_push( $lineage , $item->id );
|
|
|
|
|
|
|
|
$contents = array( );
|
|
|
|
foreach ( Loader::DAO( 'items' )->getAll( $lineage ) as $ancestor ) {
|
|
|
|
if ( ! empty( $contents ) ) {
|
|
|
|
array_push( $contents , ' » ' );
|
|
|
|
}
|
|
|
|
array_push( $contents , HTML::make( 'a' )
|
|
|
|
->setAttribute( 'href' , $this->base . '/items/view?id=' . $ancestor->id )
|
|
|
|
->appendText( $ancestor->name ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $contents;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function formatDescription( )
|
|
|
|
{
|
|
|
|
$description = HTML::from( $this->task->description );
|
|
|
|
return preg_replace( '/\n/s' , '<br/>' , $description );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function formatAction( $timestamp , $user )
|
|
|
|
{
|
|
|
|
$ts = strtotime( $timestamp );
|
|
|
|
$tsDate = date( 'd/m/o' , $ts );
|
|
|
|
$tsTime = date( 'H:i:s' , $ts );
|
|
|
|
return "$tsDate at $tsTime by $user";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class View_TaskNote
|
|
|
|
implements View
|
|
|
|
{
|
|
|
|
private $note;
|
|
|
|
|
|
|
|
public function __construct( $note )
|
|
|
|
{
|
|
|
|
$this->note = $note;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render( )
|
|
|
|
{
|
|
|
|
$text = HTML::make( 'p' )
|
|
|
|
->appendRaw( preg_replace( '/\n/s' , '<br/>' , HTML::from( $this->note->text ) ) );
|
|
|
|
|
|
|
|
$ts = strtotime( $this->note->added_at );
|
|
|
|
$tsDate = date( 'd/m/o' , $ts );
|
|
|
|
$tsTime = date( 'H:i:s' , $ts );
|
|
|
|
$details = HTML::make( 'div')
|
|
|
|
->setAttribute( 'style' , 'font-size: 9pt' )
|
|
|
|
->appendElement( HTML::make( 'em' )
|
|
|
|
->appendText( "Note added $tsDate at $tsTime by {$this->note->author}" ) );
|
|
|
|
|
|
|
|
return array( $text , $details );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class View_TaskDependencies
|
2012-02-05 19:59:51 +01:00
|
|
|
extends BaseURLAwareView
|
2012-02-05 18:37:25 +01:00
|
|
|
{
|
|
|
|
private $task;
|
|
|
|
private $reverse;
|
|
|
|
|
|
|
|
public function __construct( $task , $reverse )
|
|
|
|
{
|
|
|
|
$this->task = $task;
|
|
|
|
$this->reverse = $reverse;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render( )
|
|
|
|
{
|
|
|
|
$source = $this->reverse ? 'reverseDependencies' : 'dependencies';
|
2012-02-05 19:59:51 +01:00
|
|
|
if ( empty( $this->task->$source ) ) {
|
|
|
|
return HTML::make( 'div' )
|
|
|
|
->setAttribute( 'class' , 'no-table' )
|
|
|
|
->appendText( 'This task has no dependencies.' );
|
|
|
|
}
|
|
|
|
|
2012-02-05 18:37:25 +01:00
|
|
|
$list = HTML::make( 'ul' )->setAttribute( 'class' , 'dep-list' );
|
2012-02-05 19:59:51 +01:00
|
|
|
$prevItem = null;
|
|
|
|
$itemList = null;
|
2012-02-05 18:37:25 +01:00
|
|
|
foreach ( $this->task->$source as $dependency ) {
|
2012-02-05 19:59:51 +01:00
|
|
|
if ( $prevItem !== $dependency->item ) {
|
|
|
|
$itemList = HTML::make( 'ul' );
|
|
|
|
$list->appendElement( HTML::make( 'li' )
|
|
|
|
->appendText( 'In ' )
|
|
|
|
->appendElement( HTML::make( 'a' )
|
|
|
|
->setAttribute( 'href' , $this->base . '/items/view?id=' . $dependency->item )
|
|
|
|
->appendText( $dependency->item_name ) )
|
|
|
|
->appendElement( $itemList ) );
|
|
|
|
$prevItem = $dependency->item;
|
|
|
|
}
|
2012-02-05 21:22:06 +01:00
|
|
|
|
|
|
|
$entry = HTML::make( 'li' )->appendElement(
|
|
|
|
$link = HTML::make( 'a' )
|
|
|
|
->setAttribute( 'href' , $this->base . '/tasks/view?id=' . $dependency->id )
|
|
|
|
->appendText( $dependency->title ) );
|
2012-02-05 18:37:25 +01:00
|
|
|
if ( ! $this->reverse ) {
|
|
|
|
$link->setAttribute( 'class' , ( $dependency->completed == 't' )
|
|
|
|
? 'satisfied' : 'missing' );
|
2012-02-05 21:22:06 +01:00
|
|
|
|
|
|
|
if ( $this->task->completed_at === null ) {
|
|
|
|
$entry->appendText( ' (' )
|
|
|
|
->appendElement( HTML::make( 'a' )
|
|
|
|
->setAttribute( 'href' , $this->base . '/tasks/deps/delete?from='
|
|
|
|
. $this->task->id . '&to=' . $dependency->id )
|
|
|
|
->appendText( 'remove') )
|
|
|
|
->appendText( ')' );
|
2012-02-06 10:45:39 +01:00
|
|
|
if ( $dependency->missing_dependencies != 0 ) {
|
|
|
|
$end = $dependency->missing_dependencies > 1 ? 'ies' : 'y';
|
|
|
|
$entry->appendElement( HTML::make( 'ul' )
|
|
|
|
->appendElement( $mdeps = HTML::make( 'li' ) ) );
|
|
|
|
$mdeps->appendText( $dependency->missing_dependencies
|
|
|
|
. " missing dependenc$end (transitively)" );
|
|
|
|
}
|
2012-02-05 21:22:06 +01:00
|
|
|
}
|
2012-02-05 18:37:25 +01:00
|
|
|
}
|
2012-02-05 21:22:06 +01:00
|
|
|
|
|
|
|
$itemList->appendElement( $entry );
|
2012-02-05 18:37:25 +01:00
|
|
|
}
|
2012-02-05 19:59:51 +01:00
|
|
|
return $list;
|
2012-02-05 18:37:25 +01:00
|
|
|
}
|
|
|
|
}
|