本文整理汇总了PHP中League\Csv\Writer::setNullHandlingMode方法的典型用法代码示例。如果您正苦于以下问题:PHP Writer::setNullHandlingMode方法的具体用法?PHP Writer::setNullHandlingMode怎么用?PHP Writer::setNullHandlingMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Csv\Writer
的用法示例。
在下文中一共展示了Writer::setNullHandlingMode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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']))
// {
//.........这里部分代码省略.........
示例2: 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]);
}
示例3: sprintf
echo 'Error: ' . $e->getMessage();
exit;
}
echo PHP_EOL;
echo sprintf('%s open and %s closed issues pulled…', (string) count($issues['open']), (string) count($issues['closed']));
// Set up the header rows for the CSV
$toWrite = [['url', 'number', 'title', 'status', 'assignee', 'milestone', 'created_at', 'updated_at', 'body']];
$prCount = 0;
// Set up the data rows for the CSV
foreach ($issues as $states) {
foreach ($states as $issue) {
// Strip out pull requests
if (strpos($issue['html_url'], '/pull/')) {
++$prCount;
continue;
}
$assignee = $issue['assignee'] == null ? '' : $issue['assignee']['login'];
$milestone = $issue['milestone'] == null ? '' : $issue['milestone']['number'] . ': ' . $issue['milestone']['title'];
$toWrite[] = [$issue['html_url'], $issue['number'], $issue['title'], $issue['state'], $assignee, $milestone, $issue['created_at'], $issue['updated_at'], $issue['body']];
}
}
echo PHP_EOL;
echo sprintf('Stripping out %s pull requests…', (string) $prCount);
echo PHP_EOL;
echo 'Writing to CSV…';
// Write the array to the CSV file
$writer = new Writer(sprintf('%s.csv', $repo->owner . '_' . $repo->name), 'ab+');
$writer->setNullHandlingMode(Writer::NULL_AS_EMPTY);
$writer->insertAll($toWrite);
echo PHP_EOL;
echo sprintf('Done! CSV file is %s.csv', $repo->name);