コード例 #1
0
        if (!$notification_user) {
            $notification_user = NotificationUser::add($proxy_id, "evaluation", $evaluation_id, $proxy_id);
        }
        $query = "SELECT * FROM `notifications` \n                    WHERE `nuser_id` = " . $db->qstr($notification_user->getID()) . " \n                    AND `proxy_id` = " . $db->qstr($proxy_id) . "\n                    AND (`sent_date` = 0 OR `sent_date` >= " . $db->qstr(strtotime("-7 days")) . ")";
        $recent_notifications = $db->GetAll($query);
        if (!isset($recent_notifications) || !$recent_notifications) {
            Notification::add($notification_user->getID(), $proxy_id, $evaluation_id, isset($pending_evaluation["event_id"]) && $pending_evaluation["event_id"] ? $pending_evaluation["event_id"] : $pending_evaluation["event_id"]);
        }
    }
}
//queue notifications for each user with the evaluations which have closed for them in the last 24 hours.
$query = "SELECT *, '0' AS `event_id` FROM `evaluations` AS a\n\t\t\tJOIN `evaluation_forms` AS b\n\t\t\tON a.`eform_id` = b.`eform_id`\n\t\t\tJOIN `evaluations_lu_targets` AS c\n\t\t\tON b.`target_id` = c.`target_id`\n\t\t\tWHERE a.`evaluation_start` <= " . $db->qstr(strtotime("-1 day")) . "\n\t\t\tAND a.`evaluation_finish` >= " . $db->qstr(strtotime("-10 weeks")) . "\n\t\t\tAND a.`evaluation_finish` <= " . $db->qstr(time()) . "\n\t\t\tAND c.`target_shortname` NOT IN ('preceptor', 'rotation_core', 'rotation_elective')\n\t\t\t\n\t\t\tUNION\n\t\t\t\n\t\t\tSELECT a.*, b.*, c.*, e.`event_id` FROM `evaluations` AS a\n\t\t\tJOIN `evaluation_forms` AS b\n\t\t\tON a.`eform_id` = b.`eform_id`\n\t\t\tJOIN `evaluations_lu_targets` AS c\n\t\t\tON b.`target_id` = c.`target_id`\n\t\t\tAND c.`target_shortname` IN ('preceptor', 'rotation_core', 'rotation_elective')\n\t\t\tJOIN `evaluation_targets` AS d\n\t\t\tON a.`evaluation_id` = d.`evaluation_id`\n\t\t\tAND d.`target_type` = 'rotation_id'\n\t\t\tJOIN `" . CLERKSHIP_DATABASE . "`.`events` AS e\n\t\t\tON d.`target_value` = e.`rotation_id`\n\t\t\tAND a.`evaluation_start` <= e.`event_finish`\n\t\t\tAND a.`evaluation_finish` >= e.`event_finish`\n\t\t\tJOIN `" . CLERKSHIP_DATABASE . "`.`event_contacts` AS f\n\t\t\tON e.`event_id` = f.`event_id`\n\t\t\tJOIN `evaluation_evaluators` AS g\n\t\t\tON a.`evaluation_id` = g.`evaluation_id`\n\t\t\tAND g.`evaluator_type` = 'cohort'\n\t\t\tJOIN `group_members` AS h\n\t\t\tON g.`evaluator_value` = h.`group_id`\n\t\t\tAND h.`proxy_id` = f.`etype_id`\n\t\t\tAND h.`member_active`\n\t\t\tWHERE a.`evaluation_start` <= " . $db->qstr(strtotime("-1 day")) . "\n\t\t\tAND e.`event_finish` >= " . $db->qstr(time() - CLERKSHIP_EVALUATION_LOCKOUT) . "\n\t\t\tAND e.`event_finish` <= " . $db->qstr(time() - CLERKSHIP_EVALUATION_TIMEOUT) . "\n\t\t\t\n\t\t\tUNION\n\t\t\t\n\t\t\tSELECT a.*, b.*, c.*, e.`event_id` FROM `evaluations` AS a\n\t\t\tJOIN `evaluation_forms` AS b\n\t\t\tON a.`eform_id` = b.`eform_id`\n\t\t\tJOIN `evaluations_lu_targets` AS c\n\t\t\tON b.`target_id` = c.`target_id`\n\t\t\tAND c.`target_shortname` IN ('preceptor', 'rotation_core', 'rotation_elective')\n\t\t\tJOIN `evaluation_targets` AS d\n\t\t\tON a.`evaluation_id` = d.`evaluation_id`\n\t\t\tAND d.`target_type` = 'rotation_id'\n\t\t\tJOIN `" . CLERKSHIP_DATABASE . "`.`events` AS e\n\t\t\tON d.`target_value` = e.`rotation_id`\n\t\t\tAND a.`evaluation_start` <= e.`event_finish`\n\t\t\tAND a.`evaluation_finish` >= e.`event_finish`\n\t\t\tJOIN `" . CLERKSHIP_DATABASE . "`.`event_contacts` AS f\n\t\t\tON e.`event_id` = f.`event_id`\n\t\t\tJOIN `evaluation_evaluators` AS g\n\t\t\tON a.`evaluation_id` = g.`evaluation_id`\n\t\t\tAND g.`evaluator_type` = 'cgroup_id'\n\t\t\tJOIN `course_group_audience` AS h\n\t\t\tON g.`evaluator_value` = h.`cgroup_id`\n\t\t\tAND h.`proxy_id` = f.`etype_id`\n\t\t\tAND h.`active` = 1\n\t\t\tWHERE a.`evaluation_start` <= " . $db->qstr(strtotime("-1 day")) . "\n\t\t\tAND e.`event_finish` >= " . $db->qstr(time() - CLERKSHIP_EVALUATION_LOCKOUT) . "\n\t\t\tAND e.`event_finish` <= " . $db->qstr(time() - CLERKSHIP_EVALUATION_TIMEOUT) . "\n\t\t\t\n\t\t\tUNION\n\t\t\t\n\t\t\tSELECT a.*, b.*, c.*, e.`event_id` FROM `evaluations` AS a\n\t\t\tJOIN `evaluation_forms` AS b\n\t\t\tON a.`eform_id` = b.`eform_id`\n\t\t\tJOIN `evaluations_lu_targets` AS c\n\t\t\tON b.`target_id` = c.`target_id`\n\t\t\tAND c.`target_shortname` IN ('preceptor', 'rotation_core', 'rotation_elective')\n\t\t\tJOIN `evaluation_targets` AS d\n\t\t\tON a.`evaluation_id` = d.`evaluation_id`\n\t\t\tAND d.`target_type` = 'rotation_id'\n\t\t\tJOIN `" . CLERKSHIP_DATABASE . "`.`events` AS e\n\t\t\tON d.`target_value` = e.`rotation_id`\n\t\t\tAND a.`evaluation_start` <= e.`event_finish`\n\t\t\tAND a.`evaluation_finish` >= e.`event_finish`\n\t\t\tJOIN `" . CLERKSHIP_DATABASE . "`.`event_contacts` AS f\n\t\t\tON e.`event_id` = f.`event_id`\n\t\t\tJOIN `evaluation_evaluators` AS g\n\t\t\tON a.`evaluation_id` = g.`evaluation_id`\n\t\t\tAND g.`evaluator_type` = 'proxy_id'\n\t\t\tAND g.`evaluator_value` = f.`etype_id`\n\t\t\tWHERE a.`evaluation_start` <= " . $db->qstr(strtotime("-1 day")) . "\n\t\t\tAND e.`event_finish` >= " . $db->qstr(time() - CLERKSHIP_EVALUATION_LOCKOUT) . "\n\t\t\tAND e.`event_finish` <= " . $db->qstr(time() - CLERKSHIP_EVALUATION_TIMEOUT);
$ended_evaluations = $db->GetAll($query);
if ($ended_evaluations) {
    foreach ($ended_evaluations as $evaluation) {
        $overdue_evaluations[$evaluation["evaluation_id"] . (isset($evaluation["event_id"]) && $evaluation["event_id"] ? "-" . $evaluation["event_id"] : "")] = Models_Evaluation::getOverdueEvaluations($evaluation);
    }
}
foreach ($overdue_evaluations as $overdue_evaluation_users) {
    foreach ($overdue_evaluation_users as $overdue_evaluation) {
        $evaluation_id = $overdue_evaluation["evaluation_id"];
        require_once "Models/notifications/NotificationUser.class.php";
        require_once "Models/notifications/Notification.class.php";
        $proxy_id = $overdue_evaluation["user"]["id"];
        $notification_user = NotificationUser::get($proxy_id, "evaluation_overdue", $evaluation_id, $proxy_id);
        if (!$notification_user) {
            $notification_user = NotificationUser::add($proxy_id, "evaluation_overdue", $evaluation_id, $proxy_id);
        }
        $query = "SELECT * FROM `notifications` \n                    WHERE `nuser_id` = " . $db->qstr($notification_user->getID()) . " \n                    AND `proxy_id` = " . $db->qstr($proxy_id) . "\n                    AND (`sent_date` = 0 OR `sent_date` >= " . $db->qstr(strtotime("-7 days")) . ")";
        $recent_notifications = $db->GetAll($query);
        if (!isset($recent_notifications) || !$recent_notifications) {