public function version_move($table, $model, $page_pid, $page_sid, $type) { if (!is_numeric($page_pid)) { throw new Exception("Must pass subject id", 1); } if (!is_numeric($page_sid)) { throw new Exception("Must pass target id", 1); } if ($page_pid == $page_sid) { throw new Exception("Subject and target cannot be the same", 1); } $types = array('move_to_last_child', 'move_to_first_child', 'move_to_next_sibling', 'move_to_prev_sibling'); if (!in_array($type, $types)) { throw new Exception("Must pass move type", 1); } versions_helper::version_position_table($table); $id_node = ORM::factory($model)->where('page_pid', $page_pid)->find(); $item = ORM::factory($model)->where('page_pid', $page_sid)->find(); if (!$item->loaded) { throw new Exception("Subject not loaded", 1); } if (!$id_node->loaded) { throw new Exception("Target not loaded", 1); } $result = $item->{$type}($id_node); if (!$result) { throw new Exception("Problem with move", 1); } }
function index() { $v = versions_helper::get_published_version(); $m = ORM::factory('version')->orderby('id', 'DESC')->find_all(); $type = Input::instance()->get('type', ''); $type = $type > '' ? '?type=' . $type : ''; View::factory('versions')->set('versions', $m)->set('current', $v)->set('type', $type)->render(true); }
/** * undocumented function * * @return void * @author Andy Bennett */ public function move() { $data = array('action' => 'edit', 'name' => $this->name, 'role' => User::instance()->get_role()); Event::run('steamcore.aclcheck', $data); try { $id = Input::instance()->post('id'); $sid = Input::instance()->post('sid'); $type = Input::instance()->post('type'); versions_helper::version_move('pages_positions', 'pages_position', $id, $sid, $type); } catch (Exception $e) { Kohana::log('error', $e->getMessage()); } url::redirect('pages/admin'); }
public function find_all($limit = NULL, $offset = NULL) { if (Kohana::config('versions.version') == 'max') { $w = new Database_Expression('(SELECT max(version) FROM ' . $this->table_name . ' AS q WHERE ' . $this->table_name . '.pid=q.pid)'); } else { $v = versions_helper::get_published_version(); $w = new Database_Expression('(SELECT max(version) FROM ' . $this->table_name . ' AS q WHERE ' . $this->table_name . '.pid=q.pid AND version <= ' . $v . ')'); } $this->db->join('page_content_positions', 'page_content_positions.page_content_pid', 'page_contents.pid'); $this->db->where('version', $w); $this->db->where('state!=', 'D'); $this->db_applied['orderby'] = true; $this->db->orderby('page_content_positions.order', 'ASC'); return parent::find_all($limit, $offset); }
public function version_position_table($table, $version = null) { if (is_null($version)) { $version = versions_helper::get_version(); } $db = new Database(); $vs = new Database_Expression('(SELECT max(version) AS version FROM ' . $table . '_store LIMIT 1)'); $r = $db->where('version', $vs)->get($table . '_store')->as_array(false); foreach ($r as $p) { unset($p['id']); $p['version'] = $version; $db->insert($table . '_store', $p); } $sql = "CREATE OR REPLACE VIEW " . $table . " AS (SELECT * FROM " . $table . "_store WHERE version=" . $version . ")"; $db->query($sql); }
/** * delete * * @return void * @author Andy Bennett */ public function delete() { $pos = ORM::factory($this->object_plural . '_position')->where($this->object_name . '_id', $this->id)->find(); $ids = $pos->delete_which(); $version = versions_helper::get_version(); $db = new Database(); foreach ($ids as $id) { $tmp = $db->getwhere($this->table_name, array('id' => $id->{$this->object_name . '_id'}))->as_array(false); if (count($tmp)) { $arr = current($tmp); unset($arr['id']); $arr['state'] = 'D'; $arr['version'] = $version; $db->insert($this->table_name, $arr); } } $pos->delete($version); return $this->clear(); }
/** * Finds multiple database rows and returns an iterator of the rows found. * * @chainable * @param integer SQL limit * @param integer SQL offset * @return ORM_Iterator */ public function find_all($limit = NULL, $offset = NULL) { if (Kohana::config('versions.version') == 'max') { $w = new Database_Expression('(SELECT max(version) FROM ' . $this->table_name . ' AS q WHERE ' . $this->table_name . '.pid=q.pid)'); } else { $v = versions_helper::get_published_version(); $w = new Database_Expression('(SELECT max(version) FROM ' . $this->table_name . ' AS q WHERE ' . $this->table_name . '.pid=q.pid AND version <= ' . $v . ')'); } $this->db->where('version', $w); $this->db->where('state!=', 'D'); return parent::find_all($limit, $offset); }
function index() { $v = versions_helper::get_published_version(); $m = ORM::factory('version')->find_all(); View::factory('versions')->set('versions', $m)->set('current', $v)->render(true); }
/** * Removes a node and it's descendants. * * $usless_param prevents a strict error that breaks PHPUnit like hell! * @access public * @param bool $descendants remove the descendants? */ public function delete($version, $usless_param = NULL) { versions_helper::version_position_table($this->table_name, $version); parent::delete($usless_param); }