/** * Export the data in the model into a particular format. Formats depend on * the formats available in the reports api. * @param $params * @return unknown_type * @see Report */ public function export($params) { switch ($params[0]) { case "pdf": $report = new PDFReport(); break; case "html": $report = new HTMLReport(); $report->htmlHeaders = true; break; case "csv": if ($params[1] == "") { $report = new CSVReport(); $this->model->datastore->dateFormat = 2; } else { if ($params[1] == "template") { $report = new CSVReport(); $table = new TableContent($this->model->getLabels(), array()); $report->add($table); $report->output(); } } break; case "xls": $report = new XLSReport(); break; } $title = new TextContent($this->label); $title->style["size"] = 12; $title->style["bold"] = true; $headers = $this->model->getLabels(); $fieldNames = $this->model->getFieldNames(); array_shift($fieldNames); $data = $this->model->get(array("fields" => $fieldNames)); //$data = $this->model->formatData(); $table = new TableContent($headers, $data); $table->style["decoration"] = true; $report->add($title, $table); $report->output(); }
/** * Export the data in the model into a particular format. Formats depend on * the formats available in the reports api. * @param $params * @return unknown_type * @see Report */ public function export($params) { $fields = $this->getForm()->getFields(); $fieldNames = array(); $headers = array(); foreach ($fields as $field) { $fieldNames[] = $field->getName(); $headers[] = $field->getLabel(); } switch ($params[0]) { case "pdf": $report = new PDFReport(); break; case "html": $report = new HTMLReport(); $report->htmlHeaders = true; break; case "csv": if ($params[1] == "") { $report = new CSVReport(); $report->setDownloadFileName("{$this->model->name}.csv"); $this->model->datastore->dateFormat = 2; } else { if ($params[1] == "template") { $report = new CSVReport(); $report->setDownloadFileName("{$this->model->name}_template.csv"); $table = new TableContent($headers, array()); $report->add($table); $report->output(); die; } } break; case "xls": $report = new XLSReport(); break; } $title = new TextContent($this->label); $title->style["size"] = 12; $title->style["bold"] = true; $this->model->setQueryResolve(false); $data = $this->model->get(array("fields" => $fieldNames)); foreach ($data as $j => $row) { for ($i = 0; $i < count($row); $i++) { $fields[$i]->setValue($row[$fieldNames[$i]]); $data[$j][$fieldNames[$i]] = strip_tags($fields[$i]->getDisplayValue()); } } $table = new TableContent($headers, $data); $table->style["decoration"] = true; $report->add($title, $table); $report->output(); die; }