本文整理汇总了PHP中DataList::stat方法的典型用法代码示例。如果您正苦于以下问题:PHP DataList::stat方法的具体用法?PHP DataList::stat怎么用?PHP DataList::stat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataList
的用法示例。
在下文中一共展示了DataList::stat方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSideloadData
/**
* Fetches and return all the data that need to be sideloaded
* for a specific source DataObject or DataList.
*
* @param DataObject|DataList $dataSource The source data to fetch sideloaded records for
* @return array A map of relation names with their data
*/
protected function getSideloadData($dataSource)
{
$data = array();
if ($dataSource instanceof DataObject) {
$has_one = $dataSource->stat('has_one');
$has_many = $dataSource->stat('has_many');
$many_many = $dataSource->stat('many_many');
$belongs_many_many = $dataSource->stat('belongs_many_many');
$relationsMap = array();
if (is_array($has_one)) {
$relationsMap = array_merge($relationsMap, $has_one);
}
if (is_array($has_many)) {
$relationsMap = array_merge($relationsMap, $has_many);
}
if (is_array($many_many)) {
$relationsMap = array_merge($relationsMap, $many_many);
}
if (is_array($belongs_many_many)) {
$relationsMap = array_merge($relationsMap, $belongs_many_many);
}
// if a single DataObject get the data for each relation
foreach ($this->sideloadedRecords[$dataSource->ClassName] as $relationName) {
$newData = $this->getEmbedData($dataSource, $relationName);
if ($newData !== null) {
// has_one are only simple array and we want arrays or array
if (is_array($has_one) && in_array($relationName, $has_one)) {
$newData = array($newData);
}
$relationClass = $relationsMap[$relationName];
$data[$relationClass] = $newData;
}
}
} elseif ($dataSource instanceof DataList) {
// if a list of DataObject, loop through each and merge all the data together
foreach ($dataSource as $dataObjectSource) {
$sideloadData = $this->getSideloadData($dataObjectSource);
//combine sideloaded records
foreach ($sideloadData as $class => $extraData) {
if (!isset($data[$class])) {
$data[$class] = array();
}
// merge for list of records, push for individual record
$arrayOfArrays = array_filter($extraData, 'is_array');
if (count($arrayOfArrays) == count($extraData)) {
//print_r('array_merge');
$data[$class] = array_merge($data[$class], $extraData);
} else {
//print_r('array_push');
array_push($data[$class], $extraData);
}
}
}
// remove duplicates
foreach ($data as $relationClass => $relationData) {
$data[$relationClass] = array_unique($relationData, SORT_REGULAR);
}
}
return $data;
}