Beispiel #1
0
 /**
  * Returns a new ChildLeagueQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildLeagueQuery
  */
 public static function create($modelAlias = null, Criteria $criteria = null)
 {
     if ($criteria instanceof ChildLeagueQuery) {
         return $criteria;
     }
     $query = new ChildLeagueQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Beispiel #2
0
 /**
  * Get the associated ChildLeague object
  *
  * @param  ConnectionInterface $con Optional Connection object.
  * @return ChildLeague The associated ChildLeague object.
  * @throws PropelException
  */
 public function getLeague(ConnectionInterface $con = null)
 {
     if ($this->aLeague === null && $this->league_id !== null) {
         $this->aLeague = ChildLeagueQuery::create()->findPk($this->league_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->aLeague->addMatches($this);
            */
     }
     return $this->aLeague;
 }
Beispiel #3
0
 /**
  * Performs an INSERT on the database, given a League or Criteria object.
  *
  * @param mixed               $criteria Criteria or League 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(LeagueTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from League object
     }
     if ($criteria->containsKey(LeagueTableMap::COL_ID) && $criteria->keyContainsValue(LeagueTableMap::COL_ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . LeagueTableMap::COL_ID . ')');
     }
     // Set the correct dbName
     $query = LeagueQuery::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);
     });
 }
Beispiel #4
0
 /**
  * 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 = \Haus23\Dtp\Model\LeagueQuery::create()->filterBySlug($this->getSlug())->filterByPrimaryKey($this->getPrimaryKey())->count();
         if (1 == $count) {
             return $this->getSlug();
         }
     }
     $adapter = \Propel\Runtime\Propel::getServiceContainer()->getAdapter('dtp');
     $col = 'q.Slug';
     $compare = $alreadyExists ? $adapter->compareRegex($col, '?') : sprintf('%s = ?', $col);
     $query = \Haus23\Dtp\Model\LeagueQuery::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('dtp');
     // 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);
 }