Example #1
0
 /**
  * Automatically generated run method
  * 
  * @param Request $request
  * @return Response
  */
 public function run(Request $request)
 {
     $body = $request->getContent();
     if (!isset($body['data'])) {
         throw new InvalidParameterException();
     }
     $data = $body['data'];
     $id = $this->getParam('id');
     $group = GroupQuery::create()->findOneById($id);
     if ($group === null) {
         throw new ResourceNotFoundException('group with id ' . $id . ' does not exist');
     }
     // remove all relationships before
     GroupActionQuery::create()->filterByGroup($group)->deleteAll();
     // add them
     foreach ($data as $entry) {
         if (!isset($entry['id'])) {
             throw new InvalidParameterException();
         }
         $action = ActionQuery::create()->findOneById($entry['id']);
         $group->addAction($action);
         $group->save();
     }
     // run response
     return $this->response->run($request, $group);
 }
Example #2
0
 private function updateActions(Module $model, ModuleSchema $module)
 {
     $actions = [];
     foreach ($module->getActionNames() as $name) {
         $action = $module->getAction($name);
         $a = new Action();
         $a->setName($name);
         $a->setModule($model);
         $a->setTitle($action->getTitle());
         $a->setDescription($action->getDescription());
         $a->setClassName($action->getClass());
         // add acl
         foreach ($action->getAcl() as $group) {
             $a->addGroup($this->getGroup($group));
         }
         $a->save();
         $actions[$name] = $a->getId();
     }
     // remove obsolete actions
     ActionQuery::create()->filterByModule($model)->where('Action.Name NOT IN ?', $module->getActionNames()->toArray())->delete();
     return $actions;
 }
Example #3
0
 /**
  * Returns a new ChildActionQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildActionQuery
  */
 public static function create($modelAlias = null, Criteria $criteria = null)
 {
     if ($criteria instanceof ChildActionQuery) {
         return $criteria;
     }
     $query = new ChildActionQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Example #4
0
File: Api.php Project: keeko/core
 /**
  * Get the associated ChildAction object
  *
  * @param  ConnectionInterface $con Optional Connection object.
  * @return ChildAction The associated ChildAction object.
  * @throws PropelException
  */
 public function getAction(ConnectionInterface $con = null)
 {
     if ($this->aAction === null && $this->action_id !== null) {
         $this->aAction = ChildActionQuery::create()->findPk($this->action_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->aAction->addApis($this);
            */
     }
     return $this->aAction;
 }
Example #5
0
 /**
  * Performs an INSERT on the database, given a Action or Criteria object.
  *
  * @param mixed               $criteria Criteria or Action 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(ActionTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Action object
     }
     if ($criteria->containsKey(ActionTableMap::COL_ID) && $criteria->keyContainsValue(ActionTableMap::COL_ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . ActionTableMap::COL_ID . ')');
     }
     // Set the correct dbName
     $query = ActionQuery::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);
     });
 }
Example #6
0
 /**
  * Returns one Action with the given id from cache
  * 
  * @param mixed $id
  * @return Action|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 = ActionQuery::create()->findOneById($id);
     $this->pool->set($id, $model);
     return $model;
 }
Example #7
0
 private function loadActions()
 {
     $models = [];
     $actions = ActionQuery::create()->filterByModule($this->model)->find();
     foreach ($actions as $action) {
         $models[$action->getName()] = $action;
     }
     $keeko = $this->package->getKeeko();
     $module = $keeko->getModule();
     $this->actions = [];
     foreach ($module->getActionNames() as $actionName) {
         if (isset($models[$actionName])) {
             $this->actions[$actionName] = ['model' => $models[$actionName], 'action' => $module->getAction($actionName)];
         }
     }
 }
Example #8
0
 /**
  * Internal update mechanism of Actions on Module
  * 
  * @param Module $model
  * @param mixed $data
  */
 protected function doUpdateActions(Module $model, $data)
 {
     // remove all relationships before
     ActionQuery::create()->filterByModule($model)->delete();
     // add them
     $errors = [];
     foreach ($data as $entry) {
         if (!isset($entry['id'])) {
             $errors[] = 'Missing id for Action';
         } else {
             $related = ActionQuery::create()->findOneById($entry['id']);
             $model->addAction($related);
         }
     }
     if (count($errors) > 0) {
         throw new ErrorsException($errors);
     }
 }
Example #9
0
 /**
  * Builds a Criteria object containing the primary key for this object.
  *
  * Unlike buildCriteria() this method includes the primary key values regardless
  * of whether or not they have been modified.
  *
  * @throws LogicException if no primary key is defined
  *
  * @return Criteria The Criteria object containing value(s) for primary key(s).
  */
 public function buildPkeyCriteria()
 {
     $criteria = ChildActionQuery::create();
     $criteria->add(ActionTableMap::COL_ID, $this->id);
     return $criteria;
 }
Example #10
0
 /**
  * Returns the number of related Action objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      ConnectionInterface $con
  * @return int             Count of related Action objects.
  * @throws PropelException
  */
 public function countActions(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
 {
     $partial = $this->collActionsPartial && !$this->isNew();
     if (null === $this->collActions || null !== $criteria || $partial) {
         if ($this->isNew() && null === $this->collActions) {
             return 0;
         }
         if ($partial && !$criteria) {
             return count($this->getActions());
         }
         $query = ChildActionQuery::create(null, $criteria);
         if ($distinct) {
             $query->distinct();
         }
         return $query->filterByModule($this)->count($con);
     }
     return count($this->collActions);
 }