1<?php 2 3namespace dokuwiki\plugin\bez\mdl; 4 5class Task_commentFactory extends Factory { 6 7 protected function select_query() { 8 return "SELECT * FROM task_comment"; 9 } 10 11 public function get_from_task(Task $task) { 12 return $this->get_all(array('task_id' => $task->id), $orderby='', $desc=true, array('task' => $task)); 13 } 14 15 /** 16 * @param Thread_comment $thread_comment 17 * @param $data 18 * @throws \Exception 19 */ 20 public function initial_save(Entity $task_comment, $data) { 21 parent::initial_save($task_comment, $data); 22 23 try { 24 $this->beginTransaction(); 25 26 //if empty content and task_do, do not save the comment 27 if ($data['fn'] == 'comment_add' || $data['content'] != '') { 28 $task_comment->set_data($data); 29 $this->save($task_comment); 30 $task_comment->task->set_participant_flags($task_comment->author, array('subscribent', 'commentator')); 31 } 32 33 if ($data['fn'] == 'task_do') { 34 $task_comment->task->set_state('done'); 35 } elseif ($data['fn'] == 'task_reopen') { 36 $task_comment->task->set_state('opened'); 37 } 38 39 $task_comment->task->thread->update_last_activity(); 40 41 $this->commitTransaction(); 42 } catch(Exception $exception) { 43 $this->rollbackTransaction(); 44 } 45 46 $task_comment->mail_notify_add(); 47 } 48 49 public function update_save(Entity $task_comment, $data) { 50 parent::update_save($task_comment, $data); 51 52 $task_comment->set_data($data); 53 try { 54 $this->beginTransaction(); 55 $this->save($task_comment); 56 57 $task_comment->task->update_last_activity(); 58 59 $this->commitTransaction(); 60 } catch(Exception $exception) { 61 $this->rollbackTransaction(); 62 } 63 } 64 65 public function delete(Entity $obj) { 66 try { 67 $this->beginTransaction(); 68 69 parent::delete($obj); 70 $obj->task->update_last_activity(); 71 72 $this->commitTransaction(); 73 } catch(Exception $exception) { 74 $this->rollbackTransaction(); 75 } 76 } 77}