Beispiel #1
0
 function create_item($data, $parent = null)
 {
     if ($parent) {
         $data['pid'] = $parent->id;
     }
     $id = $this->collection->create($data);
     return $this->collection->get_item_by_id($id);
 }
Beispiel #2
0
 /**
  * @param $data
  */
 function render_before($data)
 {
     $data['children'] = $this->_children ? $this->_children->render() : false;
     $data['parent'] = $this->_parent ? $this->render_parent() : false;
     $data['_template'] = $this->get_template();
     parent::render_before($data);
 }
Beispiel #3
0
 function _toggle_flag($flag)
 {
     $this->collection->toggle_flag($flag, $this->params->id, 'true' == functions::request_var('to', 'false'));
     if ($this->in_ajax()) {
         $this->_ajax_answer(true, i18n::T('Status changed'));
     }
     $this->_update_tree($this->params->pid);
 }
Beispiel #4
0
 /**
  * @param array $data initial
  * @param mixed $parent
  * @return node_collection
  */
 function create($data, $isDir = false)
 {
     $data['pid'] = @$data['pid'] ?: $this->node_id;
     $data['owner_uid'] = 1;
     $data['active'] = 1;
     $data['site_id'] = $this->site_id;
     $data['title'] = $this->iconv(@$data['title']);
     $data['text'] = htmlspecialchars($this->iconv(@$data['text']), ENT_COMPAT, 'UTF-8');
     $data['description'] = htmlspecialchars($this->iconv(@$data['description']), ENT_COMPAT, 'UTF-8');
     $this->counter++;
     // skip
     if ($this->limit && $this->counter > $this->limit) {
         return false;
     }
     if ($this->dry_run) {
         $result = $this->counter;
     } else {
         $result = $this->collection->create($data);
     }
     core::dprint(array('created: %-4d|%-4d|%s%s', $data['pid'], $result, $isDir ? '*' : '', $data['title']), core::E_MESSAGE);
     return $result;
 }
Beispiel #5
0
 function get_tree($site_id = 0)
 {
     $with_spl = class_exists('SplFixedArray');
     $count = $this->set_where('site_id = %d', $site_id)->count_sql();
     if (!$count) {
         return;
     }
     self::$_tree_index_counter = -1;
     self::$_tree_index = $with_spl ? new SplFixedArray(1 + $count) : array();
     $nodes = array();
     $sql = sprintf("SELECT id, pid, title, html_title, url, c_children, active, b_system, b_featured FROM %s WHERE site_id = %d ORDER BY pid, position", $this->get_table(), $site_id);
     $return = array(tf_sat::TREE_URL => array(), tf_sat::TREE_ID => array());
     if ($query_id = $this->db->query($sql)) {
         while ($row = $this->db->fetch_row()) {
             $nodes[(int) $row['id']] = $row;
         }
     }
     core::dprint(array('count: %d, nodes: %d', $count, count($nodes)));
     if (empty($nodes)) {
         return $return;
     }
     $item = array('url' => '', 'c_children' => 1, 'id' => 0, 'level' => -1);
     $this->_get_tree($item, $nodes);
     core::dprint(array('_tree_index_counter: %d, _tree_index: %d, nodes: %d', self::$_tree_index_counter, count(self::$_tree_index), count($nodes)));
     // Note: splFixedArray return wrong count(self::$_tree_index)
     // $count = $with_spl ? ($count - 1) : $count;
     // 0 goes for root, skip it
     for ($index = 1; $index <= $count; $index++) {
         $check_ti = isset(self::$_tree_index[$index]);
         $check_node = $check_ti && isset($nodes[self::$_tree_index[$index]]);
         if (!$check_ti || !$check_node) {
             core::dprint(array('Waring! Update tree goes wrong, index %d | %s, %s', $index, $check_ti ? 'Y' : 'N', $check_node ? 'Y' : 'N'));
         } else {
             $r = $nodes[self::$_tree_index[$index]];
             $r['url'] = '/' . $r['url'];
             $return[tf_sat::TREE_URL][$r['url']] = $r['id'];
             $return[tf_sat::TREE_ID][$r['id']] = $r;
         }
     }
     core::dprint(array('$return[tf_sat::TREE_ID]: %d', count($return[tf_sat::TREE_ID])));
     /*
     //debug:
     core::var_dump(
         $count, 
         self::$_tree_index_counter,
         count((array)self::$_tree_index),
         array_diff((array)self::$_tree_index, $return[tf_sat::TREE_URL])            
     );
     */
     unset($nodes);
     self::$_tree_index = null;
     if ($count != count($return[tf_sat::TREE_ID])) {
         core::dprint(array('Update tree count mismatch! ALL: %d <> INDEX: %d', $count, count($return[tf_sat::TREE_ID])), core::E_CRIT);
     }
     return $return;
 }