예제 #1
0
파일: Match.php 프로젝트: haus23/dtp.model
 /**
  * Get the associated ChildTeam object
  *
  * @param  ConnectionInterface $con Optional Connection object.
  * @return ChildTeam The associated ChildTeam object.
  * @throws PropelException
  */
 public function getAwayteam(ConnectionInterface $con = null)
 {
     if ($this->aAwayteam === null && $this->awayteam_id !== null) {
         $this->aAwayteam = ChildTeamQuery::create()->findPk($this->awayteam_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->aAwayteam->addMatchesRelatedByAwayteamId($this);
            */
     }
     return $this->aAwayteam;
 }
예제 #2
0
 /**
  * Performs an INSERT on the database, given a Team or Criteria object.
  *
  * @param mixed               $criteria Criteria or Team 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(TeamTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Team object
     }
     if ($criteria->containsKey(TeamTableMap::COL_ID) && $criteria->keyContainsValue(TeamTableMap::COL_ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . TeamTableMap::COL_ID . ')');
     }
     // Set the correct dbName
     $query = TeamQuery::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);
     });
 }
예제 #3
0
 /**
  * Returns a new ChildTeamQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildTeamQuery
  */
 public static function create($modelAlias = null, Criteria $criteria = null)
 {
     if ($criteria instanceof ChildTeamQuery) {
         return $criteria;
     }
     $query = new ChildTeamQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
예제 #4
0
파일: Team.php 프로젝트: haus23/dtp.model
 /**
  * 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\TeamQuery::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\TeamQuery::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);
 }