load($id); } $this->setActions(array("view"=>_("View"), "edit"=>_("Edit"), "add"=>_("New folder"), "TestFolder/add"=>_("New test folder"), "import"=>_("Import test asset"))); } function load($id) { $id = (int) $id; if (is_numeric($id)) { $data = query_row("SELECT * FROM " . DB_PREFIX . "folder WHERE id='{$id}'"); if ($data) { $this->id = $id; $this->setFolder($data->folder); $this->setTitle($data->title); $this->setDescription($data->description); $this->setCreated($data->created); $this->setModified($data->modified); $this->setCreator($data->creator); $this->setSecurity($data->security); $this->setPosition($data->position); return $data; } } return false; } function create() { $this->setCreator(get_logged_in_user()->getId()); if (!$this->getFolder()) $this->setFolder("NULL"); echo "INSERT INTO " . DB_PREFIX . "folder (folder, title, description, created, creator) values (".$this->getFolder().", '".mysql_real_escape_string($this->getTitle())."', '".mysql_real_escape_string($this->getDescription())."', NOW(), ".$this->getCreator().")"; $insert = query_insert("INSERT INTO " . DB_PREFIX . "folder (folder, title, description, created, creator) values (".$this->getFolder().", '".mysql_real_escape_string($this->getTitle())."', '".mysql_real_escape_string($this->getDescription())."', NOW(), ".$this->getCreator().")"); return $insert; } function save() { $update = query_update("UPDATE " . DB_PREFIX . "folder SET title='".mysql_real_escape_string($this->getTitle())."', description='".mysql_real_escape_string($this->getDescription())."', modified=NOW() WHERE id=".$this->getId()); if ($update) { return $this->id; } return false; } function copy() { $this->setTitle($this->getTitle()." ("._("Copy of").")"); $content = query_rows("SELECT id, type FROM " . DB_PREFIX . "test_folder WHERE !locked AND folder=".$this->getId()." ORDER BY position ASC"); $some_failed = false; $copy = $this->create(); if ($copy) { $psy = new Psyhvel(); foreach ($content as $cont) { $type = $psy->loadType($cont->type, $cont->id); if ($type) { $type->setFolder($copy); $test_id = $type->copy(); } else { $some_failed = true; } } } if ($some_failed) return false; return $copy; } function build($data) { if (!isset($data["title"]) || empty($data["title"])) { return false; } else { $this->setTitle($data["title"]); if (isset($data["description"])) $this->setDescription($data["description"]); } if ($this->id > 0) { return $this->save(); } else { return $this->create(); } } function delete() { if (is_numeric($this->getId()) && $this->getId() > 0) { if (is_admin() || $this->creator==get_logged_in_user()->getId()) { $psyhvel = new Psyhvel(); $content = query_rows("SELECT id, type FROM " . DB_PREFIX . "test_folder WHERE folder=".$this->getId()); $some_failed = false; foreach ($content as $cont) { if (!$psyhvel->deleteType($cont->type, $cont->id)) { $some_failed = true; } } if (!$some_failed) { return query("DELETE FROM " . DB_PREFIX . "folder WHERE id=".$this->getId()); } } } return false; } function move_up() { } function move_down() { } public function getId() { return $this->id; } public function getFolder() { return $this->folder; } function setFolder($folder) { $this->folder = $folder; } public function getType() { return $this->type; } public function getName() { return $this->name; } function getActions() { return $this->actions; } function setActions($actions) { $this->actions = $actions; } public function getPosition() { return $this->position; } function setPosition($pos) { $this->position = $pos; } public function getTitle() { return $this->title; } function setTitle($title) { $this->title = $title; } public function getDescription() { return $this->description; } function setDescription($desc) { $this->description = $desc; } public function getCreated() { return $this->created; } function setCreated($created) { $this->created = $created; } public function getModified() { return $this->modified; } function setModified($modified) { $this->modified = $modified; } public function getCreator() { return $this->creator; } function setCreator($creator) { $this->creator = $creator; } public function getStatus() { return $this->status; } function setStatus($status) { $this->status = $status; } public function getSecurity() { return $this->security; } function setSecurity($security) { $this->security = $security; } function repositionContents($positions) { $positionCounter = 1; foreach ($positions as $position_id) { query_update("UPDATE " . DB_PREFIX . "test_folder SET position = " . $positionCounter . " WHERE id = " . $position_id." AND folder=".$this->getId()); $positionCounter = $positionCounter + 1; } return true; } function getContent($pos) { if (is_numeric($this->getId())) { $row = query_row("SELECT id, type FROM " . DB_PREFIX . "test_folder WHERE folder=".$this->getId()." ORDER BY position ASC LIMIT 1 OFFSET ".$pos); return $row; } return false; } function getContents() { if (is_numeric($this->getId())) { $rows = query_rows("SELECT * FROM " . DB_PREFIX . "test_folder WHERE !locked AND folder=".$this->getId()." ORDER BY position ASC"); return $rows; } return false; } function buildFromXML($obj, $folder=0) { $this->setTitle($obj->title[0][0]); $this->setDescription($obj->description[0][0]); $this->setCreated($obj->created[0][0]); return $this->create(); } public function getBaseXML() { $xml = "\n\n"; $xml .= "".$this->getType()."\n"; $xml .= "getCreated()."]]>\n"; $xml .= "<![CDATA[".$this->getTitle()."]]>\n"; $xml .= "getDescription()."]]>\n"; //$xml .= $this->getObjectsXML(); $xml .= "\n"; return $xml; } public function getNavigationTree() { $nav = array(); $nav []= array('title' => $this->getTitle(), 'url'=>"library/".$this->getType()."/".$this->getId()."/view", 'current'=>true, 'level'=>1); return $nav; } } ?>