/**
  * Set Global
  *
  * Add a variable to the EE javascript object.  Useful if you need
  * to dynamically set variables for your external script.  Will intelligently
  * resolve namespaces (i.e. filemanager.filelist) - use them.
  *
  * @access	public
  */
 function set_global($var, $val = '')
 {
     if (is_array($var)) {
         foreach ($var as $k => $v) {
             $this->set_global($k, $v);
         }
         return;
     }
     $sections = explode('.', $var);
     $var_name = array_pop($sections);
     $current =& $this->global_vars;
     foreach ($sections as $namespace) {
         if (!isset($current[$namespace])) {
             $current[$namespace] = array();
         }
         $current =& $current[$namespace];
     }
     if (is_array($val) && isset($current[$var_name]) && is_array($current[$var_name])) {
         $current[$var_name] = ee_array_unique(array_merge($current[$var_name], $val), SORT_STRING);
     } else {
         $current[$var_name] = $val;
     }
 }
Esempio n. 2
0
 /**
  * Find All Relationships of the Given Entries in the Template
  *
  * Searches the template the parser was constructed with for relationship
  * tags and then builds a tree of all the requested related entries for
  * each of the entries passed in the array.
  *
  * For space savings and subtree querying each node is pushed
  * its own set of entry ids per parent ids:
  *
  *						 {[6, 7]}
  *						/		\
  *		 {6:[2,4], 7:[8,9]}    	{6:[], 7:[2,5]}
  *				/					\
  *	  		...				  		 ...
  *
  * By pushing them down like this the subtree query is very simple.
  * And when we parse we simply go through all of them and make that
  * many copies of the node's tagdata.
  *
  * @param	int[]	An array of entry ids who's relations we need
  *					to find.
  * @return	object	The tree root node
  */
 public function build_tree(array $entry_ids, $tagdata)
 {
     // first, we need a tag tree
     $root = $this->_build_tree($tagdata);
     if ($root === NULL) {
         return NULL;
     }
     // not strictly necessary, but keeps all the id loops parent => children
     // it has no side-effects since all we really care about for the root
     // node are the children.
     foreach ($entry_ids as $id) {
         $root->add_entry_id((int) $id, (int) $id);
     }
     $all_entry_ids = array($entry_ids);
     if (isset($this->grid_field_id)) {
         $all_entry_ids = array(array());
     }
     $query_node_iterator = new RecursiveIteratorIterator(new QueryNodeIterator(array($root)), RecursiveIteratorIterator::SELF_FIRST);
     // For every query node we now run the query and push the ids
     // down onto their subtrees.
     foreach ($query_node_iterator as $node) {
         // the root uses the main entry ids, all others use all
         // of the parent's child ids. These form all of their potential
         // parents, and thus the where_in for our query.
         if (!$node->is_root() && !$node->in_grid) {
             $entry_ids = $node->parent()->entry_ids();
             $entry_ids = call_user_func_array('array_merge', $entry_ids);
         }
         // Store flattened ids for the big entry query
         $all_entry_ids[] = $this->_propagate_ids($node, ee()->relationship_model->node_query($node, $entry_ids, $this->grid_field_id));
     }
     $this->_unique_ids = ee_array_unique(call_user_func_array('array_merge', $all_entry_ids), SORT_NUMERIC);
     return $root;
 }