Beispiel #1
0
 public static function create($params, $currentUser, $con)
 {
     // check role's permission
     $permission = RolePermissionQuery::create()->select('create_role')->findOneById($currentUser->role_id, $con);
     if (!$permission || $permission != 1) {
         throw new \Exception('Akses ditolak. Anda tidak mempunyai izin untuk melakukan operasi ini.');
     }
     // check whether role is already exist
     $role = RoleQuery::create()->filterByStatus('Active')->filterByName($params->name)->count($con);
     if ($role != 0) {
         throw new \Exception('Jabatan ' . $params->name . ' sudah ada dalam data');
     }
     // create new role
     $role = new Role();
     $role->setName($params->name)->save($con);
     // create new role permission with default value
     $rolePermission = new RolePermission();
     $rolePermission->setId($role->getId())->save($con);
     // log history
     $rowHistory = new RowHistory();
     $rowHistory->setRowId($role->getId())->setData('role')->setTime(time())->setOperation('create')->setUserId($currentUser->id)->save($con);
     $params->id = $role->getId();
     $results['success'] = true;
     $results['data'] = $params;
     return $results;
 }
 /**
  * Filter the query by a related \ORM\Role object
  *
  * @param \ORM\Role|ObjectCollection $role The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildNotificationOptionQuery The current query, for fluid interface
  */
 public function filterByRole($role, $comparison = null)
 {
     if ($role instanceof \ORM\Role) {
         return $this->addUsingAlias(NotificationOptionTableMap::COL_ROLE_ID, $role->getId(), $comparison);
     } elseif ($role instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(NotificationOptionTableMap::COL_ROLE_ID, $role->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByRole() only accepts arguments of type \\ORM\\Role or Collection');
     }
 }
Beispiel #3
0
 /**
  * Declares an association between this object and a ChildRole object.
  *
  * @param  ChildRole $v
  * @return $this|\ORM\RolePermission The current object (for fluent API support)
  * @throws PropelException
  */
 public function setRole(ChildRole $v = null)
 {
     if ($v === null) {
         $this->setId(NULL);
     } else {
         $this->setId($v->getId());
     }
     $this->aRole = $v;
     // Add binding for other direction of this 1:1 relationship.
     if ($v !== null) {
         $v->setPermission($this);
     }
     return $this;
 }
Beispiel #4
0
 /**
  * Exclude object from result
  *
  * @param   ChildRole $role Object to remove from the list of results
  *
  * @return $this|ChildRoleQuery The current query, for fluid interface
  */
 public function prune($role = null)
 {
     if ($role) {
         $this->addUsingAlias(RoleTableMap::COL_ID, $role->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Beispiel #5
0
 /**
  * Declares an association between this object and a ChildRole object.
  *
  * @param  ChildRole $v
  * @return $this|\ORM\NotificationOption The current object (for fluent API support)
  * @throws PropelException
  */
 public function setRole(ChildRole $v = null)
 {
     if ($v === null) {
         $this->setRoleId(NULL);
     } else {
         $this->setRoleId($v->getId());
     }
     $this->aRole = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the ChildRole object, it will not be re-added.
     if ($v !== null) {
         $v->addNotificationOption($this);
     }
     return $this;
 }