protected function buildForm($change_mode = false) { $this->formBuilder->add("id", "hidden", array("required" => true, "constraints" => array(new Constraints\NotBlank(), new Constraints\Callback(array("methods" => array(array($this, "verifyProfileId"))))))); foreach (ResourceQuery::create()->find() as $resource) { $this->formBuilder->add(self::RESOURCE_ACCESS_FIELD_PREFIX . ':' . str_replace(".", ":", $resource->getCode()), "choice", array("choices" => array(AccessManager::VIEW => AccessManager::VIEW, AccessManager::CREATE => AccessManager::CREATE, AccessManager::UPDATE => AccessManager::UPDATE, AccessManager::DELETE => AccessManager::DELETE), "attr" => array("tag" => "resources", "resource_code" => $resource->getCode()), "multiple" => true, "constraints" => array())); } }
protected function addResource($code) { if (null === ResourceQuery::create()->findOneByCode($code)) { $resource = new Resource(); $resource->setCode($code); $resource->setTitle($code); $resource->save(); } }
/** * @param ProfileEvent $event */ public function updateResourceAccess(ProfileEvent $event) { if (null !== ($profile = ProfileQuery::create()->findPk($event->getId()))) { ProfileResourceQuery::create()->filterByProfileId($event->getId())->delete(); foreach ($event->getResourceAccess() as $resourceCode => $accesses) { $manager = new AccessManager(0); $manager->build($accesses); $profileResource = new ProfileResource(); $profileResource->setProfileId($event->getId())->setResource(ResourceQuery::create()->findOneByCode($resourceCode))->setAccess($manager->getAccessValue()); $profileResource->save(); } $event->setProfile($profile); } }
public function buildModelCriteria() { $search = ResourceQuery::create(); /* manage translations */ $this->configureI18nProcessing($search); $profile = $this->getProfile(); if (null !== $profile) { $search->leftJoinProfileResource('profile_resource')->addJoinCondition('profile_resource', 'profile_resource.PROFILE_ID=?', $profile, null, \PDO::PARAM_INT)->withColumn('profile_resource.access', 'access'); } $code = $this->getCode(); if (null !== $code) { $search->filterByCode($code, Criteria::IN); } $search->orderById(Criteria::ASC); return $search; }
/** * Removes this object from datastore and sets delete attribute. * * @param ConnectionInterface $con * @return void * @throws PropelException * @see Resource::setDeleted() * @see Resource::isDeleted() */ public function delete(ConnectionInterface $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getServiceContainer()->getWriteConnection(ResourceTableMap::DATABASE_NAME); } $con->beginTransaction(); try { $deleteQuery = ChildResourceQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }
/** * Get the associated ChildResource object * * @param ConnectionInterface $con Optional Connection object. * @return ChildResource The associated ChildResource object. * @throws PropelException */ public function getResource(ConnectionInterface $con = null) { if ($this->aResource === null && $this->resource_id !== null) { $this->aResource = ChildResourceQuery::create()->findPk($this->resource_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->aResource->addProfileResources($this); */ } return $this->aResource; }
/** * Performs an INSERT on the database, given a Resource or Criteria object. * * @param mixed $criteria Criteria or Resource 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(ResourceTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from Resource object } if ($criteria->containsKey(ResourceTableMap::ID) && $criteria->keyContainsValue(ResourceTableMap::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . ResourceTableMap::ID . ')'); } // Set the correct dbName $query = ResourceQuery::create()->mergeWith($criteria); try { // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) $con->beginTransaction(); $pk = $query->doInsert($con); $con->commit(); } catch (PropelException $e) { $con->rollBack(); throw $e; } return $pk; }
/** * Gets the number of ChildResource objects related by a many-to-many relationship * to the current object by way of the profile_resource 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 ChildResource objects */ public function countResources($criteria = null, $distinct = false, ConnectionInterface $con = null) { if (null === $this->collResources || null !== $criteria) { if ($this->isNew() && null === $this->collResources) { return 0; } else { $query = ChildResourceQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterByProfile($this)->count($con); } } else { return count($this->collResources); } }