本文整理汇总了PHP中X2Model::autoPopulateFields方法的典型用法代码示例。如果您正苦于以下问题:PHP X2Model::autoPopulateFields方法的具体用法?PHP X2Model::autoPopulateFields怎么用?PHP X2Model::autoPopulateFields使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类X2Model
的用法示例。
在下文中一共展示了X2Model::autoPopulateFields方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionExportModelRecords
/**
* An AJAX called function which exports data to a CSV via pagination.
* This is a generalized version of the Contacts export.
* @param int $page The page of the data provider to export
*/
public function actionExportModelRecords($page, $model)
{
X2Model::$autoPopulateFields = false;
$file = $this->safePath($_SESSION['modelExportFile']);
$staticModel = X2Model::model(str_replace(' ', '', $model));
$fields = $staticModel->getFields();
$fp = fopen($file, 'a+');
// Load data provider based on export criteria
$excludeHidden = !isset($_GET['includeHidden']) || $_GET['includeHidden'] === 'false';
if ($page == 0 && $excludeHidden && isset($_SESSION['exportModelCriteria']) && $_SESSION['exportModelCriteria'] instanceof CDbCriteria) {
// Save hidden condition in criteria
$hiddenConditions = $staticModel->getHiddenCondition();
$_SESSION['exportModelCriteria']->addCondition($hiddenConditions);
}
$dp = new CActiveDataProvider($model, array('criteria' => isset($_SESSION['exportModelCriteria']) ? $_SESSION['exportModelCriteria'] : array(), 'pagination' => array('pageSize' => 100)));
// Flip through to the right page.
$pg = $dp->getPagination();
$pg->setCurrentPage($page);
$dp->setPagination($pg);
$records = $dp->getData();
$pageCount = $dp->getPagination()->getPageCount();
// Retrieve specified export delimeter and enclosure
$delimeter = isset($_GET['delimeter']) ? $_GET['delimeter'] : ',';
$enclosure = isset($_GET['enclosure']) ? $_GET['enclosure'] : '"';
// We need to set our data to be human friendly, so loop through all the
// records and format any date / link / visibility fields.
foreach ($records as $record) {
foreach ($fields as $field) {
$fieldName = $field->fieldName;
if ($field->type == 'date' || $field->type == 'dateTime') {
if (is_numeric($record->{$fieldName})) {
$record->{$fieldName} = Formatter::formatLongDateTime($record->{$fieldName});
}
} elseif ($field->type == 'link') {
$name = $record->{$fieldName};
if (!empty($field->linkType)) {
list($name, $id) = Fields::nameAndId($name);
}
if (!empty($name)) {
$record->{$fieldName} = $name;
}
} elseif ($fieldName == 'visibility') {
switch ($record->{$fieldName}) {
case 0:
$record->{$fieldName} = 'Private';
break;
case 1:
$record->{$fieldName} = 'Public';
break;
case 2:
$record->{$fieldName} = 'User\'s Groups';
break;
default:
$record->{$fieldName} = 'Private';
}
}
}
// Enforce metadata to ensure accuracy of column order, then export.
$combinedMeta = array_combine($_SESSION['modelExportMeta'], $_SESSION['modelExportMeta']);
$recordAttributes = $record->attributes;
if ($model === 'Actions') {
// Export descriptions with Actions
$actionText = $record->actionText;
if ($actionText) {
$actionDescription = $actionText->text;
$recordAttributes = array_merge($recordAttributes, array('actionDescription' => $actionDescription));
}
}
if ($_SESSION['includeTags']) {
$tags = $record->getTags();
$recordAttributes = array_merge($recordAttributes, array('tags' => implode(',', $tags)));
}
$tempAttributes = array_intersect_key($recordAttributes, $combinedMeta);
$tempAttributes = array_merge($combinedMeta, $tempAttributes);
fputcsv($fp, $tempAttributes, $delimeter, $enclosure);
}
unset($dp);
fclose($fp);
if ($page + 1 < $pageCount) {
echo $page + 1;
}
}
示例2: __construct
public function __construct($owner = null)
{
X2Model::$autoPopulateFields = false;
parent::__construct($owner);
}