本文整理汇总了PHP中League\Csv\Writer::insertOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Writer::insertOne方法的具体用法?PHP Writer::insertOne怎么用?PHP Writer::insertOne使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Csv\Writer
的用法示例。
在下文中一共展示了Writer::insertOne方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$experiments = Experiment::active()->get();
$goals = array_unique(Goal::active()->orderBy('name')->lists('name')->toArray());
$columns = array_merge(['Experiment', 'Visitors', 'Engagement'], array_map('ucfirst', $goals));
$writer = new Writer(new SplTempFileObject());
$writer->insertOne($columns);
foreach ($experiments as $experiment) {
$engagement = $experiment->visitors ? $experiment->engagement / $experiment->visitors * 100 : 0;
$row = [$experiment->name, $experiment->visitors, number_format($engagement, 2) . " % (" . $experiment->engagement . ")"];
$results = $experiment->goals()->lists('count', 'name');
foreach ($goals as $column) {
$count = array_get($results, $column, 0);
$percentage = $experiment->visitors ? $count / $experiment->visitors * 100 : 0;
$row[] = number_format($percentage, 2) . " % ({$count})";
}
$writer->insertOne($row);
}
$output = (string) $writer;
if ($file = $this->argument('file')) {
$this->info("Creating {$file}");
File::put($file, $output);
} else {
$this->line($output);
}
}
示例2: writeItem
/**
* Write the given item.
*
* @param mixed $item
*
* @throws LogicException if no valid handle exists.
*/
public function writeItem($item)
{
$this->verifyHandle();
if ($this->autoDetectHeader && !$this->header && is_array($item)) {
$this->header = array_keys($item);
$this->writeItem($this->header);
}
$this->csv->insertOne($item);
}
示例3: generate
/**
* Generate a spreadsheet by transforming 3D data into 2D data.
*
* @param array $filters (optional)
* @return League\Csv\Writer
*/
public function generate(array $filters = [])
{
// Query the repository for filtered set of objects to export
$objects = $this->query($filters);
// Insert headers
$this->data->insertOne($this->getHeaders());
// Add objects as rows
if ($objects) {
// Transform a 3D object into a 2D row
$objects->transform([$this, 'transform']);
// Insert all the objects as rows
$this->data->insertAll($objects->toArray());
}
return $this->data;
}
示例4: getIndex
public function getIndex()
{
$c = Input::get('collection', 'Entity');
$collection = $this->repository->returnCollectionObjectFor($c);
// Filter data for projects for which the authenticated user has permissions.
if (Input::has('authkey')) {
$user = \MongoDB\UserAgent::where('api_key', Input::get('authkey'))->first();
if (is_null($user)) {
return ['error' => 'Invalid auth key: ' . Input::get('authkey')];
}
} elseif (Auth::check()) {
$user = Auth::user();
} else {
return ['error' => 'Authentication required. Please supply authkey.'];
}
$projects = ProjectHandler::getUserProjects($user, Permissions::PROJECT_READ);
$projectNames = array_column($projects, 'name');
$collection = $collection->whereIn('project', $projectNames);
if (Input::has('match')) {
$collection = $this->processFields($collection);
}
$start = (int) Input::get('start', 0);
$limit = (int) Input::get('limit', 100);
$only = Input::get('only', array());
if ($orderBy = Input::get('orderBy')) {
foreach ($orderBy as $sortingColumnName => $sortingDirection) {
$collection = $collection->orderBy($sortingColumnName, $sortingDirection);
}
}
$collection = $collection->paginate($limit, $only);
$pagination = $collection->links()->render();
$count = $collection->toArray();
unset($count['data']);
$documents = $collection->toArray()['data'];
if (array_key_exists('tocsv', Input::all())) {
set_time_limit(1200);
$writer = new Writer(new \SplTempFileObject());
$writer->setNullHandlingMode(Writer::NULL_AS_EMPTY);
$headerDotted = array();
foreach ($documents as $line_index => $row) {
unset($row['metrics'], $row['platformJobId'], $row['results'], $row['cache']);
if (isset($row['parents'])) {
$row['wasDerivedFrom'] = implode(",", $row['parents']);
unset($row['parents']);
}
foreach (array_dot($row) as $k => $v) {
array_push($headerDotted, $k);
}
}
$headerDotted = array_unique($headerDotted);
natcasesort($headerDotted);
$csvHeader = array_change_key_case(str_replace('.', '_', array_values($headerDotted)), CASE_LOWER);
$writer->insertOne($csvHeader);
foreach ($documents as $line_index => $row) {
if (isset($row['parents'])) {
$row['wasDerivedFrom'] = implode(",", $row['parents']);
unset($row['parents']);
}
$row = array_dot($row);
foreach ($headerDotted as $column) {
if (isset($row[$column])) {
$csvRow[str_replace('.', '_', $column)] = $row[$column];
} else {
$csvRow[str_replace('.', '_', $column)] = "";
}
}
$writer->insertOne($csvRow);
}
$writer->output(time() . '.csv');
die;
}
return Response::json(["count" => $count, "pagination" => $pagination, "searchQuery" => Input::except('page'), "documents" => $documents]);
}
示例5: getIndex
/**
* Display a listing of the resource.
*
* @return Response
*/
public function getIndex()
{
//return Input::all();
$c = Input::get('collection', 'Entity');
$collection = $this->repository->returnCollectionObjectFor($c);
if (Input::has('createMetrics')) {
exec('/usr/bin/python2.7 ' . base_path() . '/app/lib/generateMetrics.py \'' . Input::get('createMetrics') . '\' \'entity/text/medical/questiontemplate/1\'', $output, $error);
return json_decode($output[0], true);
}
if (Input::has('field')) {
$collection = $this->processFields($collection);
}
if (!array_key_exists('noCache', Input::all())) {
$collection = $collection->remember(1, md5(serialize(array_values(Input::except('pretty')))));
}
$start = (int) Input::get('start', 0);
$limit = (int) Input::get('limit', 100);
$only = Input::get('only', array());
if (Input::has('datatables')) {
$start = (int) Input::get('iDisplayStart', 0);
$limit = (int) Input::get('iDisplayLength', 100);
$sortingColumnIndex = (int) Input::get('iSortCol_0', 0);
$sortingColumnName = Input::get('mDataProp_' . $sortingColumnIndex, '_id');
$sortingDirection = Input::get('sSortDir_0', 'asc');
$sortingColumnName = $sortingColumnName == "_id" ? "natural" : $sortingColumnName;
$iTotalDisplayRecords = new Entity();
$iTotalDisplayRecords = $this->processFields($iTotalDisplayRecords);
$iTotalDisplayRecords = $iTotalDisplayRecords->count();
$collection = $collection->skip($start)->orderBy($sortingColumnName, $sortingDirection)->take($limit)->get($only);
if ($input = Input::get('field')) {
$iTotalRecords = new Entity();
if (isset($input['format'])) {
$iTotalRecords = $iTotalRecords->whereIn('format', array_flatten([$input['format']]));
}
if (isset($input['domain'])) {
$iTotalRecords = $iTotalRecords->whereIn('domain', array_flatten([$input['domain']]));
}
if (isset($input['documentType'])) {
$iTotalRecords = $iTotalRecords->whereIn('documentType', array_flatten([$input['documentType']]));
}
$iTotalRecords = $iTotalRecords->count();
}
return Response::json(["sEcho" => Input::get('sEcho', 10), "iTotalRecords" => $iTotalRecords, "iTotalDisplayRecords" => $iTotalDisplayRecords, "aaData" => $collection->toArray()]);
}
$collection = $collection->skip($start)->take($limit)->get($only);
if (array_key_exists('getQueryLog', Input::all())) {
return Response::json(\DB::getQueryLog());
}
if (array_key_exists('pretty', Input::all())) {
echo "<pre>";
return json_encode($collection->toArray(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
}
if (array_key_exists('tocsv', Input::all())) {
$documents = $collection->toArray();
$writer = new Writer(new \SplTempFileObject());
$writer->setNullHandlingMode(Writer::NULL_AS_EMPTY);
foreach ($documents as $documentKey => $documentValue) {
if (!isset($documentValue['content']['sentence']['formatted'])) {
$documentValue['content']['sentence']['formatted'] = " ";
}
$this->recur_ksort($documentValue['content']);
$row['_id'] = $documentValue['_id'];
if (isset($documentValue['parents'])) {
$row['wasDerivedFrom'] = implode(",", $documentValue['parents']);
}
$row['content'] = $documentValue['content'];
$row = $documentValue;
if ($documentKey == 0) {
$writer->insertOne(array_change_key_case(str_replace('.', '_', array_keys(array_dot($row))), CASE_LOWER));
}
$row = array_dot($row);
$csvRow = array();
foreach ($row as $columnKey => $columnValue) {
$csvRow[str_replace('.', '_', $columnKey)] = $columnValue;
}
$writer->insertOne($csvRow);
}
$writer->output('test.csv');
die;
// return array_dot($csv);
}
// if(array_key_exists('tocsv', Input::all()))
// {
// $documents = $collection->toArray();
// $writer = new Writer(new \SplTempFileObject);
// foreach($documents as $documentKey => $documentValue)
// {
// if(!isset($documentValue['content']['sentence']['formatted']))
// {
// $documentValue['content']['sentence']['formatted'] = " ";
// }
// $this->recur_ksort($documentValue['content']);
// $row['_id'] = $documentValue['_id'];
// if(isset($documentValue['parents']))
// {
//.........这里部分代码省略.........
示例6: writeItem
/**
* {@inheritdoc}
*/
public function writeItem(array $item)
{
return $this->writer->insertOne($item);
}
示例7: renderContent
/**
* renders content of the csv file
*/
protected function renderContent()
{
foreach ($this->dates as $dates) {
$this->csvWriter->insertOne([$dates['month']->format($this->currentMonthFormat), $dates['salaryDate']->format($this->salaryDateFormat), $dates['bonusDate']->format($this->bonusDateFormat)]);
}
}