/** * Add relevant header info to the pdf output * * @param object $newpdf The report pdf we are creating */ public function print_pdf_header($newpdf) { global $CFG; //obtain margins $margins = $newpdf->getMargins(); //initial y position $initial_y = $newpdf->getY() + 0.08; // ELIS-3167: + 0.08 bottom-of-line //determine page with, not including margins $effective_page_width = $newpdf->getPageWidth() - $margins['left'] - $margins['right']; //store the original font size $old_font_size = $newpdf->getFontSizePt(); //use a large font size for the header info $newpdf->setFontSize(12); //used to track vertical positioning $i = 0; //render any appropriate text for each header if ($header_info = $this->get_gas_gauge_header_info()) { foreach ($header_info as $header_entry) { //render across $newpdf->Cell($effective_page_width, 0, $header_entry, 0, 0, 'C'); //draw a line below the text $line_top = $initial_y + 0.2 * $i + 0.1; $newpdf->Line($margins['left'], $line_top, $margins['left'] + $effective_page_width, $line_top); //add necessary spacing $newpdf->Ln(0.2); $i++; } } //if the max value is not zero, render the gas gauge if ($this->gas_gauge_max_value != 0) { //retrieve the color palette as defined by the report $palette = $this->get_gas_gauge_color_palette(); //approximate pixels using points $actual_radius = PHP_REPORT_GAS_GAUGE_MAXIMUM_WIDTH / 2 / 72; //set up the variables needed by the gas-gauge-generating script //current value on the gas gauge $passthru_value = $this->gas_gauge_value; //maximum value on the gauge $passthru_total = $this->gas_gauge_max_value; //radius of the gas gauge $passthru_radius = PHP_REPORT_GAS_GAUGE_MAXIMUM_WIDTH; //colour palette to use (also specifies number of sections) $passthru_palette = $palette; //indicate that we are persisting the image $passthru_persist = 1; //filename to save the image to $passthru_filename = tempnam($CFG->dataroot . '/temp', 'gas_gauge_'); //generate the necessary image file $gas_gauge_url = $CFG->dirroot . '/local/elisreports/gas_gauge_output.php'; require_once($gas_gauge_url); //leftmost position of the gas gauge $left_position = $newpdf->getPageWidth() / 2 - $actual_radius; //vertical offset, based on number of headers $top_position = $initial_y + 0.2 * count($header_info) + 0.1; //draw the gas gauge and add appropriate vertical space $newpdf->Image($passthru_filename, $left_position, $top_position, 2 * $actual_radius, $actual_radius, 'png'); $newpdf->Ln($actual_radius + 0.2); //delete the temporary image file unlink($passthru_filename); } //revert the font size to its initial value $newpdf->setFontSize($old_font_size); }
/** * Displays the items in the $items array as a bulleted or ordered list * * @param array $items * @param array $options * @param bool $ordered */ public static function alist(array $items, $options = array(), $ordered = false) { //Save x $bak_x = $pdf->x; if ($ordered) { $bullet = '•'; } else { $bullet = 1; } for ($i = 0; $i < count($items); $i++) { //Get bullet width including margin $blt_width = self::$pdf->GetStringWidth($bullet . $options['margin']) + self::$pdf->cMargin * 2; // SetX self::$pdf->SetX($bak_x); //Output indent if ($options['indent'] > 0) { self::$pdf->Cell($options['indent']); } //Output bullet self::$pdf->Cell($blt_width, $h, $bullet . $options['margin'], 0, '', $fill); $items[$i] = self::decode_utf8($items[$i]); //Output text self::$pdf->MultiCell($w - $blt_width, $h, $items[$i], $border, $align, $fill); //Insert a spacer between items if not the last item if ($i != count($items) - 1) { self::$pdf->Ln($options['spacer']); } //Increment bullet if it's a number if (is_numeric($bullet)) { $bullet++; } } //Restore x self::$pdf->x = $bak_x; return $pdf; }