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