protected function updateExtensions(Package &$model, KeekoPackageSchema $pkg)
 {
     // remove all existing extensions from this package first
     ExtensionQuery::create()->filterByPackage($model)->delete();
     // add them one by one
     foreach ($pkg->getAllExtensions() as $key => $exts) {
         foreach ($exts as $data) {
             $ext = new Extension();
             $ext->setKey($key);
             $ext->setData(Json::encode($data, Json::UNESCAPED_SLASHES));
             $ext->setPackage($model);
             $ext->save();
         }
     }
 }
 /**
  * @param Request $request
  * @param Created $payload
  */
 public function created(Request $request, Created $payload)
 {
     $serializer = Extension::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 = Extension::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude([]));
     $resource = $resource->fields($params->getFields(['extension' => Extension::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 = Extension::getSerializer();
     $resource = new Collection($data, $serializer);
     $resource = $resource->with($params->getInclude([]));
     $resource = $resource->fields($params->getFields(['extension' => Extension::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());
 }
Example #5
0
 /**
  * @param ChildExtension $extension The ChildExtension object to add.
  */
 protected function doAddExtension(ChildExtension $extension)
 {
     $this->collExtensions[] = $extension;
     $extension->setPackage($this);
 }
Example #6
0
 /**
  * Filter the query by a related \keeko\core\model\Extension object
  *
  * @param \keeko\core\model\Extension|ObjectCollection $extension the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildPackageQuery The current query, for fluid interface
  */
 public function filterByExtension($extension, $comparison = null)
 {
     if ($extension instanceof \keeko\core\model\Extension) {
         return $this->addUsingAlias(PackageTableMap::COL_ID, $extension->getPackageId(), $comparison);
     } elseif ($extension instanceof ObjectCollection) {
         return $this->useExtensionQuery()->filterByPrimaryKeys($extension->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByExtension() only accepts arguments of type \\keeko\\core\\model\\Extension or Collection');
     }
 }
Example #7
0
 /**
  * Updates a Extension with the given idand the provided data
  * 
  * @param mixed $id
  * @param mixed $data
  * @return PayloadInterface
  */
 public function update($id, $data)
 {
     // find
     $model = $this->get($id);
     if ($model === null) {
         return new NotFound(['message' => 'Extension not found.']);
     }
     // hydrate
     $data = $this->normalize($data);
     $serializer = Extension::getSerializer();
     $model = $serializer->hydrate($model, $data);
     $this->hydrateRelationships($model, $data);
     // dispatch pre save hooks
     $this->dispatch(ExtensionEvent::PRE_UPDATE, $model, $data);
     $this->dispatch(ExtensionEvent::PRE_SAVE, $model, $data);
     // validate
     $validator = $this->getValidator($model);
     if ($validator !== null && !$validator->validate($model)) {
         return new NotValid(['errors' => $validator->getValidationFailures()]);
     }
     // save and dispath post save hooks
     $rows = $model->save();
     $this->dispatch(ExtensionEvent::POST_UPDATE, $model, $data);
     $this->dispatch(ExtensionEvent::POST_SAVE, $model, $data);
     $payload = ['model' => $model];
     if ($rows === 0) {
         return new NotUpdated($payload);
     }
     return new Updated($payload);
 }
Example #8
0
 /**
  * Exclude object from result
  *
  * @param   ChildExtension $extension Object to remove from the list of results
  *
  * @return $this|ChildExtensionQuery The current query, for fluid interface
  */
 public function prune($extension = null)
 {
     if ($extension) {
         $this->addUsingAlias(ExtensionTableMap::COL_ID, $extension->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }