예제 #1
0
 /**
  * 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;
 }
 /**
  * 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;
 }
예제 #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 = new Manager();
         if ($this->request->get('include')) {
             $fractal->parseIncludes($this->request->get('include'));
         }
         $serializer = $this->serializer ?: Config::get('datatables.fractal.serializer', DataArraySerializer::class);
         $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);
     }
     return new JsonResponse($output);
 }
예제 #4
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);
         $data[$value['name']] = $value['content'];
     }
     return $data;
 }