Mysql($faqDB); $this->data = $data; } // Is this instance valid? function isValid() { if ($this->data["version_id"] <> "" && $this->data["question_id"] <> "" && $this->data["andup"] <> "") { return true; } else { return false; } } // Access to member variables function getID() { return $this->data["id"]; } function setVersionID($v) { $this->data["version_id"] = $v; } function getVersionID() { return $this->data["version_id"]; } function setQuestionID($v) { $this->data["question_id"] = $v; } function getQuestionID() { return $this->data["question_id"]; } function setAndUp($v) { $this->data["andup"] = $v; } function getAndUp() { return $this->data["andup"]; } 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 version (only if the version does not already exist) function create() { global $theUser; global $verXrefTable; if (!$this->isValid()) return; // Ensure that this one doesn't already exist if ($this->getID() != "") { $q = "SELECT * FROM $verXrefTable 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 $verXrefTable VALUES (1, NULL, " . $this->getVersionID() . ", " . $this->getQuestionID() . ", " . $this->getAndUp() . ", '" . $this->getLastModDate() . "', '" . $this->getLastModUser() . "')"; $this->do_query($q, 0); // Update the global "last updated" date $sys = new System(); $sys->update(); } // Update a version (only if the version already exists) function update() { global $theUser; global $verTable; if (!$this->isValid()) return; // Set the right values $this->setLastModDate(date("Y-m-d")); $this->setLastModUser($theUser->getID()); $q = "UPDATE $verTable SET " . "version_id = " . $this->getVersionID() . ", " . "question_id = " . $this->getQuestionID() . ", " . "andup = " . $this->getAndUp() . ", '" . "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 do a generic query and return an array of VersionXrefs function doVerXrefQuery($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 VersionXref($quests[$i]->getData()); else $ret[] = new VersionXref(""); return $ret; } // Function to return an array of all version xrefs in objects function getAllVerXrefs() { global $verXrefTable; return doVerXrefQuery("SELECT * FROM $verXrefTable", 1); } // Find a version xref by ID number function getVerXrefByID($id) { global $verXrefTable; $vers = doVerXrefQuery("SELECT * FROM $verXrefTable WHERE id = $id", 1); return $vers[0]; } // Find all version xrefs for a given question ID function getVerXrefsByQID($qid) { global $verXrefTable; $vers = doVerXrefQuery("SELECT * FROM $verXrefTable WHERE question_id = $qid", 1); return $vers; } // Delete a version xref by ID number function deleteVerXrefByID($id) { global $verXrefTable; $vers = doVerXrefQuery("DELETE FROM $verXrefTable WHERE id = $id", 0); return $vers[0]; } // Delete a version xref by question ID number function deleteVerXrefByQID($qid) { global $verXrefTable; $vers = doVerXrefQuery("DELETE FROM $verXrefTable WHERE question_id = $qid", 0); return $vers[0]; } }