Exemple #1
0
    /**

     * Delete User

     *

     * @param string $usrUid Unique id of User

     *

     * return void

     */

    public function delete($usrUid)

    {

        try {

            //Verify data

            $this->throwExceptionIfNotExistsUser($usrUid, $this->arrayFieldNameForException["usrUid"]);



            \G::LoadClass('case');

            $oProcessMap = new \Cases();

            $USR_UID = $usrUid;

            $total = 0;

            $history = 0;

            $c = $oProcessMap->getCriteriaUsersCases('TO_DO', $USR_UID);

            $total += \ApplicationPeer::doCount($c);

            $c = $oProcessMap->getCriteriaUsersCases('DRAFT', $USR_UID);

            $total += \ApplicationPeer::doCount($c);

            $c = $oProcessMap->getCriteriaUsersCases('COMPLETED', $USR_UID);

            $history += \ApplicationPeer::doCount($c);

            $c = $oProcessMap->getCriteriaUsersCases('CANCELLED', $USR_UID);

            $history += \ApplicationPeer::doCount($c);

            if ($total > 0) {

                throw new \Exception(\G::LoadTranslation("ID_USER_CAN_NOT_BE_DELETED", array($USR_UID)));

            } else {

                $UID = $usrUid;

                \G::LoadClass('tasks');

                $oTasks = new \Tasks();

                $oTasks->ofToAssignUserOfAllTasks($UID);

                \G::LoadClass('groups');

                $oGroups = new \Groups();

                $oGroups->removeUserOfAllGroups($UID);

                $this->changeUserStatus($UID, 'CLOSED');

                $_GET['USR_USERNAME'] = '';

                $this->updateUser(array('USR_UID' => $UID, 'USR_USERNAME' => $_GET['USR_USERNAME']), '');

                require_once (PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "Users.php");

                $oUser = new \Users();

                $aFields = $oUser->load($UID);

                $aFields['USR_STATUS'] = 'CLOSED';

                $aFields['USR_USERNAME'] = '';

                $oUser->update($aFields);

                //Delete Dashboard

                require_once (PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "DashletInstance.php");

                $criteria = new \Criteria( 'workflow' );

                $criteria->add( \DashletInstancePeer::DAS_INS_OWNER_UID, $UID );

                $criteria->add( \DashletInstancePeer::DAS_INS_OWNER_TYPE , 'USER');

                \DashletInstancePeer::doDelete( $criteria );

            }

        } catch (\Exception $e) {

            throw $e;

        }

    }