Prepares content for csv

@param ActivityLogs $datatable
@param array $data
@return array
559664
protected function prepareContent(ActivityLogs $datatable, array $data)
    {
        $collection = $datatable->query()->get();
        $return     = [];
        foreach ($collection as $log) {
            $element = [];
            foreach ($data as $key => $method) {
                if (method_exists($datatable, $method)) {

                    $called = call_user_func($datatable->{$method}(), $log);
                    $value  = is_object($called) ? $called->__toString() : $called;
                } else {
                    $value = $log->{$key};
                }
                array_push($element, strip_tags($value));
            }
            array_push($return, implode(self::separator, $element));
        }
        return $return;
    }
291413
protected function prepareChartData(StatsTable $stats)
    {
        $totals = $stats->totals()->all();

        return json_encode([
            'labels'   => Arr::pluck($totals, 'label'),
            'datasets' => [
                [
                    'data'                 => Arr::pluck($totals, 'value'),
                    'backgroundColor'      => Arr::pluck($totals, 'color'),
                    'hoverBackgroundColor' => Arr::pluck($totals, 'highlight'),
                ],
            ],
        ]);
    }
180283
private function prepareResponseData($data)
    {
        switch (true)
        {
            case is_object($data):
                if (method_exists($data, 'toArray'))
                {
                    $data = $data->toArray();
                }
                else
                {
                    $data = get_object_vars($data);
                }
                $data = $this->prepareResponseData($data);
                break;
            case is_array($data):
                foreach ($data as $key => $value)
                {
                    $data[$key] = $this->prepareResponseData($value);
                }
                break;
        }
        return $data;
    }
1272819
public static function arrayToXLS(Array $data, String $file = 'excel.xls')
    {
        $file = Base::suffix($file, '.xls');

        header("Content-Disposition: attachment; filename=\"$file\"");
        header("Content-Type: application/vnd.ms-excel;");
        header("Pragma: no-cache");
        header("Expires: 0");

        $output = fopen("php://output", 'w');

        foreach( $data as $column )
        {
            fputcsv($output, $column, "\t");
        }

        fclose($output);
    }
356619
protected function prepareList(array $addresses, array $data)
    {
        $countries = $this->country->getList();

        $list = array();
        foreach ($addresses as $address_id => $address) {

            $list[$address_id] = $address;

            if (empty($data['status'])) {
                continue; // Do not check enabled country, state and city
            }

            if (empty($countries)) {
                continue; // No countries defined in the system
            }

            if ($address['country'] !== '' && $address['country_status'] == 0) {
                unset($list[$address_id]);
                continue;
            }

            if (!empty($address['state_id']) && $address['state_status'] == 0) {
                unset($list[$address_id]);
                continue;
            }

            // City ID can also be not numeric (user input)
            if (is_numeric($address['city_id']) && $address['city_status'] == 0) {
                unset($list[$address_id]);
            }
        }

        return $list;
    }
980584
private function prepareDataForUpdate(array $data)
	{
		$result = array();
		foreach ($data as $key => $value) {
			$result[$key] = array(
				'Action' => AttributeAction::PUT,
				'Value' => array(
					$this->getValueType($value) => $value
				)
			);
		}
		Debugger::barDump($result);
		return $result;
	}
997087
public function prepareContent($data, ParameterBag $options, OutputInterface $output = null)
    {
        if ($output === null) {
            $output = new NullOutput();
        }

        $content = array();

        foreach ($data as $contentTypeId => $items) {
            $progress = new ProgressBar($output, count($items));
            $progress->start();

            foreach ($items as $contentValue) {
                $contentValue = $contentValue->valueObject;
                $contentType = $this->contentTypeService->loadContentType($contentValue->contentInfo->contentTypeId);
                $location = $this->locationService->loadLocation($contentValue->contentInfo->mainLocationId);
                $language = $options->get('lang', $location->contentInfo->mainLanguageCode);
                $this->value->setFieldDefinitionsList($contentType);

                $content[$contentTypeId][$contentValue->id] = array(
                    'contentId' => $contentValue->id,
                    'contentTypeId' => $contentType->id,
                    'identifier' => $contentType->identifier,
                    'language' => $language,
                    'publishedDate' => $contentValue->contentInfo->publishedDate->format('c'),
                    'author' => $this->getAuthor($contentValue, $contentType),
                    'uri' => $this->generator->generate($location, array(), false),
                    'mainLocation' => array(
                        'href' => '/api/ezp/v2/content/locations' . $location->pathString,
                    ),
                    'locations' => array(
                        'href' => '/api/ezp/v2/content/objects/' . $contentValue->id . '/locations',
                    ),
                    'categoryPath' => $location->pathString,
                    'fields' => array(),
                );

                $fields = $this->prepareFields($contentType, $options->get('fields'));
                if (!empty($fields)) {
                    foreach ($fields as $field) {
                        $field = $this->value->getConfiguredFieldIdentifier($field, $contentType);
                        $content[$contentTypeId][$contentValue->id]['fields'][$field] =
                            $this->value->getFieldValue($contentValue, $field, $language, $options->all());
                    }
                }

                $progress->advance();
            }

            $progress->finish();
            $output->writeln('');
        }

        return $content;
    }
805705
protected function _prepareEvent($eventName, array $data = [])
    {
        if (is_array($eventName)) {
            list($eventName, $subject) = $eventName;
        } else {
            $subject = new EventDispatcher();
        }

        return new Event($eventName, $subject, $data);
    }
973118
public function logs(Request $request, DataTables $dataTables)
    {
        if ($request->input('l')) {
            LaravelLogViewer::setFile(base64_decode($request->input('l')));
        }

        if ($request->input('dl')) {
            return response()->download(LaravelLogViewer::pathToLogFile(base64_decode($request->input('dl'))));
        } elseif ($request->has('del')) {
            File::delete(LaravelLogViewer::pathToLogFile(base64_decode($request->input('del'))));

            return redirect()->to($request->url());
        }

        $logs = LaravelLogViewer::all();

        if ($request->wantsJson()) {
            return $dataTables->collection(collect($logs))
                              ->editColumn('stack', '{!! nl2br($stack) !!}')
                              ->editColumn('level', function ($log) {
                                  $content = html()->tag('span', '', [
                                      'class' => "glyphicon glyphicon-{$log['level_img']}-sign",
                                  ]);

                                  $content .= '&nbsp;' . $log['level'];

                                  return html()->tag('span', $content, ['class' => "text-{$log['level_class']}"]);
                              })
                              ->addColumn('content', function ($log) {
                                  $html = '';
                                  if ($log['stack']) {
                                      $html = '<a class="pull-right expand btn btn-default btn-xs"><span class="glyphicon glyphicon-search"></span></a>';
                                  }

                                  $html .= $log['text'];

                                  if (isset($log['in_file'])) {
                                      $html .= '<br>' . $log['in_file'];
                                  }

                                  return $html;
                              })
                              ->rawColumns(['content'])
                              ->toJson();
        }

        return view('administrator.utilities.log', [
            'logs'         => $logs,
            'files'        => LaravelLogViewer::getFiles(true),
            'current_file' => LaravelLogViewer::getFileName(),
        ]);
    }
1233886
public function dataTableAction()
    {
        $source = $this->getSource();
        $table = new TableExample\DataTable();
        $table->setAdapter($this->getDbAdapter())
                ->setSource($source)
                ->setParamAdapter(new AdapterDataTables($this->getRequest()->getPost()))
        ;

        return new ViewModel(array(
            'tableDataTable' => $table,
        ));
    }
1039359
public function getTemplateData($data = [])
    {
        // generate fields
        $fillableColumns = $this->schemaParser->getFillableFields($data['TABLE_NAME']);
        logger($fillableColumns);

        $faker = Factory::create();

        $fieldStr = [];
        foreach ($fillableColumns as $column) {
            try {
                if ($column['field'] === 'password') {
                    $func = 'bcrypt(str_random(10))';
                } else {
                    $faker->getFormatter($column['field']);

                    $func = '$faker->'.$column['field'];
                }
            } catch (\Exception $e) {
                logger($column['type']);
                switch ($column['type']) {
                    case 'tinyInteger':
                        $func = '$faker->randomNumber(2)';
                        break;
                    case 'smallInteger':
                        $func = '$faker->randomNumber(2)';
                        break;
                    case 'mediumInteger':
                        $func = '$faker->randomNumber(4)';
                        break;
                    case 'integer':
                        $func = '$faker->randomNumber(8)';
                        break;
                    case 'char':
                    case 'string':
                        logger($column['field']);
                        if (isset($column['args']) && !empty($column['args'])) {
                            $max = $column['args'];
                        } else {
                            $max = 100;
                        }
                        $func = "str_random($max)";
                        break;
                    case 'text':
                    case 'boolean':
                        $func = '$faker->'.$column['type'].'()';
                        break;
                    case 'date':
                        $func = '$faker->'.'dateTimeBetween()';
                        break;
                    default:
                        $func = '';
                }
            }

            if (!empty($func)) {
                $fieldStr[] = "'".$column['field']."' => ".$func;
            }
            
        }
        $data['FIELDS'] = implode(",\n\t\t", $fieldStr);

        return $data;
    }
1081959
public function toCsv(ResultSetInterface $resultSet, array $fields, Table $table) : array
    {
        if ($resultSet->isEmpty()) {
            return [];
        }

        $alias = $table->getAlias();

        $result = [];
        foreach ($resultSet as $key => $entity) {
            foreach ($fields as $field) {
                list($tableName, $fieldName) = explode('.', $field);
                // current table field
                if ($alias === $tableName) {
                    $result[$key][$field] = $entity->get($fieldName);
                    continue;
                }

                if (!$entity->get('_matchingData')) {
                    continue;
                }

                if (!isset($entity->_matchingData[$tableName])) {
                    continue;
                }
                // associated table field
                $result[$key][$field] = $entity->_matchingData[$tableName]->get($fieldName);
            }
        }

        return $result;
    }
1342446
protected function prepareDatasourceFiles(array $datasourceFiles)
    {

        // initialize the array for the prepared datasources
        $ds = array();

        // prepare the datasources
        foreach ($datasourceFiles as $datasourceFile) {
            // explode the directoriy names from the app base path
            $contextPath = explode(DIRECTORY_SEPARATOR, ltrim(str_replace(sprintf('%s', $this->getAppBase()), '', $datasourceFile), DIRECTORY_SEPARATOR));
            // the first element IS the context name
            $contextName = reset($contextPath);
            // create the path to the web application
            $webappPath = $this->getDatasourceService()->getWebappsDir($this->getContainer()->getContainerNode(), $contextName);
            // append it to the array with the prepared datasources
            $ds[] = array($datasourceFile, $webappPath, $contextName);
        }

        // return the array with the prepared datasources
        return $ds;
    }
1061740
protected function prepareData($data)
    {
        $callback = function ($value) {
            return $value !== null && $value !== [] && $value !== '';
        };

        foreach ($data as &$value) {
            if (is_array($value)) {
                $value = $this->prepareData($value);
            }
        }
        return array_filter($data, $callback);
    }
892479
public static function getDataList($dataFiled = 'text')
    {
        $result = [];
        foreach (static::getData() as $key => $value) {
            $result[$key] = $value[$dataFiled];
        }
        return $result;
    }
676700
private static function _arr2xml($data, $content = '')
    {
        foreach ($data as $key => $val) {
            is_numeric($key) && $key = 'item';
            $content .= "<{$key}>";
            if (is_array($val) || is_object($val)) {
                $content .= self::_arr2xml($val);
            } elseif (is_string($val)) {
                $content .= '<![CDATA[' . preg_replace("/[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]/", '', $val) . ']]>';
            } else {
                $content .= $val;
            }
            $content .= "</{$key}>";
        }
        return $content;
    }
302407
private function prepareRecord(array $data, array $rules, array $messages)
    {
        // Reset error bag
        $this->errors = new MessageBag;

        // Capture data
        $this->setDataset($data);
        $this->setRuleset($rules);
        $this->setMessageset($messages);

        // Fill model
        $this->fillModel();
    }