65 lines
1.7 KiB
PHP
65 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Trinity\Bundle\ContentManagerBundle\Model;
|
|
|
|
use Trinity\Bundle\ContentManagerBundle\Model\om\BasePageQuery;
|
|
|
|
class PageQuery extends BasePageQuery
|
|
{
|
|
public static function getOrphansQuery()
|
|
{
|
|
return self::create()->filterByNodeId(null)->orderByName(\Criteria::ASC);
|
|
}
|
|
|
|
public static function getModelForDataModels($dataModels)
|
|
{
|
|
$choices = array();
|
|
|
|
foreach ($dataModels as $class => $name) {
|
|
$query = \PropelQuery::from($class);
|
|
$method = method_exists(
|
|
$query,
|
|
'dataModelsCollectionFind'
|
|
) ? 'dataModelsCollectionFind' : 'find';
|
|
|
|
$objects = call_user_func(array($query, $method));
|
|
|
|
$choices[$name] = array();
|
|
|
|
foreach ($objects as $object) {
|
|
if (method_exists($object, '__toString')) {
|
|
$choices[$name][$object->getId()] = (string) $object;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $choices;
|
|
}
|
|
|
|
|
|
public function getDataModelsCollection($raw = false)
|
|
{
|
|
$method = method_exists(
|
|
$this->getDataModelQuery(),
|
|
'dataModelsCollectionFind'
|
|
) ? 'dataModelsCollectionFind' : 'find';
|
|
|
|
$method = ($raw) ? 'find' : $method;
|
|
|
|
return $this->layOnDataModels() ? call_user_func(array($this->getDataModelQuery(), $method)) : array();
|
|
}
|
|
|
|
public function filterByIsOrphan($key)
|
|
{
|
|
if ($key === true) {
|
|
return $this->addUsingAlias(PagePeer::NODE_ID, null, \Criteria::EQUAL);
|
|
}
|
|
|
|
if ($key === false) {
|
|
return $this->addUsingAlias(PagePeer::NODE_ID, null, \Criteria::NOT_EQUAL);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
}
|