Пример #1
0
    /**

     * Validate the data if they are invalid (INSERT and UPDATE)

     *

     * @param string $userUid   Unique id of User

     * @param array  $arrayData Data

     *

     * return void Throw exception if data has an invalid value

     */

    public function throwExceptionIfDataIsInvalid($userUid, array $arrayData)

    {

        try {

            //Set variables

            $arrayUserData = ($userUid == "")? array() : $this->getUser($userUid, true);

            $flagInsert = ($userUid == "")? true : false;



            $arrayFinalData = array_merge($arrayUserData, $arrayData);



            //Verify data - Field definition.

            $process = new \ProcessMaker\BusinessModel\Process();



            $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, $flagInsert);



            //Verify data

            if (isset($arrayData["USR_USERNAME"])) {

                $this->throwExceptionIfExistsName($arrayData["USR_USERNAME"], $this->arrayFieldNameForException["usrUsername"], $userUid);

            }



            if (isset($arrayData["USR_EMAIL"])) {

                if (!filter_var($arrayData["USR_EMAIL"], FILTER_VALIDATE_EMAIL)) {

                    throw new \Exception($this->arrayFieldNameForException["usrEmail"] . ": " . \G::LoadTranslation("ID_INCORRECT_EMAIL"));

                }

            }



            if (isset($arrayData["USR_NEW_PASS"])) {

                $this->throwExceptionIfPasswordIsInvalid($arrayData["USR_NEW_PASS"], $this->arrayFieldNameForException["usrNewPass"]);

            }



            if (isset($arrayData["USR_REPLACED_BY"]) && $arrayData["USR_REPLACED_BY"] != "") {

                $obj = \UsersPeer::retrieveByPK($arrayData["USR_REPLACED_BY"]);



                if (is_null($obj)) {

                    throw new \Exception(\G::LoadTranslation("ID_USER_DOES_NOT_EXIST", array($this->arrayFieldNameForException["usrReplacedBy"], $arrayData["USR_REPLACED_BY"])));

                }

            }



            if (isset($arrayData["USR_DUE_DATE"])) {

                $arrayUserDueDate = explode("-", $arrayData["USR_DUE_DATE"]);



                if (ctype_digit($arrayUserDueDate[0])) {

                    if (!checkdate($arrayUserDueDate[1], $arrayUserDueDate[2], $arrayUserDueDate[0])) {

                        throw new \Exception($this->arrayFieldNameForException["usrDueDate"] . ": " . \G::LoadTranslation("ID_MSG_ERROR_DUE_DATE"));

                    }

                } else {

                    throw new \Exception($this->arrayFieldNameForException["usrDueDate"] . ": " . \G::LoadTranslation("ID_MSG_ERROR_DUE_DATE"));

                }

            }



            if (isset($arrayData["USR_ROLE"])) {

                require_once (PATH_RBAC_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "Roles.php");



                $criteria = new \Criteria("rbac");



                $criteria->add(\RolesPeer::ROL_CODE, $arrayData["USR_ROLE"]);

                $rsCriteria = \RolesPeer::doSelectRS($criteria);



                if (!$rsCriteria->next()) {

                    throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array($this->arrayFieldNameForException["usrRole"])));

                }

            }



            if (isset($arrayData["USR_COUNTRY"]) && $arrayData["USR_COUNTRY"] != "") {

                $obj = \IsoCountryPeer::retrieveByPK($arrayData["USR_COUNTRY"]);



                if (is_null($obj)) {

                    throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array($this->arrayFieldNameForException["usrCountry"])));

                }

            }



            if (isset($arrayData["USR_CITY"]) && $arrayData["USR_CITY"] != "") {

                if (!isset($arrayFinalData["USR_COUNTRY"]) || $arrayFinalData["USR_COUNTRY"] == "") {

                    throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array($this->arrayFieldNameForException["usrCountry"])));

                }



                $obj = \IsoSubdivisionPeer::retrieveByPK($arrayFinalData["USR_COUNTRY"], $arrayData["USR_CITY"]);



                if (is_null($obj)) {

                    throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array($this->arrayFieldNameForException["usrCity"])));

                }

            }



            if (isset($arrayData["USR_LOCATION"]) && $arrayData["USR_LOCATION"] != "") {

                if (!isset($arrayFinalData["USR_COUNTRY"]) || $arrayFinalData["USR_COUNTRY"] == "") {

                    throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array($this->arrayFieldNameForException["usrCountry"])));

                }



                $obj = \IsoLocationPeer::retrieveByPK($arrayFinalData["USR_COUNTRY"], $arrayData["USR_LOCATION"]);



                if (is_null($obj)) {

                    throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array($this->arrayFieldNameForException["usrLocation"])));

                }

            }



            if (isset($arrayData["USR_CALENDAR"]) && $arrayData["USR_CALENDAR"] != "") {

                $obj = \CalendarDefinitionPeer::retrieveByPK($arrayData["USR_CALENDAR"]);



                if (is_null($obj)) {

                    throw new \Exception(\G::LoadTranslation("ID_CALENDAR_DOES_NOT_EXIST", array($this->arrayFieldNameForException["usrCalendar"], $arrayData["USR_CALENDAR"])));

                }

            }



            if (isset($arrayData["DEP_UID"]) && $arrayData["DEP_UID"] != "") {

                $department = new \Department();



                if (!$department->existsDepartment($arrayData["DEP_UID"])) {

                    throw new \Exception(\G::LoadTranslation("ID_DEPARTMENT_NOT_EXIST", array($this->arrayFieldNameForException["depUid"], $arrayData["DEP_UID"])));

                }

            }

        } catch (\Exception $e) {

            throw $e;

        }

    }
Пример #2
0
 /**
  * Look for Children for department
  * @var array $dataDep. Data for child department
  *
  * @access public
  * @author Brayan Pereyra (Cochalo) <*****@*****.**>
  * @copyright Colosa - Bolivia
  *
  * @return array
  */
 protected function getChildren($dataDep)
 {
     $children = array();
     if ((int) $dataDep['HAS_CHILDREN'] > 0) {
         $oDepartment = new \Department();
         $aDepts = $oDepartment->getDepartments($dataDep['DEP_UID']);
         foreach ($aDepts as &$depData) {
             $depData['DEP_CHILDREN'] = $this->getChildren($depData);
             $depData = array_change_key_case($depData, CASE_LOWER);
             $children[] = $depData;
         }
     }
     return $children;
 }