Esempio n. 1
0
 /**
  * Obtain the appropriate information regarding program courses as needed
  * by the dashboard
  *
  * @param boolean $tab_sensitive true if we need to be concerned about whether
  *                               we are on the current or archived tab, otherwise
  *                               false
  * @param boolean $show_archived specifies whether we're showing archived or non-
  *                               archived courses (ignored if tab_sensitive is false)
  * @param boolean $showcompleted specifies whether we're showing passed and failed
  *                               courses in addition to ones in progress
  * @param mixed $programid a specific program id to look for data related to, or
  *                         NULL for all
  * @return array a list of values, where the first entry is the user's course list,
  *               the second is a mapping of programs to a course listing, the third
  *               is a list of classes handled, and the fourth is the number of programs
  *               handled, the fifth is a mapping of program ids to number of compelted
  *               courses, the sixth is a mapping of program ids to total number of courses
  */
 function get_dashboard_program_data($tab_sensitive, $show_archived, $showcompleted = false, $programid = NULL)
 {
     global $CFG, $DB;
     $archive_var = '_elis_program_archive';
     $classids = array();
     //track mapping of programs to course / class listings
     $curriculas = array();
     $totalcurricula = 0;
     //map program ids to appropriate counts
     $completecoursesmap = array();
     $totalcoursesmap = array();
     $params = array($this->id);
     //set up a condition for when handling a specific program
     $program_condition = '';
     if ($programid !== NULL) {
         $program_condition = 'AND cur.id = ?';
         $params[] = $programid;
     }
     $sql = 'SELECT curstu.id, curstu.curriculumid as curid, cur.name as name
               FROM {' . curriculumstudent::TABLE . '} curstu
               JOIN {' . curriculum::TABLE . '} cur
                 ON cur.id = curstu.curriculumid
              WHERE curstu.userid = ?
              ' . $program_condition . '
           ORDER BY cur.priority ASC, cur.name ASC';
     //mapping of completion status to display string
     $status_mapping = array(STUSTATUS_PASSED => get_string('passed', 'local_elisprogram'), STUSTATUS_FAILED => get_string('failed', 'local_elisprogram'), STUSTATUS_NOTCOMPLETE => get_string('n_completed', 'local_elisprogram'));
     if ($usercurs = $DB->get_records_sql($sql, $params)) {
         //^pre-ELIS-3615 WAS: if ($usercurs = curriculumstudent::get_curricula($this->id)) {
         foreach ($usercurs as $usercur) {
             // Check if this curricula is set as archived and whether we want to display it
             $crlm_context = \local_elisprogram\context\program::instance($usercur->curid);
             $data_array = field_data::get_for_context_and_field($crlm_context, $archive_var);
             $crlm_archived = 0;
             if (!empty($data_array) && is_object($data_array->rs) && !empty($data_array->rs)) {
                 $crlm_archived = !empty($data_array->rs->current()->data) ? 1 : 0;
             }
             //being insensitive to which tab we're on gets us this listing "for free"
             if (!$tab_sensitive || $show_archived == $crlm_archived) {
                 $totalcurricula++;
                 $curriculas[$usercur->curid]['id'] = $usercur->curid;
                 $curriculas[$usercur->curid]['name'] = $usercur->name;
                 $data = array();
                 //count our totals per-program
                 //note that "course" is really one enrolment, so this should
                 //count each enrolment, plus one for each unenrolled program course
                 $totalcourses = 0;
                 $completecourses = 0;
                 $courses = curriculumcourse_get_listing($usercur->curid, 'curcrs.position, crs.name', 'ASC');
                 foreach ($courses as $course) {
                     $course_obj = new course($course->courseid);
                     $coursedesc = $course_obj->syllabus;
                     $cdata = student_get_class_from_course($course->courseid, $this->id);
                     if ($cdata->valid() === true) {
                         foreach ($cdata as $classdata) {
                             //count each enrolment as one "course"
                             $totalcourses++;
                             if (!in_array($classdata->id, $classids)) {
                                 $classids[] = $classdata->id;
                             }
                             if ($classdata->completestatusid == STUSTATUS_PASSED || $classdata->completestatusid == STUSTATUS_FAILED) {
                                 //count completed enrolments
                                 $completecourses++;
                             }
                             if (!$showcompleted && ($classdata->completestatusid == STUSTATUS_PASSED || $classdata->completestatusid == STUSTATUS_FAILED)) {
                                 //not showing completed courses, so skip this course
                                 continue;
                             }
                             if ($mdlcrs = moodle_get_course($classdata->id)) {
                                 $coursename = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $mdlcrs . '">' . $course->coursename . '</a>';
                             } else {
                                 $coursename = $course->coursename;
                             }
                             $data[] = array($coursename, $classdata->idnumber, $coursedesc, pm_display_grade($classdata->grade), $status_mapping[$classdata->completestatusid], $classdata->completestatusid == STUSTATUS_PASSED && !empty($classdata->completetime) ? userdate($classdata->completetime, get_string('pm_date_format', 'local_elisprogram')) : get_string('na', 'local_elisprogram'));
                         }
                     } else {
                         //count this unenrolled course toward the total
                         $totalcourses++;
                         $data[] = array($course->coursename, get_string('dashboard_na', 'local_elisprogram'), $coursedesc, 0, get_string('not_enrolled', 'local_elisprogram'), get_string('na', 'local_elisprogram'));
                     }
                     unset($cdata);
                 }
                 unset($courses);
                 $curriculas[$usercur->curid]['data'] = $data;
                 //associate this program id with the appropriate counts
                 $completecoursesmap[$usercur->curid] = $completecourses;
                 $totalcoursesmap[$usercur->curid] = $totalcourses;
             } else {
                 // Keep note of the classid's regardless if set archived or not for later use in determining non-curricula courses
                 $courses = curriculumcourse_get_listing($usercur->curid, 'curcrs.position, crs.name', 'ASC');
                 foreach ($courses as $course) {
                     $cdata = student_get_class_from_course($course->courseid, $this->id);
                     foreach ($cdata as $classdata) {
                         if (!in_array($classdata->id, $classids)) {
                             $classids[] = $classdata->id;
                         }
                     }
                     unset($cdata);
                 }
                 unset($courses);
             }
         }
     }
     return array($usercurs, $curriculas, $classids, $totalcurricula, $completecoursesmap, $totalcoursesmap);
 }
Esempio n. 2
0
 /**
  * Get the user dashboard report view.
  *
  * @uses $CFG, $CURMAN
  * @param none
  * @return string The HTML for the dashboard report.
  */
 function get_dashboard()
 {
     global $CFG, $CURMAN;
     require_once CURMAN_DIRLOCATION . '/lib/curriculumstudent.class.php';
     //needed for AJAX calls
     require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_connection', "{$CFG->wwwroot}/curriculum/js/util.js", "{$CFG->wwwroot}/curriculum/js/dashboard.js"), true);
     if (optional_param('tab', '', PARAM_CLEAN) == 'archivedlp') {
         $tab = 'archivedlp';
         $show_archived = 1;
     } else {
         $tab = 'currentlp';
         $show_archived = 0;
     }
     $content = '';
     $archive_var = '_elis_curriculum_archive';
     $totalcourses = 0;
     $totalcurricula = 0;
     $completecourses = 0;
     $curriculas = array();
     $classids = array();
     $sql = 'SELECT curstu.id, curstu.curriculumid as curid, cur.name as name
               FROM ' . $CURMAN->db->prefix_table(CURASSTABLE) . ' curstu
               JOIN ' . $CURMAN->db->prefix_table(CURTABLE) . ' cur
                 ON cur.id = curstu.curriculumid
              WHERE curstu.userid = \'' . $this->id . '\' ORDER BY cur.priority ASC, cur.name ASC';
     if ($usercurs = get_records_sql($sql)) {
         foreach ($usercurs as $usercur) {
             // Check if this curricula is set as archived and whether we want to display it
             $crlm_context = get_context_instance(context_level_base::get_custom_context_level('curriculum', 'block_curr_admin'), $usercur->curid);
             $data_array = field_data::get_for_context_and_field($crlm_context, $archive_var);
             $crlm_archived = 0;
             if (is_array($data_array) && !empty($data_array)) {
                 foreach ($data_array as $data_key => $data_obj) {
                     $crlm_archived = !empty($data_obj->data) ? 1 : 0;
                 }
             }
             if ($show_archived == $crlm_archived) {
                 $totalcurricula++;
                 $curriculas[$usercur->curid]['id'] = $usercur->curid;
                 $curriculas[$usercur->curid]['name'] = $usercur->name;
                 $data = array();
                 if ($courses = curriculumcourse_get_listing($usercur->curid, 'curcrs.position, crs.name', 'ASC')) {
                     foreach ($courses as $course) {
                         $totalcourses++;
                         $course_obj = new course($course->courseid);
                         $coursedesc = $course_obj->syllabus;
                         if ($cdata = student_get_class_from_course($course->courseid, $this->id)) {
                             foreach ($cdata as $classdata) {
                                 if (!in_array($classdata->id, $classids)) {
                                     $classids[] = $classdata->id;
                                 }
                                 if ($classdata->completestatusid == STUSTATUS_PASSED) {
                                     $completecourses++;
                                 }
                                 if ($mdlcrs = moodle_get_course($classdata->id)) {
                                     $coursename = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $mdlcrs . '">' . $course->coursename . '</a>';
                                 } else {
                                     $coursename = $course->coursename;
                                 }
                                 $data[] = array($coursename, $coursedesc, $classdata->grade, $classdata->completestatusid == STUSTATUS_PASSED ? get_string('yes') : get_string('no'), $classdata->completestatusid == STUSTATUS_PASSED && !empty($classdata->completetime) ? date('M j, Y', $classdata->completetime) : get_string('na', 'block_curr_admin'));
                             }
                         } else {
                             $data[] = array($course->coursename, $coursedesc, 0, get_string('no'), get_string('na', 'block_curr_admin'));
                         }
                     }
                 }
                 $curriculas[$usercur->curid]['data'] = $data;
             } else {
                 // Keep note of the classid's regardless if set archived or not for later use in determining non-curricula courses
                 if ($courses = curriculumcourse_get_listing($usercur->curid, 'curcrs.position, crs.name', 'ASC')) {
                     foreach ($courses as $course) {
                         if ($cdata = student_get_class_from_course($course->courseid, $this->id)) {
                             foreach ($cdata as $classdata) {
                                 if (!in_array($classdata->id, $classids)) {
                                     $classids[] = $classdata->id;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // Show different css for IE below version 8
     if (check_browser_version('MSIE', 7.0) && !check_browser_version('MSIE', 8.0)) {
         // IEs that are lower than version 8 do not get the float because it messes up the tabs at the top of the page for some reason
         $float_style = 'text-align:right;';
     } else {
         // Sane browsers get the float tag
         $float_style = 'text-align:right; float:right;';
     }
     // Tab header
     $field_exists = field::get_for_context_level_with_name('curriculum', $archive_var);
     if (!empty($field_exists)) {
         $tabrow = array();
         $tabrow[] = new tabobject('currentlp', $CFG->wwwroot . '/curriculum/index.php?tab=currentlp', get_string('tab_current_learning_plans', 'block_curr_admin'));
         $tabrow[] = new tabobject('archivedlp', $CFG->wwwroot . '/curriculum/index.php?tab=archivedlp', get_string('tab_archived_learning_plans', 'block_curr_admin'));
         $tabrows = array($tabrow);
         print_tabs($tabrows, $tab);
     }
     $content .= print_heading_block(get_string('learningplanwelcome', 'block_curr_admin', fullname($this)), '', true);
     if ($totalcurricula === 0) {
         $blank_lang = $tab == 'archivedlp' ? 'noarchivedplan' : 'nolearningplan';
         $content .= '<br /><center>' . get_string($blank_lang, 'block_curr_admin') . '</center>';
     }
     // Load the user preferences for hide/show button states
     if ($collapsed = get_user_preferences('crlm_learningplan_collapsed_curricula')) {
         $collapsed_array = explode(',', $collapsed);
     } else {
         $collapsed = '';
         $collapsed_array = array();
     }
     $content .= '<input type="hidden" name="collapsed" id="collapsed" value="' . $collapsed . '">';
     if (!empty($usercurs)) {
         foreach ($usercurs as $usercur) {
             if (!isset($curriculas[$usercur->curid])) {
                 continue;
             }
             $curricula = $curriculas[$usercur->curid];
             $table = new stdClass();
             $table->head = array(get_string('class', 'block_curr_admin'), get_string('description', 'block_curr_admin'), get_string('score', 'block_curr_admin'), get_string('completed_label', 'block_curr_admin'), get_string('date', 'block_curr_admin'));
             $table->data = $curricula['data'];
             $curricula_name = empty($CURMAN->config->disablecoursecatalog) ? '<a href="index.php?s=crscat&section=curr&showcurid=' . $curricula['id'] . '">' . $curricula['name'] . '</a>' : $curricula['name'];
             $header_curr_name = get_string('learningplanname', 'block_curr_admin', $curricula_name);
             if (in_array($curricula['id'], $collapsed_array)) {
                 $button_label = get_string('showcourses', 'block_curr_admin');
                 $extra_class = ' hide';
             } else {
                 $button_label = get_string('hidecourses', 'block_curr_admin');
                 $extra_class = '';
             }
             $heading = '<div class="clearfix"></div>' . '<div style="' . $float_style . '">' . '<script id="curriculum' . $curricula['id'] . 'script" type="text/javascript">toggleVisibleInitWithState("curriculum' . $curricula['id'] . 'script", "curriculum' . $curricula['id'] . 'button", "' . $button_label . '", "' . get_string('hidecourses', 'block_curr_admin') . '", "' . get_string('showcourses', 'block_curr_admin') . '", "curriculum-' . $curricula['id'] . '");</script></div>' . $header_curr_name;
             $content .= '<div class="dashboard_curricula_block">';
             $content .= print_heading($heading, 'left', 2, 'main', true);
             $content .= '<div id="curriculum-' . $curricula['id'] . '" class="yui-skin-sam ' . $extra_class . '">';
             if (empty($curricula['data'])) {
                 $content .= get_string('nocourseassoc', 'block_curr_admin');
             } else {
                 $content .= print_table($table, true);
             }
             $content .= '</div>';
             $content .= '</div>';
         }
     }
     /// Completed non-curricula course data
     if ($tab != 'archivedlp') {
         if (!empty($classids)) {
             $sql = "SELECT stu.id, stu.classid, crs.name as coursename, stu.completetime, stu.grade, stu.completestatusid\n                        FROM " . $CURMAN->db->prefix_table(STUTABLE) . " stu\n                        INNER JOIN " . $CURMAN->db->prefix_table(CLSTABLE) . " cls ON cls.id = stu.classid\n                        INNER JOIN " . $CURMAN->db->prefix_table(CRSTABLE) . " crs ON crs.id = cls.courseid\n                        WHERE userid = {$this->id}\n                        AND classid " . (count($classids) == 1 ? "!= " . current($classids) : "NOT IN (" . implode(", ", $classids) . ")") . "\n                        ORDER BY crs.name ASC, stu.completetime ASC";
         } else {
             $sql = "SELECT stu.id, stu.classid, crs.name as coursename, stu.completetime, stu.grade, stu.completestatusid\n                        FROM " . $CURMAN->db->prefix_table(STUTABLE) . " stu\n                        INNER JOIN " . $CURMAN->db->prefix_table(CLSTABLE) . " cls ON cls.id = stu.classid\n                        INNER JOIN " . $CURMAN->db->prefix_table(CRSTABLE) . " crs ON crs.id = cls.courseid\n                        WHERE userid = {$this->id}\n                        ORDER BY crs.name ASC, stu.completetime ASC";
         }
         if ($classes = get_records_sql($sql)) {
             $table = new stdClass();
             $table->head = array(get_string('class', 'block_curr_admin'), get_string('score', 'block_curr_admin'), get_string('completed_label', 'block_curr_admin'), get_string('date', 'block_curr_admin'));
             $table->data = array();
             foreach ($classes as $class) {
                 if ($mdlcrs = moodle_get_course($class->classid)) {
                     $coursename = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $mdlcrs . '">' . $class->coursename . '</a>';
                 } else {
                     $coursename = $class->coursename;
                 }
                 $table->data[] = array($coursename, $class->grade, $class->completestatusid == STUSTATUS_PASSED ? get_string('yes') : get_string('no'), $class->completestatusid == STUSTATUS_PASSED && !empty($class->completetime) ? date('M j, Y', $class->completetime) : get_string('na', 'block_curr_admin'));
             }
             $header_curr_name = get_string('noncurriculacourses', 'block_curr_admin');
             if (in_array('na', $collapsed_array)) {
                 $button_label = get_string('showcourses', 'block_curr_admin');
                 $extra_class = ' hide';
             } else {
                 $button_label = get_string('hidecourses', 'block_curr_admin');
                 $extra_class = '';
             }
             $heading = '<div class="clearfix"></div>' . '<div style="' . $float_style . '">' . '<script id="noncurriculascript" type="text/javascript">toggleVisibleInitWithState("noncurriculascript", "noncurriculabutton", "' . $button_label . '", "' . get_string('hidecourses', 'block_curr_admin') . '", "' . get_string('showcourses', 'block_curr_admin') . '", "curriculum-na");</script></div>' . $header_curr_name;
             $content .= '<div class="dashboard_curricula_block">';
             $content .= print_heading($heading, 'left', 2, 'main', true);
             $content .= '<div id="curriculum-na" class="yui-skin-sam ' . $extra_class . '">';
             $content .= print_table($table, true);
             $content .= '</div>';
             $content .= '</div>';
         }
     }
     return $content;
 }
Esempio n. 3
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;
}