public function modifyDatabase() { foreach ($this->getDatabase()->getTables() as $table) { $behaviors = $table->getBehaviors(); if (!isset($behaviors['symfony'])) { $behavior = clone $this; $table->addBehavior($behavior); } // symfony behaviors if (!isset($behaviors['symfony_behaviors']) && $this->getBuildProperty('propel.builder.addBehaviors')) { $class = Propel::importClass($this->getBuildProperty('propel.behavior.symfony_behaviors.class')); $behavior = new $class(); $behavior->setName('symfony_behaviors'); $table->addBehavior($behavior); } // timestampable if (!isset($behaviors['symfony_timestampable'])) { $parameters = array(); foreach ($table->getColumns() as $column) { if (!isset($parameters['create_column']) && in_array($column->getName(), array('created_at', 'created_on'))) { $parameters['create_column'] = $column->getName(); } if (!isset($parameters['update_column']) && in_array($column->getName(), array('updated_at', 'updated_on'))) { $parameters['update_column'] = $column->getName(); } } if ($parameters) { $class = Propel::importClass($this->getBuildProperty('propel.behavior.symfony_timestampable.class')); $behavior = new $class(); $behavior->setName('symfony_timestampable'); $behavior->setParameters($parameters); $table->addBehavior($behavior); } } } }
/** * Looks for tables marked as I18N and adds behaviors. */ public function modifyDatabase() { $translationBehavior = Propel::importClass($this->getBuildProperty('propel.behavior.symfony_i18n_translation.class')); foreach ($this->getDatabase()->getTables() as $table) { $behaviors = $table->getBehaviors(); if (!isset($behaviors['symfony_i18n']) && 'true' == $table->getAttribute('isI18N')) { $i18nTable = $this->getDatabase()->getTable($table->getAttribute('i18nTable')); // add the current behavior to the translatable model $behavior = clone $this; $behavior->setParameters(array('i18n_table' => $i18nTable->getName())); $table->addBehavior($behavior); // add the translation behavior to the translation model $behavior = new $translationBehavior(); $behavior->setName('symfony_i18n_translation'); $behavior->setParameters(array('culture_column' => $this->getCultureColumn($i18nTable)->getName())); $i18nTable->addBehavior($behavior); } } }
/** * This function searches for the given validator $name under propel/validator/$name.php, * imports and caches it. * * @param string $classname The dot-path name of class (e.g. myapp.propel.MyValidator) * @return Validator object or null if not able to instantiate validator class (and error will be logged in this case) */ public static function getValidator($classname) { try { $v = isset(self::$validatorMap[$classname]) ? self::$validatorMap[$classname] : null; if ($v === null) { $cls = Propel::importClass($classname); $v = new $cls(); self::$validatorMap[$classname] = $v; } return $v; } catch (Exception $e) { Propel::log("BasePeer::getValidator(): failed trying to instantiate " . $classname . ": " . $e->getMessage(), Propel::LOG_ERR); } }
/** * Implements the abstract loadDataFromArray method and loads the data using the generated data model. * * @param array $data The data to be loaded into the data source * * @throws Exception If data is unnamed. * @throws sfException If an object defined in the model does not exist in the data * @throws sfException If a column that does not exist is referenced */ public function loadDataFromArray($data) { if ($data === null) { // no data return; } foreach ($data as $class => $datas) { $class = trim($class); $tableMap = $this->dbMap->getTable(constant(constant($class . '::PEER') . '::TABLE_NAME')); $column_names = call_user_func_array(array(constant($class . '::PEER'), 'getFieldNames'), array(BasePeer::TYPE_FIELDNAME)); // iterate through datas for this class // might have been empty just for force a table to be emptied on import if (!is_array($datas)) { continue; } foreach ($datas as $key => $data) { // create a new entry in the database if (!class_exists($class)) { throw new InvalidArgumentException(sprintf('Unknown class "%s".', $class)); } $obj = new $class(); if (!$obj instanceof BaseObject) { throw new RuntimeException(sprintf('The class "%s" is not a Propel class. This probably means there is already a class named "%s" somewhere in symfony or in your project.', $class, $class)); } if (!is_array($data)) { throw new InvalidArgumentException(sprintf('You must give a name for each fixture data entry (class %s).', $class)); } foreach ($data as $name => $value) { if (is_array($value) && 's' == substr($name, -1)) { // many to many relationship $this->loadMany2Many($obj, substr($name, 0, -1), $value); continue; } $isARealColumn = true; try { $column = $tableMap->getColumn($name); } catch (PropelException $e) { $isARealColumn = false; } // foreign key? if ($isARealColumn) { if ($column->isForeignKey() && null !== $value) { $relatedTable = $this->dbMap->getTable($column->getRelatedTableName()); if (!isset($this->object_references[$relatedTable->getPhpName() . '_' . $value])) { throw new InvalidArgumentException(sprintf('The object "%s" from class "%s" is not defined in your data file.', $value, $relatedTable->getPhpName())); } $value = $this->object_references[$relatedTable->getPhpName() . '_' . $value]->getByName($column->getRelatedName(), BasePeer::TYPE_COLNAME); } } if (false !== ($pos = array_search($name, $column_names))) { $obj->setByPosition($pos, $value); } else { if (is_callable(array($obj, $method = 'set' . sfInflector::camelize($name)))) { $obj->{$method}($value); } else { throw new InvalidArgumentException(sprintf('Column "%s" does not exist for class "%s".', $name, $class)); } } } $obj->save($this->con); // save the object for future reference if (method_exists($obj, 'getPrimaryKey')) { $this->object_references[Propel::importClass(constant(constant($class . '::PEER') . '::CLASS_DEFAULT')) . '_' . $key] = $obj; } } } }
/** * @deprecated Use Propel::importClass() instead */ public static function importClass($path) { return Propel::importClass($path); }
public static function doSelectWithI18n(Criteria $c, $culture = null, PropelPDO $con = null) { $c = clone $c; if ($culture === null) { $culture = sfPropel::getDefaultCulture(); } foreach (sfMixer::getCallables('BaseProductPeer:doSelectJoin:doSelectJoin') as $callable) { call_user_func($callable, 'BaseProductPeer', $c, $con); } if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } ProductPeer::addSelectColumns($c); $startcol = ProductPeer::NUM_COLUMNS - ProductPeer::NUM_LAZY_LOAD_COLUMNS; ProductI18nPeer::addSelectColumns($c); $c->addJoin(ProductPeer::ID, ProductI18nPeer::ID); $c->add(ProductI18nPeer::CULTURE, $culture); $stmt = BasePeer::doSelect($c, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $omClass = ProductPeer::getOMClass(); $cls = Propel::importClass($omClass); $obj1 = new $cls(); $obj1->hydrate($row); $obj1->setCulture($culture); $omClass = ProductI18nPeer::getOMClass(); $cls = Propel::importClass($omClass); $obj2 = new $cls(); $obj2->hydrate($row, $startcol); $obj1->setProductI18nForCulture($obj2, $culture); $obj2->setProduct($obj1); $results[] = $obj1; } return $results; }