Esempio n. 1
0
 /**
  * Render mr_file_export
  *
  * @param mr_file_export $export mr_file_export instance
  * @return string
  */
 protected function render_mr_file_export(mr_file_export $export)
 {
     $select = new url_select($export->get_url_select_options(), '');
     $select->set_label(get_string('export', 'local_mr'));
     return html_writer::tag('div', $this->output->render($select), array('class' => 'mr_file_export'));
 }
Esempio n. 2
0
 /**
  * Extract column data from a row while trying
  * to keep everything in the same order as the
  * columns.  Generally, don't need to call this
  * method unless you are micro managing an export.
  *
  * @param mixed $row Can be an object, array or html_table_row (if this, then ensure proper cell ordering!)
  * @return array
  */
 public function extract_data($row)
 {
     if (is_object($row)) {
         $row = (array) $row;
     }
     $data = array();
     $columns = $this->get_columns(true);
     // Try our best with html_table_row
     if ($row instanceof html_table_row) {
         foreach ($row->cells as $cell) {
             if ($cell instanceof html_table_cell) {
                 $data[] = $cell->text;
             } else {
                 $data[] = $cell;
             }
         }
     } else {
         foreach ($columns as $key => $column) {
             if ($this->export instanceof mr_file_export and $this->export->is_exporting() and !$column->get_config()->export) {
                 unset($columns[$key]);
                 continue;
             }
             $cell = $column->get_cell($row);
             if ($cell instanceof html_table_cell) {
                 $data[] = $cell->text;
             } else {
                 $data[] = $cell;
             }
         }
     }
     // Make sure we return even number of columns
     if (count($data) < count($columns)) {
         $data = array_pad($data, count($columns), '');
     }
     return $data;
 }
Esempio n. 3
0
 /**
  * Export report
  *
  * Example Code:
  * <code>
  * <?php
  *      $report = new some_report_class(...);
  *      $file   = $report->export('text/csv');
  *
  *      // Do something with $file, then to delete it...
  *      $report->get_export()->cleanup();
  * ?>
  * </code>
  *
  * @param string $exporter The exporter to use, like 'text/csv'
  * @param string $filename Override the file name
  * @return string The file path
  */
 public function export($exporter, $filename = NULL)
 {
     // Initialize the table and the filters
     $this->table_init();
     $this->filter_init();
     if ($this->filter instanceof mr_html_filter) {
         $this->filter->set_report($this);
     }
     // Set the exporter
     $this->export->init($exporter, $filename);
     // Send rows to export
     $this->table_fill();
     // Return the file
     return $this->export->close();
 }
Esempio n. 4
0
 /**
  * Set the export instance
  *
  * This will set the limitfrom and limitnum
  * appropriately for exporting
  *
  * @param mr_file_export $export The export plugin
  * @return mr_html_paging
  */
 public function set_export($export)
 {
     if ($export->is_exporting()) {
         // Start from the beginning
         $this->page = 0;
         // Grab as many rows as the exporter can handle
         $this->perpage = $export->instance()->max_rows();
     }
     return $this;
 }