Esempio n. 1
0
 /**
  * Implementation for 'GET' method for Rest API
  *
  * @param  mixed $icUid, $isUid Primary key
  *
  * @return array $result Returns array within multiple records or a single record depending if
  *                       a single selection was requested passing id(s) as param
  */
 protected function get($icUid = null, $isUid = null)
 {
     $result = array();
     try {
         $noArguments = true;
         $argumentList = func_get_args();
         foreach ($argumentList as $arg) {
             if (!is_null($arg)) {
                 $noArguments = false;
             }
         }
         if ($noArguments) {
             $criteria = new Criteria('workflow');
             $criteria->addSelectColumn(IsoSubdivisionPeer::IC_UID);
             $criteria->addSelectColumn(IsoSubdivisionPeer::IS_UID);
             $criteria->addSelectColumn(IsoSubdivisionPeer::IS_NAME);
             $dataset = AppEventPeer::doSelectRS($criteria);
             $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
             while ($dataset->next()) {
                 $result[] = $dataset->getRow();
             }
         } else {
             $record = IsoSubdivisionPeer::retrieveByPK($icUid, $isUid);
             if ($record) {
                 $result = $record->toArray(BasePeer::TYPE_FIELDNAME);
             } else {
                 $paramValues = "";
                 foreach ($argumentList as $arg) {
                     $paramValues .= strlen($paramValues) ? ', ' : '';
                     if (!is_null($arg)) {
                         $paramValues .= "{$arg}";
                     } else {
                         $paramValues .= "NULL";
                     }
                 }
                 throw new RestException(417, "table IsoSubdivision ({$paramValues})");
             }
         }
     } catch (RestException $e) {
         throw new RestException($e->getCode(), $e->getMessage());
     } catch (Exception $e) {
         throw new RestException(412, $e->getMessage());
     }
     return $result;
 }
Esempio n. 2
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;

        }

    }