Beispiel #1
0
 /**
  * @param Skill $skill
  * @param mixed $data
  */
 protected function postSave(Skill $skill, $data)
 {
     SkillQuery::disableVersioning();
     // calculate
     $calculator = new Calculator();
     $calculator->calculate($skill);
     $calculator->getModifiedGenerationSkills()->each(function (Skill $skill) {
         LineageQuery::create()->filterBySkillId($skill->getId())->delete();
     });
     $calculator->getModifiedSkills()->each(function (Skill $skill) {
         $skill->save();
     });
     // set sequence picture
     if (isset($data['meta']) && isset($data['meta']['filename'])) {
         $module = $this->getServiceContainer()->getModuleManager()->load('gossi/trixionary');
         $destpath = $module->getSequencePath($skill);
         $dest = new File($destpath);
         if ($dest->exists()) {
             $dest->delete();
         }
         $file = new File($module->getUploadPath()->append($data['meta']['filename']));
         $file->move($destpath);
         $skill->setSequencePictureUrl($module->getSequenceUrl($skill));
         $skill->save();
     }
     SkillQuery::enableVersioning();
     // activity
     $user = $this->getServiceContainer()->getAuthManager()->getUser();
     $user->newActivity(array('verb' => $this->isNew ? Activity::VERB_CREATE : Activity::VERB_AUTHOR, 'object' => $skill, 'target' => $skill->getSport()));
 }
Beispiel #2
0
 /**
  * Get the associated ChildSkill object
  *
  * @param  ConnectionInterface $con Optional Connection object.
  * @return ChildSkill The associated ChildSkill object.
  * @throws PropelException
  */
 public function getSkill(ConnectionInterface $con = null)
 {
     if ($this->aSkill === null && $this->skill_id !== null) {
         $this->aSkill = ChildSkillQuery::create()->findPk($this->skill_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->aSkill->addSkillReferences($this);
            */
     }
     return $this->aSkill;
 }
Beispiel #3
0
 /**
  * Returns one Skill with the given id from cache
  * 
  * @param mixed $id
  * @return Skill|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 = SkillQuery::create()->findOneById($id);
     $this->pool->set($id, $model);
     return $model;
 }
Beispiel #4
0
 /**
  * Gets the number of Skill objects related by a many-to-many relationship
  * to the current object by way of the kk_trixionary_skill_group cross-reference table.
  *
  * @param      Criteria $criteria Optional query object to filter the query
  * @param      boolean $distinct Set to true to force count distinct
  * @param      ConnectionInterface $con Optional connection object
  *
  * @return int the number of related Skill objects
  */
 public function countSkills(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
 {
     $partial = $this->collSkillsPartial && !$this->isNew();
     if (null === $this->collSkills || null !== $criteria || $partial) {
         if ($this->isNew() && null === $this->collSkills) {
             return 0;
         } else {
             if ($partial && !$criteria) {
                 return count($this->getSkills());
             }
             $query = ChildSkillQuery::create(null, $criteria);
             if ($distinct) {
                 $query->distinct();
             }
             return $query->filterByGroup($this)->count($con);
         }
     } else {
         return count($this->collSkills);
     }
 }
 /**
  * Internal update mechanism of Skills on Reference
  * 
  * @param Reference $model
  * @param mixed $data
  */
 protected function doUpdateSkills(Reference $model, $data)
 {
     // remove all relationships before
     SkillReferenceQuery::create()->filterByReference($model)->delete();
     // add them
     $errors = [];
     foreach ($data as $entry) {
         if (!isset($entry['id'])) {
             $errors[] = 'Missing id for Skill';
         } else {
             $related = SkillQuery::create()->findOneById($entry['id']);
             $model->addSkill($related);
         }
     }
     if (count($errors) > 0) {
         throw new ErrorsException($errors);
     }
 }
Beispiel #6
0
 /**
  * Returns a new ChildSkillQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildSkillQuery
  */
 public static function create($modelAlias = null, Criteria $criteria = null)
 {
     if ($criteria instanceof ChildSkillQuery) {
         return $criteria;
     }
     $query = new ChildSkillQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Beispiel #7
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this Kstruktur is new, it will return
  * an empty collection; or if this Kstruktur has previously
  * been saved, it will retrieve related RootSkills from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in Kstruktur.
  *
  * @param      Criteria $criteria optional Criteria object to narrow the query
  * @param      ConnectionInterface $con optional connection object
  * @param      string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN)
  * @return ObjectCollection|ChildSkill[] List of ChildSkill objects
  */
 public function getRootSkillsJoinFunctionPhaseRoot(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN)
 {
     $query = ChildSkillQuery::create(null, $criteria);
     $query->joinWith('FunctionPhaseRoot', $joinBehavior);
     return $this->getRootSkills($query, $con);
 }
Beispiel #8
0
 /**
  * Performs an INSERT on the database, given a Skill or Criteria object.
  *
  * @param mixed               $criteria Criteria or Skill 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(SkillTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Skill object
     }
     if ($criteria->containsKey(SkillTableMap::COL_ID) && $criteria->keyContainsValue(SkillTableMap::COL_ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . SkillTableMap::COL_ID . ')');
     }
     // Set the correct dbName
     $query = SkillQuery::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);
     });
 }