2012-10-09 09:47:33 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Implementation of an generic object in the document management system
|
|
|
|
*
|
|
|
|
* @category DMS
|
2013-02-14 11:10:53 +00:00
|
|
|
* @package SeedDMS_Core
|
2012-10-09 09:47:33 +00:00
|
|
|
* @license GPL2
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2010-2012 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class to represent a generic object in the document management system
|
|
|
|
*
|
2013-02-14 11:10:53 +00:00
|
|
|
* This is the base class for generic objects in SeedDMS.
|
2012-10-09 09:47:33 +00:00
|
|
|
*
|
|
|
|
* @category DMS
|
2013-02-14 11:10:53 +00:00
|
|
|
* @package SeedDMS_Core
|
2012-10-09 09:47:33 +00:00
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2010-2012 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
2013-02-14 11:10:53 +00:00
|
|
|
class SeedDMS_Core_Object { /* {{{ */
|
2012-10-09 09:47:33 +00:00
|
|
|
/**
|
|
|
|
* @var integer unique id of object
|
|
|
|
*/
|
2013-01-24 08:23:24 +00:00
|
|
|
protected $_id;
|
2012-10-09 09:47:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array list of attributes
|
|
|
|
*/
|
2013-01-24 08:23:24 +00:00
|
|
|
protected $_attributes;
|
2012-10-09 09:47:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var object back reference to document management system
|
|
|
|
*/
|
2013-01-24 08:23:24 +00:00
|
|
|
public $_dms;
|
2012-10-09 09:47:33 +00:00
|
|
|
|
2013-02-14 11:10:53 +00:00
|
|
|
function SeedDMS_Core_Object($id) { /* {{{ */
|
2012-10-09 09:47:33 +00:00
|
|
|
$this->_id = $id;
|
|
|
|
$this->_dms = null;
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set dms this object belongs to.
|
|
|
|
*
|
|
|
|
* Each object needs a reference to the dms it belongs to. It will be
|
|
|
|
* set when the object is created.
|
|
|
|
* The dms has a references to the currently logged in user
|
|
|
|
* and the database connection.
|
|
|
|
*
|
|
|
|
* @param object $dms reference to dms
|
|
|
|
*/
|
|
|
|
function setDMS($dms) { /* {{{ */
|
|
|
|
$this->_dms = $dms;
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the internal id of the document
|
|
|
|
*
|
|
|
|
* @return integer id of document
|
|
|
|
*/
|
|
|
|
function getID() { return $this->_id; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns all attributes set for the object
|
|
|
|
*
|
2013-02-14 11:10:53 +00:00
|
|
|
* @return array list of objects of class SeedDMS_Core_Attribute
|
2012-10-09 09:47:33 +00:00
|
|
|
*/
|
|
|
|
function getAttributes() { /* {{{ */
|
|
|
|
if (!$this->_attributes) {
|
|
|
|
$db = $this->_dms->getDB();
|
|
|
|
|
|
|
|
switch(get_class($this)) {
|
2013-02-14 11:10:53 +00:00
|
|
|
case "SeedDMS_Core_Document":
|
2012-10-09 09:47:33 +00:00
|
|
|
$queryStr = "SELECT * FROM tblDocumentAttributes WHERE document = " . $this->_id." ORDER BY `id`";
|
|
|
|
break;
|
2013-02-14 11:10:53 +00:00
|
|
|
case "SeedDMS_Core_DocumentContent":
|
2012-10-09 09:47:33 +00:00
|
|
|
$queryStr = "SELECT * FROM tblDocumentContentAttributes WHERE content = " . $this->_id." ORDER BY `id`";
|
|
|
|
break;
|
2013-02-14 11:10:53 +00:00
|
|
|
case "SeedDMS_Core_Folder":
|
2012-10-09 09:47:33 +00:00
|
|
|
$queryStr = "SELECT * FROM tblFolderAttributes WHERE folder = " . $this->_id." ORDER BY `id`";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$resArr = $db->getResultArray($queryStr);
|
|
|
|
if (is_bool($resArr) && !$resArr) return false;
|
|
|
|
|
|
|
|
$this->_attributes = array();
|
|
|
|
|
|
|
|
foreach ($resArr as $row) {
|
|
|
|
$attrdef = $this->_dms->getAttributeDefinition($row['attrdef']);
|
2013-02-14 11:10:53 +00:00
|
|
|
$attr = new SeedDMS_Core_Attribute($row["id"], $this, $attrdef, $row["value"]);
|
2012-10-09 09:47:33 +00:00
|
|
|
$attr->setDMS($this->_dms);
|
|
|
|
$this->_attributes[$attrdef->getId()] = $attr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->_attributes;
|
|
|
|
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an attribute of the object for the given attribute definition
|
|
|
|
*
|
2013-02-14 11:10:53 +00:00
|
|
|
* @return object object of class SeedDMS_Core_Attribute or false
|
2012-10-09 09:47:33 +00:00
|
|
|
*/
|
|
|
|
function getAttributeValue($attrdef) { /* {{{ */
|
|
|
|
if (!$this->_attributes) {
|
|
|
|
$this->getAttributes();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($this->_attributes[$attrdef->getId()]))
|
|
|
|
return $this->_attributes[$attrdef->getId()]->getValue();
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set an attribute of the object for the given attribute definition
|
|
|
|
*
|
|
|
|
* @return boolean true if operation was successful, otherwise false
|
|
|
|
*/
|
|
|
|
function setAttributeValue($attrdef, $value) { /* {{{ */
|
|
|
|
$db = $this->_dms->getDB();
|
|
|
|
if (!$this->_attributes) {
|
|
|
|
$this->getAttributes();
|
|
|
|
}
|
|
|
|
if(!isset($this->_attributes[$attrdef->getId()])) {
|
|
|
|
switch(get_class($this)) {
|
2013-02-14 11:10:53 +00:00
|
|
|
case "SeedDMS_Core_Document":
|
2012-10-09 09:47:33 +00:00
|
|
|
$queryStr = "INSERT INTO tblDocumentAttributes (document, attrdef, value) VALUES (".$this->_id.", ".$attrdef->getId().", ".$db->qstr($value).")";
|
|
|
|
break;
|
2013-02-14 11:10:53 +00:00
|
|
|
case "SeedDMS_Core_DocumentContent":
|
2012-10-09 09:47:33 +00:00
|
|
|
$queryStr = "INSERT INTO tblDocumentContentAttributes (content, attrdef, value) VALUES (".$this->_id.", ".$attrdef->getId().", ".$db->qstr($value).")";
|
|
|
|
break;
|
2013-02-14 11:10:53 +00:00
|
|
|
case "SeedDMS_Core_Folder":
|
2012-10-09 09:47:33 +00:00
|
|
|
$queryStr = "INSERT INTO tblFolderAttributes (folder, attrdef, value) VALUES (".$this->_id.", ".$attrdef->getId().", ".$db->qstr($value).")";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$res = $db->getResult($queryStr);
|
|
|
|
if (!$res)
|
|
|
|
return false;
|
|
|
|
|
2013-02-14 11:10:53 +00:00
|
|
|
$attr = new SeedDMS_Core_Attribute($db->getInsertID(), $this, $attrdef, $value);
|
2012-10-09 09:47:33 +00:00
|
|
|
$attr->setDMS($this->_dms);
|
|
|
|
$this->_attributes[$attrdef->getId()] = $attr;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->_attributes[$attrdef->getId()]->setValue($value);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} /* }}} */
|
|
|
|
|
2013-05-28 07:01:04 +00:00
|
|
|
/**
|
|
|
|
* Remove an attribute of the object for the given attribute definition
|
|
|
|
*
|
|
|
|
* @return boolean true if operation was successful, otherwise false
|
|
|
|
*/
|
|
|
|
function removeAttribute($attrdef) { /* {{{ */
|
|
|
|
$db = $this->_dms->getDB();
|
|
|
|
if (!$this->_attributes) {
|
|
|
|
$this->getAttributes();
|
|
|
|
}
|
|
|
|
if(isset($this->_attributes[$attrdef->getId()])) {
|
|
|
|
switch(get_class($this)) {
|
|
|
|
case "SeedDMS_Core_Document":
|
|
|
|
$queryStr = "DELETE FROM tblDocumentAttributes WHERE document=".$this->_id." AND attrdef=".$attrdef->getId();
|
|
|
|
break;
|
|
|
|
case "SeedDMS_Core_DocumentContent":
|
|
|
|
$queryStr = "DELETE FROM tblDocumentContentAttributes WHERE content=".$this->_id." AND attrdef=".$attrdef->getId();
|
|
|
|
break;
|
|
|
|
case "SeedDMS_Core_Folder":
|
|
|
|
$queryStr = "DELETE FROM tblFolderAttributes WHERE folder=".$this->_id." AND attrdef=".$attrdef->getId();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$res = $db->getResult($queryStr);
|
|
|
|
if (!$res)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
unset($this->_attributes[$attrdef->getId()]);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} /* }}} */
|
2012-10-09 09:47:33 +00:00
|
|
|
} /* }}} */
|
|
|
|
?>
|