/** * @param string $class * @param string $property * @param array $choices * @param \ModelCriteria $queryObject */ public function __construct($class, $property = null, $choices = array(), $queryObject = null) { $this->class = $class; $queryClass = $this->class . 'Query'; $query = new $queryClass(); $this->table = $query->getTableMap(); $this->identifier = $this->table->getPrimaryKeys(); $this->query = $queryObject ?: $query; // The property option defines, which property (path) is used for // displaying models as strings if ($property) { $this->propertyPath = new PropertyPath($property); } parent::__construct($choices); }
/** * Constructor. * * @param string $modelClass * @param string $url * @param array $options * @param ModelCriteria|null $query * @param string|null $id * @param string|null $title */ public function __construct($modelClass, $url, $options = array(), $query = null, $id = null, $title = null) { // Accept Peerclass instead of modelclass for backwards compatibility if (substr($modelClass, -4) == 'Peer') { $modelClass = substr($modelClass, 0, -4); trace("Deprecated: Use plain modelClass instead of PeerClass for Flexigrid_Propel"); } if ($id === null) { $id = $modelClass . "_flexigrid"; } if ($title === null) { $title = $modelClass . "s"; } parent::__construct($id, $title, $url, $options); $this->modelClass = $modelClass; if ($query) { $this->setCriteria($query); } else { $this->query = PropelQuery::from($this->modelClass); } $this->tableMap = PropelQuery::from($this->modelClass)->getTableMap(); $colNames = array_map(create_function('$col', 'return strtolower($col->getName());'), $this->tableMap->getColumns()); foreach ($colNames as $colName) { $this->addColumn($colName, ucfirst(str_replace("_", " ", $colName))); } // Autoset the primary key if it's only one and hide it $pkColumns = $this->tableMap->getPrimaryKeys(); if (count($pkColumns) == 1) { $pkColName = strtolower(array_pop($pkColumns)->getName()); $this->setPrimaryKey($pkColName); $this->setColumnOption($pkColName, array('hide' => true)); } if (in_array('sortable', array_keys($this->tableMap->getBehaviors()))) { $this->makeSortable(); $tmp = $this->tableMap->getBehaviors(); $this->setColumnOption($tmp['sortable']['rank_column'], array('hide' => true)); $this->setDefaultSort($tmp['sortable']['rank_column']); //$this->query->orderByRank(); } }