/** * Get columns to create fields from. * * @return array */ public function getFieldColumns() { $columns = array(); foreach ($this->modelMap->getColumns() as $column) { if ($column->isForeignKey() && $this->ignoreFks) { continue; } if ($column->isPrimaryKey() && $this->ignorePks) { continue; } $columns[strtolower($column->getName())] = $column; } if (array_key_exists('sortable', $tmp = $this->modelMap->getBehaviors())) { unset($columns[strtolower($tmp['sortable']['rank_column'])]); } return $columns; }
/** * Run flexigrid commands. */ protected function runCommands() { // execute commands before we return the list if (!isset($_POST['cmd'])) { return; } switch ($_POST['cmd']) { case 'delete': if (isset($_POST['id'])) { $id = $_POST['id']; PropelQuery::from($this->modelClass)->findPks(is_array($id) ? $id : array($id))->delete(); } break; case 'reorder': if (isset($_POST['reorder'])) { $reorder = array(); parse_str($_POST['reorder'], $reorder); if (isset($this->columns['sort_index'])) { // OLD SORTING METHOD // get objects $objs = array(); foreach ($reorder['row'] as $rowId) { $objs[] = call_user_func(array($this->modelClass . 'Peer', 'retrieveByPk'), $rowId); } // get sort indices $sortIndices = array(); foreach ($objs as $obj) { $sortIndices[] = $obj->getSortIndex(); } // sort our indices sort($sortIndices); // set new sort indices $i = 0; foreach ($objs as $obj) { $obj->setSortIndex($sortIndices[$i++]); $obj->save(); } } else { // get ranks $objs = PropelQuery::from($this->modelClass)->findPks($reorder['row']); // move all objs with null rank to the bottom $ranks = array(); foreach ($objs as $obj) { if ($obj->getRank() === null) { $obj->insertAtBottom(); $obj->save(); } $ranks[] = $obj->getRank(); } // check for duplicate ranks $dups = array_filter(array_count_values($ranks), create_function('$a', 'return $a > 1;')); if ($dups) { // Duplicate indices, move to bottom $tmp = $this->tableMap->getBehaviors(); $scope = null; if (strtolower($tmp['sortable']['use_scope']) == 'true') { // need scope, find from one object $scope = PropelQuery::from($this->modelClass)->findPk(reset($reorder['row']))->getScopeValue(); } foreach ($dups as $rank => $f) { $objs = PropelQuery::from($this->modelClass)->filterByRank($rank, $scope)->offset(1)->find(); foreach ($objs as $obj) { $obj->insertAtBottom(); $obj->save(); } } $ranks = Curry_Array::objectsToArray($objs, null, 'getRank'); } // sort our indices sort($ranks); // reorder PropelQuery::from($this->modelClass)->reorder(array_combine($reorder['row'], $ranks)); } } break; } }
/** * Return the specified behavior properties * * @param string $behavior * @param TableMap $tableMap * @return array */ public static function getBehavior($behavior, TableMap $tableMap) { $behaviors = $tableMap->getBehaviors(); return (array) $behaviors[strtolower($behavior)]; }
protected function getI18nTableName(\TableMap $tableMap) { $behaviors = $tableMap->getBehaviors(); if (!array_key_exists('i18n', $behaviors)) { return null; } return str_replace('%PHPNAME%', $tableMap->getPhpName(), $behaviors['i18n']['i18n_phpname']); }