public function test_course_management_without_data()
 {
     global $CFG, $DB;
     $this->resetAfterTest(false);
     $open = EclassCourseManager::get_course_open($this->referenceobjects['course2']->id);
     $close = EclassCourseManager::get_course_close($this->referenceobjects['course2']->id);
     $this->assertEquals(false, $open);
     $this->assertEquals(false, $close);
 }
 public function get_content()
 {
     global $COURSE;
     if ($this->content !== null) {
         return $this->content;
     }
     // Create empty content.
     $this->content = new stdClass();
     $this->content->text = '';
     // Use Strict as this block should only ever be in a course context.
     $context = context_course::instance($this->page->course->id);
     if (!has_capability('block/eclass_course_management:canseeblock', $context)) {
         return $this->content->text = '';
     }
     $open = EclassCourseManager::get_course_open($context->instanceid);
     $close = EclassCourseManager::get_course_close($context->instanceid);
     if ($open) {
         $date = usergetdate($open);
         $this->content->text .= '<br/>' . get_string('open_label', 'block_eclass_course_management') . ' ' . "{$date['month']} {$date['mday']}, {$date['year']}";
     } else {
         $this->content->text .= '<br/>' . get_string('nostartdate', 'block_eclass_course_management');
     }
     if ($close) {
         $date = usergetdate($close);
         $this->content->text .= '<br/>' . get_string('close_label', 'block_eclass_course_management') . ' ' . "{$date['month']} {$date['mday']}, {$date['year']}";
     } else {
         $this->content->text .= '<br/>' . get_string('noenddate', 'block_eclass_course_management');
     }
     if ($COURSE->visible) {
         $this->content->text .= '<br/>' . get_string('status_label', 'block_eclass_course_management') . ' ' . get_string('visible', 'block_eclass_course_management');
     } else {
         $this->content->text .= '<br/>' . get_string('status_label', 'block_eclass_course_management') . ' ' . get_string('notvisible', 'block_eclass_course_management');
     }
     if (!empty($this->content->text)) {
         $this->content->text = get_string('blockpreamble', 'block_eclass_course_management') . '<br/>' . $this->content->text;
     }
     if (has_capability('moodle/course:update', $context)) {
         $this->content->text .= "<br/><a href='/blocks/eclass_course_management/configure.php?course={$COURSE->id}'>Edit</a>";
     }
     return $this->content;
 }
Пример #3
0
 public function cron()
 {
     global $CFG, $DB;
     $starttime = time();
     mtrace('----------------------------------------------------------------------');
     mtrace('enrol-uaims cron cron process launched at ' . userdate(time()));
     $dbtables = $DB->get_tables(false);
     if (!array_key_exists('eclass_course_management', $dbtables)) {
         mtrace('Automatic course opening/closing disabled. (eclass_course_management table does not exist.)');
     } else {
         $autoopenclose = $this->get_config('enableautocourseopenclose');
         if (isset($autoopenclose) && $autoopenclose) {
             $ecm = new EclassCourseManager($starttime);
             $coursesopened = $ecm->auto_open_courses();
             $courseidstrings = $coursesopened == false ? array('none') : array_map('strval', $coursesopened);
             mtrace('Courses auto-opened: ' . implode(',', $courseidstrings));
             $coursesclosed = $ecm->auto_close_courses();
             $courseidstrings = $coursesclosed == false ? array('none') : array_map('strval', $coursesclosed);
             mtrace('Courses auto-closed: ' . implode(',', $courseidstrings));
         } else {
             mtrace("Automatic course opening/closing disabled! (enrol_uaims/enableautocourseopenclose = {$autoopenclose})");
         }
     }
     $timeelapsed = time() - $starttime;
     mtrace('enrol-uaims cron process has completed. Time taken: ' . $timeelapsed . ' seconds.');
 }
 /**
  * Helper for test_auto_openclose_courses() and test_enrol_uaims_cron().
  * @param $visible
  * @param $startdate
  * @param $enddate
  * @param null $lastopened
  * @param null $lastclosed
  * @return stdClass The created course object
  */
 public function create_course_vis_start_end($visible, $startdate, $enddate, $lastopened = null, $lastclosed = null)
 {
     global $DB;
     $ecm = new EclassCourseManager(time());
     $course = $this->getDataGenerator()->create_course();
     $ecm->set_courseid_visible($course->id, $visible);
     $ecmrecord = new stdClass();
     $ecmrecord->courseid = $course->id;
     $ecmrecord->startdate = $startdate;
     $ecmrecord->enddate = $enddate;
     if (isset($lastopened)) {
         $ecmrecord->lastopened = $lastopened;
     }
     if (isset($lastclosed)) {
         $ecmrecord->lastclosed = $lastclosed;
     }
     $DB->insert_record('eclass_course_management', $ecmrecord);
     return $course;
 }