task.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * View for task object
  4. *
  5. * @package ElggTasks
  6. *
  7. * @uses $vars['entity'] The task object
  8. * @uses $vars['full_view'] Whether to display the full view
  9. */
  10. elgg_load_library('elgg:tasks');
  11. $full = elgg_extract('full_view', $vars, FALSE);
  12. $task = elgg_extract('entity', $vars, FALSE);
  13. if (!$task) {
  14. return TRUE;
  15. }
  16. $options = array('metadata_name' => 'list_guid', 'metadata_value' => $task->guid, 'type' => 'object', 'subtype' => 'task');
  17. $has_children = elgg_get_entities_from_metadata($options);
  18. if ($has_children) {
  19. echo elgg_view('object/tasklist_top', $vars);
  20. return;
  21. }
  22. $icon = elgg_view_entity_icon($task, 'tiny');
  23. $status = $task->status;
  24. if(!in_array($status, array('new', 'assigned', 'unassigned', 'active', 'done', 'closed', 'reopened'))){
  25. $status = 'new';
  26. }
  27. $annotation = $task->getAnnotations('task_state_changed', 2, 0, 'desc');
  28. $more_than_one = count($annotation) > 1;
  29. if ($annotation) {
  30. $annotation = $annotation[0];
  31. } else {
  32. $annotation = new stdClass();
  33. $annotation->owner_guid = $task->owner_guid;
  34. $annotation->time_created = $task->time_created;
  35. }
  36. if (in_array($status, array('assigned', 'active', 'done')) && $more_than_one) {
  37. $owner_link = elgg_view('tasks/participant_count', array('entity' => $task));
  38. } else {
  39. $owner = get_entity($annotation->owner_guid);
  40. $owner_link = elgg_view('output/url', array(
  41. 'href' => $owner->getURL(),
  42. 'text' => $owner->name,
  43. ));
  44. }
  45. $date = elgg_view_friendly_time($annotation->time_created);
  46. $strapline = elgg_echo("tasks:strapline:$status", array($date, $owner_link));
  47. $tags = elgg_view('output/tags', array('tags' => $task->tags));
  48. $comments_count = $task->countComments();
  49. //only display if there are commments
  50. if ($comments_count != 0) {
  51. $text = elgg_echo("comments") . " ($comments_count)";
  52. $comments_link = elgg_view('output/url', array(
  53. 'href' => $task->getURL() . '#task-comments',
  54. 'text' => $text,
  55. ));
  56. } else {
  57. $comments_link = '';
  58. }
  59. $metadata = elgg_view_menu('entity', array(
  60. 'entity' => $task,
  61. 'handler' => 'tasks',
  62. 'sort_by' => 'priority',
  63. 'class' => 'elgg-menu-hz',
  64. ));
  65. $subtitle = "$strapline $categories $comments_link";
  66. // do not show the metadata and controls in widget view
  67. if (elgg_in_context('widgets')) {
  68. $metadata = '';
  69. }
  70. if ($full) {
  71. $body = elgg_view('output/longtext', array('value' => $task->description));
  72. $new_task_form = elgg_view_form('tasks/inline', array(
  73. 'id' => 'tasks-inline-form',
  74. 'class' => 'hidden',
  75. 'action' => 'action/tasks/edit',
  76. ), array(
  77. 'list' => $task,
  78. ));
  79. $body .= elgg_view('tasks/info/extend', $vars);
  80. $body .= $new_task_form;
  81. $params = array(
  82. 'entity' => $page,
  83. 'title' => false,
  84. 'metadata' => $metadata,
  85. 'subtitle' => $subtitle,
  86. 'tags' => $tags,
  87. );
  88. $params = $params + $vars;
  89. $list_body = elgg_view('object/elements/summary', $params);
  90. $info = elgg_view_image_block($icon, $list_body);
  91. echo <<<HTML
  92. $info
  93. $body
  94. HTML;
  95. } else {
  96. // brief view
  97. $excerpt = elgg_get_excerpt($task->description);
  98. $params = array(
  99. 'entity' => $task,
  100. 'metadata' => $metadata,
  101. 'subtitle' => $subtitle,
  102. 'tags' => false,
  103. );
  104. $params = $params + $vars;
  105. $list_body = elgg_view('object/elements/summary', $params);
  106. echo elgg_view_image_block($icon, $list_body);
  107. }