/** * @param Request $request * @param Created $payload */ public function created(Request $request, Created $payload) { $serializer = Group::getSerializer(); $resource = new Resource($payload->getModel(), $serializer); $document = new Document($resource); return new JsonResponse($document->toArray(), 201, ['Location' => $resource->getLinks()['self']]); }
/** * @param Request $request * @param Found $payload */ public function found(Request $request, Found $payload) { $params = new Parameters($request->query->all()); $serializer = Action::getSerializer(); $resource = new Resource($payload->getModel(), $serializer); $resource = $resource->with($params->getInclude(['module', 'groups', 'apis'])); $resource = $resource->fields($params->getFields(['action' => Action::getSerializer()->getFields(), 'module' => Module::getSerializer()->getFields(), 'group' => Group::getSerializer()->getFields(), 'api' => Api::getSerializer()->getFields()])); $document = new Document($resource); return new JsonResponse($document->toArray(), 200); }
/** * @param Request $request * @param Updated $payload */ public function updated(Request $request, Updated $payload) { $params = new Parameters($request->query->all()); $serializer = Group::getSerializer(); $resource = new Resource($payload->getModel(), $serializer); $resource = $resource->with($params->getInclude(['users', 'actions'])); $resource = $resource->fields($params->getFields(['group' => Group::getSerializer()->getFields(), 'user' => User::getSerializer()->getFields(), 'action' => Action::getSerializer()->getFields()])); $document = new Document($resource); return new JsonResponse($document->toArray(), 200); }
/** * @param Request $request * @param Found $payload */ public function found(Request $request, Found $payload) { $params = new Parameters($request->query->all()); $data = $payload->getModel(); $serializer = Group::getSerializer(); $resource = new Collection($data, $serializer); $resource = $resource->with($params->getInclude(['users', 'actions'])); $resource = $resource->fields($params->getFields(['group' => Group::getSerializer()->getFields(), 'user' => User::getSerializer()->getFields(), 'action' => Action::getSerializer()->getFields()])); $document = new Document($resource); // meta if ($params->getPage('size') != -1) { $document->setMeta(['total' => $data->getNbResults(), 'first' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getFirstPage()]]), 'next' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getNextPage()]]), 'previous' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getPreviousPage()]]), 'last' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getLastPage()]])]); } // return response return new JsonResponse($document->toArray()); }
/** * Clears the current object, sets all attributes to their default values and removes * outgoing references as well as back-references (from other objects to this one. Results probably in a database * change of those foreign objects when you call `save` there). */ public function clear() { if (null !== $this->aGroup) { $this->aGroup->removeUserGroup($this); } if (null !== $this->aUser) { $this->aUser->removeUserGroup($this); } $this->user_id = null; $this->group_id = null; $this->alreadyInSave = false; $this->clearAllReferences(); $this->resetModified(); $this->setNew(true); $this->setDeleted(false); }
/** * @param mixed $model * @return Relationship */ public function groups($model) { $method = 'get' . $this->getCollectionMethodPluralName('groups'); $relationship = new Relationship(new Collection($model->{$method}(), Group::getSerializer())); return $this->addRelationshipSelfLink($relationship, $model, 'group'); }
/** * Filter the query by a related \keeko\core\model\Group object * * @param \keeko\core\model\Group|ObjectCollection $group The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @throws \Propel\Runtime\Exception\PropelException * * @return ChildUserGroupQuery The current query, for fluid interface */ public function filterByGroup($group, $comparison = null) { if ($group instanceof \keeko\core\model\Group) { return $this->addUsingAlias(UserGroupTableMap::COL_GROUP_ID, $group->getId(), $comparison); } elseif ($group instanceof ObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this->addUsingAlias(UserGroupTableMap::COL_GROUP_ID, $group->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { throw new PropelException('filterByGroup() only accepts arguments of type \\keeko\\core\\model\\Group or Collection'); } }
/** * Automatically generated run method * * @param Request $request * @param mixed $data * @return JsonResponse */ public function run(Request $request, $data = null) { $serializer = Group::getSerializer(); $relationship = $serializer->actions(); return new JsonResponse($relationship->toArray()); }
/** * Automatically generated method, will be overridden * * @param Group $group */ protected function groupToArray(Group $group) { return $this->filter($group->toArray(TableMap::TYPE_CAMELNAME)); }
/** * @param Request $request * @param Updated $payload */ public function updated(Request $request, Updated $payload) { $serializer = Group::getSerializer(); $relationship = $serializer->users($payload->getModel()); return new JsonResponse($relationship->toArray()); }
/** * Exclude object from result * * @param ChildGroup $group Object to remove from the list of results * * @return $this|ChildGroupQuery The current query, for fluid interface */ public function prune($group = null) { if ($group) { $this->addUsingAlias(GroupTableMap::COL_ID, $group->getId(), Criteria::NOT_EQUAL); } return $this; }
/** * Interal mechanism to remove Users from Group * * @param Group $model * @param mixed $data */ protected function doRemoveUsers(Group $model, $data) { $errors = []; foreach ($data as $entry) { if (!isset($entry['id'])) { $errors[] = 'Missing id for User'; } else { $related = UserQuery::create()->findOneById($entry['id']); $model->removeUser($related); } } if (count($errors) > 0) { return new ErrorsException($errors); } }