/**
  * Process DT Row Data and Attr.
  *
  * @param string $attribute
  * @param array $template
  * @return $this
  */
 public function rowData($attribute, array $template)
 {
     if (count($template)) {
         $this->data[$attribute] = [];
         foreach ($template as $key => $value) {
             $this->data[$attribute][$key] = Helper::compileContent($value, $this->data, $this->row);
         }
     }
     return $this;
 }
Esempio n. 2
0
 /**
  * @inheritdoc
  */
 public function ordering()
 {
     foreach ($this->request->orderableColumns() as $orderable) {
         $column = $this->getColumnName($orderable['column']);
         $this->collection = $this->collection->sortBy(function ($row) use($column) {
             $row = Helper::castToArray($row);
             return $row[$column];
         });
         if ($orderable['direction'] == 'desc') {
             $this->collection = $this->collection->reverse();
         }
     }
 }
Esempio n. 3
0
 /**
  * Render json response.
  *
  * @param bool $object
  * @return \Illuminate\Http\JsonResponse
  */
 public function render($object = false)
 {
     $output = array_merge(['draw' => (int) $this->request['draw'], 'recordsTotal' => $this->totalRecords, 'recordsFiltered' => $this->filteredRecords], $this->appends);
     if (isset($this->transformer)) {
         $fractal = app('datatables.fractal');
         if ($this->serializer) {
             $fractal->setSerializer(new $this->serializer());
         }
         //Get transformer reflection
         //Firs method parameter should be data/object to transform
         $reflection = new \ReflectionMethod($this->transformer, 'transform');
         $parameter = $reflection->getParameters()[0];
         //If parameter is class assuming it requires object
         //Else just pass array by default
         if ($parameter->getClass()) {
             $resource = new Collection($this->results(), $this->createTransformer());
         } else {
             $resource = new Collection($this->getProcessedData($object), $this->createTransformer());
         }
         $collection = $fractal->createData($resource)->toArray();
         $output['data'] = $collection['data'];
     } else {
         $output['data'] = Helper::transform($this->getProcessedData($object));
     }
     if ($this->isDebugging()) {
         $output = $this->showDebugger($output);
     }
     return new JsonResponse($output);
 }
 /**
  * Build Query Builder Parameters.
  *
  * @return array
  */
 protected function parameterize()
 {
     $args = func_get_args();
     $keyword = count($args) > 2 ? $args[2] : $args[1];
     $parameters = Helper::buildParameters($args);
     $parameters = Helper::replacePatternWithKeyword($parameters, $keyword, '$1');
     return $parameters;
 }
Esempio n. 5
0
 /**
  * Wrap a column and cast in pgsql
  *
  * @param  string $column
  * @return string
  */
 public function castColumn($column)
 {
     $column = Helper::wrapDatabaseValue($this->database, $column);
     if ($this->database === 'pgsql') {
         $column = 'CAST(' . $column . ' as TEXT)';
     }
     return $column;
 }
 /**
  * Process edit columns.
  *
  * @param array $data
  * @param mixed $row
  * @return array
  */
 protected function editColumns(array $data, $row)
 {
     foreach ($this->editColumns as $key => $value) {
         $value['content'] = Helper::compileContent($value['content'], $data, $row);
         $data[$value['name']] = $value['content'];
     }
     return $data;
 }
Esempio n. 7
0
 /**
  * Render json response.
  *
  * @param bool $object
  * @return \Illuminate\Http\JsonResponse
  */
 public function render($object = false)
 {
     $processor = new DataProcessor($this->results(), $this->columnDef, $this->templates);
     $data = $processor->process($object);
     $output = ['draw' => (int) $this->request['draw'], 'recordsTotal' => $this->totalRecords, 'recordsFiltered' => $this->filteredRecords];
     if (isset($this->transformer)) {
         $fractal = new Manager();
         $resource = new Collection($data, new $this->transformer());
         $collection = $fractal->createData($resource)->toArray();
         $output['data'] = $collection['data'];
     } else {
         $output['data'] = Helper::transform($data);
     }
     if ($this->isDebugging()) {
         $output = $this->showDebugger($output);
     }
     return new JsonResponse($output);
 }
Esempio n. 8
0
 /**
  * Process edit columns.
  *
  * @param mixed $data
  * @param mixed $row
  * @return array
  */
 protected function editColumns($data, $row)
 {
     foreach ($this->editColumns as $key => $value) {
         $value['content'] = Helper::compileContent($value['content'], $data, $row);
         Arr::set($data, $value['name'], $value['content']);
     }
     return $data;
 }
 /**
  * Render json response.
  *
  * @param bool $object
  * @return \Illuminate\Http\JsonResponse
  */
 public function render($object = false)
 {
     $output = ['draw' => (int) $this->request['draw'], 'recordsTotal' => $this->totalRecords, 'recordsFiltered' => $this->filteredRecords];
     if (isset($this->transformer)) {
         $fractal = new Manager();
         if ($this->request->get('include')) {
             $fractal->parseIncludes($this->request->get('include'));
         }
         $serializer = $this->serializer ?: Config::get('datatables.fractal.serializer', 'League\\Fractal\\Serializer\\DataArraySerializer');
         $fractal->setSerializer(new $serializer());
         //Get transformer reflection
         //Firs method parameter should be data/object to transform
         $reflection = new \ReflectionMethod($this->transformer, 'transform');
         $parameter = $reflection->getParameters()[0];
         //If parameter is class assuming it requires object
         //Else just pass array by default
         if ($parameter->getClass()) {
             $resource = new Collection($this->results(), new $this->transformer());
         } else {
             $resource = new Collection($this->getProcessedData($object), new $this->transformer());
         }
         $collection = $fractal->createData($resource)->toArray();
         $output['data'] = $collection['data'];
     } else {
         $output['data'] = Helper::transform($this->getProcessedData($object));
     }
     if ($this->isDebugging()) {
         $output = $this->showDebugger($output);
     }
     foreach ($this->anotherData as $key => $value) {
         $output[$key] = $value;
     }
     return new JsonResponse($output);
 }
 public function test_replace_pattern_with_keyword()
 {
     $subject = ['foo in ?', ['$1']];
     $keyword = 'bar';
     $result = Helper::replacePatternWithKeyword($subject, $keyword, '$1');
     $this->assertEquals(['foo in ?', ['bar']], $result);
 }