Esempio n. 1
0
 public function createNodePartialsFromExistsClauses(NodeQuery $nodeQuery)
 {
     $nodePartials = new NodePartials();
     foreach ($nodeQuery->getParameters() as $key => $value) {
         switch ($key) {
             case 'Meta.exist':
                 $nodePartials->increaseMetaPartials($value);
                 break;
             case 'OutTags.exist':
                 $nodePartials->increaseOutPartials($value);
                 break;
             case 'InTags.exist':
                 $nodePartials->increaseInPartials($value);
                 break;
                 //                    case 'Sections.exist':
                 //                        $nodePartials->increaseSectionPartials($value);
                 //                        break;
         }
     }
     $metaParams = $this->getMetaFilters($nodeQuery);
     foreach ($metaParams as $mArgs) {
         $nodePartials->increaseMetaPartials($mArgs[0]);
     }
     return $nodePartials;
 }
 /**
  * Fetches a specific media node.
  *
  * @param ElementSlug  _required_  e.g. image
  * @param NodeSlug  _required_  the Slug of the node to retrieve
  * @param Thumbnails _optional_  comma delimited list of thumbnail sizes to return e.g. "150,100x100" or "all"
  * @param Meta.select  _optional_  list of Meta fields to return as per NodeApiController
  * @param OutTags.select  _optional_  list of OutTags to retrieve as per NodeApiController
  * @param Depth _optional_ whether to include original/thumbnail tags (TBD)
  */
 public function get()
 {
     $noderef = $this->getNodeRef();
     $hasJsonThumbnails = $noderef->getElement()->hasAspect('mixin-json-thumbnails');
     $nodePartials = new NodePartials($this->Request->getParameter('Meta_select'), $this->Request->getParameter('OutTags_select'), $this->Request->getParameter('InTags_select'));
     $nodePartials->increaseOutPartials('#original.fields');
     if ($hasJsonThumbnails && StringUtils::strToBool($this->Request->getParameter('retrieveThumbnails'))) {
         $nodePartials->increaseMetaPartials('#thumbnails-json');
     }
     $node = $this->RegulatedNodeService->getByNodeRef($noderef, $nodePartials);
     $c = $this->_buildNodeJSON($node, true, StringUtils::strToBool($this->Request->getParameter('retrieveThumbnails')));
     //todo: include metas
     //todo: include tags
     $this->sendJSON($c);
 }
 /**
  * Updates a node with fields specified in params.
  *
  * @param array $params The user-supplied parameters/fields
  * @throws MediaServiceException
  * @throws ValidationException
  */
 public function edit($params)
 {
     $node = $this->getNode($params);
     // will spit error if not found
     // set any persistent fields
     $this->NodeBinder->bindPersistentFields($node, $this->getErrors(), $params, $params);
     $this->NodeBinder->fireEditBindEvents($node, $this->getErrors(), $params, $params);
     // throw any validation errors
     $this->getErrors()->throwOnError();
     $nodePartials = new NodePartials();
     // add any meta fields
     foreach ($params as $name => $value) {
         if (substr($name, 0, 1) == '#') {
             $node->setMeta($name, $value);
             $nodePartials->increaseMetaPartials($name);
         }
     }
     // add any out tags
     $outTagParam = !empty($params['AddOutTags']) ? $params['AddOutTags'] : null;
     if ($outTagParam) {
         $outTags = $this->buildTags($outTagParam);
         $node->addOutTags($outTags);
         foreach ($outTags as $tag) {
             $role = $tag->getTagRole();
             $val = $tag->getTagValue();
             $nodePartials->increaseOutPartials($role . '=' . $val);
         }
     }
     // add any in tags
     $inTagParam = !empty($params['AddInTags']) ? $params['AddInTags'] : null;
     if ($inTagParam) {
         $inTags = $this->buildTags($inTagParam);
         $node->addInTags($inTags);
         foreach ($inTags as $tag) {
             $role = $tag->getTagRole();
             $val = $tag->getTagValue();
             $nodePartials->increaseInPartials($role . '=' . $val);
         }
     }
     // set node partials to specify exactly what's added/updated
     $node->setNodePartials($nodePartials);
     // do the update
     $this->RegulatedNodeService->edit($node);
 }