Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 178 |
|
0.00% |
0 / 25 |
CRAP | |
0.00% |
0 / 2 |
| SeedDMS_Core_Transmittal | |
0.00% |
0 / 115 |
|
0.00% |
0 / 15 |
1980 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| getInstance | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
72 | |||
| getAllInstances | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
30 | |||
| getAllInstancesByObject | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
56 | |||
| setDMS | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getID | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setName | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| getComment | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setComment | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| getUser | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getItems | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
30 | |||
| getSize | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
| addContent | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 | |||
| remove | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| SeedDMS_Core_TransmittalItem | |
0.00% |
0 / 63 |
|
0.00% |
0 / 10 |
650 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| getInstance | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
42 | |||
| getAllInstancesByObject | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
72 | |||
| setDMS | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getID | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTransmittal | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getContent | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| remove | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| updateContent | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Implementation of the transmittal object in the document management system |
| 5 | * |
| 6 | * @category DMS |
| 7 | * @package SeedDMS_Core |
| 8 | * @license GPL 2 |
| 9 | * @version @version@ |
| 10 | * @author Uwe Steinmann <uwe@steinmann.cx> |
| 11 | * @copyright Copyright (C) 2002-2005 Markus Westphal, 2006-2008 Malcolm Cowe, |
| 12 | * 2010 Uwe Steinmann |
| 13 | * @version Release: @package_version@ |
| 14 | */ |
| 15 | |
| 16 | /** |
| 17 | * Class to represent a transmittal in the document management system |
| 18 | * |
| 19 | * @category DMS |
| 20 | * @package SeedDMS_Core |
| 21 | * @author Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx> |
| 22 | * @copyright Copyright (C) 2002-2005 Markus Westphal, 2006-2008 Malcolm Cowe, |
| 23 | * 2010 Uwe Steinmann |
| 24 | * @version Release: @package_version@ |
| 25 | */ |
| 26 | class SeedDMS_Core_Transmittal { |
| 27 | /** |
| 28 | * @var integer id of transmittal |
| 29 | * |
| 30 | * @access protected |
| 31 | */ |
| 32 | protected $_id; |
| 33 | |
| 34 | /** |
| 35 | * @var string name of transmittal |
| 36 | * |
| 37 | * @access protected |
| 38 | */ |
| 39 | protected $_name; |
| 40 | |
| 41 | /** |
| 42 | * @var string comment of transmittal |
| 43 | * |
| 44 | * @access protected |
| 45 | */ |
| 46 | protected $_comment; |
| 47 | |
| 48 | /** |
| 49 | * @var boolean true if transmittal is public |
| 50 | * |
| 51 | * @access protected |
| 52 | */ |
| 53 | protected $_isPublic; |
| 54 | |
| 55 | /** |
| 56 | * @var object user this transmittal belongs to |
| 57 | * |
| 58 | * @access protected |
| 59 | */ |
| 60 | protected $_user; |
| 61 | |
| 62 | /** |
| 63 | * @var object date of creation |
| 64 | * |
| 65 | * @access protected |
| 66 | */ |
| 67 | protected $_date; |
| 68 | |
| 69 | /** |
| 70 | * @var object items |
| 71 | * |
| 72 | * @access protected |
| 73 | */ |
| 74 | protected $_items; |
| 75 | |
| 76 | /** |
| 77 | * @var object reference to the dms instance this user belongs to |
| 78 | * |
| 79 | * @access protected |
| 80 | */ |
| 81 | protected $_dms; |
| 82 | |
| 83 | public function __construct($id, $user, $name, $comment, $isPublic = 0, $date = '') { |
| 84 | $this->_id = $id; |
| 85 | $this->_name = $name; |
| 86 | $this->_comment = $comment; |
| 87 | $this->_user = $user; |
| 88 | $this->_isPublic = $isPublic; |
| 89 | $this->_date = $date; |
| 90 | $this->_items = array(); |
| 91 | $this->_dms = null; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Get an instance of a transmittal object |
| 96 | * |
| 97 | * @param string|integer $id id or name of transmittal, depending |
| 98 | * on the 3rd parameter. |
| 99 | * @param object $dms instance of dms |
| 100 | * @param string $by search by [id|name]. If this |
| 101 | * parameter is left empty, the user will be search by its Id. |
| 102 | * @return object instance of class SeedDMS_Core_Transmittal |
| 103 | */ |
| 104 | public static function getInstance($id, $dms, $by = '') { /* {{{ */ |
| 105 | if (!$dms || get_class($dms) != 'SeedDMS_Core_DMS') |
| 106 | return false; |
| 107 | |
| 108 | $db = $dms->getDB(); |
| 109 | |
| 110 | switch ($by) { |
| 111 | case 'name': |
| 112 | $queryStr = "SELECT * FROM `tblTransmittals` WHERE `name` = ".$db->qstr($id); |
| 113 | break; |
| 114 | default: |
| 115 | $queryStr = "SELECT * FROM `tblTransmittals` WHERE id = " . (int) $id; |
| 116 | } |
| 117 | |
| 118 | $resArr = $db->getResultArray($queryStr); |
| 119 | |
| 120 | if (is_bool($resArr) && $resArr == false) return false; |
| 121 | if (count($resArr) != 1) return false; |
| 122 | |
| 123 | $resArr = $resArr[0]; |
| 124 | |
| 125 | $uclassname = $dms->getClassname('user'); |
| 126 | $user = $uclassname::getInstance($resArr['userID'], $dms); |
| 127 | $transmittal = new self($resArr["id"], $user, $resArr["name"], $resArr["comment"], $resArr["public"], $resArr["date"]); |
| 128 | $transmittal->setDMS($dms); |
| 129 | return $transmittal; |
| 130 | } /* }}} */ |
| 131 | |
| 132 | /** |
| 133 | * Get all instances of a transmittal object |
| 134 | * |
| 135 | * @param SeedDMS_Core_User $user user owning the transmittals |
| 136 | * @param string $orderby order by [id|name]. If this |
| 137 | * parameter is left empty, the list will be ordered by id. |
| 138 | * @param object $dms instance of dms |
| 139 | * @return array instances of class SeedDMS_Core_Transmittal |
| 140 | */ |
| 141 | public static function getAllInstances($user, $orderby, $dms) { /* {{{ */ |
| 142 | $db = $dms->getDB(); |
| 143 | |
| 144 | $queryStr = "SELECT * FROM `tblTransmittals`"; |
| 145 | if ($user) |
| 146 | $queryStr .= " WHERE `userID` = " . $user->getID(); |
| 147 | |
| 148 | $resArr = $db->getResultArray($queryStr); |
| 149 | |
| 150 | if (is_bool($resArr) && $resArr == false) return false; |
| 151 | |
| 152 | $uclassname = $dms->getClassname('user'); |
| 153 | $transmittals = array(); |
| 154 | foreach ($resArr as $res) { |
| 155 | $user = $uclassname::getInstance($res['userID'], $dms); |
| 156 | $transmittal = new self($res["id"], $user, $res["name"], $res["comment"], $res["public"], $res["date"]); |
| 157 | $transmittal->setDMS($dms); |
| 158 | $transmittals[] = $transmittal; |
| 159 | } |
| 160 | return $transmittals; |
| 161 | } /* }}} */ |
| 162 | |
| 163 | /** |
| 164 | * Get all instances of a transmittal object containing a document |
| 165 | * |
| 166 | * @param SeedDMS_Core_User $user user owning the transmittals |
| 167 | * @param string $orderby order by [id|name]. If this |
| 168 | * parameter is left empty, the list will be ordered by id. |
| 169 | * @param SeedDMS_Core_DocumentContent|SeedDMS_Core_Document $contains object contained in transmittal |
| 170 | * @param object $dms instance of dms |
| 171 | * @return array instances of class SeedDMS_Core_Transmittal |
| 172 | */ |
| 173 | public static function getAllInstancesByObject($user, $orderby, $contains, $dms) { /* {{{ */ |
| 174 | $db = $dms->getDB(); |
| 175 | |
| 176 | $queryStr = "SELECT * FROM `tblTransmittals` LEFT JOIN `tblTransmittalItems` ON `tblTransmittals`.`id` = `tblTransmittalItems`.`transmittal`"; |
| 177 | if ($user) |
| 178 | $queryStr .= " WHERE `userID` = " . $user->getID(); |
| 179 | if ($contains->isType('document')) { |
| 180 | $queryStr .= " AND `tblTransmittalItems`.`document` = " . (int) $contains->getId(); |
| 181 | } elseif ($contains->isType('documentcontent')) { |
| 182 | $queryStr .= " AND `tblTransmittalItems`.`document` = " . (int) $contains->getDocument()->getId()." AND `tblTransmittalItems`.`version` = ".$contains->getVersion(); |
| 183 | } |
| 184 | |
| 185 | $resArr = $db->getResultArray($queryStr); |
| 186 | |
| 187 | if (is_bool($resArr) && $resArr == false) return false; |
| 188 | |
| 189 | $uclassname = $dms->getClassname('user'); |
| 190 | $transmittals = array(); |
| 191 | foreach ($resArr as $res) { |
| 192 | $user = $uclassname::getInstance($res['userID'], $dms); |
| 193 | $transmittal = new self($res["id"], $user, $res["name"], $res["comment"], $res["public"], $res["date"]); |
| 194 | $transmittal->setDMS($dms); |
| 195 | $transmittals[] = $transmittal; |
| 196 | } |
| 197 | return $transmittals; |
| 198 | } /* }}} */ |
| 199 | |
| 200 | public function setDMS($dms) { |
| 201 | $this->_dms = $dms; |
| 202 | } |
| 203 | |
| 204 | public function getID() { return $this->_id; } |
| 205 | |
| 206 | public function getName() { return $this->_name; } |
| 207 | |
| 208 | public function setName($newName) { /* {{{ */ |
| 209 | $db = $this->_dms->getDB(); |
| 210 | |
| 211 | $queryStr = "UPDATE `tblTransmittals` SET `name` =".$db->qstr($newName)." WHERE `id` = " . $this->_id; |
| 212 | $res = $db->getResult($queryStr); |
| 213 | if (!$res) |
| 214 | return false; |
| 215 | |
| 216 | $this->_name = $newName; |
| 217 | return true; |
| 218 | } /* }}} */ |
| 219 | |
| 220 | public function getComment() { return $this->_comment; } |
| 221 | |
| 222 | public function setComment($newComment) { /* {{{ */ |
| 223 | $db = $this->_dms->getDB(); |
| 224 | |
| 225 | $queryStr = "UPDATE `tblTransmittals` SET `comment` =".$db->qstr($newComment)." WHERE `id` = " . $this->_id; |
| 226 | $res = $db->getResult($queryStr); |
| 227 | if (!$res) |
| 228 | return false; |
| 229 | |
| 230 | $this->_comment = $newComment; |
| 231 | return true; |
| 232 | } /* }}} */ |
| 233 | |
| 234 | public function getUser() { return $this->_user; } |
| 235 | |
| 236 | public function getItems() { /* {{{ */ |
| 237 | $db = $this->_dms->getDB(); |
| 238 | |
| 239 | if (!$this->_items) { |
| 240 | $queryStr = "SELECT `tblTransmittalItems`.* FROM `tblTransmittalItems` ". |
| 241 | "LEFT JOIN `tblDocuments` ON `tblTransmittalItems`.`document`=`tblDocuments`.`id` ". |
| 242 | "WHERE `tblTransmittalItems`.`transmittal` = '". $this->_id ."'"; |
| 243 | $resArr = $db->getResultArray($queryStr); |
| 244 | if (is_bool($resArr) && $resArr == false) |
| 245 | return false; |
| 246 | |
| 247 | $this->_users = array(); |
| 248 | |
| 249 | $classname = $this->_dms->getClassname('transmittalitem'); |
| 250 | foreach ($resArr as $row) { |
| 251 | $document = $this->_dms->getDocument($row['document']); |
| 252 | $content = $document->getContentByVersion($row['version']); |
| 253 | $item = new $classname($row["id"], $this, $content, $row["date"]); |
| 254 | array_push($this->_items, $item); |
| 255 | } |
| 256 | } |
| 257 | return $this->_items; |
| 258 | } /* }}} */ |
| 259 | |
| 260 | public function getSize() { /* {{{ */ |
| 261 | $db = $this->_dms->getDB(); |
| 262 | |
| 263 | if (!$this->_items) { |
| 264 | self::getItems(); |
| 265 | } |
| 266 | |
| 267 | $size = 0; |
| 268 | foreach ($this->_items as $item) { |
| 269 | if ($content = $item->getContent()) { |
| 270 | $size += $content->getFileSize(); |
| 271 | } |
| 272 | } |
| 273 | return $size; |
| 274 | } /* }}} */ |
| 275 | |
| 276 | /** |
| 277 | * Add an item to the transmittal |
| 278 | * |
| 279 | * @param object $item instance of SeedDMS_Core_DocumentContent |
| 280 | * @return boolean true if item could be added, otherwise false |
| 281 | */ |
| 282 | public function addContent($item) { /* {{{ */ |
| 283 | $db = $this->_dms->getDB(); |
| 284 | |
| 285 | if (get_class($item) != $this->_dms->getClassname('documentcontent')) |
| 286 | return false; |
| 287 | |
| 288 | $document = $item->getDocument(); |
| 289 | $queryStr = "INSERT INTO `tblTransmittalItems` (`transmittal`, `document`, `version`, `date`) ". |
| 290 | "VALUES ('". $this->_id ."', ".$document->getID().", ".$item->getVersion().", ".$db->getCurrentDatetime().")"; |
| 291 | $res = $db->getResult($queryStr); |
| 292 | if (!$res) { |
| 293 | return false; |
| 294 | } |
| 295 | $itemID = $db->getInsertID('tblTransmittalItems'); |
| 296 | |
| 297 | return SeedDMS_Core_TransmittalItem::getInstance($itemID, $this->_dms); |
| 298 | } /* }}} */ |
| 299 | |
| 300 | public function remove() { /* {{{ */ |
| 301 | $db = $this->_dms->getDB(); |
| 302 | |
| 303 | $queryStr = "DELETE FROM `tblTransmittals` WHERE `id` = " . $this->_id; |
| 304 | if (!$db->getResult($queryStr)) { |
| 305 | return false; |
| 306 | } |
| 307 | |
| 308 | return true; |
| 309 | } /* }}} */ |
| 310 | |
| 311 | } |
| 312 | |
| 313 | /** |
| 314 | * Class to represent a transmittal in the document management system |
| 315 | * |
| 316 | * @category DMS |
| 317 | * @package SeedDMS_Core |
| 318 | * @author Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx> |
| 319 | * @copyright Copyright (C) 2002-2005 Markus Westphal, 2006-2008 Malcolm Cowe, |
| 320 | * 2010 Uwe Steinmann |
| 321 | * @version Release: @package_version@ |
| 322 | */ |
| 323 | class SeedDMS_Core_TransmittalItem { |
| 324 | /** |
| 325 | * @var integer id of transmittal item |
| 326 | * |
| 327 | * @access protected |
| 328 | */ |
| 329 | protected $_id; |
| 330 | |
| 331 | /** |
| 332 | * @var object document content |
| 333 | * |
| 334 | * @access protected |
| 335 | */ |
| 336 | protected $_content; |
| 337 | |
| 338 | /** |
| 339 | * @var object transmittal |
| 340 | * |
| 341 | * @access protected |
| 342 | */ |
| 343 | protected $_transmittal; |
| 344 | |
| 345 | /** |
| 346 | * @var object date of creation |
| 347 | * |
| 348 | * @access protected |
| 349 | */ |
| 350 | protected $_date; |
| 351 | |
| 352 | public function __construct($id, $transmittal, $content, $date = '') { |
| 353 | $this->_id = $id; |
| 354 | $this->_transmittal = $transmittal; |
| 355 | $this->_content = $content; |
| 356 | $this->_date = $date; |
| 357 | $this->_dms = null; |
| 358 | } |
| 359 | |
| 360 | public static function getInstance($id, $dms) { /* {{{ */ |
| 361 | if (!$dms || get_class($dms) != 'SeedDMS_Core_DMS') |
| 362 | return false; |
| 363 | |
| 364 | $db = $dms->getDB(); |
| 365 | |
| 366 | $queryStr = "SELECT * FROM `tblTransmittalItems` WHERE `id` = " . (int) $id; |
| 367 | $resArr = $db->getResultArray($queryStr); |
| 368 | if (is_bool($resArr) && $resArr == false) |
| 369 | return false; |
| 370 | if (count($resArr) != 1) |
| 371 | return false; |
| 372 | $resArr = $resArr[0]; |
| 373 | |
| 374 | $transmittal = SeedDMS_Core_Transmittal::getInstance($resArr['transmittal'], $dms); |
| 375 | $dclassname = $dms->getClassname('document'); |
| 376 | $document = $dclassname::getInstance($resArr['document'], $dms); |
| 377 | $content = $document->getContentByVersion((int) $resArr['version']); |
| 378 | |
| 379 | $item = new self($resArr["id"], $transmittal, $content, $resArr["date"]); |
| 380 | $item->setDMS($dms); |
| 381 | return $item; |
| 382 | } /* }}} */ |
| 383 | |
| 384 | public static function getAllInstancesByObject($user, $contains, $dms) { /* {{{ */ |
| 385 | if (!$dms || get_class($dms) != 'SeedDMS_Core_DMS') |
| 386 | return false; |
| 387 | |
| 388 | $db = $dms->getDB(); |
| 389 | |
| 390 | $queryStr = "SELECT `tblTransmittalItems`.*, `tblTransmittals`.`userID` FROM `tblTransmittalItems` LEFT JOIN `tblTransmittals` ON `tblTransmittalItems`.`transmittal` = `tblTransmittals`.`id` WHERE `userID` = ".(int) $user->getId(); |
| 391 | if ($contains->isType('document')) { |
| 392 | $queryStr .= " AND `tblTransmittalItems`.`document` = " . (int) $contains->getId(); |
| 393 | } elseif ($contains->isType('documentcontent')) { |
| 394 | $queryStr .= " AND `tblTransmittalItems`.`document` = " . (int) $contains->getDocument()->getId()." AND `tblTransmittalItems`.`version` = ".$contains->getVersion(); |
| 395 | } |
| 396 | |
| 397 | $resArr = $db->getResultArray($queryStr); |
| 398 | if (is_bool($resArr) && $resArr == false) |
| 399 | return false; |
| 400 | $items = []; |
| 401 | foreach ($resArr as $res) { |
| 402 | $transmittal = SeedDMS_Core_Transmittal::getInstance($res['transmittal'], $dms); |
| 403 | $dclassname = $dms->getClassname('document'); |
| 404 | $document = $dclassname::getInstance($res['document'], $dms); |
| 405 | $content = $document->getContentByVersion((int) $res['version']); |
| 406 | |
| 407 | $item = new self($res["id"], $transmittal, $content, $res["date"]); |
| 408 | $item->setDMS($dms); |
| 409 | $items[] = $item; |
| 410 | } |
| 411 | return $items; |
| 412 | } /* }}} */ |
| 413 | |
| 414 | public function setDMS($dms) { |
| 415 | $this->_dms = $dms; |
| 416 | } |
| 417 | |
| 418 | public function getID() { return $this->_id; } |
| 419 | |
| 420 | public function getTransmittal() { return $this->_transmittal; } |
| 421 | |
| 422 | public function getContent() { return $this->_content; } |
| 423 | |
| 424 | public function getDate() { return $this->_date; } |
| 425 | |
| 426 | public function remove() { /* {{{ */ |
| 427 | $db = $this->_dms->getDB(); |
| 428 | $transmittal = $this->_transmittal; |
| 429 | |
| 430 | $queryStr = "DELETE FROM `tblTransmittalItems` WHERE `id` = " . $this->_id; |
| 431 | if (!$db->getResult($queryStr)) { |
| 432 | return false; |
| 433 | } |
| 434 | |
| 435 | return true; |
| 436 | } /* }}} */ |
| 437 | |
| 438 | /** |
| 439 | * Check if the content referenzed by the transmittal item is unequal |
| 440 | * to the latest content of the document. |
| 441 | * |
| 442 | * This function updateѕ always to the latest version of the document, |
| 443 | * even if the version in the item is higher. This can happen if a |
| 444 | * version has been removed. |
| 445 | * |
| 446 | * @return boolean/integer false in case of an error, otherwise the new |
| 447 | * version. |
| 448 | */ |
| 449 | public function updateContent() { /* {{{ */ |
| 450 | $db = $this->_dms->getDB(); |
| 451 | $transmittal = $this->_transmittal; |
| 452 | |
| 453 | $document = $this->_content->getDocument(); |
| 454 | $latestcontent = $document->getLatestContent(); |
| 455 | if ($latestcontent->getVersion() != $this->_content->getVersion()) { |
| 456 | $queryStr = "UPDATE `tblTransmittalItems` set `version` = ".$latestcontent->getVersion()." WHERE `id` = " . $this->_id; |
| 457 | if (!$db->getResult($queryStr)) { |
| 458 | return false; |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | return $latestcontent->getVersion(); |
| 463 | } /* }}} */ |
| 464 | } |