本文整理汇总了PHP中Piwik_DataTable::loadFromSimpleArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Piwik_DataTable::loadFromSimpleArray方法的具体用法?PHP Piwik_DataTable::loadFromSimpleArray怎么用?PHP Piwik_DataTable::loadFromSimpleArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik_DataTable
的用法示例。
在下文中一共展示了Piwik_DataTable::loadFromSimpleArray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleReturnedValue
/**
* This method post processes the data resulting from the API call.
*
* - If the data resulted from the API call is a Piwik_DataTable then
* - we apply the standard filters if the parameters have been found
* in the URL. For example to offset,limit the Table you can add the following parameters to any API
* call that returns a DataTable: filter_limit=10&filter_offset=20
* - we apply the filters that have been previously queued on the DataTable
* @see Piwik_DataTable::queueFilter()
* - we apply the renderer that generate the DataTable in a given format (XML, PHP, HTML, JSON, etc.)
* the format can be changed using the 'format' parameter in the request.
* Example: format=xml
*
* - If there is nothing returned (void) we display a standard success message
*
* - If there is a PHP array returned, we try to convert it to a dataTable
* It is then possible to convert this datatable to any requested format (xml/etc)
*
* - If a bool is returned we convert to a string (true is displayed as 'true' false as 'false')
*
* - If an integer / float is returned, we simply return it
*
* @throws Exception If an object/resource is returned, if any of conversion fails, etc.
*
* @param mixed The initial returned value, before post process
* @return mixed Usually a string, but can still be a PHP data structure if the format requested is 'original'
*/
protected function handleReturnedValue($returnedValue)
{
$toReturn = $returnedValue;
// If the returned value is an object DataTable we
// apply the set of generic filters if asked in the URL
// and we render the DataTable according to the format specified in the URL
if ($returnedValue instanceof Piwik_DataTable || $returnedValue instanceof Piwik_DataTable_Array) {
if ($returnedValue instanceof Piwik_DataTable) {
$this->applyDataTableGenericFilters($returnedValue);
} elseif ($returnedValue instanceof Piwik_DataTable_Array) {
$tables = $returnedValue->getArray();
foreach ($tables as $table) {
$this->applyDataTableGenericFilters($table);
}
}
// if the flag disable_queued_filters is defined we skip the filters that were queued
// useful in some very rare cases but better to use this than a bad hack on the data returned...
if (Piwik_Common::getRequestVar('disable_queued_filters', 'false', 'string', $this->requestToUse) == 'false') {
$returnedValue->applyQueuedFilters();
}
$toReturn = $this->getRenderedDataTable($returnedValue);
} elseif (!isset($toReturn)) {
$toReturn = $this->getStandardSuccessOutput($this->outputFormatRequested);
} elseif (is_array($toReturn)) {
if ($this->outputFormatRequested == 'original') {
// we handle the serialization. Because some php array have a very special structure that
// couldn't be converted with the automatic DataTable->loadFromSimpleArray
// the user may want to request the original PHP data structure serialized by the API
// in case he has to setup serialize=1 in the URL
if ($this->caseRendererPHPSerialize($defaultSerialize = 0)) {
$toReturn = serialize($toReturn);
}
} else {
$dataTable = new Piwik_DataTable();
$dataTable->loadFromSimpleArray($toReturn);
$toReturn = $this->getRenderedDataTable($dataTable);
}
} else {
// original data structure requested, we return without process
if ($this->outputFormatRequested == 'original') {
return $toReturn;
}
if ($toReturn === true) {
$toReturn = 'true';
} elseif ($toReturn === false) {
$toReturn = 'false';
} elseif (is_object($toReturn) || is_resource($toReturn)) {
return $this->getExceptionOutput(' The API cannot handle this data structure. You can get the data internally by directly using the class.', $this->outputFormatRequested);
}
require_once "DataTable/Simple.php";
$dataTable = new Piwik_DataTable_Simple();
$dataTable->loadFromArray(array($toReturn));
$toReturn = $this->getRenderedDataTable($dataTable);
}
return $toReturn;
}