Commit 1d1deac971031650c659ec8ade8e357462f123a8

Authored by rob
1 parent 73724c71

Initial revision. Object that represents web_documents table


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@353 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 129 additions and 0 deletions
lib/web/WebDocument.inc 0 → 100644
  1 +<?php
  2 +/**
  3 +* Class Web Documents
  4 +*
  5 +* Represents a web document as per the web_documents table in the database
  6 +*
  7 +* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa
  8 +* @date 19 January 2003
  9 +*/
  10 +
  11 +class WebDocument {
  12 +
  13 + /** primary key of web document */
  14 + var $iId;
  15 + /** primary key of document to which this web document related*/
  16 + var $iDocumentID;
  17 + /** primary key of web site on which document is published */
  18 + var $iWebSiteID;
  19 + /** unit to which this document belongs */
  20 + var $iUnitID;
  21 + /** status of document */
  22 + var $iStatusID;
  23 +
  24 + var $dDateTime;
  25 +
  26 + function WebDocument($iNewDocumentID, $iNewWebSiteID, $iNewUnitID, $iNewStatusID, $dNewDateTime) {
  27 + //object not yet created in database
  28 + $this->iId = -1;
  29 + $this->iDocumentID = $iNewDocumentID;
  30 + $this->iWebSiteID = $iNewWebSiteID;
  31 + $this->iUnitID = $iNewUnitID;
  32 + $this->iStatusID = $iNewStatusID;
  33 + $this->dDateTime = $dNewDateTime;
  34 + }
  35 +
  36 + /**
  37 + * Create the current object in the database
  38 + *
  39 + * @return boolean on successful store, false otherwise and set $_SESSION["errorMessage"]
  40 + *
  41 + */
  42 + function create() {
  43 + global $default, $lang_err_database, $lang_err_object_exists;
  44 + //if the object hasn't been created
  45 + if ($this->iId < 0) {
  46 + $sql = new Owl_DB();
  47 + $result = $sql->query("INSERT INTO " . $default->owl_web_documents_table . " (document_id, web_site_id, unit_id, status_id, datetime) VALUES ($this->iDocumentID, $this->iWebSiteID, $this->iUnitID, $this->iStatusID, '$this->dDateTime')");
  48 + if ($result) {
  49 + $this->iId = $sql->insert_id();
  50 + return true;
  51 + }
  52 + $_SESSION["errorMessage"] = $lang_err_database;
  53 + return false;
  54 + }
  55 + $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iId . " table = document_fields";
  56 + return false;
  57 + }
  58 +
  59 + /**
  60 + * Update the values in the database table with the object's current values
  61 + *
  62 + * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"]
  63 + *
  64 + */
  65 + function update() {
  66 + global $default, $lang_err_database, $lang_err_object_key;
  67 + //only update if the object has been stored
  68 + if ($this->iId > 0) {
  69 + $sql = new Owl_DB();
  70 + $result = $sql->query("UPDATE " . $default->owl_web_documents_table . " SET document_id = $this->iDocumentID, web_site_id = $this->iWebSiteID, unit_id = $this->iUnitID, status_id = $this->iStatusID, datetime = '$this->dDateTime' WHERE id = $this->iId");
  71 + if ($result) {
  72 + return true;
  73 + }
  74 + $_SESSION["errorMessage"] = $lang_err_database;
  75 + return false;
  76 + }
  77 + $_SESSION["errorMessage"] = $lang_err_object_key;
  78 + return false;
  79 + }
  80 +
  81 + /**
  82 + * Delete the current object from the database
  83 + *
  84 + * @return boolean true on successful deletion, false otherwise and set $_SESSION["errorMessage"]
  85 + *
  86 + */
  87 + function delete() {
  88 + global $default, $lang_err_database, $lang_err_object_key;
  89 + //only delete the object if it exists in the database
  90 + if ($this->iId >= 0) {
  91 + $sql = new Owl_DB();
  92 + $result = $sql->query("DELETE FROM $default->owl_web_documents_table WHERE id = $this->iId");
  93 + if ($result) {
  94 + return true;
  95 + }
  96 + $_SESSION["errorMessage"] = $lang_err_database;
  97 + return false;
  98 + }
  99 + $_SESSION["errorMessage"] = $lang_err_object_key;
  100 + return false;
  101 + }
  102 +
  103 + /**
  104 + * Static function.
  105 + * Given a web_documents primary key it will create a
  106 + * WebDocuments object and populate it with the
  107 + * corresponding database values
  108 + *
  109 + * @return WebDocument populated WebDocument object on successful query, false otherwise and set $_SESSION["errorMessage"]
  110 + */
  111 + function & get($iWebDocumentsID) {
  112 + global $default;
  113 + $sql = new Owl_DB();
  114 + $result = $sql->query("SELECT * FROM $default->owl_web_documents_table WHERE id = $iWebDocumentsID");
  115 + if ($result) {
  116 + if ($sql->next_record()) {
  117 + $oWebDocument = & new WebDocument($sql->f("document_id"), $sql->f("web_site_id"), $sql->f("unit_id"), $sql->f("status_id"), $sql->f("datetime"));
  118 + $oWebDocument->iId = $iWebDocumentsID;
  119 + return $oWebDocument;
  120 + }
  121 + $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iWebDocumentsID . " table = $default->owl_web_documents_table";
  122 + return false;
  123 + }
  124 + $_SESSION["errorMessage"] = $lang_err_database;
  125 + return false;
  126 + }
  127 +
  128 +}
  129 +?>