Mysql($faqDB); $this->data = $data; } // Is this instance valid? function isValid() { if ($this->data["cat_id"] <> "" && $this->data["question_id"] <> "" && $this->data["rank"] <> "") { return true; } else { return false; } } // Access to member variables function getID() { return $this->data["id"]; } function setID($i) { $this->data["id"] = $i; } function setCategoryID($v) { $this->data["cat_id"] = $v; } function getCategoryID() { return $this->data["cat_id"]; } function setQuestionID($v) { $this->data["question_id"] = $v; } function getQuestionID() { return $this->data["question_id"]; } function setRank($v) { $this->data["rank"] = $v; } function getRank() { return $this->data["rank"]; } function setLastModDate($d) { $this->data["last_mod_date"] = $d; } function getLastModDate() { return $this->data["last_mod_date"]; } function setLastModUser($u) { $this->data["last_mod_user"] = $u; } function getLastModUser() { return $this->data["last_mod_user"]; } // Create a category (only if the category does not already exist) function create() { global $theUser; global $catXrefTable; if (!$this->isValid()) return; // Ensure that this one doesn't already exist if ($this->getID() != "") { $q = "SELECT * FROM $catXrefTable WHERE id = " . $this->getID(); $foo = $this->do_query($q, 1); if ($foo[0]->isValid()) return; } $this->setLastModDate(date("Y-m-d")); $this->setLastModUser($theUser->getID()); $q = "INSERT INTO $catXrefTable VALUES (1, NULL, " . $this->getCategoryID() . ", " . $this->getQuestionID() . ", " . $this->getRank() . ", '" . $this->getLastModDate() . "', '" . $this->getLastModUser() . "')"; $this->do_query($q, 0); // Update the global "last updated" date $sys = new System(); $sys->update(); } // Update a category (only if the category already exists) function update() { global $theUser; global $catXrefTable; if (!$this->isValid()) return; // Set the right values $this->setLastModDate(date("Y-m-d")); $this->setLastModUser($theUser->getID()); $q = "UPDATE $catXrefTable SET " . "cat_id = " . $this->getCategoryID() . ", " . "question_id = " . $this->getQuestionID() . ", " . "rank = " . $this->getRank() . ", " . "last_mod_date = '" . $this->getLastModDate() . "', " . "last_mod_user = '" . $this->getLastModUser() . "' " . "WHERE id = " . $this->getID(); $this->do_query($q, 0); // Update the global "last updated" date $sys = new System(); $sys->update(); } } // Function to sort category cross references function catxref_sort($a, $b) { if ($a->getCategoryID() != $b->getCategoryID()) return ($a->getCategoryID() < $b->getCategoryID()) ? -1 : 1; else if ($a->getRank() != $b->getRank()) return ($a->getRank() < $b->getRank()) ? -1 : 1; else return 0; } // Function to do a generic query and return an array of CategoryXrefs function doCatXrefQuery($q, $want_rows) { global $faqDB; $m = new Mysql($faqDB); $quests = $m->do_query($q, $want_rows); if ($want_rows && $quests[0]->isValid()) { for ($i = 0; $i < sizeof($quests); $i++) $ret[] = new CategoryXref($quests[$i]->getData()); usort($ret, catxref_sort); } else $ret[] = new CategoryXref(""); return $ret; } // Function to return an array of all category xrefs in objects function getAllCatXrefs() { global $catXrefTable; return doCatXrefQuery("SELECT * FROM $catXrefTable", 1); } // Find a category xref by ID number function getCatXrefByID($id) { global $catXrefTable; $vers = doCatXrefQuery("SELECT * FROM $catXrefTable WHERE id = $id", 1); return $vers[0]; } // Find all category xrefs for a given category ID function getCatXrefsByCID($cid) { global $catXrefTable; return doCatXrefQuery("SELECT * FROM $catXrefTable WHERE cat_id = $cid", 1); } // Delete a category xref by ID number function deleteCatXrefByID($id) { global $catXrefTable; $vers = doCatXrefQuery("DELETE FROM $catXrefTable WHERE id = $id", 0); return $vers[0]; } // Delete a category xref by category ID number function deleteCatXrefByCID($cid) { global $catXrefTable; $vers = docatXrefQuery("DELETE FROM $catXrefTable WHERE cat_id = $cid", 0); return $vers[0]; } // Delete a category xref by question ID number function deleteCatXrefByQID($qid) { global $catXrefTable; $vers = docatXrefQuery("DELETE FROM $catXrefTable WHERE question_id = $qid", 0); return $vers[0]; } }