/** * Send the details of the newly created activity back to the client browser * * @param cm_info $mod details of the mod just created */ protected function send_response($mod) { global $OUTPUT; $resp = new stdClass(); $resp->error = self::ERROR_OK; $resp->icon = $mod->get_icon_url()->out(); $resp->name = $mod->name; $resp->link = $mod->get_url()->out(); $resp->elementid = 'module-' . $mod->id; $resp->commands = make_editing_buttons($mod, true, true, 0, $mod->sectionnum); $resp->onclick = $mod->get_on_click(); // if using groupings, then display grouping name if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', $this->context)) { $groupings = groups_get_all_groupings($this->course->id); $resp->groupingname = format_string($groupings[$mod->groupingid]->name); } echo $OUTPUT->header(); echo json_encode($resp); die; }
/** * Send the details of the newly created activity back to the client browser * * @param cm_info $mod details of the mod just created */ protected function send_response($mod) { global $OUTPUT; $resp = new stdClass(); $resp->error = self::ERROR_OK; $resp->icon = $mod->get_icon_url()->out(); $resp->name = $mod->name; $resp->link = $mod->get_url()->out(); $resp->elementid = 'module-' . $mod->id; $resp->commands = make_editing_buttons($mod, true, true, 0, $mod->sectionnum); $resp->onclick = $mod->get_on_click(); echo $OUTPUT->header(); echo json_encode($resp); die; }
/** * Send the details of the newly created activity back to the client browser * * @param cm_info $mod details of the mod just created */ protected function send_response($mod) { global $OUTPUT, $PAGE; $courserenderer = $PAGE->get_renderer('core', 'course'); $resp = new stdClass(); $resp->error = self::ERROR_OK; $resp->icon = $mod->get_icon_url()->out(); $resp->name = $mod->name; if ($mod->has_view()) { $resp->link = $mod->get_url()->out(); } else { $resp->link = null; } $resp->content = $mod->get_content(); $resp->elementid = 'module-' . $mod->id; $actions = course_get_cm_edit_actions($mod, 0, $mod->sectionnum); $resp->commands = ' ' . $courserenderer->course_section_cm_edit_actions($actions); $resp->onclick = $mod->get_on_click(); $resp->visible = $mod->visible; // if using groupings, then display grouping name if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', $this->context)) { $groupings = groups_get_all_groupings($this->course->id); $resp->groupingname = format_string($groupings[$mod->groupingid]->name); } echo $OUTPUT->header(); echo json_encode($resp); die; }
/** * Called when viewing course page. Adds information to the course-module object. * * @see: /lib/modinfolib.php class cm_info * * Allowed methods: * - {@link cm_info::set_after_edit_icons()} * - {@link cm_info::set_after_link()} * - {@link cm_info::set_content()} * - {@link cm_info::set_extra_classes() * * @param cm_info $cm Course-module object */ function activitytask_cm_info_view(cm_info $cm) { global $USER, $PAGE, $DB; //we will create a done button for marking whether or not an item is complete $done = ''; $view = ''; //create a view button if ($cm->customdata) { $view = '<a class="activitytask-button-view btn btn-primary"' . ' href="' . new moodle_url('/mod/activitytask/view.php?id=' . $cm->id) . '"' . '>' . get_string('btn_label_view', 'activitytask') . '</a>'; } //let's see if the user has a capability to add an activity instance //this indicates that they are a teacher or the like and not a student //we don't need to show a done button if the user can edit the instance if (!has_capability('mod/activitytask:addinstance', context_course::instance($cm->course))) { //pull this users status for this activity $params = array('userid' => $USER->id, 'activitytask' => $cm->instance); $fields = 'datedone'; $status = $DB->get_record('activitytask_status', $params, $fields); //if not done, then show a button if (!$status || !$status->datedone) { //add the javascript to make it possible to update using ajax $PAGE->requires->js('/mod/activitytask/activitytask.js'); $done = '<a class="activitytask-button btn btn-primary"' . ' href="' . new moodle_url('/mod/activitytask/markdone.php?id=' . $cm->instance) . '"' . ' >' . get_string('btn_label_done', 'activitytask') . '</a>'; } else { $dt = new DateTime($status->datedone); $done = '<span class="activitytask-done">(' . $dt->format('M j') . ')</span>'; } } if (!$PAGE->user_is_editing()) { //if no view link is set, then the url will be blank if (!$cm->url) { //we have to add our own icon $cm->set_content('<img role="presentation" class="iconlarge activityicon" src="' . $cm->get_icon_url() . '">' . '<span class="instancename">' . $cm->name . '<span class="accesshide "> Activity Task</span>' . '</span>' . $view . $done); } else { $cm->set_after_link($view . $done); } } }