/** overload values to fix checkboxes * * @param array values * @return $this */ public function values(array $values) { if ($this->loaded()) { $new = array('islink' => 0, 'showmap' => 0, 'shownav' => 0.0); return parent::values(array_merge($new, $values)); } else { return parent::values($values); } }
/** * Move * * @param Sprig_MPTT|integer $target target node id or Sprig_MPTT object. * @param bool $left_column use the left column or right column from target * @param integer $left_offset left value for the new node position. * @param integer $level_offset level * @param bool allow this movement to be allowed on the root node */ protected function move($target, $left_column, $left_offset, $level_offset, $allow_root_target) { if (!$this->loaded()) { return FALSE; } // Make sure we have the most upto date version of this AFTER we lock $this->lock(); $this->reload(); // Catch any database or other excpetions and unlock try { if (!$target instanceof $this) { $target = Sprig_MPTT::factory($this->_model, array($this->pk() => $target))->load(); if (!$target->loaded()) { $this->unlock(); return FALSE; } } else { $target->reload(); } // Stop $this being moved into a descendant or itself or disallow if target is root if ($target->is_descendant($this) or $this->{$this->pk()} === $target->{$this->pk()} or $allow_root_target === FALSE and $target->is_root()) { $this->unlock(); return FALSE; } $left_offset = ($left_column === TRUE ? $target->{$this->left_column} : $target->{$this->right_column}) + $left_offset; $level_offset = $target->{$this->level_column} - $this->{$this->level_column} + $level_offset; $size = $this->get_size(); $this->create_space($left_offset, $size); // if node is moved to a position in the tree "above" its current placement // then its lft/rgt may have been altered by create_space $this->reload(); $offset = $left_offset - $this->{$this->left_column}; // Update the values. Database::instance($this->_db)->query(NULL, 'UPDATE ' . $this->_table . ' SET `' . $this->left_column . '` = `' . $this->left_column . '` + ' . $offset . ', `' . $this->right_column . '` = `' . $this->right_column . '` + ' . $offset . ' , `' . $this->level_column . '` = `' . $this->level_column . '` + ' . $level_offset . ' , `' . $this->scope_column . '` = ' . $target->{$this->scope_column} . ' WHERE `' . $this->left_column . '` >= ' . $this->{$this->left_column} . ' AND `' . $this->right_column . '` <= ' . $this->{$this->right_column} . ' AND `' . $this->scope_column . '` = ' . $this->{$this->scope_column}, TRUE); $this->delete_space($this->{$this->left_column}, $size); } catch (Exception $e) { //Unlock table and re-throw exception $this->unlock(); throw $e; } $this->unlock(); return $this; }
/** * Move * * @param Sprig_MPTT|integer $target target node id or Sprig_MPTT object. * @param bool $left_column use the left column or right column from target * @param integer $left_offset left value for the new node position. * @param integer $level_offset level * @param bool allow this movement to be allowed on the root node */ protected function move($target, $left_column, $left_offset, $level_offset, $allow_root_target) { if (!$this->loaded()) { return FALSE; } // Make sure we have the most upto date version of this AFTER we lock $this->lock(); $this->reload(); // Catch any database or other excpetions and unlock try { if (!$target instanceof $this) { $target = Sprig_MPTT::factory($this->_model, array($this->pk() => $target))->load(); if (!$target->loaded()) { $this->unlock(); return FALSE; } } else { $target->reload(); } // Stop $this being moved into a descendant or itself or disallow if target is root if ($target->is_descendant($this) or $this->{$this->pk()} === $target->{$this->pk()} or $allow_root_target === FALSE and $target->is_root()) { $this->unlock(); return FALSE; } $left_offset = ($left_column === TRUE ? $target->{$this->left_column} : $target->{$this->right_column}) + $left_offset; $level_offset = $target->{$this->level_column} - $this->{$this->level_column} + $level_offset; $size = $this->get_size(); $this->create_space($left_offset, $size); // if node is moved to a position in the tree "above" its current placement // then its lft/rgt may have been altered by create_space $this->reload(); $offset = $left_offset - $this->{$this->left_column}; // Get the database instance $db = $this->_db instanceof Database ? $this->_db : Database::instance($this->_db); // Update the values. DB::update($this->_table)->set(array($this->left_column => DB::expr($db->quote_identifier($this->left_column) . ' + ' . $offset), $this->right_column => DB::expr($db->quote_identifier($this->right_column) . ' + ' . $offset), $this->level_column => DB::expr($db->quote_identifier($this->level_column) . ' + ' . $level_offset), $this->scope_column => $target->{$this->scope_column}))->where($this->left_column, '>=', $this->{$this->left_column})->where($this->right_column, '<=', $this->{$this->right_column})->where($this->scope_column, '=', $this->{$this->scope_column})->execute($db); $this->delete_space($this->{$this->left_column}, $size); } catch (Exception $e) { //Unlock table and re-throw exception $this->unlock(); throw $e; } $this->unlock(); return $this; }