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,295 +70,288 @@ 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);
|
||||
$oAppDocument = AppDocumentPeer::retrieveByPK($sAppDocUid,$iVersion);
|
||||
if (!is_null($oAppDocument))
|
||||
{
|
||||
$aFields = $oAppDocument->toArray(BasePeer::TYPE_FIELDNAME);
|
||||
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);
|
||||
$this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME );
|
||||
return $aFields;
|
||||
} else {
|
||||
throw (new Exception( 'Error loading Document ' . $sAppDocUid . '/' . $iVersion . '. This row doesn\'t exist!' ));
|
||||
}
|
||||
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 )
|
||||
|
||||
public function getLastIndex ($sAppUid)
|
||||
{
|
||||
try {
|
||||
$oCriteria = new Criteria();
|
||||
$oCriteria->add( AppDocumentPeer::APP_UID , $sAppUid );
|
||||
$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))
|
||||
{
|
||||
$lastAppDoc = AppDocumentPeer::doSelectOne( $oCriteria );
|
||||
if (! is_null( $lastAppDoc )) {
|
||||
return $lastAppDoc->getAppDocIndex();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (Exception $oError) {
|
||||
throw($oError);
|
||||
} catch (Exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last Document Version based on Doc UID
|
||||
*
|
||||
* @param s $sAppDocUid
|
||||
* @return integer
|
||||
**/
|
||||
public function getLastDocVersion( $sDocUid ,$appUID)
|
||||
*
|
||||
*/
|
||||
public function getLastDocVersion ($sDocUid, $appUID)
|
||||
{
|
||||
try {
|
||||
$oCriteria = new Criteria();
|
||||
$oCriteria->add(AppDocumentPeer::DOC_UID, $sDocUid );
|
||||
$oCriteria->add(AppDocumentPeer::APP_UID, $appUID);
|
||||
$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))
|
||||
{
|
||||
$lastAppDocVersion = AppDocumentPeer::doSelectOne( $oCriteria );
|
||||
if (! is_null( $lastAppDocVersion )) {
|
||||
return $lastAppDocVersion->getDocVersion();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (Exception $oError) {
|
||||
throw($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)
|
||||
*
|
||||
*/
|
||||
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();
|
||||
$oCriteria->add( AppDocumentPeer::APP_DOC_UID, $sAppDocUid );
|
||||
if ($appUID != 0) {
|
||||
$oCriteria->add( AppDocumentPeer::APP_UID, $appUID );
|
||||
}
|
||||
else {
|
||||
$oCriteria->addDescendingOrderByColumn( AppDocumentPeer::DOC_VERSION );
|
||||
$lastAppDocVersion = AppDocumentPeer::doSelectOne( $oCriteria );
|
||||
if (! is_null( $lastAppDocVersion )) {
|
||||
return $lastAppDocVersion->getDocVersion();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (Exception $oError) {
|
||||
throw($oError);
|
||||
} catch (Exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the application document registry
|
||||
*
|
||||
* @param array $aData
|
||||
* @return string
|
||||
**/
|
||||
public function create($aData)
|
||||
*
|
||||
*/
|
||||
public function create ($aData)
|
||||
{
|
||||
$oConnection = Propel::getConnection(AppDocumentPeer::DATABASE_NAME);
|
||||
$oConnection = Propel::getConnection( AppDocumentPeer::DATABASE_NAME );
|
||||
try {
|
||||
$oAppDocument = new AppDocument();
|
||||
|
||||
if(!isset($aData['APP_DOC_UID'])){
|
||||
if (! isset( $aData['APP_DOC_UID'] )) {
|
||||
$sUID = G::generateUniqueID();
|
||||
$docVersion = 1;
|
||||
}else{
|
||||
} 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
|
||||
$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());
|
||||
$oOutputDocument = $o->load( $oAppDocument->getDocUid() );
|
||||
|
||||
if( !$oOutputDocument['OUT_DOC_VERSIONING'] ){
|
||||
throw(new Exception('The Output document has not versioning enabled!'));
|
||||
if (! $oOutputDocument['OUT_DOC_VERSIONING']) {
|
||||
throw (new Exception( 'The Output document has not versioning enabled!' ));
|
||||
}
|
||||
break;
|
||||
case "INPUT":// Input versioning
|
||||
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'));
|
||||
$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'));
|
||||
default: //Not a valid type
|
||||
throw (new Exception( 'The document is not of a valid Type' ));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$docVersion++;
|
||||
$docVersion ++;
|
||||
}
|
||||
|
||||
$oAppDocument->fromArray($aData, BasePeer::TYPE_FIELDNAME);
|
||||
$oAppDocument->setDocVersion($docVersion);
|
||||
$oAppDocument->fromArray( $aData, BasePeer::TYPE_FIELDNAME );
|
||||
$oAppDocument->setDocVersion( $docVersion );
|
||||
|
||||
$oAppDocument->setAppDocUid( $sUID );
|
||||
$oAppDocument->setAppDocIndex($this->getLastIndex( $oAppDocument->getAppUid() )+1);
|
||||
$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_TITLE'] )) {
|
||||
$oAppDocument->setAppDocTitle( $aData['APP_DOC_TITLE'] );
|
||||
}
|
||||
if (isset($aData['APP_DOC_COMMENT'])) {
|
||||
$oAppDocument->setAppDocComment($aData['APP_DOC_COMMENT']);
|
||||
if (isset( $aData['APP_DOC_COMMENT'] )) {
|
||||
$oAppDocument->setAppDocComment( $aData['APP_DOC_COMMENT'] );
|
||||
}
|
||||
if (isset($aData['APP_DOC_FILENAME'])) {
|
||||
$oAppDocument->setAppDocFilename($aData['APP_DOC_FILENAME']);
|
||||
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);
|
||||
$this->fromArray( $oAppDocument->toArray( BasePeer::TYPE_FIELDNAME ), BasePeer::TYPE_FIELDNAME );
|
||||
return $sUID;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$sMessage = '';
|
||||
$aValidationFailures = $oAppDocument->getValidationFailures();
|
||||
foreach($aValidationFailures as $oValidationFailure) {
|
||||
foreach ($aValidationFailures as $oValidationFailure) {
|
||||
$sMessage .= $oValidationFailure->getMessage() . '<br />';
|
||||
}
|
||||
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();
|
||||
throw($oError);
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the application document registry
|
||||
*
|
||||
* @param array $aData
|
||||
* @return string
|
||||
**/
|
||||
public function update($aData)
|
||||
*
|
||||
*/
|
||||
public function update ($aData)
|
||||
{
|
||||
$oConnection = Propel::getConnection(AppDocumentPeer::DATABASE_NAME);
|
||||
$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);
|
||||
$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_TITLE'] )) {
|
||||
$oAppDocument->setAppDocTitle( $aData['APP_DOC_TITLE'] );
|
||||
}
|
||||
if (isset($aData['APP_DOC_COMMENT']))
|
||||
{
|
||||
$oAppDocument->setAppDocComment($aData['APP_DOC_COMMENT']);
|
||||
if (isset( $aData['APP_DOC_COMMENT'] )) {
|
||||
$oAppDocument->setAppDocComment( $aData['APP_DOC_COMMENT'] );
|
||||
}
|
||||
if (isset($aData['APP_DOC_FILENAME']))
|
||||
{
|
||||
$oAppDocument->setAppDocFilename($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) {
|
||||
foreach ($aValidationFailures as $oValidationFailure) {
|
||||
$sMessage .= $oValidationFailure->getMessage() . '<br />';
|
||||
}
|
||||
throw(new Exception('The registry cannot be updated!<br />'.$sMessage));
|
||||
throw (new Exception( 'The registry cannot be updated!<br />' . $sMessage ));
|
||||
}
|
||||
} else {
|
||||
throw (new Exception( 'This row doesn\'t exist!' ));
|
||||
}
|
||||
else {
|
||||
throw(new Exception('This row doesn\'t exist!'));
|
||||
}
|
||||
}
|
||||
catch (Exception $oError) {
|
||||
} catch (Exception $oError) {
|
||||
$oConnection->rollback();
|
||||
throw($oError);
|
||||
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)
|
||||
*
|
||||
*/
|
||||
public function remove ($sAppDocUid, $iVersion = 1)
|
||||
{
|
||||
$oConnection = Propel::getConnection(AppDocumentPeer::DATABASE_NAME);
|
||||
$oConnection = Propel::getConnection( AppDocumentPeer::DATABASE_NAME );
|
||||
try {
|
||||
$oAppDocument = AppDocumentPeer::retrieveByPK($sAppDocUid,$iVersion);
|
||||
if (!is_null($oAppDocument)){
|
||||
$arrayDocumentsToDelete=array();
|
||||
if($oAppDocument->getAppDocType()=="INPUT"){
|
||||
$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);
|
||||
$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']);
|
||||
$arrayDocumentsToDelete[] = array ('sAppDocUid' => $aRow['APP_DOC_UID'],'iVersion' => $aRow['DOC_VERSION']
|
||||
);
|
||||
$oDataset->next();
|
||||
}
|
||||
|
||||
}else{
|
||||
$arrayDocumentsToDelete[]=array('sAppDocUid'=>$sAppDocUid,'iVersion'=>$iVersion);
|
||||
} 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');
|
||||
foreach ($arrayDocumentsToDelete as $key => $docToDelete) {
|
||||
$aFields = array ('APP_DOC_UID' => $docToDelete['sAppDocUid'],'DOC_VERSION' => $docToDelete['iVersion'],'APP_DOC_STATUS' => 'DELETED'
|
||||
);
|
||||
|
||||
|
||||
$oAppDocument->update($aFields);
|
||||
$oAppDocument->update( $aFields );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
throw (new Exception( 'This row doesn\'t exist!' ));
|
||||
}
|
||||
else {
|
||||
throw(new Exception('This row doesn\'t exist!'));
|
||||
}
|
||||
}
|
||||
catch (Exception $oError) {
|
||||
} catch (Exception $oError) {
|
||||
$oConnection->rollback();
|
||||
throw($oError);
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [app_doc_title] column value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAppDocTitle()
|
||||
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
|
||||
$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);
|
||||
} catch (Exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
return $this->app_doc_title;
|
||||
@@ -365,36 +363,37 @@ class AppDocument extends BaseAppDocument {
|
||||
* @param string $sValue new value
|
||||
* @return void
|
||||
*/
|
||||
public function setAppDocTitle($sValue)
|
||||
public function setAppDocTitle ($sValue)
|
||||
{
|
||||
if ($sValue !== null && !is_string($sValue)) {
|
||||
$sValue = (string)$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) {
|
||||
$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);
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [app_doc_comment] column value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAppDocComment()
|
||||
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
|
||||
$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);
|
||||
} catch (Exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
return $this->app_doc_comment;
|
||||
@@ -406,36 +405,37 @@ class AppDocument extends BaseAppDocument {
|
||||
* @param string $sValue new value
|
||||
* @return void
|
||||
*/
|
||||
public function setAppDocComment($sValue)
|
||||
public function setAppDocComment ($sValue)
|
||||
{
|
||||
if ($sValue !== null && !is_string($sValue)) {
|
||||
$sValue = (string)$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) {
|
||||
$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);
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [app_doc_filename] column value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAppDocFilename()
|
||||
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
|
||||
$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);
|
||||
} catch (Exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
return $this->app_doc_filename;
|
||||
@@ -447,84 +447,86 @@ class AppDocument extends BaseAppDocument {
|
||||
* @param string $sValue new value
|
||||
* @return void
|
||||
*/
|
||||
public function setAppDocFilename($sValue)
|
||||
public function setAppDocFilename ($sValue)
|
||||
{
|
||||
if ($sValue !== null && !is_string($sValue)) {
|
||||
$sValue = (string)$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) {
|
||||
$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);
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function isEmptyInContent ( $content, $field, $lang ) {
|
||||
if ( isset ( $content[$field][ $lang ] ) ) {
|
||||
if ( trim( $content[$field][ $lang ] ) != '' )
|
||||
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' ] ) ) {
|
||||
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 ();
|
||||
$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 ();
|
||||
} 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 ) {
|
||||
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 ) ) {
|
||||
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 );
|
||||
$value = $content[$field][$lang];
|
||||
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' ];
|
||||
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 ) != '' ) {
|
||||
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 );
|
||||
if ($lan != 'en') {
|
||||
$this->updateInsertContent( $content, $field, $value );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->updateInsertContent ( $content, $field , '' );
|
||||
} else {
|
||||
$this->updateInsertContent( $content, $field, '' );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -533,14 +535,15 @@ class AppDocument extends BaseAppDocument {
|
||||
|
||||
/**
|
||||
* Get the [app_description] , [app_title] column values.
|
||||
*
|
||||
* @return array of string
|
||||
*/
|
||||
public function getContentFields()
|
||||
public function getContentFields ()
|
||||
{
|
||||
if ( $this->getAppDocUid() == '' ) {
|
||||
throw ( new Exception( "Error in getContentFields, the APP_DOC_UID can't be blank") );
|
||||
if ($this->getAppDocUid() == '') {
|
||||
throw (new Exception( "Error in getContentFields, the APP_DOC_UID can't be blank" ));
|
||||
}
|
||||
$lang = defined ( 'SYS_LANG') ? SYS_LANG : 'en';
|
||||
$lang = defined( 'SYS_LANG' ) ? SYS_LANG : 'en';
|
||||
$c = new Criteria();
|
||||
$c->clearSelectColumns();
|
||||
$c->addSelectColumn( ContentPeer::CON_CATEGORY );
|
||||
@@ -549,17 +552,21 @@ class AppDocument extends BaseAppDocument {
|
||||
$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');
|
||||
$c->addAscendingOrderByColumn( 'CON_CATEGORY' );
|
||||
$c->addAscendingOrderByColumn( 'CON_LANG' );
|
||||
$rs = ContentPeer::doSelectRS( $c );
|
||||
$rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
$rs->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
||||
$rs->next();
|
||||
$content = array();
|
||||
$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();
|
||||
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();
|
||||
@@ -571,15 +578,15 @@ class AppDocument extends BaseAppDocument {
|
||||
return $res;
|
||||
}
|
||||
|
||||
function getObject($APP_UID, $DEL_INDEX, $STEP_UID_OBJ, $APP_DOC_TYPE)
|
||||
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);
|
||||
$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();
|
||||
@@ -587,25 +594,28 @@ class AppDocument extends BaseAppDocument {
|
||||
|
||||
/**
|
||||
* Get all docuemnts for a folder
|
||||
*
|
||||
* @param array $sFolderUid
|
||||
* @return array
|
||||
*/
|
||||
public function getDocumentsinFolders($sFolderUid)
|
||||
public function getDocumentsinFolders ($sFolderUid)
|
||||
{
|
||||
$documents = array();
|
||||
$documents = array ();
|
||||
|
||||
$oCriteria = new Criteria('workflow');
|
||||
$oCriteria->add(AppDocumentPeer::FOLDER_UID, $sFolderUid);
|
||||
$oDataset = AppDocumentPeer::doSelectRS($oCriteria);
|
||||
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
$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']);
|
||||
$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,93 +39,103 @@ require_once 'classes/model/Users.php';
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
||||
function create ($aData ) {
|
||||
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_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_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_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_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_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_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_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 (isset( $aData['DEP_TITLE'] )) {
|
||||
$this->setDepTitle( $aData['DEP_TITLE'] );
|
||||
} else {
|
||||
$this->setDepTitle( '' );
|
||||
}
|
||||
|
||||
if ( $this->validate() ) {
|
||||
if ($this->validate()) {
|
||||
$con->begin();
|
||||
$res = $this->save();
|
||||
|
||||
$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 " ) );
|
||||
}
|
||||
|
||||
throw (new Exception( " The Department row cannot be created $msg " ));
|
||||
}
|
||||
catch (Exception $e) {
|
||||
|
||||
} catch (Exception $e) {
|
||||
$con->rollback();
|
||||
throw ($e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get the [depo_title] column value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDepTitle()
|
||||
public function getDepTitle ()
|
||||
{
|
||||
if ( $this->getDepUid() == '' ) {
|
||||
throw ( new Exception( "Error in getDepTitle, the DEP_UID can't be blank") );
|
||||
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 );
|
||||
$lang = defined( 'SYS_LANG' ) ? SYS_LANG : 'en';
|
||||
$this->depo_title = Content::load( 'DEPO_TITLE', '', $this->getDepUid(), $lang );
|
||||
return $this->depo_title;
|
||||
}
|
||||
|
||||
@@ -135,209 +145,210 @@ protected $depo_title = '';
|
||||
* @param string $v new value
|
||||
* @return void
|
||||
*/
|
||||
public function setDepTitle($v)
|
||||
public function setDepTitle ($v)
|
||||
{
|
||||
if ( $this->getDepUid() == '' ) {
|
||||
throw ( new Exception( "Error in setGrpTitle, the GRP_UID can't be blank") );
|
||||
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)) {
|
||||
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';
|
||||
$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);
|
||||
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 );
|
||||
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!" ));
|
||||
}
|
||||
else {
|
||||
throw(new Exception( "The row '$DepUid' in table Department doesn't exist!" ));
|
||||
}
|
||||
}
|
||||
catch (Exception $oError) {
|
||||
throw($oError);
|
||||
} catch (Exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Update the Dep row
|
||||
*
|
||||
* @param array $aData
|
||||
* @return variant
|
||||
**/
|
||||
*
|
||||
*/
|
||||
|
||||
public function update($aData)
|
||||
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' ) {
|
||||
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 ) ) );
|
||||
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!" ));
|
||||
throw (new Exception( "The row '" . $aData['DEP_UID'] . "' in table Department doesn't exist!" ));
|
||||
}
|
||||
} catch (Exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
catch (Exception $oError) {
|
||||
throw($oError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove the row
|
||||
*
|
||||
* @param array $aData or string $ProUid
|
||||
* @return string
|
||||
**/
|
||||
public function remove($ProUid)
|
||||
*
|
||||
*/
|
||||
public function remove ($ProUid)
|
||||
{
|
||||
if ( is_array ( $ProUid ) ) {
|
||||
$ProUid = ( isset ( $ProUid['DEP_UID'] ) ? $ProUid['DEP_UID'] : '' );
|
||||
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);
|
||||
$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();
|
||||
$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') {
|
||||
$oDepto = UsersPeer::retrieveByPk( $aFields['USR_UID'] );
|
||||
if (is_object( $oDepto ) && get_class( $oDepto ) == 'UsersPeer') {
|
||||
return true;
|
||||
} else {
|
||||
$oDepto = new Users();
|
||||
$oDepto->update($aFields);
|
||||
$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());
|
||||
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!" ));
|
||||
}
|
||||
else {
|
||||
throw(new Exception( "The row '$ProUid' in table Group doesn't exist!" ));
|
||||
}
|
||||
}
|
||||
catch (Exception $oError) {
|
||||
throw($oError);
|
||||
} 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);
|
||||
function existsDepartment ($DepUid)
|
||||
{
|
||||
$con = Propel::getConnection( DepartmentPeer::DATABASE_NAME );
|
||||
$oPro = DepartmentPeer::retrieveByPk( $DepUid );
|
||||
if (is_object($oPro) && get_class ($oPro) == 'Department' ) {
|
||||
if (is_object( $oPro ) && get_class( $oPro ) == 'Department') {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function existsUserInDepartment( $depId, $userId ) {
|
||||
$con = Propel::getConnection(DepartmentPeer::DATABASE_NAME);
|
||||
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 (is_object( $oUser ) && get_class( $oUser ) == 'Users') {
|
||||
if ($oUser->getDepUid() == $depId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function updateDepartmentManager ($depId) {
|
||||
function updateDepartmentManager ($depId)
|
||||
{
|
||||
$managerId = '';
|
||||
$depParent = '';
|
||||
$oDept = DepartmentPeer::retrieveByPk( $depId );
|
||||
if (is_object($oDept) && get_class ($oDept) == 'Department' ) {
|
||||
$managerId = $oDept->getDepManager( );
|
||||
$depParent = $oDept->getDepParent( );
|
||||
if (is_object( $oDept ) && get_class( $oDept ) == 'Department') {
|
||||
$managerId = $oDept->getDepManager();
|
||||
$depParent = $oDept->getDepParent();
|
||||
}
|
||||
|
||||
// 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);
|
||||
$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);
|
||||
$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' ) {
|
||||
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) != '' ) {
|
||||
if (is_object( $oDept ) && get_class( $oDept ) == 'Department') {
|
||||
$managerParentId = $oDept->getDepManager();
|
||||
if (trim( $managerParentId ) != '') {
|
||||
$oUser->setUsrReportsTo( $managerParentId );
|
||||
}
|
||||
}
|
||||
@@ -345,16 +356,16 @@ protected $depo_title = '';
|
||||
}
|
||||
|
||||
// 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);
|
||||
$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 );
|
||||
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();
|
||||
@@ -363,48 +374,49 @@ 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 );
|
||||
if (is_object($oUser) && get_class ($oUser) == 'Users' ) {
|
||||
if (is_object( $oUser ) && get_class( $oUser ) == 'Users') {
|
||||
$oUser->setDepUid( $depId );
|
||||
$oUser->save();
|
||||
}
|
||||
|
||||
//if the user is a manager update Department Table
|
||||
if ( $manager ) {
|
||||
if ($manager) {
|
||||
$oDept = DepartmentPeer::retrieveByPk( $depId );
|
||||
if (is_object($oDept) && get_class ($oDept) == 'Department' ) {
|
||||
if (is_object( $oDept ) && get_class( $oDept ) == 'Department') {
|
||||
$oDept->setDepManager( $userId );
|
||||
$oDept->save();
|
||||
}
|
||||
}
|
||||
|
||||
//now update the reportsto to all
|
||||
if ( $updateManager ) {
|
||||
$this->updateDepartmentManager ($depId);
|
||||
if ($updateManager) {
|
||||
$this->updateDepartmentManager( $depId );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch ( Exception $oError) {
|
||||
throw($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');
|
||||
$criteria->add(DepartmentPeer::DEP_PARENT, $DepParent, Criteria::EQUAL);
|
||||
$con = Propel::getConnection(DepartmentPeer::DATABASE_NAME);
|
||||
$objects = DepartmentPeer::doSelect($criteria, $con);
|
||||
$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();
|
||||
foreach ($objects as $oDepartment) {
|
||||
$node = array ();
|
||||
$node['DEP_UID'] = $oDepartment->getDepUid();
|
||||
$node['DEP_PARENT'] = $oDepartment->getDepParent();
|
||||
$node['DEP_TITLE'] = $oDepartment->getDepTitle();
|
||||
@@ -414,114 +426,115 @@ function getDepartments( $DepParent ) {
|
||||
$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{
|
||||
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 = new Criteria( 'workflow' );
|
||||
$criteriaCount->clearSelectColumns();
|
||||
$criteriaCount->addSelectColumn( 'COUNT(*)' );
|
||||
$criteriaCount->add(DepartmentPeer::DEP_PARENT, $oDepartment->getDepUid(), Criteria::EQUAL);
|
||||
$rs = DepartmentPeer::doSelectRS($criteriaCount);
|
||||
$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;
|
||||
if (count( $result ) >= 1) {
|
||||
$result[count( $result ) - 1]['DEP_LAST'] = 1;
|
||||
}
|
||||
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
|
||||
* @return boolean $Fields true or false
|
||||
*
|
||||
*/
|
||||
function checkDepartmentName($departmentName, $parentUID, $departmentUID = '' )
|
||||
function checkDepartmentName ($departmentName, $parentUID, $departmentUID = '')
|
||||
{
|
||||
$oCriteria = new Criteria('workflow');
|
||||
$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);
|
||||
$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 = DepartmentPeer::doSelectRS( $oCriteria );
|
||||
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
||||
$oDataset->next();
|
||||
$aRow = $oDataset->getRow();
|
||||
|
||||
return ($aRow) ? true : false;
|
||||
}
|
||||
|
||||
function getUsersFromDepartment( $sDepUid, $sManagerUid ) {
|
||||
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);
|
||||
$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);
|
||||
$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');
|
||||
$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) ) {
|
||||
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['USR_MANAGER'] = $row['USR_UID'] == $sManagerUid ? G::loadTranslation( "ID_YES" ) : G::loadTranslation( "ID_NO" );
|
||||
$row['DEP_UID'] = $sDepUid;
|
||||
if ( $row['USR_REPORTS_TO'] != '' ) {
|
||||
if ($row['USR_REPORTS_TO'] != '') {
|
||||
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();
|
||||
}
|
||||
|
||||
G::LoadClass('ArrayPeer');
|
||||
G::LoadClass( 'ArrayPeer' );
|
||||
global $_DBArray;
|
||||
$_DBArray['DepartmentUserList'] = $aUsers ;
|
||||
$_DBArray['DepartmentUserList'] = $aUsers;
|
||||
$_SESSION['_DBArray'] = $_DBArray;
|
||||
$oCriteriaT = new Criteria('dbarray');
|
||||
$oCriteriaT->setDBArrayTable('DepartmentUserList');
|
||||
$oCriteriaT = new Criteria( 'dbarray' );
|
||||
$oCriteriaT->setDBArrayTable( 'DepartmentUserList' );
|
||||
|
||||
return $oCriteriaT;
|
||||
}
|
||||
catch (exception $e) {
|
||||
} catch (exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@@ -531,18 +544,19 @@ 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' ) {
|
||||
if (is_object( $oUser ) && get_class( $oUser ) == 'Users') {
|
||||
//$oDepto = new Users();
|
||||
$oUser->setDepUid ( '');
|
||||
$oUser->setUsrReportsTo ( '');
|
||||
$oUser->setDepUid( '' );
|
||||
$oUser->setUsrReportsTo( '' );
|
||||
$oUser->save();
|
||||
}
|
||||
}
|
||||
catch (exception $oError) {
|
||||
} catch (exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
@@ -552,18 +566,17 @@ function getDepartments( $DepParent ) {
|
||||
* @param string $sGroupUID
|
||||
* @return object
|
||||
*/
|
||||
function getAvailableUsersCriteria($sGroupUID = '')
|
||||
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');
|
||||
$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) {
|
||||
} catch (exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
@@ -573,80 +586,88 @@ function getDepartments( $DepParent ) {
|
||||
* @param string $sDepUID
|
||||
* @return object
|
||||
*/
|
||||
function cantUsersInDepartment ( $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);
|
||||
$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 = UsersPeer::doSelectRS( $c );
|
||||
$rs->next();
|
||||
$row = $rs->getRow();
|
||||
$count = $row[0];
|
||||
return $count;
|
||||
}
|
||||
catch (exception $oError) {
|
||||
} catch (exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
function loadByGroupname ( $Groupname ) {
|
||||
$c = new Criteria('workflow');
|
||||
|
||||
function loadByGroupname ($Groupname)
|
||||
{
|
||||
$c = new Criteria( 'workflow' );
|
||||
$del = DBAdapter::getStringDelimiter();
|
||||
|
||||
$c->clearSelectColumns();
|
||||
$c->addSelectColumn( ContentPeer::CON_CATEGORY );
|
||||
$c->addSelectColumn( ContentPeer::CON_VALUE );
|
||||
|
||||
$c->add(ContentPeer::CON_CATEGORY, 'DEPO_TITLE');
|
||||
$c->add(ContentPeer::CON_VALUE, $Groupname);
|
||||
$c->add(ContentPeer::CON_LANG, SYS_LANG );
|
||||
$c->add( ContentPeer::CON_CATEGORY, 'DEPO_TITLE' );
|
||||
$c->add( ContentPeer::CON_VALUE, $Groupname );
|
||||
$c->add( ContentPeer::CON_LANG, SYS_LANG );
|
||||
return $c;
|
||||
}
|
||||
|
||||
//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()){
|
||||
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);
|
||||
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);
|
||||
$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();
|
||||
$departments = array ();
|
||||
while ($row = $dataset->getRow()) {
|
||||
if (!isset($departments[$row['DEP_UID']])) {
|
||||
if (! isset( $departments[$row['DEP_UID']] )) {
|
||||
$departments[$row['DEP_UID']] = $row;
|
||||
}
|
||||
$dataset->next();
|
||||
}
|
||||
return $departments;
|
||||
}
|
||||
}
|
||||
// Department
|
||||
|
||||
} // Department
|
||||
|
||||
Reference in New Issue
Block a user