public function save($con = null) { $con = Propel::getConnection(); try { $con->begin(); $ret = parent::save($con); // update vocabulary_has_user table $userId = sfContext::getInstance()->getUser()->getSubscriberId(); $vocabularyId = $this->getId(); $mode = sfContext::getInstance()->getRequest()->getParameter('action'); if ($userId && $vocabularyId) { //see if there's already an entry in the table and if not, add it $criteria = new Criteria(); $criteria->add(VocabularyHasUserPeer::USER_ID, $userId); $VocabularyHasUsersColl = $this->getVocabularyHasUsers($criteria, $con); if (!count($VocabularyHasUsersColl)) { $vocabularyUser = new VocabularyHasUser(); $vocabularyUser->setVocabularyId($vocabularyId); $vocabularyUser->setUserId($userId); $vocabularyUser->setIsRegistrarFor(true); $vocabularyUser->setIsAdminFor(true); $vocabularyUser->setIsMaintainerFor(true); $vocabularyUser->save($con); } } $con->commit(); return $ret; } catch (Exception $e) { $con->rollback(); throw $e; } }
/** * setDefaults * * @param VocabularyHasUser $VocabularyHasUser */ public function setDefaults($VocabularyHasUser) { if (!isset($this->vocabulary)) { $this->vocabulary = myActionTools::findCurrentVocabulary(); } if ($this->vocabulary) { $VocabularyHasUser->setVocabularyId($this->vocabulary->getId()); } $VocabularyHasUser->setIsRegistrarFor(false); parent::setDefaults($VocabularyHasUser); }