Ejemplo n.º 1
0
 public function build($view = '')
 {
     $view == '' and $view = 'rapyd::datagrid';
     parent::build();
     foreach ($this->data as $tablerow) {
         $row = new Row();
         foreach ($this->columns as $column) {
             $cell = new Cell();
             $value = $this->getCellValue($column, $tablerow);
             $cell->value($value);
             $row->add($cell);
         }
         if ($this->row_callable) {
             $callable = $this->row_callable;
             $callable($row);
         }
         $this->rows[] = $row;
     }
     return \View::make($view, array('dg' => $this, 'buttons' => $this->button_container, 'label' => $this->label));
 }
Ejemplo n.º 2
0
 protected function makeRow($item)
 {
     $row = new Row($item);
     $row->children = array();
     $row->attributes(array('class' => 'datatree-item', 'data-id' => $row->data->getKey()));
     $index = 0;
     foreach ($this->columns as $column) {
         $index++;
         $cell = new Cell($column->name);
         $attrs = array();
         $attrs['data-field-name'] = strpos($column->name, '{{') === false ? $column->name : '_blade_' . $index;
         $cell->attributes($attrs);
         $sanitize = count($column->filters) || $column->cell_callable ? false : true;
         $value = $this->getCellValue($column, $item, $sanitize);
         $cell->value($value);
         $cell->parseFilters($column->filters);
         if ($column->cell_callable) {
             $callable = $column->cell_callable;
             $cell->value($callable($cell->value));
         }
         $row->add($cell);
     }
     if (count($this->row_callable)) {
         foreach ($this->row_callable as $callable) {
             $callable($row);
         }
     }
     return $row;
 }
 public function buildCSV($file = '', $timestamp = '', $sanitize = true, $del = array())
 {
     $this->limit = null;
     parent::build();
     $segments = \Request::segments();
     $filename = $file != '' ? basename($file, '.csv') : end($segments);
     $filename = preg_replace('/[^0-9a-z\\._-]/i', '', $filename);
     $filename .= $timestamp != "" ? date($timestamp) . ".csv" : ".csv";
     $save = (bool) strpos($file, "/");
     //Delimiter
     $delimiter = array();
     $delimiter['delimiter'] = isset($del['delimiter']) ? $del['delimiter'] : ';';
     $delimiter['enclosure'] = isset($del['enclosure']) ? $del['enclosure'] : '"';
     $delimiter['line_ending'] = isset($del['line_ending']) ? $del['line_ending'] : "\n";
     if ($save) {
         $handle = fopen(public_path() . '/' . dirname($file) . "/" . $filename, 'w');
     } else {
         $headers = array('Content-Type' => 'text/csv', 'Pragma' => 'no-cache', '"Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Content-Disposition' => 'attachment; filename="' . $filename . '"');
         $handle = fopen('php://output', 'w');
         ob_start();
     }
     fputs($handle, $delimiter['enclosure'] . implode($delimiter['enclosure'] . $delimiter['delimiter'] . $delimiter['enclosure'], $this->headers) . $delimiter['enclosure'] . $delimiter['line_ending']);
     foreach ($this->data as $tablerow) {
         $row = new Row($tablerow);
         foreach ($this->columns as $column) {
             if (in_array($column->name, array("_edit"))) {
                 continue;
             }
             $cell = new Cell($column->name);
             $value = str_replace('"', '""', str_replace(PHP_EOL, '', strip_tags($this->getCellValue($column, $tablerow, $sanitize))));
             $cell->value($value);
             $row->add($cell);
         }
         if (count($this->row_callable)) {
             foreach ($this->row_callable as $callable) {
                 $callable($row);
             }
         }
         fputs($handle, $delimiter['enclosure'] . implode($delimiter['enclosure'] . $delimiter['delimiter'] . $delimiter['enclosure'], $row->toArray()) . $delimiter['enclosure'] . $delimiter['line_ending']);
     }
     fclose($handle);
     if ($save) {
         //redirect, boolean or filename?
     } else {
         $output = ob_get_clean();
         return \Response::make(rtrim($output, "\n"), 200, $headers);
     }
 }
Ejemplo n.º 4
0
 public function buildCSV($file = '', $timestamp = '', $sanitize = true, $del = array())
 {
     $this->limit = null;
     parent::build();
     $segments = \Request::segments();
     $filename = $file != '' ? basename($file, '.csv') : end($segments);
     $filename = preg_replace('/[^0-9a-z\\._-]/i', '', $filename);
     $filename .= $timestamp != "" ? date($timestamp) . ".csv" : ".csv";
     $save = (bool) strpos($file, "/");
     //Delimiter
     $delimiter = array();
     $delimiter['delimiter'] = isset($del['delimiter']) ? $del['delimiter'] : ';';
     $delimiter['enclosure'] = isset($del['enclosure']) ? $del['enclosure'] : '"';
     $delimiter['line_ending'] = isset($del['line_ending']) ? $del['line_ending'] : "\n";
     if ($save) {
         $handle = fopen(public_path() . '/' . dirname($file) . "/" . $filename, 'w');
     } else {
         $headers = array('Content-Type' => 'text/csv', 'Pragma' => 'no-cache', '"Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Content-Disposition' => 'attachment; filename="' . $filename . '"');
         $handle = fopen('php://output', 'w');
         ob_start();
     }
     fputs($handle, $delimiter['enclosure'] . implode($delimiter['enclosure'] . $delimiter['delimiter'] . $delimiter['enclosure'], $this->headers) . $delimiter['enclosure'] . $delimiter['line_ending']);
     foreach ($this->data as $tablerow) {
         $row = new Row($tablerow);
         foreach ($this->columns as $column) {
             if (in_array($column->name, array("_edit"))) {
                 continue;
             }
             $cell = new Cell($column->name);
             $value = str_replace('"', '""', str_replace(PHP_EOL, '', strip_tags($this->getCellValue($column, $tablerow, $sanitize))));
             // Excel for Mac is pretty stupid, and will break a cell containing \r, such as user input typed on a
             // old Mac.
             // On the other hand, PHP will not deal with the issue for use, see for instance:
             // http://stackoverflow.com/questions/12498337/php-preg-replace-replacing-line-break
             // We need to normalize \r and \r\n into \n, otherwise the CSV will break on Macs
             $value = preg_replace('/\\r\\n|\\n\\r|\\n|\\r/', "\n", $value);
             $cell->value($value);
             $row->add($cell);
         }
         if (count($this->row_callable)) {
             foreach ($this->row_callable as $callable) {
                 $callable($row);
             }
         }
         fputs($handle, $delimiter['enclosure'] . implode($delimiter['enclosure'] . $delimiter['delimiter'] . $delimiter['enclosure'], $row->toArray()) . $delimiter['enclosure'] . $delimiter['line_ending']);
     }
     fclose($handle);
     if ($save) {
         //redirect, boolean or filename?
     } else {
         $output = ob_get_clean();
         return \Response::make(rtrim($output, "\n"), 200, $headers);
     }
 }