/** * createPdf * * @param mixed $params params * @param mixed $event event * * @access public * @return void */ function createPDF($params, $event) { App::import('Vendor', 'xtcpdf'); $this->User = ClassRegistry::init('User'); $this->GroupsMembers = ClassRegistry::init('GroupsMembers'); $this->responseModelName = EvaluationResponseBase::$types[$event['Event']['event_template_type_id']]; $this->responseModel = ClassRegistry::init($this->responseModelName); $epdf = new XTCPDF(); // Construct the filename and extension $fileName = !empty($params['file_name']) ? $params['file_name'] . '.pdf' : date('m.d.y') . '.pdf'; $epdf->AddPage(); $courseName = $params['include']['course'] ? ': ' . $event['Course']['course'] : ''; $eventName = $params['include']['eval_event_names'] ? ' - ' . $event['Event']['title'] : ''; $headerText = '<h2>Evaluation Event Detail' . $courseName . $eventName . '</h2>'; $epdf->writeHTML($headerText, true, false, true, false, ''); $pageCount = 0; foreach ($event['GroupEvent'] as $groupEvent) { $grpEventId = $groupEvent['id']; $grpId = $groupEvent['group_id']; // write group/event details $evalDetails = $this->_writeEvalDetails($event, $grpId, $params); $epdf->writeHTML($evalDetails, true, false, true, false, ''); // get incomplete/unenrolled members $submitted = $this->responseModel->findAllByGrpEventId($grpEventId); $members = Set::extract('/GroupsMembers/user_id', $this->GroupsMembers->findAllByGroupId($grpId)); $evaluators = Set::extract('/' . $this->responseModelName . '/evaluator', $submitted); $evaluatees = Set::extract('/' . $this->responseModelName . '/evaluatee', $submitted); $inComplete = array_diff($members, $evaluators); $inComplete = empty($inComplete) ? array() : $this->User->getFullNames($inComplete); $unEnrolled = array_diff(array_unique(array_merge($evaluators, $evaluatees)), $members); $unEnrolled = empty($unEnrolled) ? array() : $this->User->getFullNames($unEnrolled); $title = !empty($inComplete) || !empty($unEnrolled) ? __('Summary', true) : ''; $epdf->writeHTML('<br><h3>' . $title . '</h3>', true, false, true, false, ''); $title = !empty($inComplete) ? __('Members who have not submitted their evaluations', true) : ''; $epdf->writeHTML('<p><b>' . $title . '</b></p>', true, false, true, false, ''); foreach ($inComplete as $name) { $epdf->writeHTML($name, true, false, true, false, ''); } $title = !empty($unEnrolled) ? __('Left the group, but had submitted or were evaluated', true) : ''; $epdf->writeHTML('<p><b>' . $title . '</b></p>', true, false, true, false, ''); foreach ($unEnrolled as $name) { $epdf->writeHTML($name, true, false, true, false, ''); } $header = '<h3>' . __('Evaluation Results', true) . '</h3><br>'; // broke the summary table and details section into two switch blocks // would be more efficient if the user is filtering out sections if ($params['include']['grade_tables']) { switch ($event['Event']['event_template_type_id']) { case 1: $table = $this->_writeScoresTbl($event, $grpEventId, $grpId, $params); break; case 2: $table = $this->_writeRubricResultsTbl($event, $grpEventId, $grpId, $params); break; case 4: $table = $this->_writeMixResultsTbl($event, $grpEventId, $grpId, $params); break; } if (!empty($table)) { $epdf->writeHTML('<br>', true, false, true, false, ''); } $epdf->writeHTML($table, true, false, true, false, ''); } switch ($event['Event']['event_template_type_id']) { case 1: $results = $params['include']['comments'] ? $this->_writeComments($grpEventId) : ''; $header = $params['include']['comments'] ? '<h3>' . __('Comments', true) . '</h3><br>' : ''; break; case 2: $results = $this->_writeRubricEvalResults($event, $grpEventId, $grpId, $params); break; case 4: $results = $this->_writeMixEvalResults($event, $grpEventId, $grpId, $params); break; } $epdf->writeHTML($header, true, false, true, false, ''); $epdf->writeHTML($results, true, false, true, false, ''); $epdf->lastPage(); $epdf->addPage(); $pageCount++; } $epdf->deletePage($epdf->getNumPages()); if (ob_get_contents()) { ob_clean(); } return $epdf->Output($fileName, 'I'); }