id = $id; } $this->load($this->id); } function load($id) { if (is_numeric($id)) { $this->id = $id; } $data = false; if (is_numeric($this->id)) { $data = query_row("SELECT * FROM " . DB_PREFIX . $this->getTable() . " WHERE id='{$id}'"); } if ($data) { $this->id = $id; $this->setTitle($data->title); //$this->setLastName($data->last_name); /*$this->setCreated($data->created); $this->setModified($data->modified); $this->setCreator($data->creator);*/ return $data; } return false; } function create() { $this->setCreator(get_logged_in_user()->getId()); $parent = "NULL"; if ($this->getParentId()) { $parent = $this->getParentId(); } $insert = query_insert("INSERT INTO " . DB_PREFIX . $this->getTable() . " (title, parent) values ('".mysql_real_escape_string($this->getTitle())."',".$parent.")"); return $insert; } function save() { $update_query = "UPDATE " . DB_PREFIX . $this->getTable() . " SET"; $update_query .= " title='" . mysql_real_escape_string($this->getTitle()) . "',"; $update_query .= " description='" . mysql_real_escape_string($this->getDescription()) . "',"; $update_query .= " modified=NOW()"; $update_query .= " WHERE id=" . $this->getId(); $update = query_update($update_query); return $update; } function build($data) { global $TeKe; $this->setTitle($data["title"]); if ($data["parent_id"] > 0) $this->setParentId($data["parent_id"]); if ($this->getId() > 0) { return $this->save(); } else { $id = $this->create(); return $id; } } function delete() { global $TeKe; if (is_numeric($this->getId()) && $this->getId() > 0) { if ($TeKe->plugin->is_test_constructor()) { $delete_result =query("DELETE FROM " . DB_PREFIX . $this->getTable() . " WHERE id=".$this->getId()); if ($delete_result) { $this->deleteChildren($this->getId()); return true; } } } return false; } function deleteChildren($category_id) { global $TeKe; $category_children = $TeKe->plugin->categories->getChildCategories($category_id); foreach ($category_children as $child_category) { $category_obj = $TeKe->plugin->loadType("category", $child_category->id); $category_obj->delete(); } } public function getId() { return $this->id; } public function setId($id) { $this->id = $id; } public function getTable() { return $this->table; } function setTable($table) { $this->table = $table; } public function getTitle() { return $this->title; } function setTitle($title) { $this->title = $title; } public function getCreator() { return $this->creator; } function setCreator($creator) { $this->creator = $creator; } public function getParentId() { return $this->parent_id; } function setParentId($parent_id) { $this->parent_id = $parent_id; } function addBuildError($err) { $this->build_error []= $err; } function getBuildError() { return $this->build_error; } } ?>