public function __construct() { $this->competitions = new Map(); $this->routines = new Map(); foreach (CompetitionQuery::create()->find() as $comp) { $this->competitions->set($comp->getLabel(), $comp); } }
/** * Returns one Competition with the given id from cache * * @param mixed $id * @return Competition|null */ protected function get($id) { if ($this->pool === null) { $this->pool = new Map(); } else { if ($this->pool->has($id)) { return $this->pool->get($id); } } $model = CompetitionQuery::create()->findOneById($id); $this->pool->set($id, $model); return $model; }
/** * Get the associated ChildCompetition object * * @param ConnectionInterface $con Optional Connection object. * @return ChildCompetition The associated ChildCompetition object. * @throws PropelException */ public function getCompetition(ConnectionInterface $con = null) { if ($this->aCompetition === null && $this->competition_id !== null) { $this->aCompetition = ChildCompetitionQuery::create()->findPk($this->competition_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aCompetition->addStartgroups($this); */ } return $this->aCompetition; }
/** * Get the slug, ensuring its uniqueness * * @param string $slug the slug to check * @param string $separator the separator used by slug * @param int $alreadyExists false for the first try, true for the second, and take the high count + 1 * @return string the unique slug */ protected function makeSlugUnique($slug, $separator = '-', $alreadyExists = false) { if (!$alreadyExists) { $slug2 = $slug; } else { $slug2 = $slug . $separator; $count = \iuf\junia\model\CompetitionQuery::create()->filterBySlug($this->getSlug())->filterByPrimaryKey($this->getPrimaryKey())->count(); if (1 == $count) { return $this->getSlug(); } } $adapter = \Propel\Runtime\Propel::getServiceContainer()->getAdapter('keeko'); $col = 'q.Slug'; $compare = $alreadyExists ? $adapter->compareRegex($col, '?') : sprintf('%s = ?', $col); $query = \iuf\junia\model\CompetitionQuery::create('q')->where($compare, $alreadyExists ? '^' . $slug2 . '[0-9]+$' : $slug2)->prune($this); if (!$alreadyExists) { $count = $query->count(); if ($count > 0) { return $this->makeSlugUnique($slug, $separator, true); } return $slug2; } $adapter = \Propel\Runtime\Propel::getServiceContainer()->getAdapter('keeko'); // Already exists $object = $query->addDescendingOrderByColumn($adapter->strLength('slug'))->addDescendingOrderByColumn('slug')->findOne(); // First duplicate slug if (null == $object) { return $slug2 . '1'; } $slugNum = substr($object->getSlug(), strlen($slug) + 1); if (0 == $slugNum[0]) { $slugNum[0] = 1; } return $slug2 . ($slugNum + 1); }
/** * Performs an INSERT on the database, given a Competition or Criteria object. * * @param mixed $criteria Criteria or Competition object containing data that is used to create the INSERT statement. * @param ConnectionInterface $con the ConnectionInterface connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(CompetitionTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from Competition object } if ($criteria->containsKey(CompetitionTableMap::COL_ID) && $criteria->keyContainsValue(CompetitionTableMap::COL_ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . CompetitionTableMap::COL_ID . ')'); } // Set the correct dbName $query = CompetitionQuery::create()->mergeWith($criteria); // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) return $con->transaction(function () use($con, $query) { return $query->doInsert($con); }); }