CODE STYLE, workflow/engine/classes/model/

FILES:
Department.php
AppDocument.php
This commit is contained in:
jennylee
2012-10-19 08:51:41 -04:00
parent 796b81cb91
commit b490c88210
2 changed files with 1150 additions and 1119 deletions

View File

@@ -1,6 +1,7 @@
<?php <?php
/** /**
* AppDocument.php * AppDocument.php
*
* @package workflow.engine.classes.model * @package workflow.engine.classes.model
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
@@ -39,22 +40,26 @@ require_once 'classes/model/InputDocument.php';
* *
* @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 * This value goes in the content table
*
* @var string * @var string
*/ */
protected $app_doc_title = ''; protected $app_doc_title = '';
/** /**
* This value goes in the content table * This value goes in the content table
*
* @var string * @var string
*/ */
protected $app_doc_comment = ''; protected $app_doc_comment = '';
/** /**
* This value goes in the content table * This value goes in the content table
*
* @var string * @var string
*/ */
protected $app_doc_filename = ''; protected $app_doc_filename = '';
@@ -65,13 +70,14 @@ class AppDocument extends BaseAppDocument {
* @param integer $iVersion (Document version) * @param integer $iVersion (Document version)
* @return variant * @return variant
*/ */
public function load($sAppDocUid,$iVersion=NULL) public function load ($sAppDocUid, $iVersion = null)
{ {
try { try {
if($iVersion==NULL) $iVersion=$this->getLastAppDocVersion($sAppDocUid); if ($iVersion == null) {
$iVersion = $this->getLastAppDocVersion( $sAppDocUid );
}
$oAppDocument = AppDocumentPeer::retrieveByPK( $sAppDocUid, $iVersion ); $oAppDocument = AppDocumentPeer::retrieveByPK( $sAppDocUid, $iVersion );
if (!is_null($oAppDocument)) if (! is_null( $oAppDocument )) {
{
$aFields = $oAppDocument->toArray( BasePeer::TYPE_FIELDNAME ); $aFields = $oAppDocument->toArray( BasePeer::TYPE_FIELDNAME );
//optimized for speed //optimized for speed
$aContentFields = $oAppDocument->getContentFields(); $aContentFields = $oAppDocument->getContentFields();
@@ -81,15 +87,14 @@ class AppDocument extends BaseAppDocument {
$this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME ); $this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME );
return $aFields; return $aFields;
} } else {
else {
throw (new Exception( 'Error loading Document ' . $sAppDocUid . '/' . $iVersion . '. This row doesn\'t exist!' )); throw (new Exception( 'Error loading Document ' . $sAppDocUid . '/' . $iVersion . '. This row doesn\'t exist!' ));
} }
} } catch (Exception $oError) {
catch (Exception $oError) {
throw ($oError); throw ($oError);
} }
} }
public function getLastIndex ($sAppUid) public function getLastIndex ($sAppUid)
{ {
try { try {
@@ -98,23 +103,23 @@ class AppDocument extends BaseAppDocument {
//$oCriteria->addAscendingOrderByColumn ( AppDocumentPeer::APP_DOC_INDEX ); //$oCriteria->addAscendingOrderByColumn ( AppDocumentPeer::APP_DOC_INDEX );
$oCriteria->addDescendingOrderByColumn( AppDocumentPeer::APP_DOC_INDEX ); $oCriteria->addDescendingOrderByColumn( AppDocumentPeer::APP_DOC_INDEX );
$lastAppDoc = AppDocumentPeer::doSelectOne( $oCriteria ); $lastAppDoc = AppDocumentPeer::doSelectOne( $oCriteria );
if (!is_null($lastAppDoc)) if (! is_null( $lastAppDoc )) {
{
return $lastAppDoc->getAppDocIndex(); return $lastAppDoc->getAppDocIndex();
} } else {
else {
return 0; return 0;
} }
} } catch (Exception $oError) {
catch (Exception $oError) {
throw ($oError); throw ($oError);
} }
} }
/** /**
* Get last Document Version based on Doc UID * Get last Document Version based on Doc UID
*
* @param s $sAppDocUid * @param s $sAppDocUid
* @return integer * @return integer
**/ *
*/
public function getLastDocVersion ($sDocUid, $appUID) public function getLastDocVersion ($sDocUid, $appUID)
{ {
try { try {
@@ -123,48 +128,50 @@ class AppDocument extends BaseAppDocument {
$oCriteria->add( AppDocumentPeer::APP_UID, $appUID ); $oCriteria->add( AppDocumentPeer::APP_UID, $appUID );
$oCriteria->addDescendingOrderByColumn( AppDocumentPeer::DOC_VERSION ); $oCriteria->addDescendingOrderByColumn( AppDocumentPeer::DOC_VERSION );
$lastAppDocVersion = AppDocumentPeer::doSelectOne( $oCriteria ); $lastAppDocVersion = AppDocumentPeer::doSelectOne( $oCriteria );
if (!is_null($lastAppDocVersion)) if (! is_null( $lastAppDocVersion )) {
{
return $lastAppDocVersion->getDocVersion(); return $lastAppDocVersion->getDocVersion();
} } else {
else {
return 0; return 0;
} }
} } catch (Exception $oError) {
catch (Exception $oError) {
throw ($oError); throw ($oError);
} }
} }
/** /**
* Get last Document Version based on APPDoc UID * Get last Document Version based on APPDoc UID
*
* @param s $sAppDocUid * @param s $sAppDocUid
* @return integer * @return integer
**/ *
*/
public function getLastAppDocVersion ($sAppDocUid, $appUID = 0) public function getLastAppDocVersion ($sAppDocUid, $appUID = 0)
{ {
try { try {
$oCriteria = new Criteria(); $oCriteria = new Criteria();
$oCriteria->add( AppDocumentPeer::APP_DOC_UID, $sAppDocUid ); $oCriteria->add( AppDocumentPeer::APP_DOC_UID, $sAppDocUid );
if($appUID!=0) $oCriteria->add(AppDocumentPeer::APP_UID, $appUID); if ($appUID != 0) {
$oCriteria->add( AppDocumentPeer::APP_UID, $appUID );
}
$oCriteria->addDescendingOrderByColumn( AppDocumentPeer::DOC_VERSION ); $oCriteria->addDescendingOrderByColumn( AppDocumentPeer::DOC_VERSION );
$lastAppDocVersion = AppDocumentPeer::doSelectOne( $oCriteria ); $lastAppDocVersion = AppDocumentPeer::doSelectOne( $oCriteria );
if (!is_null($lastAppDocVersion)) if (! is_null( $lastAppDocVersion )) {
{
return $lastAppDocVersion->getDocVersion(); return $lastAppDocVersion->getDocVersion();
} } else {
else {
return 0; return 0;
} }
} } catch (Exception $oError) {
catch (Exception $oError) {
throw ($oError); throw ($oError);
} }
} }
/** /**
* Create the application document registry * Create the application document registry
*
* @param array $aData * @param array $aData
* @return string * @return string
**/ *
*/
public function create ($aData) public function create ($aData)
{ {
$oConnection = Propel::getConnection( AppDocumentPeer::DATABASE_NAME ); $oConnection = Propel::getConnection( AppDocumentPeer::DATABASE_NAME );
@@ -199,7 +206,6 @@ class AppDocument extends BaseAppDocument {
break; break;
} }
$docVersion ++; $docVersion ++;
} }
@@ -223,8 +229,7 @@ class AppDocument extends BaseAppDocument {
$oConnection->commit(); $oConnection->commit();
$this->fromArray( $oAppDocument->toArray( BasePeer::TYPE_FIELDNAME ), BasePeer::TYPE_FIELDNAME ); $this->fromArray( $oAppDocument->toArray( BasePeer::TYPE_FIELDNAME ), BasePeer::TYPE_FIELDNAME );
return $sUID; return $sUID;
} } else {
else {
$sMessage = ''; $sMessage = '';
$aValidationFailures = $oAppDocument->getValidationFailures(); $aValidationFailures = $oAppDocument->getValidationFailures();
foreach ($aValidationFailures as $oValidationFailure) { foreach ($aValidationFailures as $oValidationFailure) {
@@ -232,8 +237,7 @@ class AppDocument extends BaseAppDocument {
} }
throw (new Exception( 'The registry cannot be created!<br />' . $sMessage )); throw (new Exception( 'The registry cannot be created!<br />' . $sMessage ));
} }
} } catch (Exception $oError) {
catch (Exception $oError) {
$oConnection->rollback(); $oConnection->rollback();
throw ($oError); throw ($oError);
} }
@@ -241,36 +245,33 @@ class AppDocument extends BaseAppDocument {
/** /**
* Update the application document registry * Update the application document registry
*
* @param array $aData * @param array $aData
* @return string * @return string
**/ *
*/
public function update ($aData) public function update ($aData)
{ {
$oConnection = Propel::getConnection( AppDocumentPeer::DATABASE_NAME ); $oConnection = Propel::getConnection( AppDocumentPeer::DATABASE_NAME );
try { try {
$oAppDocument = AppDocumentPeer::retrieveByPK( $aData['APP_DOC_UID'], $aData['DOC_VERSION'] ); $oAppDocument = AppDocumentPeer::retrieveByPK( $aData['APP_DOC_UID'], $aData['DOC_VERSION'] );
if (!is_null($oAppDocument)) if (! is_null( $oAppDocument )) {
{
$oAppDocument->fromArray( $aData, BasePeer::TYPE_FIELDNAME ); $oAppDocument->fromArray( $aData, BasePeer::TYPE_FIELDNAME );
if ($oAppDocument->validate()) { if ($oAppDocument->validate()) {
$oConnection->begin(); $oConnection->begin();
if (isset($aData['APP_DOC_TITLE'])) if (isset( $aData['APP_DOC_TITLE'] )) {
{
$oAppDocument->setAppDocTitle( $aData['APP_DOC_TITLE'] ); $oAppDocument->setAppDocTitle( $aData['APP_DOC_TITLE'] );
} }
if (isset($aData['APP_DOC_COMMENT'])) if (isset( $aData['APP_DOC_COMMENT'] )) {
{
$oAppDocument->setAppDocComment( $aData['APP_DOC_COMMENT'] ); $oAppDocument->setAppDocComment( $aData['APP_DOC_COMMENT'] );
} }
if (isset($aData['APP_DOC_FILENAME'])) if (isset( $aData['APP_DOC_FILENAME'] )) {
{
$oAppDocument->setAppDocFilename( $aData['APP_DOC_FILENAME'] ); $oAppDocument->setAppDocFilename( $aData['APP_DOC_FILENAME'] );
} }
$iResult = $oAppDocument->save(); $iResult = $oAppDocument->save();
$oConnection->commit(); $oConnection->commit();
return $iResult; return $iResult;
} } else {
else {
$sMessage = ''; $sMessage = '';
$aValidationFailures = $oAppDocument->getValidationFailures(); $aValidationFailures = $oAppDocument->getValidationFailures();
foreach ($aValidationFailures as $oValidationFailure) { foreach ($aValidationFailures as $oValidationFailure) {
@@ -278,12 +279,10 @@ class AppDocument extends BaseAppDocument {
} }
throw (new Exception( 'The registry cannot be updated!<br />' . $sMessage )); throw (new Exception( 'The registry cannot be updated!<br />' . $sMessage ));
} }
} } else {
else {
throw (new Exception( 'This row doesn\'t exist!' )); throw (new Exception( 'This row doesn\'t exist!' ));
} }
} } catch (Exception $oError) {
catch (Exception $oError) {
$oConnection->rollback(); $oConnection->rollback();
throw ($oError); throw ($oError);
} }
@@ -292,9 +291,11 @@ class AppDocument extends BaseAppDocument {
/** /**
* Remove the application document registry by changing status only * Remove the application document registry by changing status only
* Modified by Hugo Loza hugo@colosa.com * Modified by Hugo Loza hugo@colosa.com
*
* @param array $aData * @param array $aData
* @return string * @return string
**/ *
*/
public function remove ($sAppDocUid, $iVersion = 1) public function remove ($sAppDocUid, $iVersion = 1)
{ {
$oConnection = Propel::getConnection( AppDocumentPeer::DATABASE_NAME ); $oConnection = Propel::getConnection( AppDocumentPeer::DATABASE_NAME );
@@ -310,32 +311,27 @@ class AppDocument extends BaseAppDocument {
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
$oDataset->next(); $oDataset->next();
while ($aRow = $oDataset->getRow()) { while ($aRow = $oDataset->getRow()) {
$arrayDocumentsToDelete[]=array('sAppDocUid'=>$aRow['APP_DOC_UID'],'iVersion'=>$aRow['DOC_VERSION']); $arrayDocumentsToDelete[] = array ('sAppDocUid' => $aRow['APP_DOC_UID'],'iVersion' => $aRow['DOC_VERSION']
);
$oDataset->next(); $oDataset->next();
} }
} else { } else {
$arrayDocumentsToDelete[]=array('sAppDocUid'=>$sAppDocUid,'iVersion'=>$iVersion); $arrayDocumentsToDelete[] = array ('sAppDocUid' => $sAppDocUid,'iVersion' => $iVersion
);
} }
foreach ($arrayDocumentsToDelete as $key => $docToDelete) { foreach ($arrayDocumentsToDelete as $key => $docToDelete) {
$aFields = array('APP_DOC_UID' => $docToDelete['sAppDocUid'], $aFields = array ('APP_DOC_UID' => $docToDelete['sAppDocUid'],'DOC_VERSION' => $docToDelete['iVersion'],'APP_DOC_STATUS' => 'DELETED'
'DOC_VERSION' => $docToDelete['iVersion'], );
'APP_DOC_STATUS' => 'DELETED');
$oAppDocument->update( $aFields ); $oAppDocument->update( $aFields );
} }
} else {
}
else {
throw (new Exception( 'This row doesn\'t exist!' )); throw (new Exception( 'This row doesn\'t exist!' ));
} }
} } catch (Exception $oError) {
catch (Exception $oError) {
$oConnection->rollback(); $oConnection->rollback();
throw ($oError); throw ($oError);
} }
@@ -343,6 +339,7 @@ class AppDocument extends BaseAppDocument {
/** /**
* Get the [app_doc_title] column value. * Get the [app_doc_title] column value.
*
* @return string * @return string
*/ */
public function getAppDocTitle () public function getAppDocTitle ()
@@ -350,9 +347,10 @@ class AppDocument extends BaseAppDocument {
if ($this->app_doc_title == '') { if ($this->app_doc_title == '') {
try { try {
$this->app_doc_title = Content::load( 'APP_DOC_TITLE', $this->getDocVersion(), $this->getAppDocUid(), (defined( 'SYS_LANG' ) ? SYS_LANG : 'en') ); $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 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) { } catch (Exception $oError) {
throw ($oError); throw ($oError);
} }
} }
@@ -374,8 +372,7 @@ class AppDocument extends BaseAppDocument {
try { try {
$this->app_doc_title = $sValue; $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 ); $iResult = Content::addContent( 'APP_DOC_TITLE', $this->getDocVersion(), $this->getAppDocUid(), (defined( 'SYS_LANG' ) ? SYS_LANG : 'en'), $this->app_doc_title );
} } catch (Exception $oError) {
catch (Exception $oError) {
$this->app_doc_title = ''; $this->app_doc_title = '';
throw ($oError); throw ($oError);
} }
@@ -384,6 +381,7 @@ class AppDocument extends BaseAppDocument {
/** /**
* Get the [app_doc_comment] column value. * Get the [app_doc_comment] column value.
*
* @return string * @return string
*/ */
public function getAppDocComment () public function getAppDocComment ()
@@ -391,9 +389,10 @@ class AppDocument extends BaseAppDocument {
if ($this->app_doc_comment == '') { if ($this->app_doc_comment == '') {
try { try {
$this->app_doc_comment = Content::load( 'APP_DOC_COMMENT', $this->getDocVersion(), $this->getAppDocUid(), (defined( 'SYS_LANG' ) ? SYS_LANG : 'en') ); $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 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) { } catch (Exception $oError) {
throw ($oError); throw ($oError);
} }
} }
@@ -415,8 +414,7 @@ class AppDocument extends BaseAppDocument {
try { try {
$this->app_doc_comment = $sValue; $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 ); $iResult = Content::addContent( 'APP_DOC_COMMENT', $this->getDocVersion(), $this->getAppDocUid(), (defined( 'SYS_LANG' ) ? SYS_LANG : 'en'), $this->app_doc_comment );
} } catch (Exception $oError) {
catch (Exception $oError) {
$this->app_doc_comment = ''; $this->app_doc_comment = '';
throw ($oError); throw ($oError);
} }
@@ -425,6 +423,7 @@ class AppDocument extends BaseAppDocument {
/** /**
* Get the [app_doc_filename] column value. * Get the [app_doc_filename] column value.
*
* @return string * @return string
*/ */
public function getAppDocFilename () public function getAppDocFilename ()
@@ -432,9 +431,10 @@ class AppDocument extends BaseAppDocument {
if ($this->app_doc_filename == '') { if ($this->app_doc_filename == '') {
try { try {
$this->app_doc_filename = Content::load( 'APP_DOC_FILENAME', $this->getDocVersion(), $this->getAppDocUid(), (defined( 'SYS_LANG' ) ? SYS_LANG : 'en') ); $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 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) { } catch (Exception $oError) {
throw ($oError); throw ($oError);
} }
} }
@@ -456,23 +456,26 @@ class AppDocument extends BaseAppDocument {
try { try {
$this->app_doc_filename = $sValue; $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 ); $iResult = Content::addContent( 'APP_DOC_FILENAME', $this->getDocVersion(), $this->getAppDocUid(), (defined( 'SYS_LANG' ) ? SYS_LANG : 'en'), $this->app_doc_filename );
} } catch (Exception $oError) {
catch (Exception $oError) {
$this->app_doc_filename = ''; $this->app_doc_filename = '';
throw ($oError); throw ($oError);
} }
} }
} }
public function isEmptyInContent ( $content, $field, $lang ) { public function isEmptyInContent ($content, $field, $lang)
{
if (isset( $content[$field][$lang] )) { if (isset( $content[$field][$lang] )) {
if ( trim( $content[$field][ $lang ] ) != '' ) if (trim( $content[$field][$lang] ) != '') {
return false; return false;
}; }
}
;
return true; return true;
} }
public function updateInsertContent ( $content, $field, $value ) { public function updateInsertContent ($content, $field, $value)
{
if (isset( $content[$field]['en'] )) { if (isset( $content[$field]['en'] )) {
//update //update
$con = ContentPeer::retrieveByPK( $field, $this->getDocVersion(), $this->getAppDocUid(), 'en' ); $con = ContentPeer::retrieveByPK( $field, $this->getDocVersion(), $this->getAppDocUid(), 'en' );
@@ -480,8 +483,8 @@ class AppDocument extends BaseAppDocument {
if ($con->validate()) { if ($con->validate()) {
$res = $con->save(); $res = $con->save();
} }
} } else {
else {//insert //insert
$con = new Content(); $con = new Content();
$con->setConCategory( $field ); $con->setConCategory( $field );
$con->setConParent( $this->getDocVersion() ); $con->setConParent( $this->getDocVersion() );
@@ -494,7 +497,8 @@ class AppDocument extends BaseAppDocument {
} }
} }
public function normalizeContent( $content, $field , $lang ) { public function normalizeContent ($content, $field, $lang)
{
$value = ''; $value = '';
//if the lang row is not empty, update in 'en' row and continue //if the lang row is not empty, update in 'en' row and continue
if (! $this->isEmptyInContent( $content, $field, $lang )) { if (! $this->isEmptyInContent( $content, $field, $lang )) {
@@ -503,8 +507,7 @@ class AppDocument extends BaseAppDocument {
if ($lang != 'en') { if ($lang != 'en') {
$this->updateInsertContent( $content, $field, $value ); $this->updateInsertContent( $content, $field, $value );
} }
} } else {
else {
//if the lang row is empty, and 'en' row is not empty return 'en' value //if the lang row is empty, and 'en' row is not empty return 'en' value
if (! $this->isEmptyInContent( $content, $field, 'en' )) { if (! $this->isEmptyInContent( $content, $field, 'en' )) {
$value = $content[$field]['en']; $value = $content[$field]['en'];
@@ -522,8 +525,7 @@ class AppDocument extends BaseAppDocument {
} }
} }
} }
} } else {
else {
$this->updateInsertContent( $content, $field, '' ); $this->updateInsertContent( $content, $field, '' );
} }
} }
@@ -533,6 +535,7 @@ class AppDocument extends BaseAppDocument {
/** /**
* Get the [app_description] , [app_title] column values. * Get the [app_description] , [app_title] column values.
*
* @return array of string * @return array of string
*/ */
public function getContentFields () public function getContentFields ()
@@ -558,8 +561,12 @@ class AppDocument extends BaseAppDocument {
while ($row = $rs->getRow()) { while ($row = $rs->getRow()) {
$conCategory = $row['CON_CATEGORY']; $conCategory = $row['CON_CATEGORY'];
$conLang = $row['CON_LANG']; $conLang = $row['CON_LANG'];
if ( !isset( $content[$conCategory] ) ) $content[$conCategory] = array(); if (! isset( $content[$conCategory] )) {
if ( !isset( $content[$conCategory][$conLang] ) ) $content[$conCategory][$conLang] = array(); $content[$conCategory] = array ();
}
if (! isset( $content[$conCategory][$conLang] )) {
$content[$conCategory][$conLang] = array ();
}
$content[$conCategory][$conLang] = $row['CON_VALUE']; $content[$conCategory][$conLang] = $row['CON_VALUE'];
$rs->next(); $rs->next();
$row = $rs->getRow(); $row = $rs->getRow();
@@ -587,6 +594,7 @@ class AppDocument extends BaseAppDocument {
/** /**
* Get all docuemnts for a folder * Get all docuemnts for a folder
*
* @param array $sFolderUid * @param array $sFolderUid
* @return array * @return array
*/ */
@@ -601,11 +609,13 @@ class AppDocument extends BaseAppDocument {
$oDataset->next(); $oDataset->next();
while ($aRow = $oDataset->getRow()) { while ($aRow = $oDataset->getRow()) {
$documents[] = array('sAppDocUid' => $aRow['APP_DOC_UID'], 'iVersion' => $aRow['DOC_VERSION']); $documents[] = array ('sAppDocUid' => $aRow['APP_DOC_UID'],'iVersion' => $aRow['DOC_VERSION']
);
$oDataset->next(); $oDataset->next();
} }
return $documents; return $documents;
} }
}
// AppDocument
} // AppDocument

View File

@@ -1,6 +1,7 @@
<?php <?php
/** /**
* Department.php * Department.php
*
* @package workflow.engine.classes.model * @package workflow.engine.classes.model
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
@@ -27,7 +28,6 @@
require_once 'classes/model/om/BaseDepartment.php'; require_once 'classes/model/om/BaseDepartment.php';
require_once 'classes/model/Users.php'; require_once 'classes/model/Users.php';
/** /**
* Skeleton subclass for representing a row from the 'DEPARTMENT' table. * Skeleton subclass for representing a row from the 'DEPARTMENT' table.
* *
@@ -39,10 +39,11 @@ require_once 'classes/model/Users.php';
* *
* @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 * Create the Department
* *
@@ -50,48 +51,57 @@ protected $depo_title = '';
* @return void * @return void
*/ */
function create ($aData ) { function create ($aData)
{
$con = Propel::getConnection( DepartmentPeer::DATABASE_NAME ); $con = Propel::getConnection( DepartmentPeer::DATABASE_NAME );
try { try {
if ( isset ( $aData['DEP_UID'] ) ) if (isset( $aData['DEP_UID'] )) {
$this->setDepUid( $aData['DEP_UID'] ); $this->setDepUid( $aData['DEP_UID'] );
else } else {
$this->setDepUid( G::generateUniqueID() ); $this->setDepUid( G::generateUniqueID() );
}
if ( isset ( $aData['DEP_PARENT'] ) ) if (isset( $aData['DEP_PARENT'] )) {
$this->setDepParent( $aData['DEP_PARENT'] ); $this->setDepParent( $aData['DEP_PARENT'] );
else } else {
$this->setDepParent( '' ); $this->setDepParent( '' );
}
if ( isset ( $aData['DEP_MANAGER'] ) ) if (isset( $aData['DEP_MANAGER'] )) {
$this->setDepManager( $aData['DEP_MANAGER'] ); $this->setDepManager( $aData['DEP_MANAGER'] );
else } else {
$this->setDepManager( '' ); $this->setDepManager( '' );
}
if ( isset ( $aData['DEP_LOCATION'] ) ) if (isset( $aData['DEP_LOCATION'] )) {
$this->setDepLocation( $aData['DEP_LOCATION'] ); $this->setDepLocation( $aData['DEP_LOCATION'] );
else } else {
$this->setDepLocation( '' ); $this->setDepLocation( '' );
}
if ( isset ( $aData['DEP_STATUS'] ) ) if (isset( $aData['DEP_STATUS'] )) {
$this->setDepStatus( $aData['DEP_STATUS'] ); $this->setDepStatus( $aData['DEP_STATUS'] );
else } else {
$this->setDepStatus( 'ACTIVE' ); $this->setDepStatus( 'ACTIVE' );
}
if ( isset ( $aData['DEP_REF_CODE'] ) ) if (isset( $aData['DEP_REF_CODE'] )) {
$this->setDepRefCode( $aData['DEP_REF_CODE'] ); $this->setDepRefCode( $aData['DEP_REF_CODE'] );
else } else {
$this->setDepRefCode( '' ); $this->setDepRefCode( '' );
}
if ( isset ( $aData['DEP_LDAP_DN'] ) ) if (isset( $aData['DEP_LDAP_DN'] )) {
$this->setDepLdapDn( $aData['DEP_LDAP_DN'] ); $this->setDepLdapDn( $aData['DEP_LDAP_DN'] );
else } else {
$this->setDepLdapDn( '' ); $this->setDepLdapDn( '' );
}
if ( isset ( $aData['DEP_TITLE'] ) ) if (isset( $aData['DEP_TITLE'] )) {
$this->setDepTitle( $aData['DEP_TITLE'] ); $this->setDepTitle( $aData['DEP_TITLE'] );
else } else {
$this->setDepTitle( '' ); $this->setDepTitle( '' );
}
if ($this->validate()) { if ($this->validate()) {
$con->begin(); $con->begin();
@@ -99,17 +109,16 @@ protected $depo_title = '';
$con->commit(); $con->commit();
return $this->getDepUid(); return $this->getDepUid();
} } else {
else {
$msg = ''; $msg = '';
foreach($this->getValidationFailures() as $objValidationFailure) foreach ($this->getValidationFailures() as $objValidationFailure) {
$msg .= $objValidationFailure->getMessage() . "<br/>"; $msg .= $objValidationFailure->getMessage() . "<br/>";
}
throw (new Exception( " The Department row cannot be created $msg " )); throw (new Exception( " The Department row cannot be created $msg " ));
} }
} } catch (Exception $e) {
catch (Exception $e) {
$con->rollback(); $con->rollback();
throw ($e); throw ($e);
} }
@@ -117,6 +126,7 @@ protected $depo_title = '';
/** /**
* Get the [depo_title] column value. * Get the [depo_title] column value.
*
* @return string * @return string
*/ */
public function getDepTitle () public function getDepTitle ()
@@ -162,7 +172,8 @@ protected $depo_title = '';
* @return array $Fields the fields * @return array $Fields the fields
*/ */
function Load ( $DepUid ) { function Load ($DepUid)
{
$con = Propel::getConnection( DepartmentPeer::DATABASE_NAME ); $con = Propel::getConnection( DepartmentPeer::DATABASE_NAME );
try { try {
$oDept = DepartmentPeer::retrieveByPk( $DepUid ); $oDept = DepartmentPeer::retrieveByPk( $DepUid );
@@ -171,21 +182,21 @@ protected $depo_title = '';
$this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME ); $this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME );
$aFields['DEPO_TITLE'] = $oDept->getDepTitle(); $aFields['DEPO_TITLE'] = $oDept->getDepTitle();
return $aFields; return $aFields;
} } else {
else {
throw (new Exception( "The row '$DepUid' in table Department doesn't exist!" )); throw (new Exception( "The row '$DepUid' in table Department doesn't exist!" ));
} }
} } catch (Exception $oError) {
catch (Exception $oError) {
throw ($oError); throw ($oError);
} }
} }
/** /**
* Update the Dep row * Update the Dep row
*
* @param array $aData * @param array $aData
* @return variant * @return variant
**/ *
*/
public function update ($aData) public function update ($aData)
{ {
@@ -196,42 +207,45 @@ protected $depo_title = '';
if (is_object( $oPro ) && get_class( $oPro ) == 'Department') { if (is_object( $oPro ) && get_class( $oPro ) == 'Department') {
$oPro->fromArray( $aData, BasePeer::TYPE_FIELDNAME ); $oPro->fromArray( $aData, BasePeer::TYPE_FIELDNAME );
if ($oPro->validate()) { if ($oPro->validate()) {
if ( isset ( $aData['DEPO_TITLE'] ) ) if (isset( $aData['DEPO_TITLE'] )) {
$oPro->setDepTitle( $aData['DEPO_TITLE'] ); $oPro->setDepTitle( $aData['DEPO_TITLE'] );
if ( isset ( $aData['DEP_STATUS'] ) ) }
if (isset( $aData['DEP_STATUS'] )) {
$oPro->setDepStatus( $aData['DEP_STATUS'] ); $oPro->setDepStatus( $aData['DEP_STATUS'] );
if ( isset ( $aData['DEP_PARENT'] ) ) }
if (isset( $aData['DEP_PARENT'] )) {
$oPro->setDepParent( $aData['DEP_PARENT'] ); $oPro->setDepParent( $aData['DEP_PARENT'] );
if ( isset ( $aData['DEP_MANAGER'] ) ) }
if (isset( $aData['DEP_MANAGER'] )) {
$oPro->setDepManager( $aData['DEP_MANAGER'] ); $oPro->setDepManager( $aData['DEP_MANAGER'] );
}
$res = $oPro->save(); $res = $oPro->save();
$con->commit(); $con->commit();
return $res; return $res;
} } else {
else {
$msg = ''; $msg = '';
foreach($this->getValidationFailures() as $objValidationFailure) foreach ($this->getValidationFailures() as $objValidationFailure) {
$msg .= $objValidationFailure->getMessage() . "<br/>"; $msg .= $objValidationFailure->getMessage() . "<br/>";
}
throw (new PropelException( 'The Department row cannot be created!', new PropelException( $msg ) )); throw (new PropelException( 'The Department row cannot be created!', new PropelException( $msg ) ));
} }
} } else {
else {
$con->rollback(); $con->rollback();
throw (new Exception( "The row '" . $aData['DEP_UID'] . "' in table Department doesn't exist!" )); throw (new Exception( "The row '" . $aData['DEP_UID'] . "' in table Department doesn't exist!" ));
} }
} } catch (Exception $oError) {
catch (Exception $oError) {
throw ($oError); throw ($oError);
} }
} }
/** /**
* Remove the row * Remove the row
*
* @param array $aData or string $ProUid * @param array $aData or string $ProUid
* @return string * @return string
**/ *
*/
public function remove ($ProUid) public function remove ($ProUid)
{ {
if (is_array( $ProUid )) { if (is_array( $ProUid )) {
@@ -262,25 +276,19 @@ protected $depo_title = '';
$oDataset->next(); $oDataset->next();
} }
$oPro = DepartmentPeer::retrieveByPK( $ProUid ); $oPro = DepartmentPeer::retrieveByPK( $ProUid );
if (!is_null($oPro)) if (! is_null( $oPro )) {
{
Content::removeContent( 'DEPO_TITLE', '', $oPro->getDepUid() ); Content::removeContent( 'DEPO_TITLE', '', $oPro->getDepUid() );
Content::removeContent( 'DEPO_DESCRIPTION', '', $oPro->getDepUid() ); Content::removeContent( 'DEPO_DESCRIPTION', '', $oPro->getDepUid() );
return $oPro->delete(); return $oPro->delete();
} } else {
else {
throw (new Exception( "The row '$ProUid' in table Group doesn't exist!" )); throw (new Exception( "The row '$ProUid' in table Group doesn't exist!" ));
} }
} } catch (Exception $oError) {
catch (Exception $oError) {
throw ($oError); throw ($oError);
} }
} }
/** /**
* Load the Department row specified in [depo_id] column value. * Load the Department row specified in [depo_id] column value.
* *
@@ -288,29 +296,32 @@ protected $depo_title = '';
* @return array $Fields the fields * @return array $Fields the fields
*/ */
function existsDepartment( $DepUid ) { function existsDepartment ($DepUid)
{
$con = Propel::getConnection( DepartmentPeer::DATABASE_NAME ); $con = Propel::getConnection( DepartmentPeer::DATABASE_NAME );
$oPro = DepartmentPeer::retrieveByPk( $DepUid ); $oPro = DepartmentPeer::retrieveByPk( $DepUid );
if (is_object( $oPro ) && get_class( $oPro ) == 'Department') { if (is_object( $oPro ) && get_class( $oPro ) == 'Department') {
return true; return true;
} } else {
else {
return false; return false;
} }
} }
function existsUserInDepartment( $depId, $userId ) { function existsUserInDepartment ($depId, $userId)
{
$con = Propel::getConnection( DepartmentPeer::DATABASE_NAME ); $con = Propel::getConnection( DepartmentPeer::DATABASE_NAME );
$oUser = UsersPeer::retrieveByPk( $userId ); $oUser = UsersPeer::retrieveByPk( $userId );
if (is_object( $oUser ) && get_class( $oUser ) == 'Users') { if (is_object( $oUser ) && get_class( $oUser ) == 'Users') {
if ( $oUser->getDepUid() == $depId ) if ($oUser->getDepUid() == $depId) {
return true; return true;
} }
}
return false; return false;
} }
function updateDepartmentManager ($depId) { function updateDepartmentManager ($depId)
{
$managerId = ''; $managerId = '';
$depParent = ''; $depParent = '';
$oDept = DepartmentPeer::retrieveByPk( $depId ); $oDept = DepartmentPeer::retrieveByPk( $depId );
@@ -363,7 +374,8 @@ protected $depo_title = '';
} }
//add an user to a department and sync all about manager info //add an user to a department and sync all about manager info
function addUserToDepartment( $depId, $userId, $manager, $updateManager = false ) { function addUserToDepartment ($depId, $userId, $manager, $updateManager = false)
{
try { try {
//update the field in user table //update the field in user table
$oUser = UsersPeer::retrieveByPk( $userId ); $oUser = UsersPeer::retrieveByPk( $userId );
@@ -386,15 +398,15 @@ protected $depo_title = '';
$this->updateDepartmentManager( $depId ); $this->updateDepartmentManager( $depId );
} }
return true; return true;
} } catch (Exception $oError) {
catch ( Exception $oError) {
throw ($oError); throw ($oError);
} }
} }
// select departments // select departments
// this function is used to draw the hierachy tree view // this function is used to draw the hierachy tree view
function getDepartments( $DepParent ) { function getDepartments ($DepParent)
{
try { try {
$result = array (); $result = array ();
$criteria = new Criteria( 'workflow' ); $criteria = new Criteria( 'workflow' );
@@ -435,17 +447,18 @@ function getDepartments( $DepParent ) {
$node['HAS_CHILDREN'] = $row[0]; $node['HAS_CHILDREN'] = $row[0];
$result[] = $node; $result[] = $node;
} }
if ( count($result) >= 1 ) if (count( $result ) >= 1) {
$result[count( $result ) - 1]['DEP_LAST'] = 1; $result[count( $result ) - 1]['DEP_LAST'] = 1;
return $result;
} }
catch (exception $e) { return $result;
} catch (exception $e) {
throw $e; throw $e;
} }
} }
/** /**
* Check department name exist in the level * Check department name exist in the level
*
* @param string $departmentName name of the department * @param string $departmentName name of the department
* @param string $parentUID parent UID of the department * @param string $parentUID parent UID of the department
* @param string $departmentUID department UID * @param string $departmentUID department UID
@@ -475,7 +488,8 @@ function getDepartments( $DepParent ) {
return ($aRow) ? true : false; return ($aRow) ? true : false;
} }
function getUsersFromDepartment( $sDepUid, $sManagerUid ) { function getUsersFromDepartment ($sDepUid, $sManagerUid)
{
try { try {
$oCriteria = new Criteria( 'workflow' ); $oCriteria = new Criteria( 'workflow' );
$oCriteria->addSelectColumn( UsersPeer::USR_UID ); $oCriteria->addSelectColumn( UsersPeer::USR_UID );
@@ -487,7 +501,8 @@ function getDepartments( $DepParent ) {
$rs->setFetchmode( ResultSet::FETCHMODE_ASSOC ); $rs->setFetchmode( ResultSet::FETCHMODE_ASSOC );
$oUser = new Users(); $oUser = new Users();
$aUsers[] = array('USR_UID' =>'char', 'USR_USERNAME' =>'char','USR_FULLNAME' =>'char', 'USR_REPORTS_TO'=>'char','USR_MANAGER' =>'char'); $aUsers[] = array ('USR_UID' => 'char','USR_USERNAME' => 'char','USR_FULLNAME' => 'char','USR_REPORTS_TO' => 'char','USR_MANAGER' => 'char'
);
$rs->next(); $rs->next();
$row = $rs->getRow(); $row = $rs->getRow();
while (is_array( $row )) { while (is_array( $row )) {
@@ -500,13 +515,12 @@ function getDepartments( $DepParent ) {
try { try {
$managerFields = $oUser->LoadDetails( $row['USR_REPORTS_TO'] ); $managerFields = $oUser->LoadDetails( $row['USR_REPORTS_TO'] );
$row['USR_REPORTS_NAME'] = $managerFields['USR_FULLNAME']; $row['USR_REPORTS_NAME'] = $managerFields['USR_FULLNAME'];
} } catch (exception $e) {
catch (exception $e) {
$row['USR_REPORTS_NAME'] = '.'; $row['USR_REPORTS_NAME'] = '.';
} }
} } else {
else
$row['USR_REPORTS_NAME'] = '.'; $row['USR_REPORTS_NAME'] = '.';
}
$aUsers[] = $row; $aUsers[] = $row;
$rs->next(); $rs->next();
$row = $rs->getRow(); $row = $rs->getRow();
@@ -520,8 +534,7 @@ function getDepartments( $DepParent ) {
$oCriteriaT->setDBArrayTable( 'DepartmentUserList' ); $oCriteriaT->setDBArrayTable( 'DepartmentUserList' );
return $oCriteriaT; return $oCriteriaT;
} } catch (exception $e) {
catch (exception $e) {
throw $e; throw $e;
} }
} }
@@ -531,8 +544,10 @@ function getDepartments( $DepParent ) {
* @param string $DepUid, $UsrUid * @param string $DepUid, $UsrUid
* @return array * @return array
*/ */
function removeUserFromDepartment($DepUid, $UsrUid) { function removeUserFromDepartment ($DepUid, $UsrUid)
$aFields = array ('USR_UID'=> $UsrUid,'DEP_UID'=> '', 'USR_REPORTS_TO' => ''); {
$aFields = array ('USR_UID' => $UsrUid,'DEP_UID' => '','USR_REPORTS_TO' => ''
);
try { try {
$oUser = UsersPeer::retrieveByPk( $UsrUid ); $oUser = UsersPeer::retrieveByPk( $UsrUid );
if (is_object( $oUser ) && get_class( $oUser ) == 'Users') { if (is_object( $oUser ) && get_class( $oUser ) == 'Users') {
@@ -541,8 +556,7 @@ function getDepartments( $DepParent ) {
$oUser->setUsrReportsTo( '' ); $oUser->setUsrReportsTo( '' );
$oUser->save(); $oUser->save();
} }
} } catch (exception $oError) {
catch (exception $oError) {
throw ($oError); throw ($oError);
} }
} }
@@ -562,8 +576,7 @@ function getDepartments( $DepParent ) {
$oCriteria->add( UsersPeer::DEP_UID, "", Criteria::EQUAL ); $oCriteria->add( UsersPeer::DEP_UID, "", Criteria::EQUAL );
$oCriteria->add( UsersPeer::USR_STATUS, 'ACTIVE' ); $oCriteria->add( UsersPeer::USR_STATUS, 'ACTIVE' );
return $oCriteria; return $oCriteria;
} } catch (exception $oError) {
catch (exception $oError) {
throw ($oError); throw ($oError);
} }
} }
@@ -573,7 +586,8 @@ function getDepartments( $DepParent ) {
* @param string $sDepUID * @param string $sDepUID
* @return object * @return object
*/ */
function cantUsersInDepartment ( $sDepUID ) { function cantUsersInDepartment ($sDepUID)
{
try { try {
$c = new Criteria( 'workflow' ); $c = new Criteria( 'workflow' );
$c->addSelectColumn( 'COUNT(*)' ); $c->addSelectColumn( 'COUNT(*)' );
@@ -585,12 +599,13 @@ function getDepartments( $DepParent ) {
$row = $rs->getRow(); $row = $rs->getRow();
$count = $row[0]; $count = $row[0];
return $count; return $count;
} } catch (exception $oError) {
catch (exception $oError) {
throw ($oError); throw ($oError);
} }
} }
function loadByGroupname ( $Groupname ) {
function loadByGroupname ($Groupname)
{
$c = new Criteria( 'workflow' ); $c = new Criteria( 'workflow' );
$del = DBAdapter::getStringDelimiter(); $del = DBAdapter::getStringDelimiter();
@@ -605,7 +620,8 @@ function getDepartments( $DepParent ) {
} }
//Added by Qennix //Added by Qennix
function getAllDepartmentsByUser(){ function getAllDepartmentsByUser ()
{
$c = new Criteria( 'workflow' ); $c = new Criteria( 'workflow' );
$c->addSelectColumn( UsersPeer::USR_UID ); $c->addSelectColumn( UsersPeer::USR_UID );
$c->addAsColumn( 'DEP_TITLE', ContentPeer::CON_VALUE ); $c->addAsColumn( 'DEP_TITLE', ContentPeer::CON_VALUE );
@@ -622,7 +638,8 @@ function getDepartments( $DepParent ) {
return $aRows; return $aRows;
} }
function getDepartmentsForUser($userUid) { function getDepartmentsForUser ($userUid)
{
$criteria = new Criteria( 'workflow' ); $criteria = new Criteria( 'workflow' );
$criteria->addSelectColumn( UsersPeer::DEP_UID ); $criteria->addSelectColumn( UsersPeer::DEP_UID );
$criteria->addAsColumn( 'DEP_TITLE', 'C.CON_VALUE' ); $criteria->addAsColumn( 'DEP_TITLE', 'C.CON_VALUE' );
@@ -630,9 +647,12 @@ function getDepartments( $DepParent ) {
$criteria->addJoin( UsersPeer::DEP_UID, DepartmentPeer::DEP_UID, Criteria::LEFT_JOIN ); $criteria->addJoin( UsersPeer::DEP_UID, DepartmentPeer::DEP_UID, Criteria::LEFT_JOIN );
$delimiter = DBAdapter::getStringDelimiter(); $delimiter = DBAdapter::getStringDelimiter();
$conditions = array (); $conditions = array ();
$conditions [] = array(DepartmentPeer::DEP_UID, 'C.CON_ID'); $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); $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->addJoinMC( $conditions, Criteria::LEFT_JOIN );
$criteria->add( UsersPeer::USR_UID, $userUid ); $criteria->add( UsersPeer::USR_UID, $userUid );
$criteria->add( UsersPeer::DEP_UID, '', Criteria::NOT_EQUAL ); $criteria->add( UsersPeer::DEP_UID, '', Criteria::NOT_EQUAL );
@@ -648,5 +668,6 @@ function getDepartments( $DepParent ) {
} }
return $departments; return $departments;
} }
}
// Department
} // Department