123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- <?php
- /**
- * Prepare the add/edit form variables
- *
- * @param ElggObject $tasklist
- * @return array
- */
- function tasklist_prepare_form_vars($tasklist = null, $list_guid = 0) {
- // input names => defaults
- $values = array(
- 'title' => '',
- 'description' => '',
- 'enddate' => '',
- 'access_id' => ACCESS_DEFAULT,
- 'write_access_id' => ACCESS_DEFAULT,
- 'tags' => '',
- 'container_guid' => elgg_get_page_owner_guid(),
- 'guid' => null,
- 'entity' => $tasklist,
- 'list_guid' => $list_guid,
- );
- if ($tasklist) {
- foreach (array_keys($values) as $field) {
- if (isset($tasklist->$field)) {
- $values[$field] = $tasklist->$field;
- }
- }
- }
- if (elgg_is_sticky_form('tasklist')) {
- $sticky_values = elgg_get_sticky_values('tasklist');
- foreach ($sticky_values as $key => $value) {
- $values[$key] = $value;
- }
- }
- elgg_clear_sticky_form('tasklist');
- return $values;
- }
- /**
- * Prepare the add/edit form variables
- *
- * @param ElggObject $task
- * @return array
- */
- function task_prepare_form_vars($task = null, $list_guid = 0) {
- // input names => defaults
- $values = array(
- 'title' => get_input('title', ''),
- 'description' => '',
- 'priority' => '',
- 'access_id' => ACCESS_DEFAULT,
- 'write_access_id' => ACCESS_DEFAULT,
- 'tags' => '',
- 'container_guid' => elgg_get_page_owner_guid(),
- 'guid' => null,
- 'entity' => $task,
- 'list_guid' => $list_guid,
- 'referer_guid' => get_input('referer_guid', ''),
- );
- if ($task) {
- foreach (array_keys($values) as $field) {
- if (isset($task->$field)) {
- $values[$field] = $task->$field;
- }
- }
- }
- if (elgg_is_sticky_form('task')) {
- $sticky_values = elgg_get_sticky_values('task');
- foreach ($sticky_values as $key => $value) {
- $values[$key] = $value;
- }
- }
- elgg_clear_sticky_form('task');
-
- if ($referer = get_input('referer')) {
- $link = elgg_view('output/url', array(
- 'href' => $referer,
- 'text' => elgg_echo('tasks:this:moreinfo:here'),
- ));
- $values['description'] .= "<p>" . elgg_echo('tasks:this:moreinfo', array($link)) . "</p>";
- }
- return $values;
- }
- function tasks_get_entities($options) {
- $default = array(
- 'type' => 'object',
- 'subtype' => 'task',
- );
- if (!isset($options['metadata_name_value_pairs']) || !is_array($options['metadata_name_value_pairs'])) {
- $options['metadata_name_value_pairs'] = array();
- }
- if (isset($options['list_guid'])) {
- $options['metadata_name_value_pairs'][] = array(
- 'name' => 'list_guid',
- 'value' => $options['list_guid'],
- );
- unset($options['parent_guid']);
- }
- if (isset($options['status'])) {
- $options['metadata_name_value_pairs'][] = array(
- 'name' => 'status',
- 'value' => $options['status'],
- );
- unset($options['status']);
- }
-
- $options = array_merge($default, $options);
- return elgg_get_entities_from_metadata($options);
- }
- function tasks_get_actions_from_state($state){
- switch($state) {
-
- case 'new':
- case 'unassigned':
- case 'reopened':
- $actions = array(
- 'assign',
- 'assign_and_activate',
- 'mark_as_done',
- 'close',
- );
- break;
-
- case 'assigned':
- $actions = array(
- 'activate',
- 'leave',
- 'mark_as_done',
- 'close',
- );
- break;
-
- case 'active':
- $actions = array(
- 'deactivate',
- 'leave',
- 'mark_as_done',
- 'close',
- );
- break;
-
- case 'done':
- case 'closed':
- $actions = array(
- 'reopen',
- );
- break;
-
- }
-
- return $actions;
- }
- function tasks_get_possible_actions($task, $user_guid = 0) {
-
- if(!$user_guid) {
- $user_guid = elgg_get_logged_in_user_guid();
- }
-
- $is_doing = check_entity_relationship($user_guid, 'is_doing', $task->guid);
- $subscribes = check_entity_relationship($user_guid, 'subscribes', $task->guid);
- if ($task->status == 'active' && $is_doing) {
- $status = 'active';
- } elseif ($task->status == 'assigned' && $subscribes) {
- $status = 'assigned';
- } elseif ($task->status == 'active' || $task->status == 'assigned') {
- $status = 'unassigned';
- } else {
- $status = $task->status;
- }
-
- return tasks_get_actions_from_state($status);
- }
- function tasks_prepare_radio_options($task) {
-
- $actions = tasks_get_possible_actions($task);
-
- $actions_labels = array(
- elgg_echo("tasks:state:action:noaction", array($task->status)) => '',
- );
-
- foreach($actions as $action) {
- $actions_labels[elgg_echo("tasks:state:action:$action")] = $action;
- }
-
- return $actions_labels;
- }
- function tasks_register_actions_menu($task) {
- foreach (tasks_get_possible_actions($task) as $action) {
- $action_url = "action/tasks/comments/add?" . http_build_query(array(
- 'entity_guid' => $task->guid,
- 'state_action' => $action,
- ), '', '&');
- $action_url = elgg_add_action_tokens_to_url($action_url);
- $item = new ElggMenuItem($action, elgg_echo("tasks:state:action:$action"), $action_url);
- elgg_register_menu_item('tasks_hover', $item);
- }
- }
- function tasks_reset_actions_menu() {
- global $CONFIG;
- if (isset($CONFIG->menus['tasks_hover'])) {
- unset($CONFIG->menus['tasks_hover']);
- }
- }
-
- function tasks_get_state_from_action($action){
- $actions_states = array(
- 'assign' => 'assigned',
- 'leave' => 'unassigned',
- 'activate' => 'active',
- 'deactivate' => 'assigned',
- 'assign_and_activate' => 'active',
- 'mark_as_done' => 'done',
- 'close' => 'closed',
- 'reopen' => 'reopened',
- );
- return $actions_states[$action];
- }
- function tasks_get_user_active_task ($user_guid) {
- return array_shift(elgg_get_entities_from_metadata(array(
- 'metadata_name' => 'status',
- 'metadata_value' => 'active',
- 'owner_guid' => $user_guid,
- )));
- }
- /**
- * Register the navigation menu
- *
- * @param ElggEntity $container Container entity for the tasks
- */
- function tasks_register_navigation_tree($container) {
- if (!$container) {
- return;
- }
- $tasklists_top = elgg_get_entities_from_metadata(array(
- 'type' => 'object',
- 'subtype' => 'task',
- 'container_guid' => $container->getGUID(),
- 'metadata_name' => 'list_guid',
- 'metadata_value' => 0,
- 'limit' => 0,
- ));
- if (!$tasklists_top) {
- return;
- }
- foreach ($tasklists_top as $tasklist) {
- elgg_register_menu_item('tasks_nav', array(
- 'name' => $tasklist->getGUID(),
- 'text' => $tasklist->title,
- 'href' => $tasklist->getURL(),
- ));
- $stack = array();
- array_push($stack, $tasklist);
- while (count($stack) > 0) {
- $list = array_pop($stack);
- $tasklists = elgg_get_entities_from_metadata(array(
- 'type' => 'object',
- 'subtype' => 'task',
- 'metadata_name' => 'list_guid',
- 'metadata_value' => $list->guid,
- 'container_guid' => $container->getGUID(),
- 'limit' => 0,
- ));
- if ($tasklists) {
- foreach ($tasklists as $tasklist) {
- elgg_register_menu_item('tasks_nav', array(
- 'name' => $tasklist->getGUID(),
- 'text' => $tasklist->title,
- 'href' => $tasklist->getURL(),
- 'parent_name' => $list->getGUID(),
- ));
- array_push($stack, $tasklist);
- }
- }
- }
- }
- }
|