CODE STYLE, workflow/engine/classes/model/
FILES: Department.php AppDocument.php
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* AppDocument.php
|
||||
*
|
||||
* @package workflow.engine.classes.model
|
||||
*
|
||||
* ProcessMaker Open Source Edition
|
||||
@@ -39,22 +40,26 @@ require_once 'classes/model/InputDocument.php';
|
||||
*
|
||||
* @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_comment = '';
|
||||
|
||||
/**
|
||||
* This value goes in the content table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $app_doc_filename = '';
|
||||
@@ -65,13 +70,14 @@ class AppDocument extends BaseAppDocument {
|
||||
* @param integer $iVersion (Document version)
|
||||
* @return variant
|
||||
*/
|
||||
public function load($sAppDocUid,$iVersion=NULL)
|
||||
public function load ($sAppDocUid, $iVersion = null)
|
||||
{
|
||||
try {
|
||||
if($iVersion==NULL) $iVersion=$this->getLastAppDocVersion($sAppDocUid);
|
||||
if ($iVersion == null) {
|
||||
$iVersion = $this->getLastAppDocVersion( $sAppDocUid );
|
||||
}
|
||||
$oAppDocument = AppDocumentPeer::retrieveByPK( $sAppDocUid, $iVersion );
|
||||
if (!is_null($oAppDocument))
|
||||
{
|
||||
if (! is_null( $oAppDocument )) {
|
||||
$aFields = $oAppDocument->toArray( BasePeer::TYPE_FIELDNAME );
|
||||
//optimized for speed
|
||||
$aContentFields = $oAppDocument->getContentFields();
|
||||
@@ -81,15 +87,14 @@ class AppDocument extends BaseAppDocument {
|
||||
|
||||
$this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME );
|
||||
return $aFields;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw (new Exception( 'Error loading Document ' . $sAppDocUid . '/' . $iVersion . '. This row doesn\'t exist!' ));
|
||||
}
|
||||
}
|
||||
catch (Exception $oError) {
|
||||
} catch (Exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
|
||||
public function getLastIndex ($sAppUid)
|
||||
{
|
||||
try {
|
||||
@@ -98,23 +103,23 @@ class AppDocument extends BaseAppDocument {
|
||||
//$oCriteria->addAscendingOrderByColumn ( AppDocumentPeer::APP_DOC_INDEX );
|
||||
$oCriteria->addDescendingOrderByColumn( AppDocumentPeer::APP_DOC_INDEX );
|
||||
$lastAppDoc = AppDocumentPeer::doSelectOne( $oCriteria );
|
||||
if (!is_null($lastAppDoc))
|
||||
{
|
||||
if (! is_null( $lastAppDoc )) {
|
||||
return $lastAppDoc->getAppDocIndex();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (Exception $oError) {
|
||||
} catch (Exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last Document Version based on Doc UID
|
||||
*
|
||||
* @param s $sAppDocUid
|
||||
* @return integer
|
||||
**/
|
||||
*
|
||||
*/
|
||||
public function getLastDocVersion ($sDocUid, $appUID)
|
||||
{
|
||||
try {
|
||||
@@ -123,48 +128,50 @@ class AppDocument extends BaseAppDocument {
|
||||
$oCriteria->add( AppDocumentPeer::APP_UID, $appUID );
|
||||
$oCriteria->addDescendingOrderByColumn( AppDocumentPeer::DOC_VERSION );
|
||||
$lastAppDocVersion = AppDocumentPeer::doSelectOne( $oCriteria );
|
||||
if (!is_null($lastAppDocVersion))
|
||||
{
|
||||
if (! is_null( $lastAppDocVersion )) {
|
||||
return $lastAppDocVersion->getDocVersion();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (Exception $oError) {
|
||||
} 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);
|
||||
if ($appUID != 0) {
|
||||
$oCriteria->add( AppDocumentPeer::APP_UID, $appUID );
|
||||
}
|
||||
$oCriteria->addDescendingOrderByColumn( AppDocumentPeer::DOC_VERSION );
|
||||
$lastAppDocVersion = AppDocumentPeer::doSelectOne( $oCriteria );
|
||||
if (!is_null($lastAppDocVersion))
|
||||
{
|
||||
if (! is_null( $lastAppDocVersion )) {
|
||||
return $lastAppDocVersion->getDocVersion();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (Exception $oError) {
|
||||
} 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 );
|
||||
@@ -199,7 +206,6 @@ class AppDocument extends BaseAppDocument {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$docVersion ++;
|
||||
}
|
||||
|
||||
@@ -223,8 +229,7 @@ class AppDocument extends BaseAppDocument {
|
||||
$oConnection->commit();
|
||||
$this->fromArray( $oAppDocument->toArray( BasePeer::TYPE_FIELDNAME ), BasePeer::TYPE_FIELDNAME );
|
||||
return $sUID;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$sMessage = '';
|
||||
$aValidationFailures = $oAppDocument->getValidationFailures();
|
||||
foreach ($aValidationFailures as $oValidationFailure) {
|
||||
@@ -232,8 +237,7 @@ class AppDocument extends BaseAppDocument {
|
||||
}
|
||||
throw (new Exception( 'The registry cannot be created!<br />' . $sMessage ));
|
||||
}
|
||||
}
|
||||
catch (Exception $oError) {
|
||||
} catch (Exception $oError) {
|
||||
$oConnection->rollback();
|
||||
throw ($oError);
|
||||
}
|
||||
@@ -241,36 +245,33 @@ class AppDocument extends BaseAppDocument {
|
||||
|
||||
/**
|
||||
* 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))
|
||||
{
|
||||
if (! is_null( $oAppDocument )) {
|
||||
$oAppDocument->fromArray( $aData, BasePeer::TYPE_FIELDNAME );
|
||||
if ($oAppDocument->validate()) {
|
||||
$oConnection->begin();
|
||||
if (isset($aData['APP_DOC_TITLE']))
|
||||
{
|
||||
if (isset( $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'] );
|
||||
}
|
||||
if (isset($aData['APP_DOC_FILENAME']))
|
||||
{
|
||||
if (isset( $aData['APP_DOC_FILENAME'] )) {
|
||||
$oAppDocument->setAppDocFilename( $aData['APP_DOC_FILENAME'] );
|
||||
}
|
||||
$iResult = $oAppDocument->save();
|
||||
$oConnection->commit();
|
||||
return $iResult;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$sMessage = '';
|
||||
$aValidationFailures = $oAppDocument->getValidationFailures();
|
||||
foreach ($aValidationFailures as $oValidationFailure) {
|
||||
@@ -278,12 +279,10 @@ class AppDocument extends BaseAppDocument {
|
||||
}
|
||||
throw (new Exception( 'The registry cannot be updated!<br />' . $sMessage ));
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw (new Exception( 'This row doesn\'t exist!' ));
|
||||
}
|
||||
}
|
||||
catch (Exception $oError) {
|
||||
} catch (Exception $oError) {
|
||||
$oConnection->rollback();
|
||||
throw ($oError);
|
||||
}
|
||||
@@ -292,9 +291,11 @@ class AppDocument extends BaseAppDocument {
|
||||
/**
|
||||
* 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 );
|
||||
@@ -310,32 +311,27 @@ class AppDocument extends BaseAppDocument {
|
||||
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
||||
$oDataset->next();
|
||||
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();
|
||||
}
|
||||
|
||||
} else {
|
||||
$arrayDocumentsToDelete[]=array('sAppDocUid'=>$sAppDocUid,'iVersion'=>$iVersion);
|
||||
$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');
|
||||
|
||||
$aFields = array ('APP_DOC_UID' => $docToDelete['sAppDocUid'],'DOC_VERSION' => $docToDelete['iVersion'],'APP_DOC_STATUS' => 'DELETED'
|
||||
);
|
||||
|
||||
$oAppDocument->update( $aFields );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw (new Exception( 'This row doesn\'t exist!' ));
|
||||
}
|
||||
}
|
||||
catch (Exception $oError) {
|
||||
} catch (Exception $oError) {
|
||||
$oConnection->rollback();
|
||||
throw ($oError);
|
||||
}
|
||||
@@ -343,6 +339,7 @@ class AppDocument extends BaseAppDocument {
|
||||
|
||||
/**
|
||||
* Get the [app_doc_title] column value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAppDocTitle ()
|
||||
@@ -350,9 +347,10 @@ class AppDocument extends BaseAppDocument {
|
||||
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
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -374,8 +372,7 @@ class AppDocument extends BaseAppDocument {
|
||||
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) {
|
||||
} catch (Exception $oError) {
|
||||
$this->app_doc_title = '';
|
||||
throw ($oError);
|
||||
}
|
||||
@@ -384,6 +381,7 @@ class AppDocument extends BaseAppDocument {
|
||||
|
||||
/**
|
||||
* Get the [app_doc_comment] column value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAppDocComment ()
|
||||
@@ -391,9 +389,10 @@ class AppDocument extends BaseAppDocument {
|
||||
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
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -415,8 +414,7 @@ class AppDocument extends BaseAppDocument {
|
||||
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) {
|
||||
} catch (Exception $oError) {
|
||||
$this->app_doc_comment = '';
|
||||
throw ($oError);
|
||||
}
|
||||
@@ -425,6 +423,7 @@ class AppDocument extends BaseAppDocument {
|
||||
|
||||
/**
|
||||
* Get the [app_doc_filename] column value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAppDocFilename ()
|
||||
@@ -432,9 +431,10 @@ class AppDocument extends BaseAppDocument {
|
||||
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
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -456,23 +456,26 @@ class AppDocument extends BaseAppDocument {
|
||||
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) {
|
||||
} catch (Exception $oError) {
|
||||
$this->app_doc_filename = '';
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function isEmptyInContent ( $content, $field, $lang ) {
|
||||
public function isEmptyInContent ($content, $field, $lang)
|
||||
{
|
||||
if (isset( $content[$field][$lang] )) {
|
||||
if ( trim( $content[$field][ $lang ] ) != '' )
|
||||
if (trim( $content[$field][$lang] ) != '') {
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function updateInsertContent ( $content, $field, $value ) {
|
||||
public function updateInsertContent ($content, $field, $value)
|
||||
{
|
||||
if (isset( $content[$field]['en'] )) {
|
||||
//update
|
||||
$con = ContentPeer::retrieveByPK( $field, $this->getDocVersion(), $this->getAppDocUid(), 'en' );
|
||||
@@ -480,8 +483,8 @@ class AppDocument extends BaseAppDocument {
|
||||
if ($con->validate()) {
|
||||
$res = $con->save();
|
||||
}
|
||||
}
|
||||
else {//insert
|
||||
} else {
|
||||
//insert
|
||||
$con = new Content();
|
||||
$con->setConCategory( $field );
|
||||
$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 = '';
|
||||
//if the lang row is not empty, update in 'en' row and continue
|
||||
if (! $this->isEmptyInContent( $content, $field, $lang )) {
|
||||
@@ -503,8 +507,7 @@ class AppDocument extends BaseAppDocument {
|
||||
if ($lang != 'en') {
|
||||
$this->updateInsertContent( $content, $field, $value );
|
||||
}
|
||||
}
|
||||
else {
|
||||
} 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'];
|
||||
@@ -522,8 +525,7 @@ class AppDocument extends BaseAppDocument {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$this->updateInsertContent( $content, $field, '' );
|
||||
}
|
||||
}
|
||||
@@ -533,6 +535,7 @@ class AppDocument extends BaseAppDocument {
|
||||
|
||||
/**
|
||||
* Get the [app_description] , [app_title] column values.
|
||||
*
|
||||
* @return array of string
|
||||
*/
|
||||
public function getContentFields ()
|
||||
@@ -558,8 +561,12 @@ class AppDocument extends BaseAppDocument {
|
||||
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();
|
||||
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();
|
||||
@@ -587,6 +594,7 @@ class AppDocument extends BaseAppDocument {
|
||||
|
||||
/**
|
||||
* Get all docuemnts for a folder
|
||||
*
|
||||
* @param array $sFolderUid
|
||||
* @return array
|
||||
*/
|
||||
@@ -601,11 +609,13 @@ class AppDocument extends BaseAppDocument {
|
||||
$oDataset->next();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
return $documents;
|
||||
}
|
||||
}
|
||||
// AppDocument
|
||||
|
||||
} // AppDocument
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Department.php
|
||||
*
|
||||
* @package workflow.engine.classes.model
|
||||
*
|
||||
* ProcessMaker Open Source Edition
|
||||
@@ -27,7 +28,6 @@
|
||||
require_once 'classes/model/om/BaseDepartment.php';
|
||||
require_once 'classes/model/Users.php';
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
class Department extends BaseDepartment {
|
||||
|
||||
class Department extends BaseDepartment
|
||||
{
|
||||
|
||||
protected $depo_title = '';
|
||||
|
||||
/**
|
||||
* Create the Department
|
||||
*
|
||||
@@ -50,48 +51,57 @@ protected $depo_title = '';
|
||||
* @return void
|
||||
*/
|
||||
|
||||
function create ($aData ) {
|
||||
function create ($aData)
|
||||
{
|
||||
$con = Propel::getConnection( DepartmentPeer::DATABASE_NAME );
|
||||
try {
|
||||
if ( isset ( $aData['DEP_UID'] ) )
|
||||
if (isset( $aData['DEP_UID'] )) {
|
||||
$this->setDepUid( $aData['DEP_UID'] );
|
||||
else
|
||||
} else {
|
||||
$this->setDepUid( G::generateUniqueID() );
|
||||
}
|
||||
|
||||
if ( isset ( $aData['DEP_PARENT'] ) )
|
||||
if (isset( $aData['DEP_PARENT'] )) {
|
||||
$this->setDepParent( $aData['DEP_PARENT'] );
|
||||
else
|
||||
} else {
|
||||
$this->setDepParent( '' );
|
||||
}
|
||||
|
||||
if ( isset ( $aData['DEP_MANAGER'] ) )
|
||||
if (isset( $aData['DEP_MANAGER'] )) {
|
||||
$this->setDepManager( $aData['DEP_MANAGER'] );
|
||||
else
|
||||
} else {
|
||||
$this->setDepManager( '' );
|
||||
}
|
||||
|
||||
if ( isset ( $aData['DEP_LOCATION'] ) )
|
||||
if (isset( $aData['DEP_LOCATION'] )) {
|
||||
$this->setDepLocation( $aData['DEP_LOCATION'] );
|
||||
else
|
||||
} else {
|
||||
$this->setDepLocation( '' );
|
||||
}
|
||||
|
||||
if ( isset ( $aData['DEP_STATUS'] ) )
|
||||
if (isset( $aData['DEP_STATUS'] )) {
|
||||
$this->setDepStatus( $aData['DEP_STATUS'] );
|
||||
else
|
||||
} else {
|
||||
$this->setDepStatus( 'ACTIVE' );
|
||||
}
|
||||
|
||||
if ( isset ( $aData['DEP_REF_CODE'] ) )
|
||||
if (isset( $aData['DEP_REF_CODE'] )) {
|
||||
$this->setDepRefCode( $aData['DEP_REF_CODE'] );
|
||||
else
|
||||
} else {
|
||||
$this->setDepRefCode( '' );
|
||||
}
|
||||
|
||||
if ( isset ( $aData['DEP_LDAP_DN'] ) )
|
||||
if (isset( $aData['DEP_LDAP_DN'] )) {
|
||||
$this->setDepLdapDn( $aData['DEP_LDAP_DN'] );
|
||||
else
|
||||
} else {
|
||||
$this->setDepLdapDn( '' );
|
||||
}
|
||||
|
||||
if ( isset ( $aData['DEP_TITLE'] ) )
|
||||
if (isset( $aData['DEP_TITLE'] )) {
|
||||
$this->setDepTitle( $aData['DEP_TITLE'] );
|
||||
else
|
||||
} else {
|
||||
$this->setDepTitle( '' );
|
||||
}
|
||||
|
||||
if ($this->validate()) {
|
||||
$con->begin();
|
||||
@@ -99,17 +109,16 @@ protected $depo_title = '';
|
||||
|
||||
$con->commit();
|
||||
return $this->getDepUid();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$msg = '';
|
||||
foreach($this->getValidationFailures() as $objValidationFailure)
|
||||
foreach ($this->getValidationFailures() as $objValidationFailure) {
|
||||
$msg .= $objValidationFailure->getMessage() . "<br/>";
|
||||
}
|
||||
|
||||
throw (new Exception( " The Department row cannot be created $msg " ));
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$con->rollback();
|
||||
throw ($e);
|
||||
}
|
||||
@@ -117,6 +126,7 @@ protected $depo_title = '';
|
||||
|
||||
/**
|
||||
* Get the [depo_title] column value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDepTitle ()
|
||||
@@ -162,7 +172,8 @@ protected $depo_title = '';
|
||||
* @return array $Fields the fields
|
||||
*/
|
||||
|
||||
function Load ( $DepUid ) {
|
||||
function Load ($DepUid)
|
||||
{
|
||||
$con = Propel::getConnection( DepartmentPeer::DATABASE_NAME );
|
||||
try {
|
||||
$oDept = DepartmentPeer::retrieveByPk( $DepUid );
|
||||
@@ -171,21 +182,21 @@ protected $depo_title = '';
|
||||
$this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME );
|
||||
$aFields['DEPO_TITLE'] = $oDept->getDepTitle();
|
||||
return $aFields;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw (new Exception( "The row '$DepUid' in table Department doesn't exist!" ));
|
||||
}
|
||||
}
|
||||
catch (Exception $oError) {
|
||||
} catch (Exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the Dep row
|
||||
*
|
||||
* @param array $aData
|
||||
* @return variant
|
||||
**/
|
||||
*
|
||||
*/
|
||||
|
||||
public function update ($aData)
|
||||
{
|
||||
@@ -196,42 +207,45 @@ protected $depo_title = '';
|
||||
if (is_object( $oPro ) && get_class( $oPro ) == 'Department') {
|
||||
$oPro->fromArray( $aData, BasePeer::TYPE_FIELDNAME );
|
||||
if ($oPro->validate()) {
|
||||
if ( isset ( $aData['DEPO_TITLE'] ) )
|
||||
if (isset( $aData['DEPO_TITLE'] )) {
|
||||
$oPro->setDepTitle( $aData['DEPO_TITLE'] );
|
||||
if ( isset ( $aData['DEP_STATUS'] ) )
|
||||
}
|
||||
if (isset( $aData['DEP_STATUS'] )) {
|
||||
$oPro->setDepStatus( $aData['DEP_STATUS'] );
|
||||
if ( isset ( $aData['DEP_PARENT'] ) )
|
||||
}
|
||||
if (isset( $aData['DEP_PARENT'] )) {
|
||||
$oPro->setDepParent( $aData['DEP_PARENT'] );
|
||||
if ( isset ( $aData['DEP_MANAGER'] ) )
|
||||
}
|
||||
if (isset( $aData['DEP_MANAGER'] )) {
|
||||
$oPro->setDepManager( $aData['DEP_MANAGER'] );
|
||||
}
|
||||
$res = $oPro->save();
|
||||
$con->commit();
|
||||
return $res;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$msg = '';
|
||||
foreach($this->getValidationFailures() as $objValidationFailure)
|
||||
foreach ($this->getValidationFailures() as $objValidationFailure) {
|
||||
$msg .= $objValidationFailure->getMessage() . "<br/>";
|
||||
}
|
||||
|
||||
throw (new PropelException( 'The Department row cannot be created!', new PropelException( $msg ) ));
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$con->rollback();
|
||||
throw (new Exception( "The row '" . $aData['DEP_UID'] . "' in table Department doesn't exist!" ));
|
||||
}
|
||||
}
|
||||
catch (Exception $oError) {
|
||||
} catch (Exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove the row
|
||||
*
|
||||
* @param array $aData or string $ProUid
|
||||
* @return string
|
||||
**/
|
||||
*
|
||||
*/
|
||||
public function remove ($ProUid)
|
||||
{
|
||||
if (is_array( $ProUid )) {
|
||||
@@ -262,25 +276,19 @@ protected $depo_title = '';
|
||||
$oDataset->next();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$oPro = DepartmentPeer::retrieveByPK( $ProUid );
|
||||
if (!is_null($oPro))
|
||||
{
|
||||
if (! is_null( $oPro )) {
|
||||
Content::removeContent( 'DEPO_TITLE', '', $oPro->getDepUid() );
|
||||
Content::removeContent( 'DEPO_DESCRIPTION', '', $oPro->getDepUid() );
|
||||
return $oPro->delete();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw (new Exception( "The row '$ProUid' in table Group doesn't exist!" ));
|
||||
}
|
||||
}
|
||||
catch (Exception $oError) {
|
||||
} catch (Exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load the Department row specified in [depo_id] column value.
|
||||
*
|
||||
@@ -288,29 +296,32 @@ protected $depo_title = '';
|
||||
* @return array $Fields the fields
|
||||
*/
|
||||
|
||||
function existsDepartment( $DepUid ) {
|
||||
function existsDepartment ($DepUid)
|
||||
{
|
||||
$con = Propel::getConnection( DepartmentPeer::DATABASE_NAME );
|
||||
$oPro = DepartmentPeer::retrieveByPk( $DepUid );
|
||||
if (is_object( $oPro ) && get_class( $oPro ) == 'Department') {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function existsUserInDepartment( $depId, $userId ) {
|
||||
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 )
|
||||
if ($oUser->getDepUid() == $depId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function updateDepartmentManager ($depId) {
|
||||
function updateDepartmentManager ($depId)
|
||||
{
|
||||
$managerId = '';
|
||||
$depParent = '';
|
||||
$oDept = DepartmentPeer::retrieveByPk( $depId );
|
||||
@@ -363,7 +374,8 @@ protected $depo_title = '';
|
||||
}
|
||||
|
||||
//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 {
|
||||
//update the field in user table
|
||||
$oUser = UsersPeer::retrieveByPk( $userId );
|
||||
@@ -386,15 +398,15 @@ protected $depo_title = '';
|
||||
$this->updateDepartmentManager( $depId );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch ( Exception $oError) {
|
||||
} catch (Exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
|
||||
// select departments
|
||||
// this function is used to draw the hierachy tree view
|
||||
function getDepartments( $DepParent ) {
|
||||
function getDepartments ($DepParent)
|
||||
{
|
||||
try {
|
||||
$result = array ();
|
||||
$criteria = new Criteria( 'workflow' );
|
||||
@@ -435,17 +447,18 @@ function getDepartments( $DepParent ) {
|
||||
$node['HAS_CHILDREN'] = $row[0];
|
||||
$result[] = $node;
|
||||
}
|
||||
if ( count($result) >= 1 )
|
||||
if (count( $result ) >= 1) {
|
||||
$result[count( $result ) - 1]['DEP_LAST'] = 1;
|
||||
return $result;
|
||||
}
|
||||
catch (exception $e) {
|
||||
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
|
||||
@@ -475,7 +488,8 @@ function getDepartments( $DepParent ) {
|
||||
return ($aRow) ? true : false;
|
||||
}
|
||||
|
||||
function getUsersFromDepartment( $sDepUid, $sManagerUid ) {
|
||||
function getUsersFromDepartment ($sDepUid, $sManagerUid)
|
||||
{
|
||||
try {
|
||||
$oCriteria = new Criteria( 'workflow' );
|
||||
$oCriteria->addSelectColumn( UsersPeer::USR_UID );
|
||||
@@ -487,7 +501,8 @@ function getDepartments( $DepParent ) {
|
||||
$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');
|
||||
$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 )) {
|
||||
@@ -500,13 +515,12 @@ function getDepartments( $DepParent ) {
|
||||
try {
|
||||
$managerFields = $oUser->LoadDetails( $row['USR_REPORTS_TO'] );
|
||||
$row['USR_REPORTS_NAME'] = $managerFields['USR_FULLNAME'];
|
||||
}
|
||||
catch (exception $e) {
|
||||
} catch (exception $e) {
|
||||
$row['USR_REPORTS_NAME'] = '.';
|
||||
}
|
||||
}
|
||||
else
|
||||
} else {
|
||||
$row['USR_REPORTS_NAME'] = '.';
|
||||
}
|
||||
$aUsers[] = $row;
|
||||
$rs->next();
|
||||
$row = $rs->getRow();
|
||||
@@ -520,8 +534,7 @@ function getDepartments( $DepParent ) {
|
||||
$oCriteriaT->setDBArrayTable( 'DepartmentUserList' );
|
||||
|
||||
return $oCriteriaT;
|
||||
}
|
||||
catch (exception $e) {
|
||||
} catch (exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@@ -531,8 +544,10 @@ function getDepartments( $DepParent ) {
|
||||
* @param string $DepUid, $UsrUid
|
||||
* @return array
|
||||
*/
|
||||
function removeUserFromDepartment($DepUid, $UsrUid) {
|
||||
$aFields = array ('USR_UID'=> $UsrUid,'DEP_UID'=> '', 'USR_REPORTS_TO' => '');
|
||||
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') {
|
||||
@@ -541,8 +556,7 @@ function getDepartments( $DepParent ) {
|
||||
$oUser->setUsrReportsTo( '' );
|
||||
$oUser->save();
|
||||
}
|
||||
}
|
||||
catch (exception $oError) {
|
||||
} catch (exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
@@ -562,8 +576,7 @@ function getDepartments( $DepParent ) {
|
||||
$oCriteria->add( UsersPeer::DEP_UID, "", Criteria::EQUAL );
|
||||
$oCriteria->add( UsersPeer::USR_STATUS, 'ACTIVE' );
|
||||
return $oCriteria;
|
||||
}
|
||||
catch (exception $oError) {
|
||||
} catch (exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
@@ -573,7 +586,8 @@ function getDepartments( $DepParent ) {
|
||||
* @param string $sDepUID
|
||||
* @return object
|
||||
*/
|
||||
function cantUsersInDepartment ( $sDepUID ) {
|
||||
function cantUsersInDepartment ($sDepUID)
|
||||
{
|
||||
try {
|
||||
$c = new Criteria( 'workflow' );
|
||||
$c->addSelectColumn( 'COUNT(*)' );
|
||||
@@ -585,12 +599,13 @@ function getDepartments( $DepParent ) {
|
||||
$row = $rs->getRow();
|
||||
$count = $row[0];
|
||||
return $count;
|
||||
}
|
||||
catch (exception $oError) {
|
||||
} catch (exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
function loadByGroupname ( $Groupname ) {
|
||||
|
||||
function loadByGroupname ($Groupname)
|
||||
{
|
||||
$c = new Criteria( 'workflow' );
|
||||
$del = DBAdapter::getStringDelimiter();
|
||||
|
||||
@@ -605,7 +620,8 @@ function getDepartments( $DepParent ) {
|
||||
}
|
||||
|
||||
//Added by Qennix
|
||||
function getAllDepartmentsByUser(){
|
||||
function getAllDepartmentsByUser ()
|
||||
{
|
||||
$c = new Criteria( 'workflow' );
|
||||
$c->addSelectColumn( UsersPeer::USR_UID );
|
||||
$c->addAsColumn( 'DEP_TITLE', ContentPeer::CON_VALUE );
|
||||
@@ -622,7 +638,8 @@ function getDepartments( $DepParent ) {
|
||||
return $aRows;
|
||||
}
|
||||
|
||||
function getDepartmentsForUser($userUid) {
|
||||
function getDepartmentsForUser ($userUid)
|
||||
{
|
||||
$criteria = new Criteria( 'workflow' );
|
||||
$criteria->addSelectColumn( UsersPeer::DEP_UID );
|
||||
$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 );
|
||||
$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);
|
||||
$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 );
|
||||
@@ -648,5 +668,6 @@ function getDepartments( $DepParent ) {
|
||||
}
|
||||
return $departments;
|
||||
}
|
||||
}
|
||||
// Department
|
||||
|
||||
} // Department
|
||||
|
||||
Reference in New Issue
Block a user