summaryrefslogtreecommitdiff
path: root/app/Model
diff options
context:
space:
mode:
Diffstat (limited to 'app/Model')
-rw-r--r--app/Model/Task.php83
-rw-r--r--app/Model/TaskModification.php73
-rw-r--r--app/Model/TaskPosition.php8
3 files changed, 81 insertions, 83 deletions
diff --git a/app/Model/Task.php b/app/Model/Task.php
index 4fed25f6..f382b604 100644
--- a/app/Model/Task.php
+++ b/app/Model/Task.php
@@ -40,89 +40,6 @@ class Task extends Base
const EVENT_ASSIGNEE_CHANGE = 'task.assignee_change';
/**
- * Prepare data before task creation or modification
- *
- * @access public
- * @param array $values Form values
- */
- public function prepare(array &$values)
- {
- $this->dateParser->convert($values, array('date_due', 'date_started'));
- $this->removeFields($values, array('another_task', 'id'));
- $this->resetFields($values, array('date_due', 'date_started', 'score', 'category_id', 'time_estimated', 'time_spent'));
- $this->convertIntegerFields($values, array('is_active'));
- }
-
- /**
- * Prepare data before task modification
- *
- * @access public
- * @param array $values Form values
- */
- public function prepareModification(array &$values)
- {
- $this->prepare($values);
- $values['date_modification'] = time();
- }
-
- /**
- * Update a task
- *
- * @access public
- * @param array $values Form values
- * @param boolean $trigger_Events Trigger events
- * @return boolean
- */
- public function update(array $values, $trigger_events = true)
- {
- // Fetch original task
- $original_task = $this->taskFinder->getById($values['id']);
-
- if (! $original_task) {
- return false;
- }
-
- // Prepare data
- $updated_task = $values;
- $this->prepareModification($updated_task);
-
- $result = $this->db->table(self::TABLE)->eq('id', $values['id'])->update($updated_task);
-
- if ($result && $trigger_events) {
- $this->triggerUpdateEvents($original_task, $updated_task);
- }
-
- return true;
- }
-
- /**
- * Trigger events for task modification
- *
- * @access public
- * @param array $original_task Original task data
- * @param array $updated_task Updated task data
- */
- public function triggerUpdateEvents(array $original_task, array $updated_task)
- {
- $events = array();
-
- if (isset($updated_task['owner_id']) && $original_task['owner_id'] != $updated_task['owner_id']) {
- $events[] = self::EVENT_ASSIGNEE_CHANGE;
- }
- else {
- $events[] = self::EVENT_CREATE_UPDATE;
- $events[] = self::EVENT_UPDATE;
- }
-
- $event_data = array_merge($original_task, $updated_task);
- $event_data['task_id'] = $original_task['id'];
-
- foreach ($events as $event) {
- $this->event->trigger($event, $event_data);
- }
- }
-
- /**
* Remove a task
*
* @access public
diff --git a/app/Model/TaskModification.php b/app/Model/TaskModification.php
new file mode 100644
index 00000000..b165ea24
--- /dev/null
+++ b/app/Model/TaskModification.php
@@ -0,0 +1,73 @@
+<?php
+
+namespace Model;
+
+/**
+ * Task Modification
+ *
+ * @package model
+ * @author Frederic Guillot
+ */
+class TaskModification extends Base
+{
+ /**
+ * Update a task
+ *
+ * @access public
+ * @param array $values
+ * @param boolean $fire_events
+ * @return boolean
+ */
+ public function update(array $values, $fire_events = true)
+ {
+ $original_task = $this->taskFinder->getById($values['id']);
+
+ $this->prepare($values);
+ $result = $this->db->table(Task::TABLE)->eq('id', $original_task['id'])->update($values);
+
+ if ($result && $fire_events) {
+ $this->fireEvents($original_task, $values);
+ }
+
+ return $result;
+ }
+
+ /**
+ * Fire events
+ *
+ * @access public
+ * @param array $task
+ * @param array $new_values
+ */
+ public function fireEvents(array $task, array $new_values)
+ {
+ $event_data = array_merge($task, $new_values, array('task_id' => $task['id']));
+
+ if (isset($new_values['owner_id']) && $task['owner_id'] != $new_values['owner_id']) {
+ $events = array(Task::EVENT_ASSIGNEE_CHANGE);
+ }
+ else {
+ $events = array(Task::EVENT_CREATE_UPDATE, Task::EVENT_UPDATE);
+ }
+
+ foreach ($events as $event) {
+ $this->event->trigger($event, $event_data);
+ }
+ }
+
+ /**
+ * Prepare data before task modification
+ *
+ * @access public
+ * @param array $values Form values
+ */
+ public function prepare(array &$values)
+ {
+ $this->dateParser->convert($values, array('date_due', 'date_started'));
+ $this->removeFields($values, array('another_task', 'id'));
+ $this->resetFields($values, array('date_due', 'date_started', 'score', 'category_id', 'time_estimated', 'time_spent'));
+ $this->convertIntegerFields($values, array('is_active'));
+
+ $values['date_modification'] = time();
+ }
+}
diff --git a/app/Model/TaskPosition.php b/app/Model/TaskPosition.php
index f8ac4fd9..c23bc3b5 100644
--- a/app/Model/TaskPosition.php
+++ b/app/Model/TaskPosition.php
@@ -109,6 +109,14 @@ class TaskPosition extends Base
});
}
+ /**
+ * Fire events
+ *
+ * @access public
+ * @param array $task
+ * @param integer $new_column_id
+ * @param integer $new_position
+ */
public function fireEvents(array $task, $new_column_id, $new_position)
{
$event_data = array(