Source for file ADDRESS.phpclass
Documentation is available at ADDRESS.phpclass
* Class file ADDRESS.phpclass
* @project Open CSP-Management
* @author Peter Krebs <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: ADDRESS.phpclass,v 1.13 2008/11/30 13:35:30 pitlinz Exp $
require_once __OCSP_PHPINCPATH__.
"db" .
_OCSP_DIRSEP_ .
"DBMS_TABLEOBJ.phpclass";
require_once dirname(__FILE__
).
_OCSP_DIRSEP_.
"CLIENT.phpclass";
* Class file ADDRESS.phpclass
* @project Open CSP-Management
* @author Peter Krebs <p.krebs@lvus.at>
* @copyright (c) 2002-2003 by Peter Krebs and Landesverlag Unternehmensservice
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: ADDRESS.phpclass,v 1.13 2008/11/30 13:35:30 pitlinz Exp $
/*** class constants --------------------------------------------- */
* @constant string CLASS_SRC_FILE
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
/*** class vars ------------------------------------------------------ */
* unit of work address objects
protected static $addrObjLst =
array();
/*** class methods --------------------------------------------------- */
* returns an instance of the unit of work
if (!isset
(self::$addrObjLst[$aId]) ||
pcf_is_instance_of(self::$addrObjLst[$aId],'ADDRESS'))
self::$addrObjLst[$aId] =
ADDRESS::factoryFromId(intval($aId));
return self::$addrObjLst[$aId];
* @staticvar string $myTable name of the db table
* @staticvar string $myClassSrcFile if is set the DBMS_FORM get the class object
* init the object and populate if an id is submitted
* @param int $cliId CLI_ID
function ADDRESS($cliId=
0,$adrId=
0,$debug=
FALSE)
if ($debug) echoDebugMethod(__FILE__
,get_class($this),"ADDRESS::ADDRESS($cliId,$adrId)");
if (($adrId) &&
($cliId)) {
* factory an address and sets dbRow
if (isset
($row['ADR_ID']) &&
intval($row['ADR_ID']))
$obj_ret->setDBRow($row);
$int_cliId =
(isset
($row['CLI_ID']) ?
intval($row['CLI_ID']) :
0);
return new ADDRESS($int_cliId,0,$debug);
* factory an address from the id
* @todo change calls to getInstance()
if (isset
(self::$addrObjLst[$aId]))
return self::$addrObjLst[$aId];
$obj_ret =
new ADDRESS();
$obj_ret->dbPopulate($debug);
self::$addrObjLst[$aId] =
$obj_ret;
return self::$addrObjLst[$aId];
return parent::setDBField("ADR_CO",$val);
self::$addrObjLst[$aId] =
$this;
* if the new value differs from $this->myClient->getId()
* $this->myClient is set to NULL
* returns if the address is the primary address
* sets this to the clients primary address
* @param bool $saveClient
function setPrimary($saveClient=
FALSE,$debug=
FALSE) {
if ($debug) echo
"<p><b>ADDRESS::setPrimary($saveClient,$debug)</b> (".
get_class($this).
")</p>";
if (($saveClient) &&
($this->getId()) &&
($this->getClient($debug))) { // make sure $this->myClient is populated
$this->myClient->dbSave($this->gDBIDX,$debug);
* returns the client object
* if $this->myClient is not an object a new one is created
return $this->setCliId($cliObj->getId());
* populates the address object and adds to self::$addrObjLst
self::$addrObjLst[$this->getId()] =
$this;
* if ADR_ISPRIMARY is set:
* - make sure no other address is primary for the client
* @param bool $debug SHOW DEBUG INFO
* @deprecated since pk-08-05-16
return parent::dbSave($debug);
if ($debug) echoDebugMethod(__FILE__,get_class($this),"ADDRESS::dbSave($debug)");
throw new Exception(_OCSP_EXCEP_NOID_ . ": CLI_ID IS NOT SET FOR ADDRESS");
if (!$this->isConnected(True))
throw new Exectption(_OCSP_)
if ($ret=parent::dbSave($debug)) { // store the return value it could be the index of a new row
if ($this->isPrimary()) { // otherwise the primary address has to check that it's the only one
if ($this->getClient($debug)) { // make sure it is populated
$cmd ="UPDATE ".$this->myTable." SET ADR_ISPRIMARY=0 WHERE CLI_ID=".$this->myClient->getId();
$cmd.=" AND ADR_ID <> ".$this->getId();
$cmd.=" AND ADR_ISPRIMARY > 0 "; // only update other primary addresses (timestamp :-)
if ($debug) echoDebugLine(__FILE__,__LINE__,"Query: <p>$query</p>");
$this->myDBObj->executeCmd($cmd);
if ($this->myClient->getPriAddrId() != $this->getId()) {
if (!$this->myClient->getPopulateTs()) {
if (!$this->myClient->dbPopulate($debug)) {
die("SYSTEM ERROR COULD NOT GET OWNER OF ADDRESS");
$this->myClient->setPriAddrId($this->getId());
$this->myClient->dbSave($debug);
* inserts a new row to the table
* @param bool $debug show debug info
* @global array $OCSP_OBJ
* @returns int returns the autoIncFld ID if exists or 1 on success
$this->ADR_CREATION =
"CURRENT_TIMESTAMP";
$str_cmd =
"UPDATE " .
$this->myTable .
" SET ADR_ISPRIMARY=0";
$str_cmd.=
" WHERE CLI_ID=" .
$this->getCliId();
$this->myDBObj->executeCmd($str_cmd);
$str_query =
"SELECT COUNT(*) FROM " .
$this->myTable .
" WHERE CLI_ID=" .
$this->getCliId();
$int_count=
$this->myDBObj->getOne($str_query);
* replaces a row in the table
* @param boolean $debug show debug info
* @param boolean $ignorPopulated (if false the table MUST have been populated)
* @global array $OCSP_OBJ
function dbReplace($debug=
FALSE,$ignorPopulated=
FALSE)
$this->ADR_LASTCHANGE =
"CURRENT_TIMESTAMP";
$str_cmd =
"UPDATE " .
$this->myTable .
" SET ADR_ISPRIMARY=0";
$str_cmd.=
" WHERE CLI_ID=" .
$this->getCliId();
$this->myDBObj->executeCmd($str_cmd);
return parent::dbReplace($debug,$ignorPopulated);
* returns an array of default values
* tries to get the form from the client type
* @param mixed $form (string) form name (int) form id
* @requires db/forms/OCSP_FORM.phpclass
function &getForm($mode=
FRM_MODE_READONLY,$form=
'',$frmClass=
'OCSP_FORM',$debug=
False)
if (empty($form) ||
!intval($form))
$form =
$obj_cliType->getAddressFormId();
return parent::getForm($mode,$form,$frmClass,$debug);
Documentation generated on Thu, 08 Jan 2009 17:37:29 +0100 by phpDocumentor 1.4.0a2