function organizer_organizer_student_action_allowed($action, $slot) { global $DB; if (!$DB->record_exists('organizer_slots', array('id' => $slot))) { return false; } $slotx = new organizer_slot($slot); list($cm, $course, $organizer, $context) = organizer_get_course_module_data(); $canregister = has_capability('mod/organizer:register', $context, null, false); $canunregister = has_capability('mod/organizer:unregister', $context, null, false); $canreregister = $canregister && $canunregister; $myapp = organizer_get_last_user_appointment($organizer); if ($myapp) { $regslot = $DB->get_record('organizer_slots', array('id' => $myapp->slotid)); if (isset($regslot)) { $regslotx = new organizer_slot($regslot); } } $myslotexists = isset($regslot); $organizerdisabled = $slotx->organizer_unavailable() || $slotx->organizer_expired(); $slotdisabled = $slotx->is_past_due() || $slotx->is_past_deadline(); $myslotpending = $myslotexists && $regslotx->is_past_deadline() && !$regslotx->is_evaluated(); $ismyslot = $myslotexists && $slotx->id == $regslot->id; $slotfull = $slotx->is_full(); $disabled = $myslotpending || $organizerdisabled || $slotdisabled || !$slotx->organizer_user_has_access() || $slotx->is_evaluated(); if ($myslotexists) { if (!$slotdisabled) { if ($ismyslot) { $disabled |= !$canunregister || isset($regslotx) && $regslotx->is_evaluated() && !$myapp->allownewappointments; } else { $disabled |= $slotfull || !$canreregister || isset($regslotx) && $regslotx->is_evaluated() && !$myapp->allownewappointments; } } $allowedaction = $ismyslot ? ORGANIZER_ACTION_UNREGISTER : ORGANIZER_ACTION_REREGISTER; } else { $disabled |= $slotfull || !$canregister || $ismyslot; $allowedaction = $ismyslot ? ORGANIZER_ACTION_UNREGISTER : ORGANIZER_ACTION_REGISTER; } return !$disabled && $action == $allowedaction; }
function organizer_student_action($params, $slot) { global $DB, $OUTPUT; $slotx = new organizer_slot($slot); list($cm, $course, $organizer, $context) = organizer_get_course_module_data(); $canregister = has_capability('mod/organizer:register', $context, null, false); $canunregister = has_capability('mod/organizer:unregister', $context, null, false); $canreregister = $canregister && $canunregister; $myapp = organizer_get_last_user_appointment($organizer); if ($myapp) { $regslot = $DB->get_record('organizer_slots', array('id' => $myapp->slotid)); if (isset($regslot)) { $regslotx = new organizer_slot($regslot); } } $myslotexists = isset($regslot); $organizerdisabled = $slotx->organizer_unavailable() || $slotx->organizer_expired(); $slotdisabled = $slotx->is_past_due() || $slotx->is_past_deadline(); $myslotpending = $myslotexists && $regslotx->is_past_deadline() && !$regslotx->is_evaluated(); $ismyslot = $myslotexists && $slotx->id == $regslot->id; $slotfull = $slotx->is_full(); $disabled = $myslotpending || $organizerdisabled || $slotdisabled || !$slotx->organizer_user_has_access() || $slotx->is_evaluated(); if ($myslotexists) { if (!$slotdisabled) { if ($ismyslot) { $disabled |= !$canunregister || isset($regslotx) && $regslotx->is_evaluated() && !$myapp->allownewappointments; } else { $disabled |= $slotfull || !$canreregister || isset($regslotx) && $regslotx->is_evaluated() && !$myapp->allownewappointments; } } $action = $ismyslot ? 'unregister' : 'reregister'; } else { $disabled |= $slotfull || !$canregister || $ismyslot; $action = $ismyslot ? 'unregister' : 'register'; } if ($ismyslot || organizer_is_my_slot($slotx)) { $comment_url = new moodle_url('/mod/organizer/comment_edit.php', array('id' => $params['id'], 'slot' => $slotx->id)); $comment_btn_disabled = $organizerdisabled || !$slotx->organizer_user_has_access(); $comment_btn = $OUTPUT->single_button($comment_url, get_string("btn_comment", 'organizer'), 'post', array('disabled' => $comment_btn_disabled)); return organizer_get_reg_button($action, $slotx->id, $params, $disabled) . '<br/>' . $comment_btn; } else { return organizer_get_reg_button($action, $slotx->id, $params, $disabled); } }