2010-12-02 23:34:41 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Department.php
|
2011-01-31 14:14:55 +00:00
|
|
|
* @package workflow.engine.classes.model
|
2011-10-10 13:25:59 -04:00
|
|
|
*
|
2010-12-02 23:34:41 +00:00
|
|
|
* ProcessMaker Open Source Edition
|
2011-01-31 14:14:55 +00:00
|
|
|
* Copyright (C) 2004 - 2011 Colosa Inc.
|
2011-10-10 13:25:59 -04:00
|
|
|
*
|
2010-12-02 23:34:41 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Affero General Public License for more details.
|
2011-10-10 13:25:59 -04:00
|
|
|
*
|
2010-12-02 23:34:41 +00:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-10-10 13:25:59 -04:00
|
|
|
*
|
|
|
|
|
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
2010-12-02 23:34:41 +00:00
|
|
|
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
2011-10-10 13:25:59 -04:00
|
|
|
*
|
2010-12-02 23:34:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
require_once 'classes/model/om/BaseDepartment.php';
|
|
|
|
|
require_once 'classes/model/Users.php';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Skeleton subclass for representing a row from the 'DEPARTMENT' table.
|
|
|
|
|
*
|
2011-10-10 13:25:59 -04:00
|
|
|
*
|
2010-12-02 23:34:41 +00:00
|
|
|
*
|
|
|
|
|
* You should add additional methods to this class to meet the
|
|
|
|
|
* application requirements. This class will only be generated as
|
|
|
|
|
* long as it does not already exist in the output directory.
|
|
|
|
|
*
|
2011-01-31 14:14:55 +00:00
|
|
|
* @package workflow.engine.classes.model
|
2010-12-02 23:34:41 +00:00
|
|
|
*/
|
|
|
|
|
class Department extends BaseDepartment {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected $depo_title = '';
|
|
|
|
|
/**
|
|
|
|
|
* Create the Department
|
2011-10-10 13:25:59 -04:00
|
|
|
*
|
|
|
|
|
* @param array $aData
|
2010-12-02 23:34:41 +00:00
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
function create ($aData ) {
|
|
|
|
|
$con = Propel::getConnection( DepartmentPeer::DATABASE_NAME );
|
|
|
|
|
try {
|
2011-10-10 13:25:59 -04:00
|
|
|
if ( isset ( $aData['DEP_UID'] ) )
|
2010-12-02 23:34:41 +00:00
|
|
|
$this->setDepUid ( $aData['DEP_UID'] );
|
2011-10-10 13:25:59 -04:00
|
|
|
else
|
2010-12-02 23:34:41 +00:00
|
|
|
$this->setDepUid ( G::generateUniqueID() );
|
2011-10-10 13:25:59 -04:00
|
|
|
|
|
|
|
|
if ( isset ( $aData['DEP_PARENT'] ) )
|
2010-12-02 23:34:41 +00:00
|
|
|
$this->setDepParent ( $aData['DEP_PARENT'] );
|
2011-10-10 13:25:59 -04:00
|
|
|
else
|
2010-12-02 23:34:41 +00:00
|
|
|
$this->setDepParent ( '' );
|
2011-10-10 13:25:59 -04:00
|
|
|
|
|
|
|
|
if ( isset ( $aData['DEP_MANAGER'] ) )
|
2010-12-02 23:34:41 +00:00
|
|
|
$this->setDepManager ( $aData['DEP_MANAGER'] );
|
2011-10-10 13:25:59 -04:00
|
|
|
else
|
2010-12-02 23:34:41 +00:00
|
|
|
$this->setDepManager ( '' );
|
2011-10-10 13:25:59 -04:00
|
|
|
|
|
|
|
|
if ( isset ( $aData['DEP_LOCATION'] ) )
|
2010-12-02 23:34:41 +00:00
|
|
|
$this->setDepLocation ( $aData['DEP_LOCATION'] );
|
2011-10-10 13:25:59 -04:00
|
|
|
else
|
2010-12-02 23:34:41 +00:00
|
|
|
$this->setDepLocation ( '' );
|
2011-10-10 13:25:59 -04:00
|
|
|
|
|
|
|
|
if ( isset ( $aData['DEP_STATUS'] ) )
|
2010-12-02 23:34:41 +00:00
|
|
|
$this->setDepStatus ( $aData['DEP_STATUS'] );
|
2011-10-10 13:25:59 -04:00
|
|
|
else
|
2010-12-02 23:34:41 +00:00
|
|
|
$this->setDepStatus ( 'ACTIVE' );
|
|
|
|
|
|
2011-10-10 13:25:59 -04:00
|
|
|
if ( isset ( $aData['DEP_REF_CODE'] ) )
|
2010-12-02 23:34:41 +00:00
|
|
|
$this->setDepRefCode ( $aData['DEP_REF_CODE'] );
|
2011-10-10 13:25:59 -04:00
|
|
|
else
|
2010-12-02 23:34:41 +00:00
|
|
|
$this->setDepRefCode ( '' );
|
|
|
|
|
|
2011-10-10 13:25:59 -04:00
|
|
|
if ( isset ( $aData['DEP_LDAP_DN'] ) )
|
2010-12-02 23:34:41 +00:00
|
|
|
$this->setDepLdapDn ( $aData['DEP_LDAP_DN'] );
|
2011-10-10 13:25:59 -04:00
|
|
|
else
|
2010-12-02 23:34:41 +00:00
|
|
|
$this->setDepLdapDn ( '' );
|
|
|
|
|
|
2011-10-10 13:25:59 -04:00
|
|
|
if ( isset ( $aData['DEP_TITLE'] ) )
|
2010-12-02 23:34:41 +00:00
|
|
|
$this->setDepTitle ( $aData['DEP_TITLE'] );
|
2011-10-10 13:25:59 -04:00
|
|
|
else
|
2010-12-02 23:34:41 +00:00
|
|
|
$this->setDepTitle ( '' );
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
if ( $this->validate() ) {
|
2011-10-10 13:25:59 -04:00
|
|
|
$con->begin();
|
2010-12-02 23:34:41 +00:00
|
|
|
$res = $this->save();
|
2011-10-10 13:25:59 -04:00
|
|
|
|
|
|
|
|
$con->commit();
|
2010-12-02 23:34:41 +00:00
|
|
|
return $this->getDepUid();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$msg = '';
|
2011-10-10 13:25:59 -04:00
|
|
|
foreach($this->getValidationFailures() as $objValidationFailure)
|
2010-12-02 23:34:41 +00:00
|
|
|
$msg .= $objValidationFailure->getMessage() . "<br/>";
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
throw ( new Exception ( " The Department row cannot be created $msg " ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception $e) {
|
2011-10-10 13:25:59 -04:00
|
|
|
$con->rollback();
|
2010-12-02 23:34:41 +00:00
|
|
|
throw ($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
/**
|
|
|
|
|
* Get the [depo_title] column value.
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getDepTitle()
|
|
|
|
|
{
|
|
|
|
|
if ( $this->getDepUid() == '' ) {
|
|
|
|
|
throw ( new Exception( "Error in getDepTitle, the DEP_UID can't be blank") );
|
|
|
|
|
}
|
|
|
|
|
$lang = defined ( 'SYS_LANG') ? SYS_LANG : 'en';
|
|
|
|
|
$this->depo_title = Content::load ( 'DEPO_TITLE', '', $this->getDepUid(), $lang );
|
|
|
|
|
return $this->depo_title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the [depo_title] column value.
|
2011-10-10 13:25:59 -04:00
|
|
|
*
|
2010-12-02 23:34:41 +00:00
|
|
|
* @param string $v new value
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function setDepTitle($v)
|
|
|
|
|
{
|
|
|
|
|
if ( $this->getDepUid() == '' ) {
|
|
|
|
|
throw ( new Exception( "Error in setGrpTitle, the GRP_UID can't be blank") );
|
|
|
|
|
}
|
|
|
|
|
// Since the native PHP type for this column is string,
|
|
|
|
|
// we will cast the input to a string (if it is not).
|
|
|
|
|
if ($v !== null && !is_string($v)) {
|
2011-10-10 13:25:59 -04:00
|
|
|
$v = (string) $v;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->depo_title !== $v || $v === '') {
|
|
|
|
|
$this->depo_title = $v;
|
|
|
|
|
$lang = defined ( 'SYS_LANG') ? SYS_LANG : 'en';
|
|
|
|
|
$res = Content::addContent( 'DEPO_TITLE', '', $this->getDepUid(), $lang, $this->depo_title );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // set()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load the Process row specified in [depo_id] column value.
|
2011-10-10 13:25:59 -04:00
|
|
|
*
|
|
|
|
|
* @param string $ProUid the uid of the Prolication
|
|
|
|
|
* @return array $Fields the fields
|
2010-12-02 23:34:41 +00:00
|
|
|
*/
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
function Load ( $DepUid ) {
|
|
|
|
|
$con = Propel::getConnection(DepartmentPeer::DATABASE_NAME);
|
|
|
|
|
try {
|
|
|
|
|
$oDept = DepartmentPeer::retrieveByPk( $DepUid );
|
2010-12-03 15:43:29 +00:00
|
|
|
if (is_object ($oDept) && get_class ($oDept) == 'Department' ) {
|
2010-12-02 23:34:41 +00:00
|
|
|
$aFields = $oDept->toArray(BasePeer::TYPE_FIELDNAME);
|
|
|
|
|
$this->fromArray ($aFields, BasePeer::TYPE_FIELDNAME );
|
|
|
|
|
$aFields['DEPO_TITLE'] = $oDept->getDepTitle();
|
|
|
|
|
return $aFields;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
throw(new Exception( "The row '$DepUid' in table Department doesn't exist!" ));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception $oError) {
|
|
|
|
|
throw($oError);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the Dep row
|
|
|
|
|
* @param array $aData
|
|
|
|
|
* @return variant
|
|
|
|
|
**/
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
public function update($aData)
|
|
|
|
|
{
|
|
|
|
|
$con = Propel::getConnection( DepartmentPeer::DATABASE_NAME );
|
|
|
|
|
try {
|
2011-10-10 13:25:59 -04:00
|
|
|
$con->begin();
|
2010-12-02 23:34:41 +00:00
|
|
|
$oPro = DepartmentPeer::retrieveByPK( $aData['DEP_UID'] );
|
2010-12-06 15:13:43 +00:00
|
|
|
if (is_object($oPro) && get_class ($oPro) == 'Department' ) {
|
2010-12-02 23:34:41 +00:00
|
|
|
$oPro->fromArray( $aData, BasePeer::TYPE_FIELDNAME );
|
|
|
|
|
if ($oPro->validate()) {
|
|
|
|
|
if ( isset ( $aData['DEPO_TITLE'] ) )
|
|
|
|
|
$oPro->setDepTitle( $aData['DEPO_TITLE'] );
|
|
|
|
|
if ( isset ( $aData['DEP_STATUS'] ) )
|
|
|
|
|
$oPro->setDepStatus( $aData['DEP_STATUS'] );
|
|
|
|
|
if ( isset ( $aData['DEP_PARENT'] ) )
|
|
|
|
|
$oPro->setDepParent( $aData['DEP_PARENT'] );
|
|
|
|
|
if ( isset ( $aData['DEP_MANAGER'] ) )
|
|
|
|
|
$oPro->setDepManager( $aData['DEP_MANAGER'] );
|
|
|
|
|
$res = $oPro->save();
|
2011-10-10 13:25:59 -04:00
|
|
|
$con->commit();
|
2010-12-02 23:34:41 +00:00
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$msg = '';
|
2011-10-10 13:25:59 -04:00
|
|
|
foreach($this->getValidationFailures() as $objValidationFailure)
|
2010-12-02 23:34:41 +00:00
|
|
|
$msg .= $objValidationFailure->getMessage() . "<br/>";
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
throw ( new PropelException ( 'The Department row cannot be created!', new PropelException ( $msg ) ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2011-10-10 13:25:59 -04:00
|
|
|
$con->rollback();
|
2010-12-02 23:34:41 +00:00
|
|
|
throw(new Exception( "The row '" . $aData['DEP_UID'] . "' in table Department doesn't exist!" ));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception $oError) {
|
|
|
|
|
throw($oError);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove the row
|
2011-10-10 13:25:59 -04:00
|
|
|
* @param array $aData or string $ProUid
|
2010-12-02 23:34:41 +00:00
|
|
|
* @return string
|
|
|
|
|
**/
|
|
|
|
|
public function remove($ProUid)
|
|
|
|
|
{
|
|
|
|
|
if ( is_array ( $ProUid ) ) {
|
|
|
|
|
$ProUid = ( isset ( $ProUid['DEP_UID'] ) ? $ProUid['DEP_UID'] : '' );
|
|
|
|
|
}
|
|
|
|
|
try {
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
$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);
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
$oDataset->next();
|
|
|
|
|
$aFields = array();
|
|
|
|
|
while ($aRow = $oDataset->getRow()) {
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
$aFields['USR_UID'] = $aRow['USR_UID'];
|
|
|
|
|
$aFields['DEP_UID'] = '';
|
|
|
|
|
$oDepto = UsersPeer::retrieveByPk($aFields['USR_UID']);
|
2010-12-06 15:13:43 +00:00
|
|
|
if (is_object($oDepto) && get_class($oDepto) == 'UsersPeer') {
|
2010-12-02 23:34:41 +00:00
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
$oDepto = new Users();
|
|
|
|
|
$oDepto->update($aFields);
|
|
|
|
|
}
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
$oDataset->next();
|
|
|
|
|
}
|
2011-10-10 13:25:59 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
$oPro = DepartmentPeer::retrieveByPK( $ProUid );
|
|
|
|
|
if (!is_null($oPro))
|
|
|
|
|
{
|
|
|
|
|
Content::removeContent('DEPO_TITLE', '', $oPro->getDepUid());
|
|
|
|
|
Content::removeContent('DEPO_DESCRIPTION', '', $oPro->getDepUid());
|
|
|
|
|
return $oPro->delete();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
throw(new Exception( "The row '$ProUid' in table Group doesn't exist!" ));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception $oError) {
|
|
|
|
|
throw($oError);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load the Department row specified in [depo_id] column value.
|
2011-10-10 13:25:59 -04:00
|
|
|
*
|
|
|
|
|
* @param string $ProUid the uid of the Prolication
|
|
|
|
|
* @return array $Fields the fields
|
2010-12-02 23:34:41 +00:00
|
|
|
*/
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
function existsDepartment( $DepUid ) {
|
|
|
|
|
$con = Propel::getConnection(DepartmentPeer::DATABASE_NAME);
|
|
|
|
|
$oPro = DepartmentPeer::retrieveByPk( $DepUid );
|
2010-12-06 15:13:43 +00:00
|
|
|
if (is_object($oPro) && get_class ($oPro) == 'Department' ) {
|
2010-12-02 23:34:41 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function existsUserInDepartment( $depId, $userId ) {
|
|
|
|
|
$con = Propel::getConnection(DepartmentPeer::DATABASE_NAME);
|
|
|
|
|
$oUser = UsersPeer::retrieveByPk( $userId );
|
2010-12-06 15:13:43 +00:00
|
|
|
if (is_object($oUser) && get_class ($oUser) == 'Users' ) {
|
2010-12-02 23:34:41 +00:00
|
|
|
if ( $oUser->getDepUid() == $depId )
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
function updateDepartmentManager ($depId) {
|
|
|
|
|
$managerId = '';
|
|
|
|
|
$depParent = '';
|
|
|
|
|
$oDept = DepartmentPeer::retrieveByPk( $depId );
|
2010-12-06 15:13:43 +00:00
|
|
|
if (is_object($oDept) && get_class ($oDept) == 'Department' ) {
|
2010-12-02 23:34:41 +00:00
|
|
|
$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);
|
|
|
|
|
|
|
|
|
|
// Create a Criteria object includes the value you want to set
|
|
|
|
|
$updateCriteria = new Criteria('workflow');
|
|
|
|
|
$updateCriteria->add(UsersPeer::USR_REPORTS_TO, $managerId );
|
|
|
|
|
BasePeer::doUpdate($selectCriteria, $updateCriteria, $conn);
|
|
|
|
|
|
|
|
|
|
// update manager's manager, getting the manager of PARENT DEPARTMENT in order to enable scalating
|
|
|
|
|
$oUser = UsersPeer::retrieveByPk( $managerId );
|
2010-12-06 15:13:43 +00:00
|
|
|
if (is_object($oUser) && get_class ($oUser) == 'Users' ) {
|
2010-12-02 23:34:41 +00:00
|
|
|
$oDept = DepartmentPeer::retrieveByPk( $depParent );
|
|
|
|
|
$oUser->setUsrReportsTo( '' ); //by default no manager
|
2011-08-09 12:15:01 -04:00
|
|
|
if (is_object($oDept) && get_class ($oDept) == 'Department' ) {
|
2010-12-02 23:34:41 +00:00
|
|
|
$managerParentId = $oDept->getDepManager( );
|
|
|
|
|
if ( trim($managerParentId) != '' ) {
|
|
|
|
|
$oUser->setUsrReportsTo( $managerParentId );
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-10-10 13:25:59 -04:00
|
|
|
$oUser->save();
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
// 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);
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
$oDataset->next();
|
|
|
|
|
while ( $aRow = $oDataset->getRow() ) {
|
|
|
|
|
$oUser = UsersPeer::retrieveByPk($aRow['DEP_MANAGER']);
|
2010-12-06 15:13:43 +00:00
|
|
|
if (is_object($oUser) && get_class($oUser) == 'Users') {
|
2010-12-02 23:34:41 +00:00
|
|
|
$oUser->setUsrReportsTo ( $managerId );
|
|
|
|
|
$oUser->save();
|
|
|
|
|
}
|
|
|
|
|
$oDataset->next();
|
2011-10-10 13:25:59 -04:00
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//add an user to a department and sync all about manager info
|
|
|
|
|
function addUserToDepartment( $depId, $userId, $manager, $updateManager = false ) {
|
|
|
|
|
try {
|
|
|
|
|
//update the field in user table
|
|
|
|
|
$oUser = UsersPeer::retrieveByPk( $userId );
|
2010-12-06 15:13:43 +00:00
|
|
|
if (is_object($oUser) && get_class ($oUser) == 'Users' ) {
|
2010-12-02 23:34:41 +00:00
|
|
|
$oUser->setDepUid( $depId );
|
|
|
|
|
$oUser->save();
|
|
|
|
|
}
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
//if the user is a manager update Department Table
|
|
|
|
|
if ( $manager ) {
|
|
|
|
|
$oDept = DepartmentPeer::retrieveByPk( $depId );
|
2010-12-06 15:13:43 +00:00
|
|
|
if (is_object($oDept) && get_class ($oDept) == 'Department' ) {
|
2010-12-02 23:34:41 +00:00
|
|
|
$oDept->setDepManager( $userId );
|
|
|
|
|
$oDept->save();
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-10-10 13:25:59 -04:00
|
|
|
|
|
|
|
|
//now update the reportsto to all
|
2010-12-02 23:34:41 +00:00
|
|
|
if ( $updateManager ) {
|
|
|
|
|
$this->updateDepartmentManager ($depId);
|
2011-10-10 13:25:59 -04:00
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch ( Exception $oError) {
|
|
|
|
|
throw($oError);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// select departments
|
|
|
|
|
// this function is used to draw the hierachy tree view
|
2011-02-07 16:54:10 +00:00
|
|
|
function getDepartments( $DepParent ) {
|
2010-12-02 23:34:41 +00:00
|
|
|
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);
|
2011-02-07 16:54:10 +00:00
|
|
|
global $RBAC;
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
foreach( $objects as $oDepartment ) {
|
|
|
|
|
$node = array();
|
|
|
|
|
$node['DEP_UID'] = $oDepartment->getDepUid();
|
|
|
|
|
$node['DEP_PARENT'] = $oDepartment->getDepParent();
|
|
|
|
|
$node['DEP_TITLE'] = $oDepartment->getDepTitle();
|
2011-02-07 16:54:10 +00:00
|
|
|
$node['DEP_STATUS'] = $oDepartment->getDepStatus();
|
|
|
|
|
$node['DEP_MANAGER'] = $oDepartment->getDepManager();
|
2011-10-10 13:25:59 -04:00
|
|
|
$node['DEP_LDAP_DN'] = $oDepartment->getDepLdapDn();
|
2010-12-02 23:34:41 +00:00
|
|
|
$node['DEP_LAST'] = 0;
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2011-02-07 16:54:10 +00:00
|
|
|
$manager = $oDepartment->getDepManager();
|
|
|
|
|
if ($manager != ''){
|
|
|
|
|
$UserUID = $RBAC->load($manager);
|
2011-02-15 19:19:25 +00:00
|
|
|
$node['DEP_MANAGER_USERNAME'] = isset($UserUID['USR_USERNAME'])?$UserUID['USR_USERNAME']:'';
|
|
|
|
|
$node['DEP_MANAGER_FIRSTNAME'] = isset($UserUID['USR_FIRSTNAME'])?$UserUID['USR_FIRSTNAME']:'';
|
2011-04-15 18:43:03 -04:00
|
|
|
$node['DEP_MANAGER_LASTNAME'] = isset($UserUID['USR_LASTNAME'])?$UserUID['USR_LASTNAME']:'';
|
2011-02-07 16:54:10 +00:00
|
|
|
}else{
|
2011-10-10 13:25:59 -04:00
|
|
|
$node['DEP_MANAGER_USERNAME'] = '';
|
2011-02-07 16:54:10 +00:00
|
|
|
$node['DEP_MANAGER_FIRSTNAME'] = '';
|
|
|
|
|
$node['DEP_MANAGER_LASTNAME'] = '';
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
|
|
|
|
$criteriaCount = new Criteria('workflow');
|
|
|
|
|
$criteriaCount->clearSelectColumns();
|
|
|
|
|
$criteriaCount->addSelectColumn( 'COUNT(*)' );
|
|
|
|
|
$criteriaCount->add(DepartmentPeer::DEP_PARENT, $oDepartment->getDepUid(), Criteria::EQUAL);
|
|
|
|
|
$rs = DepartmentPeer::doSelectRS($criteriaCount);
|
|
|
|
|
$rs->next();
|
|
|
|
|
$row = $rs->getRow();
|
|
|
|
|
$node['HAS_CHILDREN'] = $row[0];
|
|
|
|
|
$result[] = $node;
|
|
|
|
|
}
|
|
|
|
|
if ( count($result) >= 1 )
|
|
|
|
|
$result[ count($result) -1 ]['DEP_LAST'] = 1;
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
catch (exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2012-01-27 17:53:06 -04:00
|
|
|
/**
|
|
|
|
|
* Check department name exist in the level
|
|
|
|
|
* @param string $departmentName name of the department
|
|
|
|
|
* @param string $parentUID parent UID of the department
|
|
|
|
|
* @param string $departmentUID department UID
|
|
|
|
|
* @return boolean $Fields true or false
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
function checkDepartmentName($departmentName, $parentUID, $departmentUID = '' )
|
|
|
|
|
{
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
|
|
|
|
|
$oCriteria->clearSelectColumns();
|
|
|
|
|
$oCriteria->addSelectColumn( ContentPeer::CON_CATEGORY );
|
|
|
|
|
$oCriteria->addSelectColumn( ContentPeer::CON_VALUE );
|
|
|
|
|
$oCriteria->addSelectColumn( DepartmentPeer::DEP_PARENT );
|
|
|
|
|
$oCriteria->add(ContentPeer::CON_CATEGORY, 'DEPO_TITLE');
|
|
|
|
|
$oCriteria->addJoin(ContentPeer::CON_ID, DepartmentPeer::DEP_UID, Criteria::LEFT_JOIN);
|
|
|
|
|
$oCriteria->add(ContentPeer::CON_VALUE, $departmentName);
|
|
|
|
|
$oCriteria->add(DepartmentPeer::DEP_UID, $departmentUID, Criteria::NOT_EQUAL);
|
|
|
|
|
$oCriteria->add(ContentPeer::CON_LANG, SYS_LANG );
|
|
|
|
|
$oCriteria->add(DepartmentPeer::DEP_PARENT, $parentUID);
|
|
|
|
|
|
|
|
|
|
$oDataset = DepartmentPeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
$aRow = $oDataset->getRow();
|
|
|
|
|
|
|
|
|
|
return ($aRow) ? true : false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
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);
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
$rs = UsersPeer::doSelectRS($oCriteria);
|
|
|
|
|
$rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
$oUser = new Users();
|
2011-10-10 13:25:59 -04:00
|
|
|
$aUsers[] = array('USR_UID' =>'char', 'USR_USERNAME' =>'char','USR_FULLNAME' =>'char', 'USR_REPORTS_TO'=>'char','USR_MANAGER' =>'char');
|
2010-12-02 23:34:41 +00:00
|
|
|
$rs->next();
|
|
|
|
|
$row = $rs->getRow();
|
|
|
|
|
while( is_array($row) ) {
|
|
|
|
|
$usrFields = $oUser->LoadDetails( $row['USR_UID'] );
|
|
|
|
|
$row['USR_USERNAME'] = $usrFields['USR_USERNAME'];
|
|
|
|
|
$row['USR_FULLNAME'] = $usrFields['USR_FULLNAME'];
|
|
|
|
|
$row['USR_MANAGER'] = $row['USR_UID'] == $sManagerUid ? G::loadTranslation("ID_YES") : G::loadTranslation("ID_NO");
|
|
|
|
|
$row['DEP_UID'] = $sDepUid;
|
|
|
|
|
if ( $row['USR_REPORTS_TO'] != '' ) {
|
|
|
|
|
try {
|
|
|
|
|
$managerFields = $oUser->LoadDetails( $row['USR_REPORTS_TO'] );
|
|
|
|
|
$row['USR_REPORTS_NAME'] = $managerFields['USR_FULLNAME'];
|
|
|
|
|
}
|
|
|
|
|
catch (exception $e) {
|
|
|
|
|
$row['USR_REPORTS_NAME'] = '.';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
$row['USR_REPORTS_NAME'] = '.';
|
|
|
|
|
$aUsers[] = $row;
|
|
|
|
|
$rs->next();
|
|
|
|
|
$row = $rs->getRow();
|
|
|
|
|
}
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
G::LoadClass('ArrayPeer');
|
|
|
|
|
global $_DBArray;
|
|
|
|
|
$_DBArray['DepartmentUserList'] = $aUsers ;
|
|
|
|
|
$_SESSION['_DBArray'] = $_DBArray;
|
|
|
|
|
$oCriteriaT = new Criteria('dbarray');
|
|
|
|
|
$oCriteriaT->setDBArrayTable('DepartmentUserList');
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
return $oCriteriaT;
|
|
|
|
|
}
|
|
|
|
|
catch (exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
/*
|
|
|
|
|
* Remove a user from Departments
|
|
|
|
|
* @param string $DepUid, $UsrUid
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2011-10-10 13:25:59 -04:00
|
|
|
function removeUserFromDepartment($DepUid, $UsrUid) {
|
2010-12-02 23:34:41 +00:00
|
|
|
$aFields = array ('USR_UID'=> $UsrUid,'DEP_UID'=> '', 'USR_REPORTS_TO' => '');
|
|
|
|
|
try {
|
|
|
|
|
$oUser = UsersPeer::retrieveByPk( $UsrUid );
|
2010-12-06 15:13:43 +00:00
|
|
|
if (is_object($oUser) && get_class($oUser) == 'Users' ) {
|
2010-12-02 23:34:41 +00:00
|
|
|
//$oDepto = new Users();
|
|
|
|
|
$oUser->setDepUid ( '');
|
|
|
|
|
$oUser->setUsrReportsTo ( '');
|
|
|
|
|
$oUser->save();
|
2011-10-10 13:25:59 -04:00
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
catch (exception $oError) {
|
|
|
|
|
throw ($oError);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Return the available users list criteria object
|
|
|
|
|
* @param string $sGroupUID
|
|
|
|
|
* @return object
|
|
|
|
|
*/
|
|
|
|
|
function getAvailableUsersCriteria($sGroupUID = '')
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->addSelectColumn(UsersPeer::USR_UID);
|
|
|
|
|
$oCriteria->addSelectColumn(UsersPeer::USR_FIRSTNAME);
|
|
|
|
|
$oCriteria->addSelectColumn(UsersPeer::USR_LASTNAME);
|
|
|
|
|
$oCriteria->add(UsersPeer::DEP_UID, "", Criteria::EQUAL);
|
|
|
|
|
$oCriteria->add(UsersPeer::USR_STATUS, 'ACTIVE');
|
|
|
|
|
return $oCriteria;
|
|
|
|
|
}
|
|
|
|
|
catch (exception $oError) {
|
|
|
|
|
throw ($oError);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
/*
|
|
|
|
|
* Return the cant Users In Department
|
|
|
|
|
* @param string $sDepUID
|
|
|
|
|
* @return object
|
|
|
|
|
*/
|
|
|
|
|
function cantUsersInDepartment ( $sDepUID ) {
|
|
|
|
|
try {
|
|
|
|
|
$c = new Criteria('workflow');
|
|
|
|
|
$c->addSelectColumn('COUNT(*)');
|
|
|
|
|
$c->add(UsersPeer::USR_STATUS, 'CLOSED', Criteria::NOT_EQUAL);
|
|
|
|
|
$c->add(UsersPeer::DEP_UID, $sDepUID);
|
|
|
|
|
|
|
|
|
|
$rs = UsersPeer::doSelectRS($c);
|
|
|
|
|
$rs->next();
|
|
|
|
|
$row = $rs->getRow();
|
|
|
|
|
$count = $row[0];
|
|
|
|
|
return $count;
|
|
|
|
|
}
|
|
|
|
|
catch (exception $oError) {
|
|
|
|
|
throw ($oError);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-10-10 13:25:59 -04:00
|
|
|
function loadByGroupname ( $Groupname ) {
|
|
|
|
|
$c = new Criteria('workflow');
|
2010-12-02 23:34:41 +00:00
|
|
|
$del = DBAdapter::getStringDelimiter();
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
$c->clearSelectColumns();
|
|
|
|
|
$c->addSelectColumn( ContentPeer::CON_CATEGORY );
|
|
|
|
|
$c->addSelectColumn( ContentPeer::CON_VALUE );
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
$c->add(ContentPeer::CON_CATEGORY, 'DEPO_TITLE');
|
|
|
|
|
$c->add(ContentPeer::CON_VALUE, $Groupname);
|
2011-10-10 13:25:59 -04:00
|
|
|
$c->add(ContentPeer::CON_LANG, SYS_LANG );
|
|
|
|
|
return $c;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2011-10-10 13:25:59 -04:00
|
|
|
|
2011-02-07 16:54:10 +00:00
|
|
|
//Added by Qennix
|
|
|
|
|
function getAllDepartmentsByUser(){
|
|
|
|
|
$c = new Criteria('workflow');
|
|
|
|
|
$c->addSelectColumn(UsersPeer::USR_UID);
|
|
|
|
|
$c->addAsColumn('DEP_TITLE', ContentPeer::CON_VALUE);
|
|
|
|
|
$c->add(ContentPeer::CON_LANG,defined(SYS_LANG)?SYS_LANG:'en');
|
|
|
|
|
$c->add(ContentPeer::CON_CATEGORY,'DEPO_TITLE');
|
|
|
|
|
$c->addJoin(UsersPeer::DEP_UID, ContentPeer::CON_ID,Criteria::INNER_JOIN);
|
|
|
|
|
$Dat = UsersPeer::doSelectRS ($c);
|
|
|
|
|
$Dat->setFetchmode (ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$aRows = Array();
|
|
|
|
|
while ($Dat->next()){
|
|
|
|
|
$row = $Dat->getRow();
|
|
|
|
|
$aRows[$row['USR_UID']] = $row['DEP_TITLE'];
|
|
|
|
|
}
|
|
|
|
|
return $aRows;
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2011-10-31 18:27:10 -04:00
|
|
|
function getDepartmentsForUser($userUid) {
|
|
|
|
|
$criteria = new Criteria('workflow');
|
2011-10-31 18:45:18 -04:00
|
|
|
$criteria->addSelectColumn(UsersPeer::DEP_UID);
|
2011-10-31 18:27:10 -04:00
|
|
|
$criteria->addAsColumn('DEP_TITLE', 'C.CON_VALUE');
|
|
|
|
|
$criteria->addAlias('C', 'CONTENT');
|
2011-10-31 18:45:18 -04:00
|
|
|
$criteria->addJoin(UsersPeer::DEP_UID, DepartmentPeer::DEP_UID, Criteria::LEFT_JOIN);
|
2011-10-31 18:27:10 -04:00
|
|
|
$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);
|
2011-10-31 18:45:18 -04:00
|
|
|
$criteria->add(UsersPeer::USR_UID, $userUid);
|
|
|
|
|
$criteria->add(UsersPeer::DEP_UID, '', Criteria::NOT_EQUAL);
|
2011-10-31 18:27:10 -04:00
|
|
|
$dataset = DepartmentPeer::doSelectRS($criteria);
|
|
|
|
|
$dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$dataset->next();
|
|
|
|
|
$departments = array();
|
|
|
|
|
while ($row = $dataset->getRow()) {
|
2011-10-31 18:45:18 -04:00
|
|
|
if (!isset($departments[$row['DEP_UID']])) {
|
|
|
|
|
$departments[$row['DEP_UID']] = $row;
|
|
|
|
|
}
|
2011-10-31 18:27:10 -04:00
|
|
|
$dataset->next();
|
|
|
|
|
}
|
|
|
|
|
return $departments;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
} // Department
|