/**
  * 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->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->get_url();
                 $record->name = '<a href="' . $url . '" target="_blank">' . $record->name . '</a>';
             }
         }
         //base url
         $url = "{$CFG->wwwroot}/blocks/php_report/render_report_page.php";
         //params being passed via url
         $url_params = array('report' => 'user_class_completion_details', 'idnumber' => urlencode($record->useridnumber), 'idnumber_op' => generalized_filter_text::$OPERATOR_IS_EQUAL_TO);
         //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('class' => 'external_report_link', '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.
         $link_text = '';
         if (0 != strcmp($this->student_id_num, $record->useridnumber)) {
             $link_text = get_string('details', $this->languagefile);
             $this->student_id_num = $record->useridnumber;
         }
         if ($export_format == table_report::$EXPORT_FORMAT_HTML) {
             //replace the empty column with the appropriate link
             $record->id = '<a href="' . $url . '"' . $attribute_string . '>' . $link_text . '</a>';
         } else {
             //in an export, so don't show link
             $record->id = '';
         }
     }
     //show link to user's profile based on capability to view the student management capability
     $fullname = fullname($record);
     if ($export_format == php_report::$EXPORT_FORMAT_HTML) {
         $userpage = new usermanagementpage(array('id' => $record->userid, 'action' => 'view'));
         if ($userpage->can_do()) {
             $record->lastname = '<span class="external_report_link"><a href="' . $userpage->get_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;
 }
 /**
  * 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)
 {
     //add entity links
     if ($export_format == table_report::$EXPORT_FORMAT_HTML) {
         //link curriculum name to its "view" page if the the current record has a curriculum
         if (!empty($record->curid) && isset($record->curriculumname)) {
             $page = new curriculumpage(array('id' => $record->curid, 'action' => 'view'));
             if ($page->can_do()) {
                 $url = $page->get_url();
                 $record->curriculumname = '<a href="' . $url . '" target="_blank">' . $record->curriculumname . '</a>';
             }
         } else {
             //non-curriculum course, so use status string with no link
             $record->curriculumname = get_string('noncurriculumcourse', $this->languagefile);
         }
         //link course name to its "view" page
         $page = new coursepage(array('id' => $record->courseid, 'action' => 'view'));
         if ($page->can_do()) {
             $url = $page->get_url();
             $record->coursename = '<a href="' . $url . '" target="_blank">' . $record->coursename . '</a>';
         }
         //link class name to its "view" page
         $page = new cmclasspage(array('id' => $record->classid, 'action' => 'view'));
         if ($page->can_do()) {
             $url = $page->get_url();
             $record->classidnumber = '<a href="' . $url . '" target="_blank">' . $record->classidnumber . '</a>';
         }
     }
     //show environment as N/A if not set
     if (empty($record->envname)) {
         $record->envname = get_string('na', $this->languagefile);
     }
     //format the start date
     $record->startdate = $this->format_date($record->startdate);
     //show number of passed and total number of completion elements
     $record->elementsdisplayed = get_string('compelements_passed', $this->languagefile, $record);
     //convert status id to a display string
     if ($record->completestatusid == STUSTATUS_PASSED) {
         $record->completionstatus = get_string('status_passed', $this->languagefile);
     } else {
         if ($record->completestatusid == STUSTATUS_FAILED) {
             $record->completionstatus = get_string('status_failed', $this->languagefile);
         } else {
             if ($record->completestatusid == STUSTATUS_NOTCOMPLETE) {
                 $record->completionstatus = get_string('status_notcomplete', $this->languagefile);
             } else {
                 $record->completionstatus = get_string('status_notstarted', $this->languagefile);
             }
         }
     }
     //if not passed, shouldn't have any credits
     if ($record->completestatusid != STUSTATUS_PASSED) {
         $record->credits = 0;
     }
     //copy result of complex sub-query into simple field
     $record->creditsdisplayed = $this->format_credits($record->credits);
     //format the completion time
     if ($record->completestatusid == STUSTATUS_NOTCOMPLETE) {
         //not complete, so don't show a completion time
         $record->completetime = '0';
     }
     //only show a completion time if passed
     if ($record->completestatusid == STUSTATUS_PASSED || $record->completestatusid == STUSTATUS_FAILED) {
         $record->completetime = $this->format_date($record->completetime);
     } else {
         $record->completetime = get_string('na', $this->languagefile);
     }
     //display whether the current record is a student or an instructor assignment
     if ($record->isinstructor) {
         $record->classrole = get_string('instructor', $this->languagefile);
     } else {
         $record->classrole = get_string('student', $this->languagefile);
     }
     //handle custom field default values and display logic
     $this->transform_custom_field_data($record);
     return $record;
 }