aboutsummaryrefslogtreecommitdiff
path: root/mod/tasks/views/default/object/task.php
blob: d8ed01233b29215e1e3f346bf33f0713019de054 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
 * View for task object
 *
 * @package ElggTasks
 *
 * @uses $vars['entity']    The task object
 * @uses $vars['full_view'] Whether to display the full view
 */

elgg_load_library('elgg:tasks');

$full = elgg_extract('full_view', $vars, FALSE);
$task = elgg_extract('entity', $vars, FALSE);

if (!$task) {
	return TRUE;
}

$options = array('metadata_name' => 'list_guid', 'metadata_value' => $task->guid, 'type' => 'object', 'subtype' => 'task');
$has_children = elgg_get_entities_from_metadata($options);
if ($has_children) {
   echo elgg_view('object/tasklist_top', $vars);
   return;
}


$icon = elgg_view_entity_icon($task, 'tiny');

$status = $task->status;

if(!in_array($status, array('new', 'assigned', 'unassigned', 'active', 'done', 'closed', 'reopened'))){
	$status = 'new';
}

$annotation = $task->getAnnotations('task_state_changed', 2, 0, 'desc');
$more_than_one = count($annotation) > 1;

if ($annotation) {
	$annotation = $annotation[0];
} else {
	$annotation = new stdClass();
	$annotation->owner_guid = $task->owner_guid;
	$annotation->time_created = $task->time_created;
}

if (in_array($status, array('assigned', 'active', 'done')) && $more_than_one) {
	$owner_link = elgg_view('tasks/participant_count', array('entity' => $task));
} else {
	$owner = get_entity($annotation->owner_guid);
	$owner_link = elgg_view('output/url', array(
		'href' => $owner->getURL(),
		'text' => $owner->name,
	));
}
$date = elgg_view_friendly_time($annotation->time_created);
$strapline = elgg_echo("tasks:strapline:$status", array($date, $owner_link));
$tags = elgg_view('output/tags', array('tags' => $task->tags));

$comments_count = $task->countComments();
//only display if there are commments
if ($comments_count != 0) {
	$text = elgg_echo("comments") . " ($comments_count)";
	$comments_link = elgg_view('output/url', array(
		'href' => $task->getURL() . '#task-comments',
		'text' => $text,
	));
} else {
	$comments_link = '';
}


$metadata = elgg_view_menu('entity', array(
	'entity' => $task,
	'handler' => 'tasks',
	'sort_by' => 'priority',
	'class' => 'elgg-menu-hz',
));

$subtitle = "$strapline $categories $comments_link";

// do not show the metadata and controls in widget view
if (elgg_in_context('widgets')) {
	$metadata = '';
}

if ($full) {
	$body = elgg_view('output/longtext', array('value' => $task->description));
	$new_task_form = elgg_view_form('tasks/inline', array(
		'id' => 'tasks-inline-form',
		'class' => 'hidden',
		'action' => 'action/tasks/edit',
	), array(
		'list' => $task,
	));

	$body .= elgg_view('tasks/info/extend', $vars);
	
	$body .= $new_task_form;

	$params = array(
		'entity' => $page,
		'title' => false,
		'metadata' => $metadata,
		'subtitle' => $subtitle,
		'tags' => $tags,
	);
	$params = $params + $vars;
	$list_body = elgg_view('object/elements/summary', $params);

	$info = elgg_view_image_block($icon, $list_body);

	echo <<<HTML
$info
$body
HTML;

} else {
	// brief view

	$excerpt = elgg_get_excerpt($task->description);

	$params = array(
		'entity' => $task,
		'metadata' => $metadata,
		'subtitle' => $subtitle,
		'tags' => false,
	);
	$params = $params + $vars;
	$list_body = elgg_view('object/elements/summary', $params);

	echo elgg_view_image_block($icon, $list_body);
}