/** * Takes a record and transforms it into an appropriate format * This method is set up as a hook to be implented by actual report class * * @param stdClass $record The current report record * @param string $export_format The format being used to render the report * @uses $CFG * @return stdClass The reformatted record */ function transform_record($record, $export_format) { global $CFG; $showcurricula = $this->check_curricula(); if (isset($record->id)) { //add a default curriculum name if appropriate if ($showcurricula && (empty($record->curid) || empty($record->name))) { if (!empty($record->preservecurname)) { //actually corresponds to class enrolments $record->name = get_string('noncurriculumcourses', $this->languagefile); } else { //doesn't correspond to anything $record->name = get_string('na', $this->languagefile); } } //link curriculum name to its "view" page if the the current record has a curriculum if ($export_format == table_report::$EXPORT_FORMAT_HTML && !empty($record->curid)) { $page = new curriculumpage(array('id' => $record->curid, 'action' => 'view')); if ($page->can_do()) { $url = $page->url; $record->name = '<span class="external_report_link">' . "<a href=\"{$url}\" target=\"_blank\">{$record->name}</a></span>"; } } //base url $url = "{$CFG->wwwroot}/local/elisreports/render_report_page.php"; //params being passed via url $url_params = array('report' => 'user_class_completion_details', 'filter-up-idnumber' => urlencode($record->useridnumber), 'filter-up-idnumber_op' => generalized_filter_text::$OPERATOR_IS_EQUAL_TO); $preferences = php_report_filtering_get_user_preferences($this->reportname); if (!empty($preferences)) { foreach ($preferences as $key => $val) { // Determine if this is one of the completion range filter values preg_match('/.+\\/(filter\\-completerange\\_[a-z]{3})/', $key, $matches); if (isset($matches[1])) { $url_params[$matches[1]] = $val; } } } //used to track whether to add a ? or a & $first = true; foreach ($url_params as $key => $value) { //append the parameter to the url if ($first) { $url .= '?'; } else { $url .= '&'; } $url .= "{$key}={$value}"; //signal the use of & on subsequent iterations $first = false; } //add parameters related to all these groups to the report $groupnames = array('filter-detailheaders', 'filter-detailcolumns'); foreach ($groupnames as $groupname) { if ($first) { $url .= '?'; } else { $url .= '&'; } $url .= $this->get_param_url_string($groupname); } //extra attributes we are including in the anchor tag $tag_attributes = array('target' => '_blank'); //build the additional attributes $attribute_string = ''; foreach ($tag_attributes as $key => $value) { $attribute_string .= " {$key}={$value}"; } // details label for the link. First check to see if this is the first instance of the // student's record. If so then show the details link. $record->id = ''; if ($this->student_id_num != $record->useridnumber) { $link_text = get_string('details', $this->languagefile); $this->student_id_num = $record->useridnumber; $record->id = '<span class="external_report_link"><a href="' . $url . '"' . $attribute_string . '>' . $link_text . '</a></span>'; } } //show link to user's profile based on capability to view the student management capability $fullname = php_report::fullname($record); if ($export_format == php_report::$EXPORT_FORMAT_HTML) { $userpage = new userpage(array('id' => $record->userid, 'action' => 'view')); if ($userpage->can_do()) { $record->lastname = '<span class="external_report_link"><a href="' . $userpage->url . '" target="_blank">' . $fullname . '</a></span>'; } else { $record->lastname = $fullname; } } else { $record->lastname = $fullname; } //convert times to appropriate format if (!empty($record->timecompleted) && !empty($record->completed)) { $record->timecompleted = $this->format_date($record->timecompleted); } else { $record->timecompleted = get_string('na', $this->languagefile); } if (!empty($record->timeexpired) && !empty($record->completed)) { $record->timeexpired = $this->format_date($record->timeexpired); } else { $record->timeexpired = get_string('na', $this->languagefile); } //N/A for cretificate number if a valid one is not set if (empty($record->certificatecode) || empty($record->completed)) { $record->certificatecode = get_string('na', $this->languagefile); } //copy result of complex query into simple field if (!empty($record->numcredits)) { //use the provided value $record->displaynumcredits = $this->format_credits($record->numcredits); } else { //default to zero $record->displaynumcredits = $this->format_credits(0); } //handle custom field default values and display logic $this->transform_custom_field_data($record); return $record; }