Пример #1
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME,
  * TYPE_NUM. The default key type is the column's phpname (e.g. 'authorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = RolesPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setRolUid($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setRolParent($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setRolSystem($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setRolCode($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setRolCreateDate($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setRolUpdateDate($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setRolStatus($arr[$keys[6]]);
     }
 }
Пример #2
0
 function verifyByCode($sRolCode = '')
 {
     try {
         $oCriteria = new Criteria('rbac');
         $oCriteria->add(RolesPeer::ROL_CODE, $sRolCode);
         $oDataset = RolesPeer::doSelectRS($oCriteria);
         $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
         $oDataset->next();
         $aRow = $oDataset->getRow();
         if (is_array($aRow)) {
             return 1;
         } else {
             return 0;
         }
     } catch (exception $oError) {
         throw $oError;
     }
 }
Пример #3
0
     $config = array();
     $config[] = $arr;
     $c->aConfig = $config;
     $c->saveConfig('rolesList', 'pageSize', '', $_SESSION['USER_LOGGED']);
     echo '{success: true}';
     break;
 case 'checkRoleCode':
     $rol_code = $_POST['ROL_CODE'];
     $rol_uid = isset($_POST['ROL_UID']) ? $_POST['ROL_UID'] : '';
     $oCriteria = new Criteria('rbac');
     $oCriteria->addSelectColumn(RolesPeer::ROL_UID);
     $oCriteria->add(RolesPeer::ROL_CODE, $rol_code);
     if ($rol_uid != '') {
         $oCriteria->add(RolesPeer::ROL_UID, $rol_uid, Criteria::NOT_EQUAL);
     }
     $oDataset = RolesPeer::doSelectRS($oCriteria);
     $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
     if ($oDataset->next()) {
         $response = 'false';
     } else {
         $response = 'true';
     }
     echo '{success:' . $response . '}';
     break;
 case 'updatePermissionContent':
     /*
     $per_code = $_POST['PER_NAME'];
     $per_uid = isset( $_POST['PER_UID'] ) ? $_POST['PER_UID'] : '';
     require_once 'classes/model/Content.php';
     $oCriteria = new Criteria( 'workflow' );
     $oCriteria->add( ContentPeer::CON_CATEGORY, 'PER_NAME' );
Пример #4
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;

        }

    }
Пример #5
0
 /**
  * Get data of a Role
  *
  * @param string $roleUid       Unique id of Role
  * @param bool   $flagGetRecord Value that set the getting
  *
  * return array Return an array with data of a Role
  */
 public function getRole($roleUid, $flagGetRecord = false)
 {
     try {
         //Verify data
         $this->throwExceptionIfNotExistsRole($roleUid, $this->arrayFieldNameForException["roleUid"]);
         //Set variables
         if (!$flagGetRecord) {
             $content = new \Content();
             $role = new \Roles();
             $arrayContentByRole = $content->getAllContentsByRole();
         }
         //Get data
         //SQL
         $criteria = $this->getRoleCriteria();
         if (!$flagGetRecord) {
             $criteria->addAsColumn("ROL_TOTAL_USERS", "(SELECT COUNT(" . \UsersRolesPeer::ROL_UID . ") FROM " . \UsersRolesPeer::TABLE_NAME . " WHERE " . \UsersRolesPeer::ROL_UID . " = " . \RolesPeer::ROL_UID . ")");
         }
         $criteria->add(\RolesPeer::ROL_UID, $roleUid, \Criteria::EQUAL);
         $rsCriteria = \RolesPeer::doSelectRS($criteria);
         $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         $rsCriteria->next();
         $row = $rsCriteria->getRow();
         if (!$flagGetRecord) {
             if (isset($arrayContentByRole[$roleUid])) {
                 $roleName = $arrayContentByRole[$roleUid];
             } else {
                 $rowAux = $role->load($roleUid);
                 $roleName = $rowAux["ROL_NAME"];
             }
             $row["ROL_NAME"] = $roleName;
         }
         //Return
         return !$flagGetRecord ? $this->getRoleDataFromRecord($row) : $row;
     } catch (\Exception $e) {
         throw $e;
     }
 }
Пример #6
0
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      Connection $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(self::DATABASE_NAME);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria();
         $criteria->add(RolesPeer::ROL_UID, $pks, Criteria::IN);
         $objs = RolesPeer::doSelect($criteria, $con);
     }
     return $objs;
 }