function definition() { global $DB, $COURSE; $mform =& $this->_form; $mform->addElement('header', 'displayinfo', get_string('unlocksystemaddheading', 'block_game_content_unlock')); $eventsarray = content_unlock_generate_events_list(); $mform->addElement('select', 'event', 'Evento', $eventsarray, null); $mform->addRule('event', null, 'required', null, 'client'); $mform->setType('event', PARAM_TEXT); $mform->addElement('text', 'description', 'Descrição'); $mform->setType('description', PARAM_TEXT); $coursemodulessarray = array(); $course = $DB->get_record('course', array('id' => $this->courseid)); $info = get_fast_modinfo($course); foreach ($info->cms as $cm) { $coursemodulessarray[$cm->id] = $cm->name; } $mform->addElement('select', 'coursemodule', 'Módulo', $coursemodulessarray, null); $mform->addRule('coursemodule', null, 'required', null, 'client'); $mform->setType('coursemodule', PARAM_INT); $mform->addElement('select', 'mode', 'Modo', array(0 => 'Por visibilidade', 1 => 'Por grupo'), null); $mform->addRule('mode', null, 'required', null, 'client'); $mform->setType('mode', PARAM_INT); $mform->addElement('html', '<hr></hr>'); $mform->addElement('select', 'coursemodulevisibility', 'Visibilidade', array(0 => 'Ocultar', 1 => 'Mostrar'), null); $mform->setType('coursemodulevisibility', PARAM_INT); $mform->disabledIf('coursemodulevisibility', 'mode', 'neq', 0); $mform->addElement('hidden', 'blockid'); $mform->setType('blockid', PARAM_INT); $mform->addElement('hidden', 'courseid'); $mform->setType('courseid', PARAM_INT); $this->add_action_buttons(true, 'Adicionar'); }
public function get_content() { global $DB, $USER; $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; if (user_has_role_assignment($USER->id, 5)) { $eventsarray = content_unlock_generate_events_list(); $us = $DB->get_records('content_unlock_system', array('deleted' => 0, 'blockinstanceid' => $this->instance->id)); if (!empty($us)) { $unlocklist = ''; $course = $DB->get_record('course', array('id' => $this->page->course->id)); $info = get_fast_modinfo($course); foreach ($us as $unlocksystem) { $sql = "SELECT *\n\t\t\t\t\t\t\tFROM {content_unlock_log} c\n\t\t\t\t\t\t\t\tINNER JOIN {logstore_standard_log} l ON c.logid = l.id\n\t\t\t\t\t\t\tWHERE l.userid = :userid\n\t\t\t\t\t\t\t\tAND c.unlocksystemid = :unlocksystemid"; $params['userid'] = $USER->id; $params['unlocksystemid'] = $unlocksystem->id; $unlocked_content = $DB->record_exists_sql($sql, $params); if ($unlocked_content) { continue; } $ccm = get_course_and_cm_from_cmid($unlocksystem->coursemoduleid); if ($this->page->course->id != $ccm[0]->id) { continue; } if (!(content_unlock_satisfies_conditions($unlocksystem->restrictions, $this->page->course->id, $USER->id) && (in_array($unlocksystem->conditions, self::$resource_events) || content_unlock_satisfies_block_conditions($unlocksystem, $this->page->course->id, $USER->id)))) { continue; } $cm = $info->get_cm($unlocksystem->coursemoduleid); $eventdescription = is_null($unlocksystem->eventdescription) ? $eventsarray[$unlocksystem->conditions] : $unlocksystem->eventdescription; $unlocklist = $unlocklist . '<li>' . $cm->name . ' (' . get_string('modulename', $cm->modname) . ') por ' . (in_array($unlocksystem->conditions, self::$resource_events) ? content_unlock_get_block_conditions_text($unlocksystem) : $eventdescription) . '</li>'; } if (strlen($unlocklist) > 0) { $this->content->text = '<p>Você pode desbloquear:<ul>' . $unlocklist . '</ul></p>'; } } if (isset($this->config)) { $lastunlocksnumber = isset($this->config->lastunlocksnumber) ? $this->config->lastunlocksnumber : 1; } else { $lastunlocksnumber = 0; } if ($lastunlocksnumber > 0) { $sql = "SELECT c.id as id, s.coursemoduleid as coursemoduleid, s.eventdescription as eventdescription, s.conditions as conditions, s.connective as connective\n\t\t\t\t\tFROM\n\t\t\t\t\t\t{content_unlock_log} c\n\t\t\t\t\tINNER JOIN {logstore_standard_log} l ON c.logid = l.id\n\t\t\t\t\tINNER JOIN {content_unlock_system} s ON c.unlocksystemid = s.id\n\t\t\t\t\tWHERE l.userid = :userid\n\t\t\t\t\t\tAND l.courseid = :courseid\n\t\t\t\t\t\tAND s.blockinstanceid = :blockinstanceid\n\t\t\t\t\tORDER BY c.id DESC"; $params['userid'] = $USER->id; $params['courseid'] = $this->page->course->id; $params['blockinstanceid'] = $this->instance->id; $lastunlocks = $DB->get_records_sql($sql, $params, 0, $lastunlocksnumber); if (!empty($lastunlocks)) { $lastunlockslist = ''; foreach ($lastunlocks as $lu) { $ccm = get_course_and_cm_from_cmid($lu->coursemoduleid); $course = $DB->get_record('course', array('id' => $ccm[0]->id)); $info = get_fast_modinfo($course); $cm = $info->get_cm($lu->coursemoduleid); $eventdescription = is_null($lu->eventdescription) ? $eventsarray[$lu->conditions] : $lu->eventdescription; $lastunlockslist = $lastunlockslist . '<li>' . $cm->name . ' (' . get_string('modulename', $cm->modname) . ') por ' . (in_array($lu->conditions, self::$resource_events) ? content_unlock_get_block_conditions_text($lu) : $eventdescription) . '</li>'; } $this->content->text = $this->content->text . '<p>Você desbloqueou recentemente:<ul>' . $lastunlockslist . '</ul></p>'; } } } return $this->content; }