diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2014-03-17 12:00:58 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2014-03-17 12:00:58 -0300 |
commit | 228d3697bcd0218605be2e28131574cc85293a2e (patch) | |
tree | 6a59c627f6226bd2b3056b959acc9cc871eb1f8f /actions/tasks | |
download | elgg-228d3697bcd0218605be2e28131574cc85293a2e.tar.gz elgg-228d3697bcd0218605be2e28131574cc85293a2e.tar.bz2 |
Squashed 'mod/tasks/' content from commit c9b1097
git-subtree-dir: mod/tasks
git-subtree-split: c9b1097ce081d6893f9c939146208559c089dc15
Diffstat (limited to 'actions/tasks')
-rw-r--r-- | actions/tasks/comments/add.php | 169 | ||||
-rw-r--r-- | actions/tasks/delete.php | 32 | ||||
-rw-r--r-- | actions/tasks/edit.php | 110 |
3 files changed, 311 insertions, 0 deletions
diff --git a/actions/tasks/comments/add.php b/actions/tasks/comments/add.php new file mode 100644 index 000000000..6221eccbd --- /dev/null +++ b/actions/tasks/comments/add.php @@ -0,0 +1,169 @@ +<?php +/** + * Tasks add comment action + * + * @package ElggTasks + */ + +group_gatekeeper(); + +elgg_load_library('elgg:tasks'); + +$entity_guid = (int) get_input('entity_guid'); +$comment_text = get_input('generic_comment'); +$state_action = get_input('state_action', false); + + +// Let's see if we can get an entity with the specified GUID +$entity = get_entity($entity_guid); +if (!$entity) { + register_error(elgg_echo("generic_comment:notfound")); + forward(REFERER); +} + +$user = elgg_get_logged_in_user_entity(); + +if($comment_text) { + $annotation = create_annotation($entity->guid, + 'generic_comment', + $comment_text, + "", + $user->guid, + $entity->access_id); + + // tell user annotation posted + if (!$annotation) { + register_error(elgg_echo("generic_comment:failure")); + forward(REFERER); + } +} +switch ($state_action) { + case 'assign': + add_entity_relationship(elgg_get_logged_in_user_guid(), 'subscribes', $entity_guid); + break; + case 'activate': + add_entity_relationship(elgg_get_logged_in_user_guid(), 'is_doing', $entity_guid); + break; + case 'assign_and_activate': + add_entity_relationship(elgg_get_logged_in_user_guid(), 'subscribes', $entity_guid); + add_entity_relationship(elgg_get_logged_in_user_guid(), 'is_doing', $entity_guid); + break; + case 'deactivate': + remove_entity_relationship(elgg_get_logged_in_user_guid(), 'is_doing', $entity_guid); + break; + case 'leave': + remove_entity_relationship(elgg_get_logged_in_user_guid(), 'is_doing', $entity_guid); + remove_entity_relationship(elgg_get_logged_in_user_guid(), 'subscribes', $entity_guid); + break; + case 'reopen': + remove_entity_relationships($entity_guid, 'is_doing', true); + remove_entity_relationships($entity_guid, 'subscribes', true); + break; +} + +if (in_array($state_action, array('activate', 'assign_and_activate'))) { + if($active_task = tasks_get_user_active_task($user->guid)) { + $active_task->status = 'assigned'; + + create_annotation($active_task->guid, + 'task_state_changed', + 'assigned', + "", + $user->guid, + $active_task->access_id); + } +} + +$new_state = tasks_get_state_from_action($state_action); + +if ($state_action == 'leave') { + $have_participants_yet = elgg_get_entities_from_relationship(array( + 'relationship' => 'subscribes', + 'relationship_guid' => $entity->guid, + 'inverse_relationship' => true, + 'count' => true, + )); + if ($have_participants_yet) { + $new_state = $entity->status; + } +} + +if ($state_action == 'deactivate') { + $have_participants_yet = elgg_get_entities_from_relationship(array( + 'relationship' => 'is_doing', + 'relationship_guid' => $entity->guid, + 'inverse_relationship' => true, + 'count' => true, + )); + if ($have_participants_yet) { + $new_state = $entity->status; + } +} + +if ($state_action == 'assign' && $entity->status == 'active') { + $new_state = $entity->status; +} + +if($new_state) { + $entity->status = $new_state; + create_annotation($entity->guid, + 'task_state_changed', + $state_action, + "", + $user->guid, + $entity->access_id); +} + +// notify if poster wasn't owner +if ($entity->owner_guid != $user->guid) { + + if($new_state) { + notify_user($entity->owner_guid, + $user->guid, + elgg_echo('tasks:email:subject'), + elgg_echo('tasks:email:body', array( + $user->name, + $entity->title, + $new_state, + $comment_text, + $entity->getURL(), + $user->name, + $user->getURL() + )) + ); + } else { + notify_user($entity->owner_guid, + $user->guid, + elgg_echo('generic_comment:email:subject'), + elgg_echo('generic_comment:email:body', array( + $entity->title, + $user->name, + $comment_text, + $entity->getURL(), + $user->name, + $user->getURL() + )) + ); + } +} + +if ($new_state) { + system_message(elgg_echo("tasks:status:changed")); + $action = $state_action; +} else { + system_message(elgg_echo("generic_comment:posted")); + $action = 'comment'; +} + +//add to river +if (!in_array($state_action, array('activate', 'deactivate'))) { + $river = 'river/annotation/generic_comment/create'; + add_to_river($river, $action, $user->guid, $entity->guid, "", 0, $annotation); +} + +if ($new_state) { + echo "{\"new_state\": \"$new_state\"}"; +} + +// Forward to the page the action occurred on +forward(REFERER); diff --git a/actions/tasks/delete.php b/actions/tasks/delete.php new file mode 100644 index 000000000..9e15831f4 --- /dev/null +++ b/actions/tasks/delete.php @@ -0,0 +1,32 @@ +<?php +/** + * Remove a task + * + * @package ElggTasks + */ + +$guid = get_input('guid'); +$task = get_entity($guid); +if ($task) { + if ($task->canEdit()) { + $container = get_entity($task->container_guid); + $list = $task->list_guid; + + if ($task->delete()) { + system_message(elgg_echo('tasks:delete:success')); + if ($list) { + if ($list = get_entity($list)) { + forward($list->getURL()); + } + } + if (elgg_instanceof($container, 'group')) { + forward("tasks/group/$container->guid/all"); + } else { + forward("tasks/owner/$container->username"); + } + } + } +} + +register_error(elgg_echo('tasks:delete:failure')); +forward(REFERER); diff --git a/actions/tasks/edit.php b/actions/tasks/edit.php new file mode 100644 index 000000000..a69ddafe9 --- /dev/null +++ b/actions/tasks/edit.php @@ -0,0 +1,110 @@ +<?php +/** + * Create or edit a task + * + * @package ElggTasks + */ + +$variables = elgg_get_config('tasks'); +$input = array(); +foreach ($variables as $name => $type) { + $input[$name] = get_input($name); + if ($name == 'title') { + $input[$name] = strip_tags($input[$name]); + } + if ($type == 'tags') { + $input[$name] = string_to_tag_array($input[$name]); + } +} + +// Get guids +$task_guid = (int)get_input('task_guid'); +$container_guid = (int)get_input('container_guid'); +$referer_guid = (int)get_input('referer_guid'); + +$container = get_entity($container_guid); + +elgg_make_sticky_form('task'); + +if (!$input['title']) { + register_error(elgg_echo('tasks:error:no_title')); + forward(REFERER); +} + +if (!$container) { + forward(REFERER); +} + +if ($input['priority'] == null) { + $input['priority'] = '2'; // normal is default +} + +if ($task_guid) { + $task = get_entity($task_guid); + if (!$task || !$task->canEdit()) { + register_error(elgg_echo('tasks:error:no_save')); + forward(REFERER); + } + $new_task = false; +} else { + $task = new ElggObject(); + $task->subtype = 'task'; + $task->status = 'new'; + $task->time_status_changed = time(); + $new_task = true; +} + +if (sizeof($input) > 0) { + foreach ($input as $name => $value) { + $task->$name = $value; + } +} + +$list_guid = $input['list_guid']; + +if ($list_guid) { + $task->list_guid = $list_guid; +} +else { + $task->list_guid = 0; +} +$task->container_guid = $container_guid; + +if ($task->save()) { + + elgg_clear_sticky_form('task'); + + // Now save description as an annotation + $task->annotate('task', $task->description, $task->access_id); + + system_message(elgg_echo('tasks:saved')); + + if ($new_task) { + add_to_river('river/object/task/create', 'create', elgg_get_logged_in_user_guid(), $task->guid); + } + + if ($new_task && $referer_guid && ($referer_entity = get_entity($referer_guid))) { + $link = elgg_view('output/url', array( + 'href' => $task->getURL(), + 'text' => $task->title, + )); + $annotation = create_annotation($referer_entity->guid, + 'generic_comment', + elgg_echo('tasks:this:referer:comment', array($link)), + "", + elgg_get_logged_in_user_guid(), + $referer_entity->access_id); + } + + $task_json = array(); + foreach ($task->getExportableValues() as $v) { + $task_json[$v] = $task->$v; + } + $task_json['list_guid'] = $task->list_guid; + echo json_encode($task_json); + + forward($task->getURL()); +} else { + register_error(elgg_echo('tasks:error:no_save')); + forward(REFERER); +} |