private static function createDataSource($view, $filters, $format = 'html') { $listView = new afListView($view); $selectedColumns = $listView->getSelectedColumns(); //TODO: support also the file datasource $sourceType = $view->get('datasource@type'); $className = $view->get('datasource@className'); $modelName = $view->get('datasource@modelName'); if ($sourceType === 'orm') { list($callback, $params) = self::getDataSourceCallback($view); $result = afCall::funcArray($callback, $params); if ($modelName == '') { $peer = $view->get('datasource/class'); afFilterUtil::setFilters($peer, $result, $filters); if ($peer == "afGenerator") { $peer = $params[0]; } $class = self::getClassFromPeerClass($peer); } else { $peer = $modelName . 'Peer'; afFilterUtil::setFilters($peer, $result, $filters); $class = $modelName; } $extractor = new afColumnExtractor($class, $selectedColumns, $format); if ($className === '') { $className = 'afPropelSource'; } $source = new $className($extractor); $source->setCriteria($result); } else { if ($sourceType === 'static') { list($callback, $params) = self::getDataSourceCallback($view); if ($className === '') { $className = 'afStaticSource'; } $source = new $className($callback, $params); if (method_exists($source, 'setFilters')) { $source->setFilters($filters); } } else { throw new XmlParserException('Unsupported datasource type: ' . $sourceType); } } return $source; }
<?php include dirname(__FILE__) . '/../bootstrap/dbunit.php'; $t = new lime_test(1, new lime_output_color()); $doc = afConfigUtils::getDoc('networkmonitor_snmp', 'listSnmpGroup'); $view = afDomAccess::wrap($doc, 'view'); $listView = new afListView($view); $t->is($listView->getSelectedColumns(), array('name', 'body', 'id'));