Example #1
0
 public function testable_show_intro()
 {
     return parent::show_intro();
 }
Example #2
0
/**
 * Serves intro attachment files.
 *
 * @param mixed $course course or id of the course
 * @param mixed $cm course module or id of the course module
 * @param context $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @param array $options additional options affecting the file serving
 * @return bool false if file not found, does not return if found - just send the file
 */
function setask_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $CFG;
    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }
    require_login($course, false, $cm);
    if (!has_capability('mod/setask:view', $context)) {
        return false;
    }
    require_once $CFG->dirroot . '/mod/setask/locallib.php';
    $setask = new setask($context, $cm, $course);
    if ($filearea !== ASSIGN_INTROATTACHMENT_FILEAREA) {
        return false;
    }
    if (!$setask->show_intro()) {
        return false;
    }
    $itemid = (int) array_shift($args);
    if ($itemid != 0) {
        return false;
    }
    $relativepath = implode('/', $args);
    $fullpath = "/{$context->id}/mod_setask/{$filearea}/{$itemid}/{$relativepath}";
    $fs = get_file_storage();
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
        return false;
    }
    send_stored_file($file, 0, 0, $forcedownload, $options);
}
Example #3
0
 /**
  * Returns an array of courses the user is enrolled in, and for each course all of the setaskments that the user can
  * view within that course.
  *
  * @param array $courseids An optional array of course ids. If provided only setaskments within the given course
  * will be returned. If the user is not enrolled in a given course a warning will be generated and returned.
  * @param array $capabilities An array of additional capability checks you wish to be made on the course context.
  * @return An array of courses and warnings.
  * @since  Moodle 2.4
  */
 public static function get_setaskments($courseids = array(), $capabilities = array())
 {
     global $USER, $DB, $CFG;
     require_once "{$CFG->dirroot}/mod/setask/locallib.php";
     $params = self::validate_parameters(self::get_setaskments_parameters(), array('courseids' => $courseids, 'capabilities' => $capabilities));
     $warnings = array();
     $fields = 'sortorder,shortname,fullname,timemodified';
     $courses = enrol_get_users_courses($USER->id, true, $fields);
     // Used to test for ids that have been requested but can't be returned.
     if (count($params['courseids']) > 0) {
         foreach ($params['courseids'] as $courseid) {
             if (!in_array($courseid, array_keys($courses))) {
                 unset($courses[$courseid]);
                 $warnings[] = array('item' => 'course', 'itemid' => $courseid, 'warningcode' => '2', 'message' => 'User is not enrolled or does not have requested capability');
             }
         }
     }
     foreach ($courses as $id => $course) {
         if (count($params['courseids']) > 0 && !in_array($id, $params['courseids'])) {
             unset($courses[$id]);
         }
         $context = context_course::instance($id);
         try {
             self::validate_context($context);
         } catch (Exception $e) {
             unset($courses[$id]);
             $warnings[] = array('item' => 'course', 'itemid' => $id, 'warningcode' => '1', 'message' => 'No access rights in course context ' . $e->getMessage() . $e->getTraceAsString());
             continue;
         }
         if (count($params['capabilities']) > 0 && !has_all_capabilities($params['capabilities'], $context)) {
             unset($courses[$id]);
         }
     }
     $extrafields = 'm.id as setaskmentid, ' . 'm.course, ' . 'm.nosubmissions, ' . 'm.submissiondrafts, ' . 'm.sendnotifications, ' . 'm.sendlatenotifications, ' . 'm.sendstudentnotifications, ' . 'm.duedate, ' . 'm.allowsubmissionsfromdate, ' . 'm.grade, ' . 'm.timemodified, ' . 'm.completionsubmit, ' . 'm.cutoffdate, ' . 'm.teamsubmission, ' . 'm.requireallteammemberssubmit, ' . 'm.teamsubmissiongroupingid, ' . 'm.blindmarking, ' . 'm.revealidentities, ' . 'm.attemptreopenmethod, ' . 'm.maxattempts, ' . 'm.markingworkflow, ' . 'm.markingallocation, ' . 'm.requiresubmissionstatement, ' . 'm.intro, ' . 'm.introformat';
     $coursearray = array();
     foreach ($courses as $id => $course) {
         $setaskmentarray = array();
         // Get a list of setaskments for the course.
         if ($modules = get_coursemodules_in_course('setask', $courses[$id]->id, $extrafields)) {
             foreach ($modules as $module) {
                 $context = context_module::instance($module->id);
                 try {
                     self::validate_context($context);
                     require_capability('mod/setask:view', $context);
                 } catch (Exception $e) {
                     $warnings[] = array('item' => 'module', 'itemid' => $module->id, 'warningcode' => '1', 'message' => 'No access rights in module context');
                     continue;
                 }
                 $configrecords = $DB->get_recordset('setask_plugin_config', array('setaskment' => $module->setaskmentid));
                 $configarray = array();
                 foreach ($configrecords as $configrecord) {
                     $configarray[] = array('id' => $configrecord->id, 'setaskment' => $configrecord->setaskment, 'plugin' => $configrecord->plugin, 'subtype' => $configrecord->subtype, 'name' => $configrecord->name, 'value' => $configrecord->value);
                 }
                 $configrecords->close();
                 $setaskment = array('id' => $module->setaskmentid, 'cmid' => $module->id, 'course' => $module->course, 'name' => $module->name, 'nosubmissions' => $module->nosubmissions, 'submissiondrafts' => $module->submissiondrafts, 'sendnotifications' => $module->sendnotifications, 'sendlatenotifications' => $module->sendlatenotifications, 'sendstudentnotifications' => $module->sendstudentnotifications, 'duedate' => $module->duedate, 'allowsubmissionsfromdate' => $module->allowsubmissionsfromdate, 'grade' => $module->grade, 'timemodified' => $module->timemodified, 'completionsubmit' => $module->completionsubmit, 'cutoffdate' => $module->cutoffdate, 'teamsubmission' => $module->teamsubmission, 'requireallteammemberssubmit' => $module->requireallteammemberssubmit, 'teamsubmissiongroupingid' => $module->teamsubmissiongroupingid, 'blindmarking' => $module->blindmarking, 'revealidentities' => $module->revealidentities, 'attemptreopenmethod' => $module->attemptreopenmethod, 'maxattempts' => $module->maxattempts, 'markingworkflow' => $module->markingworkflow, 'markingallocation' => $module->markingallocation, 'requiresubmissionstatement' => $module->requiresubmissionstatement, 'configs' => $configarray);
                 // Return or not intro and file attachments depending on the plugin settings.
                 $setask = new setask($context, null, null);
                 if ($setask->show_intro()) {
                     list($setaskment['intro'], $setaskment['introformat']) = external_format_text($module->intro, $module->introformat, $context->id, 'mod_setask', ASSIGN_INTROATTACHMENT_FILEAREA, 0);
                     $fs = get_file_storage();
                     if ($files = $fs->get_area_files($context->id, 'mod_setask', ASSIGN_INTROATTACHMENT_FILEAREA, 0, 'timemodified', false)) {
                         $setaskment['introattachments'] = array();
                         foreach ($files as $file) {
                             $filename = $file->get_filename();
                             $setaskment['introattachments'][] = array('filename' => $filename, 'mimetype' => $file->get_mimetype(), 'fileurl' => moodle_url::make_webservice_pluginfile_url($context->id, 'mod_setask', ASSIGN_INTROATTACHMENT_FILEAREA, 0, '/', $filename)->out(false));
                         }
                     }
                 }
                 $setaskmentarray[] = $setaskment;
             }
         }
         $coursearray[] = array('id' => $courses[$id]->id, 'fullname' => $courses[$id]->fullname, 'shortname' => $courses[$id]->shortname, 'timemodified' => $courses[$id]->timemodified, 'setaskments' => $setaskmentarray);
     }
     $result = array('courses' => $coursearray, 'warnings' => $warnings);
     return $result;
 }