Example #1
0
 public function nodes()
 {
     $collection = new NodeCollection();
     $collection->orderBy('updated');
     // add node type
     $collection->joinNodetype();
     $collection->getQuery()->addSelect('nodetype.name AS nodetype_name');
     return (object) ['data' => $collection->toArray()];
 }
Example #2
0
 public function searchJson()
 {
     $q = Ajde::app()->getRequest()->getParam('query');
     $collection = new NodeCollection();
     // split search terms
     $terms = explode(' ', $q);
     // search on node fields
     $searchGroup = new Ajde_Filter_WhereGroup(Ajde_Query::OP_OR);
     foreach ($terms as $term) {
         $termGroup = $collection->getTextFilterGroup($term, Ajde_Query::OP_OR);
         if ($termGroup !== false) {
             $searchGroup->addFilter($termGroup);
         }
     }
     $collection->addFilter($searchGroup);
     // search on meta search
     $collection->addFilter(new Ajde_Filter_LeftJoin('node_meta', 'node_meta.node', 'node.id'));
     $searchGroup = new Ajde_Filter_WhereGroup(Ajde_Query::OP_OR);
     foreach ($terms as $term) {
         $searchGroup->addFilter(new Ajde_Filter_Where('node_meta.value', Ajde_Filter::FILTER_LIKE, '%' . $term . '%', Ajde_Query::OP_OR));
     }
     $collection->addFilter($searchGroup);
     $collection->getQuery()->addGroupBy('node.id');
     // join in nodetype info
     $collection->joinNodetype();
     $collection->getQuery()->addSelect('nodetype.name AS nodetype_name');
     $collection->getQuery()->addSelect('nodetype.icon AS nodetype_icon');
     $suggestions = [];
     foreach ($collection as $node) {
         /* @var $node NodeModel */
         $suggestions[] = ['value' => "<i class='" . $node->get('nodetype_icon') . "'></i> " . $node->displayField(), 'data' => $node->getPK()];
     }
     return ['query' => $q, 'suggestions' => $suggestions];
 }
Example #3
0
 /**
  * Copies this node to a new parent. This copies the node
  * to the new parent node/tree and all its child nodes (ie
  * a deep copy). Technically, new nodes are created with copies
  * of the tag data, since this is for all intents and purposes
  * the only thing that needs copying.
  *
  * @param  object $newParent The new parent Tree_Node or Tree object
  * @return object            The new node
  */
 public function copyTo($newParent)
 {
     $newNode = $newParent->nodes->add(new Tree_Node($this->getTag()));
     // Copy child nodes
     $this->nodes->copyTo($newNode);
     return $newNode;
 }
Example #4
0
 /**
  * @return NodeCollection
  */
 public function getLinks()
 {
     $collection = new NodeCollection();
     $collection->addFilter(new Ajde_Filter_Join('menu', 'menu.node', 'node.id'));
     $collection->addFilter(new Ajde_Filter_Where('menu.parent', Ajde_Filter::FILTER_EQUALS, $this->getPK()));
     $collection->getQuery()->addSelect('menu.name as name');
     $collection->orderBy('menu.sort');
     return $collection;
 }
Example #5
0
 public function navJson()
 {
     $recursive = true;
     $parent = Ajde::app()->getRequest()->getInt('node', false);
     $nodes = new NodeCollection();
     $nodes->addFilter(new Ajde_Filter_Where('level', Ajde_Filter::FILTER_EQUALS, 0));
     if ($recursive) {
         $nodes->orderBy('sort');
         $json = [];
         foreach ($nodes as $node) {
             /* @var $node NodeModel */
             $nodeArray = ['label' => $this->navLabel($node), 'id' => $node->getPK()];
             $children = $node->getChildren();
             if ($children->count()) {
                 $nodeArray['children'] = $this->navChildrenArray($children);
             }
             $json[] = $nodeArray;
         }
         return $json;
     } else {
         if ($parent) {
             $nodes->addFilter(new Ajde_Filter_Where('parent', Ajde_Filter::FILTER_EQUALS, $parent));
         } else {
             $nodes->addFilter(new Ajde_Filter_Where('level', Ajde_Filter::FILTER_EQUALS, 0));
         }
         $nodes->getQuery()->addSelect('id AS aid');
         $nodes->getQuery()->addSelect('(SELECT count(b.id) FROM node b WHERE b.parent = aid) AS children');
         $nodes->orderBy('sort');
         $json = [];
         foreach ($nodes as $node) {
             /* @var $node NodeModel */
             $children = $node->get('children');
             $json[] = ['label' => $this->navLabel($node), 'id' => $node->getPK(), 'load_on_demand' => $children ? true : false];
         }
         return $json;
     }
 }
Example #6
0
 public function getSibling($dir, $loop = true)
 {
     if ($dir == 'next') {
         $filter = Ajde_Filter::FILTER_GREATER;
         $order = Ajde_Query::ORDER_ASC;
     } else {
         $filter = Ajde_Filter::FILTER_LESS;
         $order = Ajde_Query::ORDER_DESC;
     }
     if ($this->has('parent')) {
         $siblings = new NodeCollection();
         $siblings->addFilter(new Ajde_Filter_Where('sort', $filter, $this->sort));
         $siblings->addFilter(new Ajde_Filter_Where('parent', Ajde_Filter::FILTER_EQUALS, (string) $this->get('parent')));
         $siblings->orderBy('sort', $order);
         $siblings->limit(1);
         if ($siblings->count()) {
             return $siblings->current();
         }
     }
     // Not found, loop?
     if ($loop === true) {
         $siblings->reset();
         $siblings->addFilter(new Ajde_Filter_Where('parent', Ajde_Filter::FILTER_EQUALS, (string) $this->get('parent')));
         $siblings->orderBy('sort', $order);
         $siblings->limit(1);
         if ($siblings->count()) {
             return $siblings->current();
         }
     }
     // No sibling
     return false;
 }
Example #7
0
 /**
  * Merges the current collection with another one, and returns the other one.
  *
  * @param NodeCollection $collection
  *  The destination collection.
  *
  * @return static
  */
 public function addTo(NodeCollection $collection)
 {
     return $collection->add($this);
 }