Ejemplo n.º 1
0
 /**
  * setDefaults
  *
  * @param  SchemaHasUser $SchemaHasUser
  */
 public function setDefaults($SchemaHasUser)
 {
     if (!isset($this->schema)) {
         $this->schema = myActionTools::findCurrentSchema();
     }
     if ($this->schema) {
         $SchemaHasUser->setSchemaId($this->schema->getId());
     }
     $SchemaHasUser->setIsRegistrarFor(false);
     parent::setDefaults($SchemaHasUser);
 }
Ejemplo n.º 2
0
 /**
  * @param null $con
  * @return int
  * @throws Exception
  * @throws PropelException
  */
 public function save($con = null)
 {
     $userId = sfContext::getInstance()->getUser()->getSubscriberId();
     if ($userId) {
         $this->setUpdatedUserId($userId);
         if ($this->isNew()) {
             $this->setCreatedUserId($userId);
         }
     }
     $con = Propel::getConnection();
     try {
         $con->begin();
         $ret = parent::save($con);
         // update schema_has_user table
         $schemaId = $this->getId();
         $mode = sfContext::getInstance()->getRequest()->getParameter('action');
         if ($userId && $schemaId) {
             //see if there's already an entry in the table and if not, add it
             $criteria = new Criteria();
             $criteria->add(SchemaHasUserPeer::USER_ID, $userId);
             $SchemaHasUsersColl = $this->getSchemaHasUsers($criteria, $con);
             if (!count($SchemaHasUsersColl)) {
                 $schemaUser = new SchemaHasUser();
                 $schemaUser->setSchemaId($schemaId);
                 $schemaUser->setUserId($userId);
                 $schemaUser->setIsRegistrarFor(true);
                 $schemaUser->setIsAdminFor(true);
                 $schemaUser->setIsMaintainerFor(true);
                 $schemaUser->save($con);
             }
         }
         $con->commit();
         return $ret;
     } catch (Exception $e) {
         $con->rollback();
         throw $e;
     }
 }