diff --git a/workflow/engine/classes/model/AppDocument.php b/workflow/engine/classes/model/AppDocument.php index 15b1fcfa6..1f171ead2 100755 --- a/workflow/engine/classes/model/AppDocument.php +++ b/workflow/engine/classes/model/AppDocument.php @@ -1,7 +1,8 @@ . + * along with this program. If not, see . * * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. @@ -34,578 +35,587 @@ require_once 'classes/model/InputDocument.php'; * * * You should add additional methods to this class to meet the - * application requirements. This class will only be generated as + * application requirements. This class will only be generated as * long as it does not already exist in the output directory. * - * @package workflow.engine.classes.model + * @package workflow.engine.classes.model */ -class AppDocument extends BaseAppDocument { +class AppDocument extends BaseAppDocument +{ - /** - * This value goes in the content table - * @var string - */ - protected $app_doc_title = ''; + /** + * This value goes in the content table + * + * @var string + */ + protected $app_doc_title = ''; - /** - * This value goes in the content table - * @var string - */ - protected $app_doc_comment = ''; + /** + * This value goes in the content table + * + * @var string + */ + protected $app_doc_comment = ''; - /** - * This value goes in the content table - * @var string - */ - protected $app_doc_filename = ''; + /** + * This value goes in the content table + * + * @var string + */ + protected $app_doc_filename = ''; - /* - * Load the application document registry - * @param string $sAppDocUid - * @param integer $iVersion (Document version) - * @return variant - */ - public function load($sAppDocUid,$iVersion=NULL) - { - try { - if($iVersion==NULL) $iVersion=$this->getLastAppDocVersion($sAppDocUid); - $oAppDocument = AppDocumentPeer::retrieveByPK($sAppDocUid,$iVersion); - if (!is_null($oAppDocument)) - { - $aFields = $oAppDocument->toArray(BasePeer::TYPE_FIELDNAME); - //optimized for speed - $aContentFields = $oAppDocument->getContentFields(); - $aFields['APP_DOC_TITLE'] = $aContentFields['APP_DOC_TITLE']; - $aFields['APP_DOC_COMMENT'] = $aContentFields['APP_DOC_COMMENT']; - $aFields['APP_DOC_FILENAME'] = $aContentFields['APP_DOC_FILENAME']; + /* + * Load the application document registry + * @param string $sAppDocUid + * @param integer $iVersion (Document version) + * @return variant + */ + public function load ($sAppDocUid, $iVersion = null) + { + try { + if ($iVersion == null) { + $iVersion = $this->getLastAppDocVersion( $sAppDocUid ); + } + $oAppDocument = AppDocumentPeer::retrieveByPK( $sAppDocUid, $iVersion ); + if (! is_null( $oAppDocument )) { + $aFields = $oAppDocument->toArray( BasePeer::TYPE_FIELDNAME ); + //optimized for speed + $aContentFields = $oAppDocument->getContentFields(); + $aFields['APP_DOC_TITLE'] = $aContentFields['APP_DOC_TITLE']; + $aFields['APP_DOC_COMMENT'] = $aContentFields['APP_DOC_COMMENT']; + $aFields['APP_DOC_FILENAME'] = $aContentFields['APP_DOC_FILENAME']; - $this->fromArray($aFields, BasePeer::TYPE_FIELDNAME); - return $aFields; - } - else { - throw(new Exception('Error loading Document '.$sAppDocUid.'/'.$iVersion.'. This row doesn\'t exist!')); - } + $this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME ); + return $aFields; + } else { + throw (new Exception( 'Error loading Document ' . $sAppDocUid . '/' . $iVersion . '. This row doesn\'t exist!' )); + } + } catch (Exception $oError) { + throw ($oError); + } } - catch (Exception $oError) { - throw($oError); - } - } - public function getLastIndex( $sAppUid ) - { - try { - $oCriteria = new Criteria(); - $oCriteria->add( AppDocumentPeer::APP_UID , $sAppUid ); - //$oCriteria->addAscendingOrderByColumn ( AppDocumentPeer::APP_DOC_INDEX ); - $oCriteria->addDescendingOrderByColumn( AppDocumentPeer::APP_DOC_INDEX ); - $lastAppDoc = AppDocumentPeer::doSelectOne($oCriteria); - if (!is_null($lastAppDoc)) - { - return $lastAppDoc->getAppDocIndex(); - } - else { - return 0; - } - } - catch (Exception $oError) { - throw($oError); - } - } - /** - * Get last Document Version based on Doc UID - * @param s $sAppDocUid - * @return integer - **/ - public function getLastDocVersion( $sDocUid ,$appUID) - { - try { - $oCriteria = new Criteria(); - $oCriteria->add(AppDocumentPeer::DOC_UID, $sDocUid ); - $oCriteria->add(AppDocumentPeer::APP_UID, $appUID); - $oCriteria->addDescendingOrderByColumn( AppDocumentPeer::DOC_VERSION ); - $lastAppDocVersion = AppDocumentPeer::doSelectOne($oCriteria); - if (!is_null($lastAppDocVersion)) - { - return $lastAppDocVersion->getDocVersion(); - } - else { - return 0; - } - } - catch (Exception $oError) { - throw($oError); - } - } - /** - * Get last Document Version based on APPDoc UID - * @param s $sAppDocUid - * @return integer - **/ - public function getLastAppDocVersion( $sAppDocUid ,$appUID=0) - { - try { - $oCriteria = new Criteria(); - $oCriteria->add(AppDocumentPeer::APP_DOC_UID, $sAppDocUid ); - if($appUID!=0) $oCriteria->add(AppDocumentPeer::APP_UID, $appUID); - $oCriteria->addDescendingOrderByColumn( AppDocumentPeer::DOC_VERSION ); - $lastAppDocVersion = AppDocumentPeer::doSelectOne($oCriteria); - if (!is_null($lastAppDocVersion)) - { - return $lastAppDocVersion->getDocVersion(); - } - else { - return 0; - } - } - catch (Exception $oError) { - throw($oError); - } - } - /** - * Create the application document registry - * @param array $aData - * @return string - **/ - public function create($aData) - { - $oConnection = Propel::getConnection(AppDocumentPeer::DATABASE_NAME); - try { - $oAppDocument = new AppDocument(); - if(!isset($aData['APP_DOC_UID'])){ - $sUID = G::generateUniqueID(); - $docVersion = 1; - }else{ - $sUID = $aData['APP_DOC_UID']; - $docVersion = $this->getLastAppDocVersion($aData['APP_DOC_UID'],$oAppDocument->getAppUid()); - $oAppDocument->load($aData['APP_DOC_UID'], $docVersion); - switch( $oAppDocument->getAppDocType() ){ - case "OUTPUT"://Output versioning - $o = new OutputDocument(); - $oOutputDocument = $o->load($oAppDocument->getDocUid()); + public function getLastIndex ($sAppUid) + { + try { + $oCriteria = new Criteria(); + $oCriteria->add( AppDocumentPeer::APP_UID, $sAppUid ); + //$oCriteria->addAscendingOrderByColumn ( AppDocumentPeer::APP_DOC_INDEX ); + $oCriteria->addDescendingOrderByColumn( AppDocumentPeer::APP_DOC_INDEX ); + $lastAppDoc = AppDocumentPeer::doSelectOne( $oCriteria ); + if (! is_null( $lastAppDoc )) { + return $lastAppDoc->getAppDocIndex(); + } else { + return 0; + } + } catch (Exception $oError) { + throw ($oError); + } + } - if( !$oOutputDocument['OUT_DOC_VERSIONING'] ){ - throw(new Exception('The Output document has not versioning enabled!')); + /** + * Get last Document Version based on Doc UID + * + * @param s $sAppDocUid + * @return integer + * + */ + public function getLastDocVersion ($sDocUid, $appUID) + { + try { + $oCriteria = new Criteria(); + $oCriteria->add( AppDocumentPeer::DOC_UID, $sDocUid ); + $oCriteria->add( AppDocumentPeer::APP_UID, $appUID ); + $oCriteria->addDescendingOrderByColumn( AppDocumentPeer::DOC_VERSION ); + $lastAppDocVersion = AppDocumentPeer::doSelectOne( $oCriteria ); + if (! is_null( $lastAppDocVersion )) { + return $lastAppDocVersion->getDocVersion(); + } else { + return 0; + } + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Get last Document Version based on APPDoc UID + * + * @param s $sAppDocUid + * @return integer + * + */ + public function getLastAppDocVersion ($sAppDocUid, $appUID = 0) + { + try { + $oCriteria = new Criteria(); + $oCriteria->add( AppDocumentPeer::APP_DOC_UID, $sAppDocUid ); + if ($appUID != 0) { + $oCriteria->add( AppDocumentPeer::APP_UID, $appUID ); + } + $oCriteria->addDescendingOrderByColumn( AppDocumentPeer::DOC_VERSION ); + $lastAppDocVersion = AppDocumentPeer::doSelectOne( $oCriteria ); + if (! is_null( $lastAppDocVersion )) { + return $lastAppDocVersion->getDocVersion(); + } else { + return 0; + } + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Create the application document registry + * + * @param array $aData + * @return string + * + */ + public function create ($aData) + { + $oConnection = Propel::getConnection( AppDocumentPeer::DATABASE_NAME ); + try { + $oAppDocument = new AppDocument(); + + if (! isset( $aData['APP_DOC_UID'] )) { + $sUID = G::generateUniqueID(); + $docVersion = 1; + } else { + $sUID = $aData['APP_DOC_UID']; + $docVersion = $this->getLastAppDocVersion( $aData['APP_DOC_UID'], $oAppDocument->getAppUid() ); + $oAppDocument->load( $aData['APP_DOC_UID'], $docVersion ); + switch ($oAppDocument->getAppDocType()) { + case "OUTPUT": //Output versioning + $o = new OutputDocument(); + $oOutputDocument = $o->load( $oAppDocument->getDocUid() ); + + if (! $oOutputDocument['OUT_DOC_VERSIONING']) { + throw (new Exception( 'The Output document has not versioning enabled!' )); + } + break; + case "INPUT": // Input versioning + $o = new InputDocument(); + $oInputDocument = $o->load( $oAppDocument->getDocUid() ); + if (! $oInputDocument['INP_DOC_VERSIONING']) { + throw (new Exception( 'This Input document does not have the versioning enabled, for this reason this operation cannot be completed' )); + } + break; + default: //Not a valid type + throw (new Exception( 'The document is not of a valid Type' )); + break; } - break; - case "INPUT":// Input versioning - $o = new InputDocument(); - $oInputDocument = $o->load($oAppDocument->getDocUid()); - if( !$oInputDocument['INP_DOC_VERSIONING'] ){ - throw(new Exception('This Input document does not have the versioning enabled, for this reason this operation cannot be completed')); - } - break; - default://Not a valid type - throw(new Exception('The document is not of a valid Type')); - break; - } - - $docVersion++; - } - - $oAppDocument->fromArray($aData, BasePeer::TYPE_FIELDNAME); - $oAppDocument->setDocVersion($docVersion); - - $oAppDocument->setAppDocUid( $sUID ); - $oAppDocument->setAppDocIndex($this->getLastIndex( $oAppDocument->getAppUid() )+1); - if ($oAppDocument->validate()) { - $oConnection->begin(); - if (isset($aData['APP_DOC_TITLE'])) { - $oAppDocument->setAppDocTitle($aData['APP_DOC_TITLE']); - } - if (isset($aData['APP_DOC_COMMENT'])) { - $oAppDocument->setAppDocComment($aData['APP_DOC_COMMENT']); - } - if (isset($aData['APP_DOC_FILENAME'])) { - $oAppDocument->setAppDocFilename($aData['APP_DOC_FILENAME']); - } - $iResult = $oAppDocument->save(); - $oConnection->commit(); - $this->fromArray($oAppDocument->toArray( BasePeer::TYPE_FIELDNAME ), BasePeer::TYPE_FIELDNAME); - return $sUID; - } - else { - $sMessage = ''; - $aValidationFailures = $oAppDocument->getValidationFailures(); - foreach($aValidationFailures as $oValidationFailure) { - $sMessage .= $oValidationFailure->getMessage() . '
'; - } - throw(new Exception('The registry cannot be created!
'.$sMessage)); - } - } - catch (Exception $oError) { - $oConnection->rollback(); - throw($oError); - } - } - - /** - * Update the application document registry - * @param array $aData - * @return string - **/ - public function update($aData) - { - $oConnection = Propel::getConnection(AppDocumentPeer::DATABASE_NAME); - try { - $oAppDocument = AppDocumentPeer::retrieveByPK($aData['APP_DOC_UID'],$aData['DOC_VERSION']); - if (!is_null($oAppDocument)) - { - $oAppDocument->fromArray($aData, BasePeer::TYPE_FIELDNAME); - if ($oAppDocument->validate()) { - $oConnection->begin(); - if (isset($aData['APP_DOC_TITLE'])) - { - $oAppDocument->setAppDocTitle($aData['APP_DOC_TITLE']); - } - if (isset($aData['APP_DOC_COMMENT'])) - { - $oAppDocument->setAppDocComment($aData['APP_DOC_COMMENT']); - } - if (isset($aData['APP_DOC_FILENAME'])) - { - $oAppDocument->setAppDocFilename($aData['APP_DOC_FILENAME']); - } - $iResult = $oAppDocument->save(); - $oConnection->commit(); - return $iResult; - } - else { - $sMessage = ''; - $aValidationFailures = $oAppDocument->getValidationFailures(); - foreach($aValidationFailures as $oValidationFailure) { - $sMessage .= $oValidationFailure->getMessage() . '
'; - } - throw(new Exception('The registry cannot be updated!
'.$sMessage)); - } - } - else { - throw(new Exception('This row doesn\'t exist!')); - } - } - catch (Exception $oError) { - $oConnection->rollback(); - throw($oError); - } - } - - /** - * Remove the application document registry by changing status only - * Modified by Hugo Loza hugo@colosa.com - * @param array $aData - * @return string - **/ - public function remove($sAppDocUid,$iVersion=1) - { - $oConnection = Propel::getConnection(AppDocumentPeer::DATABASE_NAME); - try { - $oAppDocument = AppDocumentPeer::retrieveByPK($sAppDocUid,$iVersion); - if (!is_null($oAppDocument)){ - $arrayDocumentsToDelete=array(); - if($oAppDocument->getAppDocType()=="INPUT"){ - - $oCriteria = new Criteria('workflow'); - $oCriteria->add(AppDocumentPeer::APP_DOC_UID, $sAppDocUid); - $oDataset = AppDocumentPeer::doSelectRS($oCriteria); - $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $arrayDocumentsToDelete[]=array('sAppDocUid'=>$aRow['APP_DOC_UID'],'iVersion'=>$aRow['DOC_VERSION']); - $oDataset->next(); + $docVersion ++; } - }else{ - $arrayDocumentsToDelete[]=array('sAppDocUid'=>$sAppDocUid,'iVersion'=>$iVersion); + $oAppDocument->fromArray( $aData, BasePeer::TYPE_FIELDNAME ); + $oAppDocument->setDocVersion( $docVersion ); + + $oAppDocument->setAppDocUid( $sUID ); + $oAppDocument->setAppDocIndex( $this->getLastIndex( $oAppDocument->getAppUid() ) + 1 ); + if ($oAppDocument->validate()) { + $oConnection->begin(); + if (isset( $aData['APP_DOC_TITLE'] )) { + $oAppDocument->setAppDocTitle( $aData['APP_DOC_TITLE'] ); + } + if (isset( $aData['APP_DOC_COMMENT'] )) { + $oAppDocument->setAppDocComment( $aData['APP_DOC_COMMENT'] ); + } + if (isset( $aData['APP_DOC_FILENAME'] )) { + $oAppDocument->setAppDocFilename( $aData['APP_DOC_FILENAME'] ); + } + $iResult = $oAppDocument->save(); + $oConnection->commit(); + $this->fromArray( $oAppDocument->toArray( BasePeer::TYPE_FIELDNAME ), BasePeer::TYPE_FIELDNAME ); + return $sUID; + } else { + $sMessage = ''; + $aValidationFailures = $oAppDocument->getValidationFailures(); + foreach ($aValidationFailures as $oValidationFailure) { + $sMessage .= $oValidationFailure->getMessage() . '
'; + } + throw (new Exception( 'The registry cannot be created!
' . $sMessage )); + } + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + + /** + * Update the application document registry + * + * @param array $aData + * @return string + * + */ + public function update ($aData) + { + $oConnection = Propel::getConnection( AppDocumentPeer::DATABASE_NAME ); + try { + $oAppDocument = AppDocumentPeer::retrieveByPK( $aData['APP_DOC_UID'], $aData['DOC_VERSION'] ); + if (! is_null( $oAppDocument )) { + $oAppDocument->fromArray( $aData, BasePeer::TYPE_FIELDNAME ); + if ($oAppDocument->validate()) { + $oConnection->begin(); + if (isset( $aData['APP_DOC_TITLE'] )) { + $oAppDocument->setAppDocTitle( $aData['APP_DOC_TITLE'] ); + } + if (isset( $aData['APP_DOC_COMMENT'] )) { + $oAppDocument->setAppDocComment( $aData['APP_DOC_COMMENT'] ); + } + if (isset( $aData['APP_DOC_FILENAME'] )) { + $oAppDocument->setAppDocFilename( $aData['APP_DOC_FILENAME'] ); + } + $iResult = $oAppDocument->save(); + $oConnection->commit(); + return $iResult; + } else { + $sMessage = ''; + $aValidationFailures = $oAppDocument->getValidationFailures(); + foreach ($aValidationFailures as $oValidationFailure) { + $sMessage .= $oValidationFailure->getMessage() . '
'; + } + throw (new Exception( 'The registry cannot be updated!
' . $sMessage )); + } + } else { + throw (new Exception( 'This row doesn\'t exist!' )); + } + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + + /** + * Remove the application document registry by changing status only + * Modified by Hugo Loza hugo@colosa.com + * + * @param array $aData + * @return string + * + */ + public function remove ($sAppDocUid, $iVersion = 1) + { + $oConnection = Propel::getConnection( AppDocumentPeer::DATABASE_NAME ); + try { + $oAppDocument = AppDocumentPeer::retrieveByPK( $sAppDocUid, $iVersion ); + if (! is_null( $oAppDocument )) { + $arrayDocumentsToDelete = array (); + if ($oAppDocument->getAppDocType() == "INPUT") { + + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( AppDocumentPeer::APP_DOC_UID, $sAppDocUid ); + $oDataset = AppDocumentPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $arrayDocumentsToDelete[] = array ('sAppDocUid' => $aRow['APP_DOC_UID'],'iVersion' => $aRow['DOC_VERSION'] + ); + $oDataset->next(); + } + + } else { + $arrayDocumentsToDelete[] = array ('sAppDocUid' => $sAppDocUid,'iVersion' => $iVersion + ); + } + + foreach ($arrayDocumentsToDelete as $key => $docToDelete) { + $aFields = array ('APP_DOC_UID' => $docToDelete['sAppDocUid'],'DOC_VERSION' => $docToDelete['iVersion'],'APP_DOC_STATUS' => 'DELETED' + ); + + $oAppDocument->update( $aFields ); + } + + } else { + throw (new Exception( 'This row doesn\'t exist!' )); + } + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + + /** + * Get the [app_doc_title] column value. + * + * @return string + */ + public function getAppDocTitle () + { + if ($this->app_doc_title == '') { + try { + $this->app_doc_title = Content::load( 'APP_DOC_TITLE', $this->getDocVersion(), $this->getAppDocUid(), (defined( 'SYS_LANG' ) ? SYS_LANG : 'en') ); + if ($this->app_doc_title == "") { + $this->app_doc_title = Content::load( 'APP_DOC_TITLE', '', $this->getAppDocUid(), (defined( 'SYS_LANG' ) ? SYS_LANG : 'en') ); //For backward compatibility + } + } catch (Exception $oError) { + throw ($oError); + } + } + return $this->app_doc_title; + } + + /** + * Set the [app_doc_title] column value. + * + * @param string $sValue new value + * @return void + */ + public function setAppDocTitle ($sValue) + { + if ($sValue !== null && ! is_string( $sValue )) { + $sValue = (string) $sValue; + } + if ($this->app_doc_title !== $sValue || $sValue === '') { + try { + $this->app_doc_title = $sValue; + $iResult = Content::addContent( 'APP_DOC_TITLE', $this->getDocVersion(), $this->getAppDocUid(), (defined( 'SYS_LANG' ) ? SYS_LANG : 'en'), $this->app_doc_title ); + } catch (Exception $oError) { + $this->app_doc_title = ''; + throw ($oError); + } + } + } + + /** + * Get the [app_doc_comment] column value. + * + * @return string + */ + public function getAppDocComment () + { + if ($this->app_doc_comment == '') { + try { + $this->app_doc_comment = Content::load( 'APP_DOC_COMMENT', $this->getDocVersion(), $this->getAppDocUid(), (defined( 'SYS_LANG' ) ? SYS_LANG : 'en') ); + if ($this->app_doc_comment == "") { + $this->app_doc_comment = Content::load( 'APP_DOC_COMMENT', '', $this->getAppDocUid(), (defined( 'SYS_LANG' ) ? SYS_LANG : 'en') ); //For backward compatibility + } + } catch (Exception $oError) { + throw ($oError); + } + } + return $this->app_doc_comment; + } + + /** + * Set the [app_doc_comment] column value. + * + * @param string $sValue new value + * @return void + */ + public function setAppDocComment ($sValue) + { + if ($sValue !== null && ! is_string( $sValue )) { + $sValue = (string) $sValue; + } + if ($this->app_doc_comment !== $sValue || $sValue === '') { + try { + $this->app_doc_comment = $sValue; + $iResult = Content::addContent( 'APP_DOC_COMMENT', $this->getDocVersion(), $this->getAppDocUid(), (defined( 'SYS_LANG' ) ? SYS_LANG : 'en'), $this->app_doc_comment ); + } catch (Exception $oError) { + $this->app_doc_comment = ''; + throw ($oError); + } + } + } + + /** + * Get the [app_doc_filename] column value. + * + * @return string + */ + public function getAppDocFilename () + { + if ($this->app_doc_filename == '') { + try { + $this->app_doc_filename = Content::load( 'APP_DOC_FILENAME', $this->getDocVersion(), $this->getAppDocUid(), (defined( 'SYS_LANG' ) ? SYS_LANG : 'en') ); + if ($this->app_doc_filename == "") { + $this->app_doc_filename = Content::load( 'APP_DOC_FILENAME', '', $this->getAppDocUid(), (defined( 'SYS_LANG' ) ? SYS_LANG : 'en') ); //For backward compatibility + } + } catch (Exception $oError) { + throw ($oError); + } + } + return $this->app_doc_filename; + } + + /** + * Set the [app_doc_filename] column value. + * + * @param string $sValue new value + * @return void + */ + public function setAppDocFilename ($sValue) + { + if ($sValue !== null && ! is_string( $sValue )) { + $sValue = (string) $sValue; + } + if ($this->app_doc_filename !== $sValue || $sValue === '') { + try { + $this->app_doc_filename = $sValue; + $iResult = Content::addContent( 'APP_DOC_FILENAME', $this->getDocVersion(), $this->getAppDocUid(), (defined( 'SYS_LANG' ) ? SYS_LANG : 'en'), $this->app_doc_filename ); + } catch (Exception $oError) { + $this->app_doc_filename = ''; + throw ($oError); + } + } + } + + public function isEmptyInContent ($content, $field, $lang) + { + if (isset( $content[$field][$lang] )) { + if (trim( $content[$field][$lang] ) != '') { + return false; + } + } + ; + return true; + } + + public function updateInsertContent ($content, $field, $value) + { + if (isset( $content[$field]['en'] )) { + //update + $con = ContentPeer::retrieveByPK( $field, $this->getDocVersion(), $this->getAppDocUid(), 'en' ); + $con->setConValue( $value ); + if ($con->validate()) { + $res = $con->save(); + } + } else { + //insert + $con = new Content(); + $con->setConCategory( $field ); + $con->setConParent( $this->getDocVersion() ); + $con->setConId( $this->getAppDocUid() ); + $con->setConLang( 'en' ); + $con->setConValue( $value ); + if ($con->validate()) { + $res = $con->save(); + } + } + } + + public function normalizeContent ($content, $field, $lang) + { + $value = ''; + //if the lang row is not empty, update in 'en' row and continue + if (! $this->isEmptyInContent( $content, $field, $lang )) { + //update/insert only if this lang is != 'en', with this always we will have an en row with last value + $value = $content[$field][$lang]; + if ($lang != 'en') { + $this->updateInsertContent( $content, $field, $value ); + } + } else { + //if the lang row is empty, and 'en' row is not empty return 'en' value + if (! $this->isEmptyInContent( $content, $field, 'en' )) { + $value = $content[$field]['en']; + } + + //if the lang row is empty, and 'en' row is empty get value for 'other' row and update in 'en' row and continue + if ($this->isEmptyInContent( $content, $field, 'en' )) { + if (isset( $content[$field] ) && is_array( $content[$field] )) { + foreach ($content[$field] as $lan => $val) { + if (trim( $val ) != '') { + $value = $val; + if ($lan != 'en') { + $this->updateInsertContent( $content, $field, $value ); + continue; + } + } + } + } else { + $this->updateInsertContent( $content, $field, '' ); + } + } + } + return $value; + } + + /** + * Get the [app_description] , [app_title] column values. + * + * @return array of string + */ + public function getContentFields () + { + if ($this->getAppDocUid() == '') { + throw (new Exception( "Error in getContentFields, the APP_DOC_UID can't be blank" )); + } + $lang = defined( 'SYS_LANG' ) ? SYS_LANG : 'en'; + $c = new Criteria(); + $c->clearSelectColumns(); + $c->addSelectColumn( ContentPeer::CON_CATEGORY ); + $c->addSelectColumn( ContentPeer::CON_PARENT ); + $c->addSelectColumn( ContentPeer::CON_LANG ); + $c->addSelectColumn( ContentPeer::CON_VALUE ); + $c->add( ContentPeer::CON_ID, $this->getAppDocUid() ); + $c->add( ContentPeer::CON_PARENT, $this->getDocVersion() ); + $c->addAscendingOrderByColumn( 'CON_CATEGORY' ); + $c->addAscendingOrderByColumn( 'CON_LANG' ); + $rs = ContentPeer::doSelectRS( $c ); + $rs->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $rs->next(); + $content = array (); + while ($row = $rs->getRow()) { + $conCategory = $row['CON_CATEGORY']; + $conLang = $row['CON_LANG']; + if (! isset( $content[$conCategory] )) { + $content[$conCategory] = array (); + } + if (! isset( $content[$conCategory][$conLang] )) { + $content[$conCategory][$conLang] = array (); + } + $content[$conCategory][$conLang] = $row['CON_VALUE']; + $rs->next(); + $row = $rs->getRow(); } - foreach($arrayDocumentsToDelete as $key => $docToDelete){ - $aFields = array('APP_DOC_UID' => $docToDelete['sAppDocUid'], - 'DOC_VERSION' => $docToDelete['iVersion'], - 'APP_DOC_STATUS' => 'DELETED'); + $res['APP_DOC_TITLE'] = $this->normalizeContent( $content, 'APP_DOC_TITLE', $lang ); + $res['APP_DOC_COMMENT'] = $this->normalizeContent( $content, 'APP_DOC_COMMENT', $lang ); + $res['APP_DOC_FILENAME'] = $this->normalizeContent( $content, 'APP_DOC_FILENAME', $lang ); + return $res; + } + function getObject ($APP_UID, $DEL_INDEX, $STEP_UID_OBJ, $APP_DOC_TYPE) + { + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( AppDocumentPeer::APP_UID, $APP_UID ); + $oCriteria->add( AppDocumentPeer::DEL_INDEX, $DEL_INDEX ); + $oCriteria->add( AppDocumentPeer::DOC_UID, $STEP_UID_OBJ ); + $oCriteria->add( AppDocumentPeer::APP_DOC_TYPE, $APP_DOC_TYPE ); + $oDataset = AppDocumentPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); - $oAppDocument->update($aFields); + return $oDataset->getRow(); + } + + /** + * Get all docuemnts for a folder + * + * @param array $sFolderUid + * @return array + */ + public function getDocumentsinFolders ($sFolderUid) + { + $documents = array (); + + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( AppDocumentPeer::FOLDER_UID, $sFolderUid ); + $oDataset = AppDocumentPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + + while ($aRow = $oDataset->getRow()) { + $documents[] = array ('sAppDocUid' => $aRow['APP_DOC_UID'],'iVersion' => $aRow['DOC_VERSION'] + ); + $oDataset->next(); } - - - - } - else { - throw(new Exception('This row doesn\'t exist!')); - } + return $documents; } - catch (Exception $oError) { - $oConnection->rollback(); - throw($oError); - } - } +} +// AppDocument - /** - * Get the [app_doc_title] column value. - * @return string - */ - public function getAppDocTitle() - { - if ($this->app_doc_title == '') { - try { - $this->app_doc_title = Content::load('APP_DOC_TITLE', $this->getDocVersion(), $this->getAppDocUid(), (defined('SYS_LANG') ? SYS_LANG : 'en')); - if($this->app_doc_title=="") $this->app_doc_title = Content::load('APP_DOC_TITLE', '', $this->getAppDocUid(), (defined('SYS_LANG') ? SYS_LANG : 'en')); //For backward compatibility - } - catch (Exception $oError) { - throw($oError); - } - } - return $this->app_doc_title; - } - - /** - * Set the [app_doc_title] column value. - * - * @param string $sValue new value - * @return void - */ - public function setAppDocTitle($sValue) - { - if ($sValue !== null && !is_string($sValue)) { - $sValue = (string)$sValue; - } - if ($this->app_doc_title !== $sValue || $sValue === '') { - try { - $this->app_doc_title = $sValue; - $iResult = Content::addContent('APP_DOC_TITLE', $this->getDocVersion(), $this->getAppDocUid(), (defined('SYS_LANG') ? SYS_LANG : 'en'), $this->app_doc_title); - } - catch (Exception $oError) { - $this->app_doc_title = ''; - throw($oError); - } - } - } - - /** - * Get the [app_doc_comment] column value. - * @return string - */ - public function getAppDocComment() - { - if ($this->app_doc_comment == '') { - try { - $this->app_doc_comment = Content::load('APP_DOC_COMMENT', $this->getDocVersion(), $this->getAppDocUid(), (defined('SYS_LANG') ? SYS_LANG : 'en')); - if($this->app_doc_comment=="") $this->app_doc_comment = Content::load('APP_DOC_COMMENT', '', $this->getAppDocUid(), (defined('SYS_LANG') ? SYS_LANG : 'en')); //For backward compatibility - } - catch (Exception $oError) { - throw($oError); - } - } - return $this->app_doc_comment; - } - - /** - * Set the [app_doc_comment] column value. - * - * @param string $sValue new value - * @return void - */ - public function setAppDocComment($sValue) - { - if ($sValue !== null && !is_string($sValue)) { - $sValue = (string)$sValue; - } - if ($this->app_doc_comment !== $sValue || $sValue === '') { - try { - $this->app_doc_comment = $sValue; - $iResult = Content::addContent('APP_DOC_COMMENT', $this->getDocVersion(), $this->getAppDocUid(), (defined('SYS_LANG') ? SYS_LANG : 'en'), $this->app_doc_comment); - } - catch (Exception $oError) { - $this->app_doc_comment = ''; - throw($oError); - } - } - } - - /** - * Get the [app_doc_filename] column value. - * @return string - */ - public function getAppDocFilename() - { - if ($this->app_doc_filename == '') { - try { - $this->app_doc_filename = Content::load('APP_DOC_FILENAME', $this->getDocVersion(), $this->getAppDocUid(), (defined('SYS_LANG') ? SYS_LANG : 'en')); - if($this->app_doc_filename=="") $this->app_doc_filename = Content::load('APP_DOC_FILENAME', '', $this->getAppDocUid(), (defined('SYS_LANG') ? SYS_LANG : 'en')); //For backward compatibility - } - catch (Exception $oError) { - throw($oError); - } - } - return $this->app_doc_filename; - } - - /** - * Set the [app_doc_filename] column value. - * - * @param string $sValue new value - * @return void - */ - public function setAppDocFilename($sValue) - { - if ($sValue !== null && !is_string($sValue)) { - $sValue = (string)$sValue; - } - if ($this->app_doc_filename !== $sValue || $sValue === '') { - try { - $this->app_doc_filename = $sValue; - $iResult = Content::addContent('APP_DOC_FILENAME', $this->getDocVersion(), $this->getAppDocUid(), (defined('SYS_LANG') ? SYS_LANG : 'en'), $this->app_doc_filename); - } - catch (Exception $oError) { - $this->app_doc_filename = ''; - throw($oError); - } - } - } - - public function isEmptyInContent ( $content, $field, $lang ) { - if ( isset ( $content[$field][ $lang ] ) ) { - if ( trim( $content[$field][ $lang ] ) != '' ) - return false; - }; - return true; - } - - public function updateInsertContent ( $content, $field, $value ) { - if ( isset ( $content[$field][ 'en' ] ) ) { - //update - $con = ContentPeer::retrieveByPK ( $field, $this->getDocVersion(), $this->getAppDocUid(), 'en' ); - $con->setConValue ( $value ); - if ($con->validate ()) { - $res = $con->save (); - } - } - else {//insert - $con = new Content ( ); - $con->setConCategory ( $field ); - $con->setConParent ($this->getDocVersion() ); - $con->setConId ( $this->getAppDocUid() ); - $con->setConLang ( 'en' ); - $con->setConValue ( $value ); - if ($con->validate ()) { - $res = $con->save (); - } - } - } - - public function normalizeContent( $content, $field , $lang ) { - $value = ''; - //if the lang row is not empty, update in 'en' row and continue - if ( !$this->isEmptyInContent ( $content, $field , $lang ) ) { - //update/insert only if this lang is != 'en', with this always we will have an en row with last value - $value = $content [ $field ][ $lang ]; - if ( $lang != 'en' ) { - $this->updateInsertContent ( $content, $field , $value ); - } - } - else { - //if the lang row is empty, and 'en' row is not empty return 'en' value - if ( !$this->isEmptyInContent ( $content, $field , 'en' ) ) { - $value = $content [ $field ][ 'en' ]; - } - - //if the lang row is empty, and 'en' row is empty get value for 'other' row and update in 'en' row and continue - if ( $this->isEmptyInContent ( $content, $field , 'en' ) ) { - if ( isset($content[$field]) && is_array ($content[$field] ) ) { - foreach ( $content [ $field ] as $lan => $val ) { - if ( trim ( $val ) != '' ) { - $value = $val; - if ( $lan != 'en' ) { - $this->updateInsertContent ( $content, $field , $value ); - continue; - } - } - } - } - else { - $this->updateInsertContent ( $content, $field , '' ); - } - } - } - return $value; - } - - /** - * Get the [app_description] , [app_title] column values. - * @return array of string - */ - public function getContentFields() - { - if ( $this->getAppDocUid() == '' ) { - throw ( new Exception( "Error in getContentFields, the APP_DOC_UID can't be blank") ); - } - $lang = defined ( 'SYS_LANG') ? SYS_LANG : 'en'; - $c = new Criteria(); - $c->clearSelectColumns(); - $c->addSelectColumn( ContentPeer::CON_CATEGORY ); - $c->addSelectColumn( ContentPeer::CON_PARENT ); - $c->addSelectColumn( ContentPeer::CON_LANG ); - $c->addSelectColumn( ContentPeer::CON_VALUE ); - $c->add( ContentPeer::CON_ID, $this->getAppDocUid() ); - $c->add( ContentPeer::CON_PARENT, $this->getDocVersion() ); - $c->addAscendingOrderByColumn('CON_CATEGORY'); - $c->addAscendingOrderByColumn('CON_LANG'); - $rs = ContentPeer::doSelectRS( $c ); - $rs->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $rs->next(); - $content = array(); - while ($row = $rs->getRow()) { - $conCategory = $row['CON_CATEGORY']; - $conLang = $row['CON_LANG']; - if ( !isset( $content[$conCategory] ) ) $content[$conCategory] = array(); - if ( !isset( $content[$conCategory][$conLang] ) ) $content[$conCategory][$conLang] = array(); - $content[$conCategory][$conLang] = $row['CON_VALUE']; - $rs->next(); - $row = $rs->getRow(); - } - - $res['APP_DOC_TITLE'] = $this->normalizeContent( $content, 'APP_DOC_TITLE', $lang ); - $res['APP_DOC_COMMENT'] = $this->normalizeContent( $content, 'APP_DOC_COMMENT', $lang ); - $res['APP_DOC_FILENAME'] = $this->normalizeContent( $content, 'APP_DOC_FILENAME', $lang ); - return $res; - } - - function getObject($APP_UID, $DEL_INDEX, $STEP_UID_OBJ, $APP_DOC_TYPE) - { - $oCriteria = new Criteria('workflow'); - $oCriteria->add(AppDocumentPeer::APP_UID, $APP_UID); - $oCriteria->add(AppDocumentPeer::DEL_INDEX, $DEL_INDEX); - $oCriteria->add(AppDocumentPeer::DOC_UID, $STEP_UID_OBJ); - $oCriteria->add(AppDocumentPeer::APP_DOC_TYPE, $APP_DOC_TYPE); - $oDataset = AppDocumentPeer::doSelectRS($oCriteria); - $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $oDataset->next(); - - return $oDataset->getRow(); - } - - /** - * Get all docuemnts for a folder - * @param array $sFolderUid - * @return array - */ - public function getDocumentsinFolders($sFolderUid) - { - $documents = array(); - - $oCriteria = new Criteria('workflow'); - $oCriteria->add(AppDocumentPeer::FOLDER_UID, $sFolderUid); - $oDataset = AppDocumentPeer::doSelectRS($oCriteria); - $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $oDataset->next(); - - while ($aRow = $oDataset->getRow()) { - $documents[] = array('sAppDocUid' => $aRow['APP_DOC_UID'], 'iVersion' => $aRow['DOC_VERSION']); - $oDataset->next(); - } - - return $documents; - } - -} // AppDocument diff --git a/workflow/engine/classes/model/Department.php b/workflow/engine/classes/model/Department.php index a834cbbf4..26330ba77 100755 --- a/workflow/engine/classes/model/Department.php +++ b/workflow/engine/classes/model/Department.php @@ -1,7 +1,8 @@ . + * along with this program. If not, see . * * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. @@ -27,543 +28,555 @@ require_once 'classes/model/om/BaseDepartment.php'; require_once 'classes/model/Users.php'; - /** * Skeleton subclass for representing a row from the 'DEPARTMENT' table. * * * * You should add additional methods to this class to meet the - * application requirements. This class will only be generated as + * application requirements. This class will only be generated as * long as it does not already exist in the output directory. * - * @package workflow.engine.classes.model + * @package workflow.engine.classes.model */ -class Department extends BaseDepartment { +class Department extends BaseDepartment +{ + protected $depo_title = ''; -protected $depo_title = ''; -/** - * Create the Department - * - * @param array $aData - * @return void - */ + /** + * Create the Department + * + * @param array $aData + * @return void + */ - function create ($aData ) { - $con = Propel::getConnection( DepartmentPeer::DATABASE_NAME ); - try { - if ( isset ( $aData['DEP_UID'] ) ) - $this->setDepUid ( $aData['DEP_UID'] ); - else - $this->setDepUid ( G::generateUniqueID() ); - - if ( isset ( $aData['DEP_PARENT'] ) ) - $this->setDepParent ( $aData['DEP_PARENT'] ); - else - $this->setDepParent ( '' ); - - if ( isset ( $aData['DEP_MANAGER'] ) ) - $this->setDepManager ( $aData['DEP_MANAGER'] ); - else - $this->setDepManager ( '' ); - - if ( isset ( $aData['DEP_LOCATION'] ) ) - $this->setDepLocation ( $aData['DEP_LOCATION'] ); - else - $this->setDepLocation ( '' ); - - if ( isset ( $aData['DEP_STATUS'] ) ) - $this->setDepStatus ( $aData['DEP_STATUS'] ); - else - $this->setDepStatus ( 'ACTIVE' ); - - if ( isset ( $aData['DEP_REF_CODE'] ) ) - $this->setDepRefCode ( $aData['DEP_REF_CODE'] ); - else - $this->setDepRefCode ( '' ); - - if ( isset ( $aData['DEP_LDAP_DN'] ) ) - $this->setDepLdapDn ( $aData['DEP_LDAP_DN'] ); - else - $this->setDepLdapDn ( '' ); - - if ( isset ( $aData['DEP_TITLE'] ) ) - $this->setDepTitle ( $aData['DEP_TITLE'] ); - else - $this->setDepTitle ( '' ); - - if ( $this->validate() ) { - $con->begin(); - $res = $this->save(); - - $con->commit(); - return $this->getDepUid(); - } - else { - $msg = ''; - foreach($this->getValidationFailures() as $objValidationFailure) - $msg .= $objValidationFailure->getMessage() . "
"; - - throw ( new Exception ( " The Department row cannot be created $msg " ) ); - } - - } - catch (Exception $e) { - $con->rollback(); - throw ($e); - } - } - -/** - * Get the [depo_title] column value. - * @return string - */ - public function getDepTitle() - { - if ( $this->getDepUid() == '' ) { - throw ( new Exception( "Error in getDepTitle, the DEP_UID can't be blank") ); - } - $lang = defined ( 'SYS_LANG') ? SYS_LANG : 'en'; - $this->depo_title = Content::load ( 'DEPO_TITLE', '', $this->getDepUid(), $lang ); - return $this->depo_title; - } - - /** - * Set the [depo_title] column value. - * - * @param string $v new value - * @return void - */ - public function setDepTitle($v) - { - if ( $this->getDepUid() == '' ) { - throw ( new Exception( "Error in setGrpTitle, the GRP_UID can't be blank") ); - } - // Since the native PHP type for this column is string, - // we will cast the input to a string (if it is not). - if ($v !== null && !is_string($v)) { - $v = (string) $v; - } - - if ($this->depo_title !== $v || $v === '') { - $this->depo_title = $v; - $lang = defined ( 'SYS_LANG') ? SYS_LANG : 'en'; - $res = Content::addContent( 'DEPO_TITLE', '', $this->getDepUid(), $lang, $this->depo_title ); - } - - } // set() - - -/** - * Load the Process row specified in [depo_id] column value. - * - * @param string $ProUid the uid of the Prolication - * @return array $Fields the fields - */ - - function Load ( $DepUid ) { - $con = Propel::getConnection(DepartmentPeer::DATABASE_NAME); - try { - $oDept = DepartmentPeer::retrieveByPk( $DepUid ); - if (is_object ($oDept) && get_class ($oDept) == 'Department' ) { - $aFields = $oDept->toArray(BasePeer::TYPE_FIELDNAME); - $this->fromArray ($aFields, BasePeer::TYPE_FIELDNAME ); - $aFields['DEPO_TITLE'] = $oDept->getDepTitle(); - return $aFields; - } - else { - throw(new Exception( "The row '$DepUid' in table Department doesn't exist!" )); - } - } - catch (Exception $oError) { - throw($oError); - } - } - -/** - * Update the Dep row - * @param array $aData - * @return variant - **/ - - public function update($aData) - { - $con = Propel::getConnection( DepartmentPeer::DATABASE_NAME ); - try { - $con->begin(); - $oPro = DepartmentPeer::retrieveByPK( $aData['DEP_UID'] ); - if (is_object($oPro) && get_class ($oPro) == 'Department' ) { - $oPro->fromArray( $aData, BasePeer::TYPE_FIELDNAME ); - if ($oPro->validate()) { - if ( isset ( $aData['DEPO_TITLE'] ) ) - $oPro->setDepTitle( $aData['DEPO_TITLE'] ); - if ( isset ( $aData['DEP_STATUS'] ) ) - $oPro->setDepStatus( $aData['DEP_STATUS'] ); - if ( isset ( $aData['DEP_PARENT'] ) ) - $oPro->setDepParent( $aData['DEP_PARENT'] ); - if ( isset ( $aData['DEP_MANAGER'] ) ) - $oPro->setDepManager( $aData['DEP_MANAGER'] ); - $res = $oPro->save(); - $con->commit(); - return $res; - } - else { - $msg = ''; - foreach($this->getValidationFailures() as $objValidationFailure) - $msg .= $objValidationFailure->getMessage() . "
"; - - throw ( new PropelException ( 'The Department row cannot be created!', new PropelException ( $msg ) ) ); - } - } - else { - $con->rollback(); - throw(new Exception( "The row '" . $aData['DEP_UID'] . "' in table Department doesn't exist!" )); - } - } - catch (Exception $oError) { - throw($oError); - } - } - - - /** - * Remove the row - * @param array $aData or string $ProUid - * @return string - **/ - public function remove($ProUid) - { - if ( is_array ( $ProUid ) ) { - $ProUid = ( isset ( $ProUid['DEP_UID'] ) ? $ProUid['DEP_UID'] : '' ); - } - try { - - $oCriteria = new Criteria('workflow'); - $oCriteria->addSelectColumn(UsersPeer::USR_UID); - $oCriteria->add(UsersPeer::DEP_UID, $ProUid, Criteria::EQUAL); - $oDataset = UsersPeer::doSelectRS($oCriteria); - $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - - $oDataset->next(); - $aFields = array(); - while ($aRow = $oDataset->getRow()) { - - $aFields['USR_UID'] = $aRow['USR_UID']; - $aFields['DEP_UID'] = ''; - $oDepto = UsersPeer::retrieveByPk($aFields['USR_UID']); - if (is_object($oDepto) && get_class($oDepto) == 'UsersPeer') { - return true; + function create ($aData) + { + $con = Propel::getConnection( DepartmentPeer::DATABASE_NAME ); + try { + if (isset( $aData['DEP_UID'] )) { + $this->setDepUid( $aData['DEP_UID'] ); } else { - $oDepto = new Users(); - $oDepto->update($aFields); + $this->setDepUid( G::generateUniqueID() ); } - $oDataset->next(); - } + if (isset( $aData['DEP_PARENT'] )) { + $this->setDepParent( $aData['DEP_PARENT'] ); + } else { + $this->setDepParent( '' ); + } + if (isset( $aData['DEP_MANAGER'] )) { + $this->setDepManager( $aData['DEP_MANAGER'] ); + } else { + $this->setDepManager( '' ); + } + if (isset( $aData['DEP_LOCATION'] )) { + $this->setDepLocation( $aData['DEP_LOCATION'] ); + } else { + $this->setDepLocation( '' ); + } - $oPro = DepartmentPeer::retrieveByPK( $ProUid ); - if (!is_null($oPro)) - { - Content::removeContent('DEPO_TITLE', '', $oPro->getDepUid()); - Content::removeContent('DEPO_DESCRIPTION', '', $oPro->getDepUid()); - return $oPro->delete(); - } - else { - throw(new Exception( "The row '$ProUid' in table Group doesn't exist!" )); - } - } - catch (Exception $oError) { - throw($oError); - } - } + if (isset( $aData['DEP_STATUS'] )) { + $this->setDepStatus( $aData['DEP_STATUS'] ); + } else { + $this->setDepStatus( 'ACTIVE' ); + } + if (isset( $aData['DEP_REF_CODE'] )) { + $this->setDepRefCode( $aData['DEP_REF_CODE'] ); + } else { + $this->setDepRefCode( '' ); + } -/** - * Load the Department row specified in [depo_id] column value. - * - * @param string $ProUid the uid of the Prolication - * @return array $Fields the fields - */ + if (isset( $aData['DEP_LDAP_DN'] )) { + $this->setDepLdapDn( $aData['DEP_LDAP_DN'] ); + } else { + $this->setDepLdapDn( '' ); + } - function existsDepartment( $DepUid ) { - $con = Propel::getConnection(DepartmentPeer::DATABASE_NAME); - $oPro = DepartmentPeer::retrieveByPk( $DepUid ); - if (is_object($oPro) && get_class ($oPro) == 'Department' ) { - return true; - } - else { - return false; - } - } + if (isset( $aData['DEP_TITLE'] )) { + $this->setDepTitle( $aData['DEP_TITLE'] ); + } else { + $this->setDepTitle( '' ); + } - function existsUserInDepartment( $depId, $userId ) { - $con = Propel::getConnection(DepartmentPeer::DATABASE_NAME); - $oUser = UsersPeer::retrieveByPk( $userId ); - if (is_object($oUser) && get_class ($oUser) == 'Users' ) { - if ( $oUser->getDepUid() == $depId ) - return true; - } + if ($this->validate()) { + $con->begin(); + $res = $this->save(); - return false; - } + $con->commit(); + return $this->getDepUid(); + } else { + $msg = ''; + foreach ($this->getValidationFailures() as $objValidationFailure) { + $msg .= $objValidationFailure->getMessage() . "
"; + } - function updateDepartmentManager ($depId) { - $managerId = ''; - $depParent = ''; - $oDept = DepartmentPeer::retrieveByPk( $depId ); - if (is_object($oDept) && get_class ($oDept) == 'Department' ) { - $managerId = $oDept->getDepManager( ); - $depParent = $oDept->getDepParent( ); - } + throw (new Exception( " The Department row cannot be created $msg " )); + } - // update the reportsTo field to all users in that department - $conn = Propel::getConnection(UsersPeer::DATABASE_NAME); - $selectCriteria = new Criteria('workflow'); - $selectCriteria->add(UsersPeer::DEP_UID, $depId ); - $selectCriteria->add(UsersPeer::USR_UID, $managerId , Criteria::NOT_EQUAL); - - // Create a Criteria object includes the value you want to set - $updateCriteria = new Criteria('workflow'); - $updateCriteria->add(UsersPeer::USR_REPORTS_TO, $managerId ); - BasePeer::doUpdate($selectCriteria, $updateCriteria, $conn); - - // update manager's manager, getting the manager of PARENT DEPARTMENT in order to enable scalating - $oUser = UsersPeer::retrieveByPk( $managerId ); - if (is_object($oUser) && get_class ($oUser) == 'Users' ) { - $oDept = DepartmentPeer::retrieveByPk( $depParent ); - $oUser->setUsrReportsTo( '' ); //by default no manager - if (is_object($oDept) && get_class ($oDept) == 'Department' ) { - $managerParentId = $oDept->getDepManager( ); - if ( trim($managerParentId) != '' ) { - $oUser->setUsrReportsTo( $managerParentId ); + } catch (Exception $e) { + $con->rollback(); + throw ($e); } - } - $oUser->save(); } - // get children departments to update the reportsTo of these children - $childrenCriteria = new Criteria('workflow'); - $childrenCriteria->add(DepartmentPeer::DEP_PARENT, $depId ); - $oDataset = DepartmentPeer::doSelectRS($childrenCriteria); - $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - - $oDataset->next(); - while ( $aRow = $oDataset->getRow() ) { - $oUser = UsersPeer::retrieveByPk($aRow['DEP_MANAGER']); - if (is_object($oUser) && get_class($oUser) == 'Users') { - $oUser->setUsrReportsTo ( $managerId ); - $oUser->save(); - } - $oDataset->next(); + /** + * Get the [depo_title] column value. + * + * @return string + */ + public function getDepTitle () + { + if ($this->getDepUid() == '') { + throw (new Exception( "Error in getDepTitle, the DEP_UID can't be blank" )); + } + $lang = defined( 'SYS_LANG' ) ? SYS_LANG : 'en'; + $this->depo_title = Content::load( 'DEPO_TITLE', '', $this->getDepUid(), $lang ); + return $this->depo_title; } - } + /** + * Set the [depo_title] column value. + * + * @param string $v new value + * @return void + */ + public function setDepTitle ($v) + { + if ($this->getDepUid() == '') { + throw (new Exception( "Error in setGrpTitle, the GRP_UID can't be blank" )); + } + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && ! is_string( $v )) { + $v = (string) $v; + } - //add an user to a department and sync all about manager info - function addUserToDepartment( $depId, $userId, $manager, $updateManager = false ) { - try { - //update the field in user table - $oUser = UsersPeer::retrieveByPk( $userId ); - if (is_object($oUser) && get_class ($oUser) == 'Users' ) { - $oUser->setDepUid( $depId ); - $oUser->save(); - } + if ($this->depo_title !== $v || $v === '') { + $this->depo_title = $v; + $lang = defined( 'SYS_LANG' ) ? SYS_LANG : 'en'; + $res = Content::addContent( 'DEPO_TITLE', '', $this->getDepUid(), $lang, $this->depo_title ); + } - //if the user is a manager update Department Table - if ( $manager ) { + } // set() + + + /** + * Load the Process row specified in [depo_id] column value. + * + * @param string $ProUid the uid of the Prolication + * @return array $Fields the fields + */ + + function Load ($DepUid) + { + $con = Propel::getConnection( DepartmentPeer::DATABASE_NAME ); + try { + $oDept = DepartmentPeer::retrieveByPk( $DepUid ); + if (is_object( $oDept ) && get_class( $oDept ) == 'Department') { + $aFields = $oDept->toArray( BasePeer::TYPE_FIELDNAME ); + $this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME ); + $aFields['DEPO_TITLE'] = $oDept->getDepTitle(); + return $aFields; + } else { + throw (new Exception( "The row '$DepUid' in table Department doesn't exist!" )); + } + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Update the Dep row + * + * @param array $aData + * @return variant + * + */ + + public function update ($aData) + { + $con = Propel::getConnection( DepartmentPeer::DATABASE_NAME ); + try { + $con->begin(); + $oPro = DepartmentPeer::retrieveByPK( $aData['DEP_UID'] ); + if (is_object( $oPro ) && get_class( $oPro ) == 'Department') { + $oPro->fromArray( $aData, BasePeer::TYPE_FIELDNAME ); + if ($oPro->validate()) { + if (isset( $aData['DEPO_TITLE'] )) { + $oPro->setDepTitle( $aData['DEPO_TITLE'] ); + } + if (isset( $aData['DEP_STATUS'] )) { + $oPro->setDepStatus( $aData['DEP_STATUS'] ); + } + if (isset( $aData['DEP_PARENT'] )) { + $oPro->setDepParent( $aData['DEP_PARENT'] ); + } + if (isset( $aData['DEP_MANAGER'] )) { + $oPro->setDepManager( $aData['DEP_MANAGER'] ); + } + $res = $oPro->save(); + $con->commit(); + return $res; + } else { + $msg = ''; + foreach ($this->getValidationFailures() as $objValidationFailure) { + $msg .= $objValidationFailure->getMessage() . "
"; + } + + throw (new PropelException( 'The Department row cannot be created!', new PropelException( $msg ) )); + } + } else { + $con->rollback(); + throw (new Exception( "The row '" . $aData['DEP_UID'] . "' in table Department doesn't exist!" )); + } + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Remove the row + * + * @param array $aData or string $ProUid + * @return string + * + */ + public function remove ($ProUid) + { + if (is_array( $ProUid )) { + $ProUid = (isset( $ProUid['DEP_UID'] ) ? $ProUid['DEP_UID'] : ''); + } + try { + + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->addSelectColumn( UsersPeer::USR_UID ); + $oCriteria->add( UsersPeer::DEP_UID, $ProUid, Criteria::EQUAL ); + $oDataset = UsersPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + + $oDataset->next(); + $aFields = array (); + while ($aRow = $oDataset->getRow()) { + + $aFields['USR_UID'] = $aRow['USR_UID']; + $aFields['DEP_UID'] = ''; + $oDepto = UsersPeer::retrieveByPk( $aFields['USR_UID'] ); + if (is_object( $oDepto ) && get_class( $oDepto ) == 'UsersPeer') { + return true; + } else { + $oDepto = new Users(); + $oDepto->update( $aFields ); + } + + $oDataset->next(); + } + + $oPro = DepartmentPeer::retrieveByPK( $ProUid ); + if (! is_null( $oPro )) { + Content::removeContent( 'DEPO_TITLE', '', $oPro->getDepUid() ); + Content::removeContent( 'DEPO_DESCRIPTION', '', $oPro->getDepUid() ); + return $oPro->delete(); + } else { + throw (new Exception( "The row '$ProUid' in table Group doesn't exist!" )); + } + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Load the Department row specified in [depo_id] column value. + * + * @param string $ProUid the uid of the Prolication + * @return array $Fields the fields + */ + + function existsDepartment ($DepUid) + { + $con = Propel::getConnection( DepartmentPeer::DATABASE_NAME ); + $oPro = DepartmentPeer::retrieveByPk( $DepUid ); + if (is_object( $oPro ) && get_class( $oPro ) == 'Department') { + return true; + } else { + return false; + } + } + + function existsUserInDepartment ($depId, $userId) + { + $con = Propel::getConnection( DepartmentPeer::DATABASE_NAME ); + $oUser = UsersPeer::retrieveByPk( $userId ); + if (is_object( $oUser ) && get_class( $oUser ) == 'Users') { + if ($oUser->getDepUid() == $depId) { + return true; + } + } + + return false; + } + + function updateDepartmentManager ($depId) + { + $managerId = ''; + $depParent = ''; $oDept = DepartmentPeer::retrieveByPk( $depId ); - if (is_object($oDept) && get_class ($oDept) == 'Department' ) { - $oDept->setDepManager( $userId ); - $oDept->save(); - } - } - - //now update the reportsto to all - if ( $updateManager ) { - $this->updateDepartmentManager ($depId); - } - return true; - } - catch ( Exception $oError) { - throw($oError); - } - } - - // select departments - // this function is used to draw the hierachy tree view -function getDepartments( $DepParent ) { - try { - $result = array(); - $criteria = new Criteria('workflow'); - $criteria->add(DepartmentPeer::DEP_PARENT, $DepParent, Criteria::EQUAL); - $con = Propel::getConnection(DepartmentPeer::DATABASE_NAME); - $objects = DepartmentPeer::doSelect($criteria, $con); - global $RBAC; - - foreach( $objects as $oDepartment ) { - $node = array(); - $node['DEP_UID'] = $oDepartment->getDepUid(); - $node['DEP_PARENT'] = $oDepartment->getDepParent(); - $node['DEP_TITLE'] = $oDepartment->getDepTitle(); - $node['DEP_STATUS'] = $oDepartment->getDepStatus(); - $node['DEP_MANAGER'] = $oDepartment->getDepManager(); - $node['DEP_LDAP_DN'] = $oDepartment->getDepLdapDn(); - $node['DEP_LAST'] = 0; - - $manager = $oDepartment->getDepManager(); - if ($manager != ''){ - $UserUID = $RBAC->load($manager); - $node['DEP_MANAGER_USERNAME'] = isset($UserUID['USR_USERNAME'])?$UserUID['USR_USERNAME']:''; - $node['DEP_MANAGER_FIRSTNAME'] = isset($UserUID['USR_FIRSTNAME'])?$UserUID['USR_FIRSTNAME']:''; - $node['DEP_MANAGER_LASTNAME'] = isset($UserUID['USR_LASTNAME'])?$UserUID['USR_LASTNAME']:''; - }else{ - $node['DEP_MANAGER_USERNAME'] = ''; - $node['DEP_MANAGER_FIRSTNAME'] = ''; - $node['DEP_MANAGER_LASTNAME'] = ''; + if (is_object( $oDept ) && get_class( $oDept ) == 'Department') { + $managerId = $oDept->getDepManager(); + $depParent = $oDept->getDepParent(); } - $criteriaCount = new Criteria('workflow'); - $criteriaCount->clearSelectColumns(); - $criteriaCount->addSelectColumn( 'COUNT(*)' ); - $criteriaCount->add(DepartmentPeer::DEP_PARENT, $oDepartment->getDepUid(), Criteria::EQUAL); - $rs = DepartmentPeer::doSelectRS($criteriaCount); - $rs->next(); - $row = $rs->getRow(); - $node['HAS_CHILDREN'] = $row[0]; - $result[] = $node; - } - if ( count($result) >= 1 ) - $result[ count($result) -1 ]['DEP_LAST'] = 1; - return $result; - } - catch (exception $e) { - throw $e; - } - } + // update the reportsTo field to all users in that department + $conn = Propel::getConnection( UsersPeer::DATABASE_NAME ); + $selectCriteria = new Criteria( 'workflow' ); + $selectCriteria->add( UsersPeer::DEP_UID, $depId ); + $selectCriteria->add( UsersPeer::USR_UID, $managerId, Criteria::NOT_EQUAL ); - /** - * Check department name exist in the level - * @param string $departmentName name of the department - * @param string $parentUID parent UID of the department - * @param string $departmentUID department UID - * @return boolean $Fields true or false - * - */ - function checkDepartmentName($departmentName, $parentUID, $departmentUID = '' ) - { - $oCriteria = new Criteria('workflow'); + // Create a Criteria object includes the value you want to set + $updateCriteria = new Criteria( 'workflow' ); + $updateCriteria->add( UsersPeer::USR_REPORTS_TO, $managerId ); + BasePeer::doUpdate( $selectCriteria, $updateCriteria, $conn ); - $oCriteria->clearSelectColumns(); - $oCriteria->addSelectColumn( ContentPeer::CON_CATEGORY ); - $oCriteria->addSelectColumn( ContentPeer::CON_VALUE ); - $oCriteria->addSelectColumn( DepartmentPeer::DEP_PARENT ); - $oCriteria->add(ContentPeer::CON_CATEGORY, 'DEPO_TITLE'); - $oCriteria->addJoin(ContentPeer::CON_ID, DepartmentPeer::DEP_UID, Criteria::LEFT_JOIN); - $oCriteria->add(ContentPeer::CON_VALUE, $departmentName); - $oCriteria->add(DepartmentPeer::DEP_UID, $departmentUID, Criteria::NOT_EQUAL); - $oCriteria->add(ContentPeer::CON_LANG, SYS_LANG ); - $oCriteria->add(DepartmentPeer::DEP_PARENT, $parentUID); - - $oDataset = DepartmentPeer::doSelectRS($oCriteria); - $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $oDataset->next(); - $aRow = $oDataset->getRow(); - - return ($aRow) ? true : false; - } - - function getUsersFromDepartment( $sDepUid, $sManagerUid ) { - try { - $oCriteria = new Criteria('workflow'); - $oCriteria->addSelectColumn(UsersPeer::USR_UID); - $oCriteria->addSelectColumn(UsersPeer::USR_REPORTS_TO); - $oCriteria->add(UsersPeer::USR_STATUS, 'CLOSED', Criteria::NOT_EQUAL); - $oCriteria->add(UsersPeer::DEP_UID, $sDepUid); - - $rs = UsersPeer::doSelectRS($oCriteria); - $rs->setFetchmode(ResultSet::FETCHMODE_ASSOC); - - $oUser = new Users(); - $aUsers[] = array('USR_UID' =>'char', 'USR_USERNAME' =>'char','USR_FULLNAME' =>'char', 'USR_REPORTS_TO'=>'char','USR_MANAGER' =>'char'); - $rs->next(); - $row = $rs->getRow(); - while( is_array($row) ) { - $usrFields = $oUser->LoadDetails( $row['USR_UID'] ); - $row['USR_USERNAME'] = $usrFields['USR_USERNAME']; - $row['USR_FULLNAME'] = $usrFields['USR_FULLNAME']; - $row['USR_MANAGER'] = $row['USR_UID'] == $sManagerUid ? G::loadTranslation("ID_YES") : G::loadTranslation("ID_NO"); - $row['DEP_UID'] = $sDepUid; - if ( $row['USR_REPORTS_TO'] != '' ) { - try { - $managerFields = $oUser->LoadDetails( $row['USR_REPORTS_TO'] ); - $row['USR_REPORTS_NAME'] = $managerFields['USR_FULLNAME']; - } - catch (exception $e) { - $row['USR_REPORTS_NAME'] = '.'; - } + // update manager's manager, getting the manager of PARENT DEPARTMENT in order to enable scalating + $oUser = UsersPeer::retrieveByPk( $managerId ); + if (is_object( $oUser ) && get_class( $oUser ) == 'Users') { + $oDept = DepartmentPeer::retrieveByPk( $depParent ); + $oUser->setUsrReportsTo( '' ); //by default no manager + if (is_object( $oDept ) && get_class( $oDept ) == 'Department') { + $managerParentId = $oDept->getDepManager(); + if (trim( $managerParentId ) != '') { + $oUser->setUsrReportsTo( $managerParentId ); + } + } + $oUser->save(); } - else - $row['USR_REPORTS_NAME'] = '.'; - $aUsers[] = $row; - $rs->next(); - $row = $rs->getRow(); - } - G::LoadClass('ArrayPeer'); - global $_DBArray; - $_DBArray['DepartmentUserList'] = $aUsers ; - $_SESSION['_DBArray'] = $_DBArray; - $oCriteriaT = new Criteria('dbarray'); - $oCriteriaT->setDBArrayTable('DepartmentUserList'); + // get children departments to update the reportsTo of these children + $childrenCriteria = new Criteria( 'workflow' ); + $childrenCriteria->add( DepartmentPeer::DEP_PARENT, $depId ); + $oDataset = DepartmentPeer::doSelectRS( $childrenCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - return $oCriteriaT; - } - catch (exception $e) { - throw $e; - } - } + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $oUser = UsersPeer::retrieveByPk( $aRow['DEP_MANAGER'] ); + if (is_object( $oUser ) && get_class( $oUser ) == 'Users') { + $oUser->setUsrReportsTo( $managerId ); + $oUser->save(); + } + $oDataset->next(); + } - /* - * Remove a user from Departments - * @param string $DepUid, $UsrUid - * @return array - */ - function removeUserFromDepartment($DepUid, $UsrUid) { - $aFields = array ('USR_UID'=> $UsrUid,'DEP_UID'=> '', 'USR_REPORTS_TO' => ''); - try { - $oUser = UsersPeer::retrieveByPk( $UsrUid ); - if (is_object($oUser) && get_class($oUser) == 'Users' ) { - //$oDepto = new Users(); - $oUser->setDepUid ( ''); - $oUser->setUsrReportsTo ( ''); - $oUser->save(); - } } - catch (exception $oError) { - throw ($oError); - } - } - /* - * Return the available users list criteria object - * @param string $sGroupUID - * @return object - */ - function getAvailableUsersCriteria($sGroupUID = '') + //add an user to a department and sync all about manager info + function addUserToDepartment ($depId, $userId, $manager, $updateManager = false) { try { - $oCriteria = new Criteria('workflow'); - $oCriteria->addSelectColumn(UsersPeer::USR_UID); - $oCriteria->addSelectColumn(UsersPeer::USR_FIRSTNAME); - $oCriteria->addSelectColumn(UsersPeer::USR_LASTNAME); - $oCriteria->add(UsersPeer::DEP_UID, "", Criteria::EQUAL); - $oCriteria->add(UsersPeer::USR_STATUS, 'ACTIVE'); - return $oCriteria; + //update the field in user table + $oUser = UsersPeer::retrieveByPk( $userId ); + if (is_object( $oUser ) && get_class( $oUser ) == 'Users') { + $oUser->setDepUid( $depId ); + $oUser->save(); + } + + //if the user is a manager update Department Table + if ($manager) { + $oDept = DepartmentPeer::retrieveByPk( $depId ); + if (is_object( $oDept ) && get_class( $oDept ) == 'Department') { + $oDept->setDepManager( $userId ); + $oDept->save(); + } + } + + //now update the reportsto to all + if ($updateManager) { + $this->updateDepartmentManager( $depId ); + } + return true; + } catch (Exception $oError) { + throw ($oError); } - catch (exception $oError) { + } + + // select departments + // this function is used to draw the hierachy tree view + function getDepartments ($DepParent) + { + try { + $result = array (); + $criteria = new Criteria( 'workflow' ); + $criteria->add( DepartmentPeer::DEP_PARENT, $DepParent, Criteria::EQUAL ); + $con = Propel::getConnection( DepartmentPeer::DATABASE_NAME ); + $objects = DepartmentPeer::doSelect( $criteria, $con ); + global $RBAC; + + foreach ($objects as $oDepartment) { + $node = array (); + $node['DEP_UID'] = $oDepartment->getDepUid(); + $node['DEP_PARENT'] = $oDepartment->getDepParent(); + $node['DEP_TITLE'] = $oDepartment->getDepTitle(); + $node['DEP_STATUS'] = $oDepartment->getDepStatus(); + $node['DEP_MANAGER'] = $oDepartment->getDepManager(); + $node['DEP_LDAP_DN'] = $oDepartment->getDepLdapDn(); + $node['DEP_LAST'] = 0; + + $manager = $oDepartment->getDepManager(); + if ($manager != '') { + $UserUID = $RBAC->load( $manager ); + $node['DEP_MANAGER_USERNAME'] = isset( $UserUID['USR_USERNAME'] ) ? $UserUID['USR_USERNAME'] : ''; + $node['DEP_MANAGER_FIRSTNAME'] = isset( $UserUID['USR_FIRSTNAME'] ) ? $UserUID['USR_FIRSTNAME'] : ''; + $node['DEP_MANAGER_LASTNAME'] = isset( $UserUID['USR_LASTNAME'] ) ? $UserUID['USR_LASTNAME'] : ''; + } else { + $node['DEP_MANAGER_USERNAME'] = ''; + $node['DEP_MANAGER_FIRSTNAME'] = ''; + $node['DEP_MANAGER_LASTNAME'] = ''; + } + + $criteriaCount = new Criteria( 'workflow' ); + $criteriaCount->clearSelectColumns(); + $criteriaCount->addSelectColumn( 'COUNT(*)' ); + $criteriaCount->add( DepartmentPeer::DEP_PARENT, $oDepartment->getDepUid(), Criteria::EQUAL ); + $rs = DepartmentPeer::doSelectRS( $criteriaCount ); + $rs->next(); + $row = $rs->getRow(); + $node['HAS_CHILDREN'] = $row[0]; + $result[] = $node; + } + if (count( $result ) >= 1) { + $result[count( $result ) - 1]['DEP_LAST'] = 1; + } + return $result; + } catch (exception $e) { + throw $e; + } + } + + /** + * Check department name exist in the level + * + * @param string $departmentName name of the department + * @param string $parentUID parent UID of the department + * @param string $departmentUID department UID + * @return boolean $Fields true or false + * + */ + function checkDepartmentName ($departmentName, $parentUID, $departmentUID = '') + { + $oCriteria = new Criteria( 'workflow' ); + + $oCriteria->clearSelectColumns(); + $oCriteria->addSelectColumn( ContentPeer::CON_CATEGORY ); + $oCriteria->addSelectColumn( ContentPeer::CON_VALUE ); + $oCriteria->addSelectColumn( DepartmentPeer::DEP_PARENT ); + $oCriteria->add( ContentPeer::CON_CATEGORY, 'DEPO_TITLE' ); + $oCriteria->addJoin( ContentPeer::CON_ID, DepartmentPeer::DEP_UID, Criteria::LEFT_JOIN ); + $oCriteria->add( ContentPeer::CON_VALUE, $departmentName ); + $oCriteria->add( DepartmentPeer::DEP_UID, $departmentUID, Criteria::NOT_EQUAL ); + $oCriteria->add( ContentPeer::CON_LANG, SYS_LANG ); + $oCriteria->add( DepartmentPeer::DEP_PARENT, $parentUID ); + + $oDataset = DepartmentPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + $aRow = $oDataset->getRow(); + + return ($aRow) ? true : false; + } + + function getUsersFromDepartment ($sDepUid, $sManagerUid) + { + try { + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->addSelectColumn( UsersPeer::USR_UID ); + $oCriteria->addSelectColumn( UsersPeer::USR_REPORTS_TO ); + $oCriteria->add( UsersPeer::USR_STATUS, 'CLOSED', Criteria::NOT_EQUAL ); + $oCriteria->add( UsersPeer::DEP_UID, $sDepUid ); + + $rs = UsersPeer::doSelectRS( $oCriteria ); + $rs->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + + $oUser = new Users(); + $aUsers[] = array ('USR_UID' => 'char','USR_USERNAME' => 'char','USR_FULLNAME' => 'char','USR_REPORTS_TO' => 'char','USR_MANAGER' => 'char' + ); + $rs->next(); + $row = $rs->getRow(); + while (is_array( $row )) { + $usrFields = $oUser->LoadDetails( $row['USR_UID'] ); + $row['USR_USERNAME'] = $usrFields['USR_USERNAME']; + $row['USR_FULLNAME'] = $usrFields['USR_FULLNAME']; + $row['USR_MANAGER'] = $row['USR_UID'] == $sManagerUid ? G::loadTranslation( "ID_YES" ) : G::loadTranslation( "ID_NO" ); + $row['DEP_UID'] = $sDepUid; + if ($row['USR_REPORTS_TO'] != '') { + try { + $managerFields = $oUser->LoadDetails( $row['USR_REPORTS_TO'] ); + $row['USR_REPORTS_NAME'] = $managerFields['USR_FULLNAME']; + } catch (exception $e) { + $row['USR_REPORTS_NAME'] = '.'; + } + } else { + $row['USR_REPORTS_NAME'] = '.'; + } + $aUsers[] = $row; + $rs->next(); + $row = $rs->getRow(); + } + + G::LoadClass( 'ArrayPeer' ); + global $_DBArray; + $_DBArray['DepartmentUserList'] = $aUsers; + $_SESSION['_DBArray'] = $_DBArray; + $oCriteriaT = new Criteria( 'dbarray' ); + $oCriteriaT->setDBArrayTable( 'DepartmentUserList' ); + + return $oCriteriaT; + } catch (exception $e) { + throw $e; + } + } + + /* + * Remove a user from Departments + * @param string $DepUid, $UsrUid + * @return array + */ + function removeUserFromDepartment ($DepUid, $UsrUid) + { + $aFields = array ('USR_UID' => $UsrUid,'DEP_UID' => '','USR_REPORTS_TO' => '' + ); + try { + $oUser = UsersPeer::retrieveByPk( $UsrUid ); + if (is_object( $oUser ) && get_class( $oUser ) == 'Users') { + //$oDepto = new Users(); + $oUser->setDepUid( '' ); + $oUser->setUsrReportsTo( '' ); + $oUser->save(); + } + } catch (exception $oError) { + throw ($oError); + } + } + + /* + * Return the available users list criteria object + * @param string $sGroupUID + * @return object + */ + function getAvailableUsersCriteria ($sGroupUID = '') + { + try { + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->addSelectColumn( UsersPeer::USR_UID ); + $oCriteria->addSelectColumn( UsersPeer::USR_FIRSTNAME ); + $oCriteria->addSelectColumn( UsersPeer::USR_LASTNAME ); + $oCriteria->add( UsersPeer::DEP_UID, "", Criteria::EQUAL ); + $oCriteria->add( UsersPeer::USR_STATUS, 'ACTIVE' ); + return $oCriteria; + } catch (exception $oError) { throw ($oError); } } @@ -573,80 +586,88 @@ function getDepartments( $DepParent ) { * @param string $sDepUID * @return object */ - function cantUsersInDepartment ( $sDepUID ) { - try { - $c = new Criteria('workflow'); - $c->addSelectColumn('COUNT(*)'); - $c->add(UsersPeer::USR_STATUS, 'CLOSED', Criteria::NOT_EQUAL); - $c->add(UsersPeer::DEP_UID, $sDepUID); + function cantUsersInDepartment ($sDepUID) + { + try { + $c = new Criteria( 'workflow' ); + $c->addSelectColumn( 'COUNT(*)' ); + $c->add( UsersPeer::USR_STATUS, 'CLOSED', Criteria::NOT_EQUAL ); + $c->add( UsersPeer::DEP_UID, $sDepUID ); - $rs = UsersPeer::doSelectRS($c); - $rs->next(); - $row = $rs->getRow(); - $count = $row[0]; - return $count; - } - catch (exception $oError) { - throw ($oError); - } + $rs = UsersPeer::doSelectRS( $c ); + $rs->next(); + $row = $rs->getRow(); + $count = $row[0]; + return $count; + } catch (exception $oError) { + throw ($oError); + } } - function loadByGroupname ( $Groupname ) { - $c = new Criteria('workflow'); - $del = DBAdapter::getStringDelimiter(); - $c->clearSelectColumns(); - $c->addSelectColumn( ContentPeer::CON_CATEGORY ); - $c->addSelectColumn( ContentPeer::CON_VALUE ); + function loadByGroupname ($Groupname) + { + $c = new Criteria( 'workflow' ); + $del = DBAdapter::getStringDelimiter(); - $c->add(ContentPeer::CON_CATEGORY, 'DEPO_TITLE'); - $c->add(ContentPeer::CON_VALUE, $Groupname); - $c->add(ContentPeer::CON_LANG, SYS_LANG ); - return $c; - } + $c->clearSelectColumns(); + $c->addSelectColumn( ContentPeer::CON_CATEGORY ); + $c->addSelectColumn( ContentPeer::CON_VALUE ); - //Added by Qennix - function getAllDepartmentsByUser(){ - $c = new Criteria('workflow'); - $c->addSelectColumn(UsersPeer::USR_UID); - $c->addAsColumn('DEP_TITLE', ContentPeer::CON_VALUE); - $c->add(ContentPeer::CON_LANG,defined(SYS_LANG)?SYS_LANG:'en'); - $c->add(ContentPeer::CON_CATEGORY,'DEPO_TITLE'); - $c->addJoin(UsersPeer::DEP_UID, ContentPeer::CON_ID,Criteria::INNER_JOIN); - $Dat = UsersPeer::doSelectRS ($c); - $Dat->setFetchmode (ResultSet::FETCHMODE_ASSOC); - $aRows = Array(); - while ($Dat->next()){ - $row = $Dat->getRow(); - $aRows[$row['USR_UID']] = $row['DEP_TITLE']; - } - return $aRows; - } - - function getDepartmentsForUser($userUid) { - $criteria = new Criteria('workflow'); - $criteria->addSelectColumn(UsersPeer::DEP_UID); - $criteria->addAsColumn('DEP_TITLE', 'C.CON_VALUE'); - $criteria->addAlias('C', 'CONTENT'); - $criteria->addJoin(UsersPeer::DEP_UID, DepartmentPeer::DEP_UID, Criteria::LEFT_JOIN); - $delimiter = DBAdapter::getStringDelimiter(); - $conditions = array(); - $conditions [] = array(DepartmentPeer::DEP_UID, 'C.CON_ID'); - $conditions [] = array('C.CON_CATEGORY', $delimiter . 'DEPO_TITLE' . $delimiter); - $conditions [] = array('C.CON_LANG', $delimiter . SYS_LANG . $delimiter); - $criteria->addJoinMC($conditions, Criteria::LEFT_JOIN); - $criteria->add(UsersPeer::USR_UID, $userUid); - $criteria->add(UsersPeer::DEP_UID, '', Criteria::NOT_EQUAL); - $dataset = DepartmentPeer::doSelectRS($criteria); - $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $dataset->next(); - $departments = array(); - while ($row = $dataset->getRow()) { - if (!isset($departments[$row['DEP_UID']])) { - $departments[$row['DEP_UID']] = $row; - } - $dataset->next(); + $c->add( ContentPeer::CON_CATEGORY, 'DEPO_TITLE' ); + $c->add( ContentPeer::CON_VALUE, $Groupname ); + $c->add( ContentPeer::CON_LANG, SYS_LANG ); + return $c; } - return $departments; - } -} // Department + //Added by Qennix + function getAllDepartmentsByUser () + { + $c = new Criteria( 'workflow' ); + $c->addSelectColumn( UsersPeer::USR_UID ); + $c->addAsColumn( 'DEP_TITLE', ContentPeer::CON_VALUE ); + $c->add( ContentPeer::CON_LANG, defined( SYS_LANG ) ? SYS_LANG : 'en' ); + $c->add( ContentPeer::CON_CATEGORY, 'DEPO_TITLE' ); + $c->addJoin( UsersPeer::DEP_UID, ContentPeer::CON_ID, Criteria::INNER_JOIN ); + $Dat = UsersPeer::doSelectRS( $c ); + $Dat->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $aRows = Array (); + while ($Dat->next()) { + $row = $Dat->getRow(); + $aRows[$row['USR_UID']] = $row['DEP_TITLE']; + } + return $aRows; + } + + function getDepartmentsForUser ($userUid) + { + $criteria = new Criteria( 'workflow' ); + $criteria->addSelectColumn( UsersPeer::DEP_UID ); + $criteria->addAsColumn( 'DEP_TITLE', 'C.CON_VALUE' ); + $criteria->addAlias( 'C', 'CONTENT' ); + $criteria->addJoin( UsersPeer::DEP_UID, DepartmentPeer::DEP_UID, Criteria::LEFT_JOIN ); + $delimiter = DBAdapter::getStringDelimiter(); + $conditions = array (); + $conditions[] = array (DepartmentPeer::DEP_UID,'C.CON_ID' + ); + $conditions[] = array ('C.CON_CATEGORY',$delimiter . 'DEPO_TITLE' . $delimiter + ); + $conditions[] = array ('C.CON_LANG',$delimiter . SYS_LANG . $delimiter + ); + $criteria->addJoinMC( $conditions, Criteria::LEFT_JOIN ); + $criteria->add( UsersPeer::USR_UID, $userUid ); + $criteria->add( UsersPeer::DEP_UID, '', Criteria::NOT_EQUAL ); + $dataset = DepartmentPeer::doSelectRS( $criteria ); + $dataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $dataset->next(); + $departments = array (); + while ($row = $dataset->getRow()) { + if (! isset( $departments[$row['DEP_UID']] )) { + $departments[$row['DEP_UID']] = $row; + } + $dataset->next(); + } + return $departments; + } +} +// Department +