Exemplo n.º 1
0
 /**
  * Test block_elisadmin_load_menu_children_course function.
  */
 public function test_block_elisadmin_load_menu_children_course()
 {
     global $DB, $USER;
     accesslib_clear_all_caches(true);
     // Create test user - ensure the returned user is NOT a site admin. if they are, our capability restrictions won't work.
     $testuser = new user();
     $testuser->username = '******';
     $testuser->idnumber = 'testELIS4093';
     $testuser->firstname = 'testELIS4093';
     $testuser->lastname = 'testELIS4093';
     $testuser->email = '*****@*****.**';
     $testuser->country = 'CA';
     $testuser->save();
     $testmuser = $testuser->get_moodleuser();
     // Create role with cap: 'local/elisprogram:class_view'.
     $testrole = new stdClass();
     $testrole->name = 'ELIS Class View';
     $testrole->shortname = '_test_ELIS_4093';
     $testrole->description = 'ELIS Class View';
     $testrole->archetype = '';
     $testrole->id = create_role($testrole->name, $testrole->shortname, $testrole->description, $testrole->archetype);
     // Ensure our new role is assignable to ELIS class contexts.
     set_role_contextlevels($testrole->id, array(CONTEXT_ELIS_CLASS));
     // Ensure the role has our required capability assigned.
     $sitecontext = context_system::instance();
     assign_capability('local/elisprogram:class_view', CAP_ALLOW, $testrole->id, $sitecontext->id, true);
     $sitecontext->mark_dirty();
     // Create ELIS Course Description.
     $testcrs = new course(array('name' => 'CD-ELIS-4093', 'idnumber' => 'CDELIS4093', 'syllabus' => ''));
     $testcrs->save();
     $testcrs->load();
     // Create three(3) Class Instances for Course Descrption.
     $testcls1 = new pmclass(array('courseid' => $testcrs->id, 'idnumber' => 'CI_ELIS_4093.1'));
     $testcls1->save();
     $testcls1->load();
     $testcls2 = new pmclass(array('courseid' => $testcrs->id, 'idnumber' => 'CI_ELIS_4093.2'));
     $testcls2->save();
     $testcls2->load();
     $testcls3 = new pmclass(array('courseid' => $testcrs->id, 'idnumber' => 'CI_ELIS_4093.3'));
     $testcls3->save();
     $testcls3->load();
     // Assign testuser new role in one Class Instance.
     $context = \local_elisprogram\context\pmclass::instance($testcls2->id);
     role_assign($testrole->id, $testmuser->id, $context->id);
     // Switch to testuser.
     $USER = $testmuser;
     $this->setUser($testmuser);
     $items = block_elisadmin_load_menu_children_course($testcrs->id, 0, 0, 5, '');
     $this->assertEquals(1, count($items));
     $this->assertTrue($items[0]->name == 'pmclass_2');
 }
Exemplo n.º 2
0
 function display_default()
 {
     //obtain a non-zero courseid if we are hitting this page for the first time
     //otherwise form data will submit back into itself
     $courseid = $this->required_param('id', PARAM_INT);
     $data = null;
     if ($courseid != 0) {
         //fetch the course record
         $course = new course($courseid);
         $course->load();
         //set up the form data
         $data = new stdClass();
         $data->idnumber = $course->idnumber;
         $data->name = $course->name;
         //used to link the program to the course description
         $data->courseid = $courseid;
     }
     $this->print_add_form($data);
 }
Exemplo n.º 3
0
 /**
  * Performs course update
  * @throws moodle_exception If there was an error in passed parameters.
  * @throws data_object_exception If there was an error updating the entity.
  * @param array $data The incoming data parameter.
  * @return array An array of parameters, if successful.
  */
 public static function course_update(array $data)
 {
     global $USER, $DB;
     if (static::require_elis_dependencies() !== true) {
         throw new moodle_exception('ws_function_requires_elis', 'local_datahub');
     }
     // Parameter validation.
     $params = self::validate_parameters(self::course_update_parameters(), array('data' => $data));
     // Context validation.
     $context = context_user::instance($USER->id);
     self::validate_context($context);
     $data = (object) $data;
     // Validate course exists
     if (!($crsid = $DB->get_field(course::TABLE, 'id', array('idnumber' => $data->idnumber)))) {
         throw new data_object_exception('ws_course_update_fail_invalid_idnumber', 'local_datahub', '', $data);
     }
     // Capability checking.
     require_capability('local/elisprogram:course_edit', \local_elisprogram\context\course::instance($crsid));
     // Initialize version1elis importplugin for utility functions.
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     // Validate credits.
     if (isset($data->credits) && !(is_numeric($data->credits) && $data->credits >= 0)) {
         throw new data_object_exception('ws_course_update_fail_invalid_credits', 'local_datahub', '', $data);
     }
     // Validate completion grade.
     if (isset($data->completion_grade) && !(is_numeric($data->completion_grade) && $data->completion_grade >= 0 && $data->completion_grade <= 100)) {
         throw new data_object_exception('ws_course_update_fail_invalid_completion_grade', 'local_datahub', '', $data);
     }
     // Handle assignment to program.
     if (isset($data->assignment) && !empty($data->assignment)) {
         $programid = $DB->get_field(curriculum::TABLE, 'id', array('idnumber' => $data->assignment));
         if ($programid) {
             $curriculumcourseid = $DB->get_field(curriculumcourse::TABLE, 'id', array('curriculumid' => $programid, 'courseid' => $crsid));
             // Only assign if it is not already assigned
             if (!$curriculumcourseid) {
                 $data->curriculum = array($programid);
             }
         } else {
             throw new data_object_exception('ws_course_update_fail_invalid_assignment', 'local_datahub', '', $data);
         }
     }
     $course = new course($crsid);
     $course->load();
     $course->set_from_data($data);
     $course->save();
     // Handle linking to Moodle course.
     if (isset($data->link) && !empty($data->link)) {
         $moodlecourseid = $DB->get_field('course', 'id', array('shortname' => $data->link));
         if ($moodlecourseid) {
             $importplugin->associate_course_to_moodle_course($data, $course->id);
         } else {
             throw new data_object_exception('ws_course_update_fail_invalid_link', 'local_datahub', '', $data);
         }
     }
     // Respond.
     if (!empty($course->id)) {
         $courserec = (array) $DB->get_record(course::TABLE, array('id' => $course->id));
         $courseobj = $course->to_array();
         // convert multi-valued custom field arrays to comma-separated listing
         $fields = self::get_course_custom_fields();
         foreach ($fields as $field) {
             // Generate name using custom field prefix.
             $fullfieldname = data_object_with_custom_fields::CUSTOM_FIELD_PREFIX . $field->shortname;
             if ($field->multivalued && isset($courseobj[$fullfieldname]) && is_array($courseobj[$fullfieldname])) {
                 $courseobj[$fullfieldname] = implode(',', $courseobj[$fullfieldname]);
             }
         }
         return array('messagecode' => get_string('ws_course_update_success_code', 'local_datahub'), 'message' => get_string('ws_course_update_success_msg', 'local_datahub'), 'record' => array_merge($courserec, $courseobj));
     } else {
         throw new data_object_exception('ws_course_update_fail', 'local_datahub');
     }
 }
Exemplo n.º 4
0
 /**
  * Test successful course creation.
  */
 public function test_success()
 {
     global $DB;
     // Create custom field.
     $fieldcat = new field_category();
     $fieldcat->name = 'Test';
     $fieldcat->save();
     $field = new field();
     $field->categoryid = $fieldcat->id;
     $field->shortname = 'testfield';
     $field->name = 'Test Field';
     $field->datatype = 'text';
     $field->save();
     $fieldctx = new field_contextlevel();
     $fieldctx->fieldid = $field->id;
     $fieldctx->contextlevel = CONTEXT_ELIS_COURSE;
     $fieldctx->save();
     // Grant permissions.
     $this->give_permissions(array('local/elisprogram:course_create'));
     // Create test program.
     $datagen = new elis_program_datagenerator($DB);
     $program = $datagen->create_program(array('idnumber' => 'TestProgram'));
     $course = array('idnumber' => 'TestCourse', 'name' => 'Test Course', 'code' => 'CRS1', 'syllabus' => 'Test syllabus', 'lengthdescription' => 'Weeks', 'length' => 2, 'credits' => 1.1, 'completion_grade' => 50, 'cost' => '$100', 'version' => '1.0.0', 'assignment' => $program->idnumber);
     // Create test course.
     $response = local_datahub_elis_course_create::course_create($course);
     $this->assertNotEmpty($response);
     $this->assertInternalType('array', $response);
     $this->assertArrayHasKey('messagecode', $response);
     $this->assertArrayHasKey('message', $response);
     $this->assertArrayHasKey('record', $response);
     $this->assertEquals(get_string('ws_course_create_success_code', 'local_datahub'), $response['messagecode']);
     $this->assertEquals(get_string('ws_course_create_success_msg', 'local_datahub'), $response['message']);
     $this->assertInternalType('array', $response['record']);
     $this->assertArrayHasKey('id', $response['record']);
     // Get course.
     $createdcourse = new course($response['record']['id']);
     $createdcourse->load();
     $createdcourse = $createdcourse->to_array();
     foreach ($course as $param => $val) {
         if ($param != 'assignment') {
             $this->assertArrayHasKey($param, $createdcourse);
             $this->assertEquals($val, $createdcourse[$param]);
         }
     }
     // Check that course was assigned to program.
     $curriculumcourseid = $DB->get_field(curriculumcourse::TABLE, 'id', array('curriculumid' => $program->id, 'courseid' => $response['record']['id']));
     $this->assertNotEmpty($curriculumcourseid);
 }
Exemplo n.º 5
0
 /**
  * This function retrieves the name of the entity and stores it into the output buffer
  * @param object $certdata Certificate issued and settings object @see get_user_certificates() for details about this object
  * @return bool Return true is the buffer is filled, otherwise false
  */
 public function get_cert_entity_name($certdata)
 {
     $name = '';
     if (!isset($certdata->entity_type)) {
         return false;
     }
     switch ($certdata->entity_type) {
         case CERTIFICATE_ENTITY_TYPE_PROGRAM:
             // Insert code to display program certificates.
             break;
         case CERTIFICATE_ENTITY_TYPE_COURSE:
             // Return the name of the course that pertains to the certificate data.
             if (!isset($certdata->entity_id)) {
                 return false;
             }
             // Retrieve the course description name.
             try {
                 $coursedescname = new course($certdata->entity_id);
                 $coursedescname->load();
                 $name = $coursedescname->name;
             } catch (dml_missing_record_exception $e) {
                 debugging($e->getMessage(), DEBUG_DEVELOPER);
                 return false;
             }
             if (!empty($name)) {
                 $url = "entity_certificate.php?id={$certdata->id}&csid={$certdata->csid}";
                 $link = html_writer::link($url, $name, array('target' => '_blank'));
                 $name = html_writer::tag('li', $link);
                 $this->entitynamebuffer[CERTIFICATE_ENTITY_TYPE_COURSE][] = $name;
             }
             break;
         case CERTIFICATE_ENTITY_TYPE_LEARNINGOBJ:
             // Insert code to display learning objective certificates.
             break;
         case CERTIFICATE_ENTITY_TYPE_CLASS:
             // Insert code to display class certificates.
             break;
         default:
             return false;
     }
     return true;
 }
Exemplo n.º 6
0
/**
 * This function does the work of retrieving the course entity metadata
 * @param object $certsetting: a certificatesettings data class object
 * @param object $certissued: a certificateissued data class object
 * @param object $student: a user data class object
 * @return array|bool - array of metadata or false if something went wrong
 */
function certificate_get_course_entity_metadata($certsetting, $certissued, $student)
{
    $params = array();
    if (!isset($certsetting->entity_id)) {
        return false;
    }
    if (!isset($student->id)) {
        return false;
    }
    // Retrieve the course description name
    /*try {
          $coursedescname = new course($certdata->entity_id);
          $coursedescname->load();
          $name = $coursedescname->name;
      } catch (dml_missing_record_exception $e) {
          debugging($e->getMessage(), DEBUG_DEVELOPER);
      }
      */
    try {
        $coursedescname = new course($certsetting->entity_id);
        $coursedescname->load();
    } catch (dml_missing_record_exception $e) {
        debugging($e->getMessage(), DEBUG_DEVELOPER);
        return false;
    }
    // Retrieve the student's classes
    $stuclasses = student_get_class_from_course($certsetting->entity_id, $student->id);
    foreach ($stuclasses as $stuclass) {
        // If timeissued property then break out of the loop
        if (!isset($certissued->timeissued)) {
            break;
        }
        // Check if the date issued is the same as the student's completion date
        if ($stuclass->completetime == $certissued->timeissued) {
            // Get the instructor information
            $instructors = new instructor();
            $instructors = $instructors->get_instructors($stuclass->id);
            // Populate with metadata info
            $params['student_name'] = $student->firstname . ' ' . $student->lastname;
            $params['class_idnumber'] = $stuclass->idnumber;
            $params['class_enrol_time'] = $stuclass->enrolmenttime;
            $params['class_startdate'] = $stuclass->startdate;
            $params['class_enddate'] = $stuclass->startdate;
            $params['class_grade'] = $stuclass->grade;
            $params['cert_timeissued'] = $certissued->timeissued;
            $params['cert_code'] = $certissued->cert_code;
        }
    }
    if (!empty($instructors)) {
        // Only get the first instructor name, (MAY NEED TO CHANGE THIS LATER ON)
        foreach ($instructors as $instructor) {
            $params['class_instructor_name'] = $instructor->firstname . ' ' . $instructor->lastname;
            break;
        }
    }
    if (!empty($params)) {
        $params['course_name'] = $coursedescname->name;
        return $params;
    }
    return false;
}
Exemplo n.º 7
0
 /**
  * Test that the pm_migrate_environments() function works correctly
  */
 public function test_pmmigrateenvironments()
 {
     global $DB;
     $this->load_csv_data();
     // Migrate the legacy environment data to new ELIS filelds.
     pm_migrate_environments();
     // Initialize the course object.
     $course = new course(100);
     $course->reset_custom_field_list();
     $course->load();
     $course = $course->to_object();
     // Get the field data from the object.
     $this->assertObjectHasAttribute('field__19upgrade_course_environment', $course);
     $this->assertEquals('Testing', $course->field__19upgrade_course_environment);
     // Let's do some extra DB-level validation (though it's probably not necessary).
     $field = $DB->get_record(field::TABLE, array('shortname' => '_19upgrade_course_environment'));
     $this->assertGreaterThan(0, $field->id);
     $context = \local_elisprogram\context\course::instance($course->id);
     $this->assertTrue($DB->record_exists(field_data_char::TABLE, array('contextid' => $context->id, 'fieldid' => $field->id)));
 }