1<?php 2 3$action = new action_plugin_bez_base(); 4$action->createObjects(true); 5 6function send_inactive_issue() { 7 global $action; 8 9 $threads = $action->get_model()->threadFactory->get_all(array( 10 'last_activity_date' => array('<=', date('c', strtotime('-26 days'))), 11 'state' => 'opened' 12 )); 13 14 foreach ($threads as $thread) { 15 //send reminder once a month 16 $day_of_issue_last_activity = date('d', strtotime($thread->last_activity_date)); 17 if ($day_of_issue_last_activity == date('d')) { 18 //send message to all 19 $thread->mail_notify_issue_inactive($thread->get_participants('subscribent')); 20 } 21 } 22} 23 24function send_one_day_task_reminder() { 25 global $action; 26 27 $tasks = $action->get_model()->taskFactory->get_all(array( 28 'plan_date' => date('Y-m-d', strtotime('+1 day')), 29 'state' => 'opened' 30 )); 31 32 foreach ($tasks as $task) { 33 $task->mail_notify_remind($task->get_participants('subscribent')); 34 } 35} 36 37function send_weekly_message() { 38 global $action; 39 global $auth; 40 41 //email => array('user' => array('issues' => array(), 'tasks' => array())) 42 $msg = array(); 43 $output = array(); 44 45 $threads = $action->get_model()->threadFactory->get_all(array( 46 'type' => 'issue', 47 'priority' => array('OR', array('2', '1')) 48 )); 49 50 foreach ($threads as $thread) { 51 $key = $thread->coordinator; 52 if (!isset($msg[$key])) { 53 $msg[$key] = array( 54 'issues' => array(), 55 'coming_tasks' => array(), 56 'outdated_tasks' => array() 57 ); 58 } 59 $msg[$key]['issues'][] = $thread; 60 } 61 62 $tasks = $action->get_model()->taskFactory->get_all(array( 63 'priority' => array('OR', array('2', '1')) 64 )); 65 66 foreach ($tasks as $task) { 67 $key = $task->assignee; 68 if (!isset($msg[$key])) { 69 $msg[$key] = array( 70 'issues' => array(), 71 'coming_tasks' => array(), 72 'outdated_tasks' => array() 73 ); 74 } 75 76 if ($task->priority == '1') { 77 $msg[$key]['coming_tasks'][] = $task; 78 } else { 79 $msg[$key]['outdated_tasks'][] = $task; 80 } 81 } 82 83 //outdated_tasks, coming_tasks, open_tasks 84 85 86 foreach ($msg as $user => $data) { 87 $udata = $auth->getUserData($user); 88 89 $issues = $data['issues']; 90 $outdated_tasks = $data['outdated_tasks']; 91 $coming_tasks = $data['coming_tasks']; 92 93 94 if (count($issues) + count($outdated_tasks) + count($coming_tasks) == 0) 95 continue; 96 97 $to = $udata['name'].' <'.$udata['mail'].'>'; 98 99 $tpl = $action->get_tpl(); 100 $tpl->set('issues', $issues); 101 $tpl->set('outdated_tasks', $outdated_tasks); 102 $tpl->set('coming_tasks', $coming_tasks); 103 $body = $action->bez_tpl_include('cron/weekly-message', true); 104 105 $mailer = new \dokuwiki\plugin\bez\meta\Mailer(); 106 $rep = array(); 107 $mailer->setBody('', $rep, NULL, $body, false); 108 109 $mailer->to($to); 110 $subject = 'Nadchodzące zadania'; 111 $mailer->subject($subject); 112 113 $mailer->send(); 114 $output[] = array($to, $subject, $body, array()); 115 } 116 117 return $output; 118} 119