Ejemplo n.º 1
0
 protected function addQueryColumns()
 {
     $tableMap = $this->query->getTableMap();
     foreach ($tableMap->getColumns() as $column) {
         if ($column->isForeignKey()) {
             continue;
         }
         $name = strtolower($column->getName());
         $this->addColumn($name, array('hide' => $column->isPrimaryKey(), 'phpName' => $column->getPhpName(), 'action' => $column->isPrimaryString() ? 'edit' : null));
     }
     // add virtual columns
     foreach ($this->query->getAsColumns() as $colName => $clause) {
         $this->addColumn($colName, array('phpName' => $colName));
     }
     $behaviors = $tableMap->getBehaviors();
     if (array_key_exists('sortable', $behaviors)) {
         $rankCol = strtolower($behaviors['sortable']['rank_column']);
         if (isset($this->columns[$rankCol])) {
             $this->addColumn($rankCol, array('hide' => true));
             $this->setOptions(array('defaultSortColumn' => $rankCol));
         }
         $this->setOptions(array('sortable' => array($this, 'sortItems')));
     }
     $i18nTableName = $this->getI18nTableName($tableMap);
     if ($i18nTableName !== null && $this->query->getJoin($i18nTableName) !== null) {
         $i18nTableMap = \PropelQuery::from($i18nTableName)->getTableMap();
         foreach ($i18nTableMap->getColumns() as $column) {
             if ($column->isPrimaryKey()) {
                 continue;
             }
             $this->addColumn(strtolower($column->getName()), array('sortCallback' => array($this, 'sortI18nColumn'), 'phpName' => $column->getPhpName()));
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Define the hydration schema based on a query object.
  * Fills the Formatter's properties using a Criteria as source
  *
  * @param ModelCriteria $criteria
  *
  * @return PropelFormatter The current formatter object
  */
 public function init(ModelCriteria $criteria)
 {
     $this->dbName = $criteria->getDbName();
     $this->setClass($criteria->getModelName());
     $this->setWith($criteria->getWith());
     $this->asColumns = $criteria->getAsColumns();
     $this->hasLimit = $criteria->getLimit() != 0;
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Get row properties.
  *
  * @param BaseObject $obj
  * @return array
  */
 protected function getRow($obj)
 {
     $columnToPhpName = array();
     foreach ($this->tableMap->getColumns() as $name => $column) {
         $columnToPhpName[strtolower($name)] = $column->getPhpName();
     }
     $celldata = array();
     foreach ($this->columns as $column => $opts) {
         if (isset($this->callbacks[$column])) {
             $value = call_user_func($this->callbacks[$column], $obj);
         } else {
             try {
                 if (isset($columnToPhpName[$column])) {
                     $phpName = $columnToPhpName[$column];
                 } else {
                     $tmp = $this->query->getAsColumns();
                     if (isset($tmp[$column])) {
                         $phpName = $column;
                     }
                 }
                 $value = $obj->{'get' . $phpName}();
             } catch (Exception $e) {
                 throw new Exception("Unable to fetch value from column '{$column}'.");
             }
         }
         if (is_null($value)) {
             $value = 'Ø';
         } else {
             if (is_bool($value)) {
                 $value = $value ? 'true' : 'false';
             } else {
                 if (is_array($value)) {
                     $value = join(', ', $value);
                 }
             }
         }
         $escape = !isset($opts['escape']) ? true : (bool) $opts['escape'];
         $value = str_replace(PHP_EOL, "", $value);
         $celldata[] = $escape ? htmlspecialchars($value) : $value;
     }
     return array("id" => "_" . $obj->getPrimaryKey(), "cell" => $celldata);
 }