Commit 97b59b4c9fbdec29dc31cc3dc2772ad3c96b9080
1 parent
23f4e3e7
initial revision of dashboard news class
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1756 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
244 additions
and
0 deletions
lib/dashboard/DashboardNews.inc
0 → 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * $Id$ | |
| 5 | + * | |
| 6 | + * Represents a dahsboard news item. | |
| 7 | + * | |
| 8 | + * Licensed under the GNU GPL. For full terms see the file COPYING. | |
| 9 | + * | |
| 10 | + * @version $Revision$ | |
| 11 | + * @author Michael Joseph <michael@jamwarehouse.com>, Jam Warehouse (Pty) Ltd, South Africa | |
| 12 | + * @package lib.authentication | |
| 13 | + */ | |
| 14 | + | |
| 15 | +class DashboardNews { | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * The primary key of the news item | |
| 19 | + */ | |
| 20 | + var $iId; | |
| 21 | + /** | |
| 22 | + * A synopsis of the news item | |
| 23 | + */ | |
| 24 | + var $sSynopsis; | |
| 25 | + /** | |
| 26 | + * The new item content | |
| 27 | + */ | |
| 28 | + var $sBody; | |
| 29 | + /** | |
| 30 | + * The rank of the news item | |
| 31 | + */ | |
| 32 | + var $iRank; | |
| 33 | + /** | |
| 34 | + * An accompanying image | |
| 35 | + */ | |
| 36 | + var $sImage; | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * Constructs a news item | |
| 40 | + * | |
| 41 | + * @param string the synopsis | |
| 42 | + * @param string the body | |
| 43 | + * @param integer the rank | |
| 44 | + * @param string the image | |
| 45 | + */ | |
| 46 | + function DashboardNews($sNewSynopsis, $sNewBody, $iNewRank, $sNewImage) { | |
| 47 | + // primary key not set as document is not stored yet | |
| 48 | + $this->iId = -1; | |
| 49 | + $this->sSynopsis = $sNewSynopsis; | |
| 50 | + $this->sBody = $sNewBody; | |
| 51 | + $this->iRank = $iNewRank; | |
| 52 | + $this->sImage = $sNewImage; | |
| 53 | + } | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * Gets the id | |
| 57 | + */ | |
| 58 | + function getID(){ | |
| 59 | + return $this->iId; | |
| 60 | + } | |
| 61 | + | |
| 62 | + /** | |
| 63 | + * Gets the synopsis | |
| 64 | + */ | |
| 65 | + function getSynopsis(){ | |
| 66 | + return $this->sSynopsis; | |
| 67 | + } | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * Sets the synopsis | |
| 71 | + * | |
| 72 | + * @param $sNewSynopsis | |
| 73 | + */ | |
| 74 | + function setSynopsis($sNewSynopsis){ | |
| 75 | + $this->sSynopsis = $sNewSynopsis; | |
| 76 | + } | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * Gets the body | |
| 80 | + */ | |
| 81 | + function getBody(){ | |
| 82 | + return $this->sBody; | |
| 83 | + } | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * Sets the body | |
| 87 | + * | |
| 88 | + * @param $sNewBody | |
| 89 | + */ | |
| 90 | + function setBody($sNewBody){ | |
| 91 | + $this->sBody = $sNewBody; | |
| 92 | + } | |
| 93 | + | |
| 94 | + /** | |
| 95 | + * Gets the rank | |
| 96 | + */ | |
| 97 | + function getRank(){ | |
| 98 | + return $this->iRank; | |
| 99 | + } | |
| 100 | + | |
| 101 | + /** | |
| 102 | + * Sets the rank | |
| 103 | + * | |
| 104 | + * @param $iNewRank | |
| 105 | + */ | |
| 106 | + function setRank($iNewRank){ | |
| 107 | + $this->iRank = $iNewRank; | |
| 108 | + } | |
| 109 | + | |
| 110 | + /** | |
| 111 | + * Gets the image | |
| 112 | + */ | |
| 113 | + function getImage(){ | |
| 114 | + return $this->sImage; | |
| 115 | + } | |
| 116 | + | |
| 117 | + /** | |
| 118 | + * Sets the image | |
| 119 | + * | |
| 120 | + * @param $sImage | |
| 121 | + */ | |
| 122 | + function setImage($sNewImage){ | |
| 123 | + $this->sImage = $sNewImage; | |
| 124 | + } | |
| 125 | + | |
| 126 | + | |
| 127 | + /** | |
| 128 | + * Inserts the current new item into the database | |
| 129 | + * | |
| 130 | + * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"] | |
| 131 | + */ | |
| 132 | + function create(){ | |
| 133 | + global $default; | |
| 134 | + //if the id >= 0, then the object has already been created | |
| 135 | + if ($this->iId < 0) { | |
| 136 | + $sql = $default->db; | |
| 137 | + $result = $sql->query("INSERT INTO $default->owl_news_table (image, synopsis, body, rank) " . | |
| 138 | + "VALUES ('" . addslashes($this->sImage) . "', '" . addslashes($this->sSynopsis) . "', '" . addslashes($this->sBody) . "', $this->iRank)"); | |
| 139 | + if ($result) { | |
| 140 | + //set the current news item primary key | |
| 141 | + $this->iId = $sql->insert_id(); | |
| 142 | + return true; | |
| 143 | + } | |
| 144 | + return false; | |
| 145 | + } | |
| 146 | + return false; | |
| 147 | + } | |
| 148 | + | |
| 149 | + /** | |
| 150 | + * Update the documents current values in the database | |
| 151 | + * | |
| 152 | + * @return boolean true on successful update, false otherwise | |
| 153 | + */ | |
| 154 | + function update(){ | |
| 155 | + global $default; | |
| 156 | + if ($this->iId >= 0) { | |
| 157 | + $sql = $default->db; | |
| 158 | + $sQuery = "UPDATE " . $default->owl_news_table . " SET " . | |
| 159 | + "image = '" . addslashes($this->sImage) . "', " . | |
| 160 | + "synopsis = '" . addslashes($this->sSynopsis) . "', " . | |
| 161 | + "body = '" . addslashes($this->sBody) . "', " . | |
| 162 | + "rank = $this->iRank " . | |
| 163 | + "WHERE id = $this->iId"; | |
| 164 | + $result = $sql->query($sQuery); | |
| 165 | + if ($result) { | |
| 166 | + return true; | |
| 167 | + } | |
| 168 | + return false; | |
| 169 | + } | |
| 170 | + return false; | |
| 171 | + } | |
| 172 | + | |
| 173 | + /** | |
| 174 | + * Delete the current news item from the database. Set the primary key to -1 | |
| 175 | + * on successful deletion | |
| 176 | + * | |
| 177 | + * @return boolean true and reset id to -1 on successful deletion, false otherwise | |
| 178 | + */ | |
| 179 | + function delete() { | |
| 180 | + global $default; | |
| 181 | + if ($this->iId >= 0) { | |
| 182 | + $sql = $default->db; | |
| 183 | + $result = $sql->query("DELETE FROM " . $default->owl_news_table . " WHERE id = $this->iId"); | |
| 184 | + if ($result) { | |
| 185 | + $this->iId = -1; | |
| 186 | + return true; | |
| 187 | + } | |
| 188 | + return false; | |
| 189 | + } | |
| 190 | + return false; | |
| 191 | + } | |
| 192 | + | |
| 193 | + /** | |
| 194 | + * Static function. Given a news item primary key will create | |
| 195 | + * a DashboardNews object and populate it with the corresponding | |
| 196 | + * database values | |
| 197 | + * | |
| 198 | + * @return DashboardNews populated DashboardNews object on success, false otherwise | |
| 199 | + */ | |
| 200 | + function & get($iNewsID) { | |
| 201 | + global $default; | |
| 202 | + $sql = $default->db; | |
| 203 | + $sql->query("SELECT * FROM $default->owl_news_table WHERE id = $iNewsID"); | |
| 204 | + if ($sql->next_record()) { | |
| 205 | + $oDashboardNews = & new DashboardNews(stripslashes($sql->f("synopsis")), stripslashes($sql->f("body")), $sql->f("rank"), $sql->f("image")); | |
| 206 | + $oDashboardNews->iId = $iDocumentID; | |
| 207 | + return $$oDashboardNews; | |
| 208 | + } | |
| 209 | + return false; | |
| 210 | + } | |
| 211 | + | |
| 212 | + /** | |
| 213 | + * Static function | |
| 214 | + * Get a list of DashboardNews objects | |
| 215 | + * | |
| 216 | + * @param String Where clause (optional) | |
| 217 | + * @return Array array of DashboardNews objects, false otherwise | |
| 218 | + */ | |
| 219 | + function getList($sWhereClause = null) { | |
| 220 | + global $default; | |
| 221 | + $aDashboardNewsArray = array(); | |
| 222 | + $sql = $default->db; | |
| 223 | + $result = $sql->query("SELECT * FROM " . $default->owl_news_table . (isset($sWhereClause) ? " WHERE " . $sWhereClause : "")); | |
| 224 | + if ($result) { | |
| 225 | + $iCount = 0; | |
| 226 | + while ($sql->next_record()) { | |
| 227 | + $oDashboardNews = & DashboardNews::get($sql->f("id")); | |
| 228 | + $aDashboardNewsArray[$iCount++] = $oDashboardNews; | |
| 229 | + } | |
| 230 | + return $aDocumentArray; | |
| 231 | + } | |
| 232 | + return false; | |
| 233 | + } | |
| 234 | + | |
| 235 | + /** | |
| 236 | + * Reads in an image file as a string and returns it | |
| 237 | + * | |
| 238 | + * @param string path to the image file | |
| 239 | + * @return string the image as a string | |
| 240 | + */ | |
| 241 | + function imageToString($sImagePath) { | |
| 242 | + | |
| 243 | + } | |
| 244 | +} | |
| 0 | 245 | \ No newline at end of file | ... | ... |