Exemplo n.º 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;
 }
Exemplo n.º 2
0
 /**
  * Sets a single ChildRolePermission object as related to this object by a one-to-one relationship.
  *
  * @param  ChildRolePermission $v ChildRolePermission
  * @return $this|\ORM\Role The current object (for fluent API support)
  * @throws PropelException
  */
 public function setPermission(ChildRolePermission $v = null)
 {
     $this->singlePermission = $v;
     // Make sure that that the passed-in ChildRolePermission isn't already associated with this object
     if ($v !== null && $v->getRole(null, false) === null) {
         $v->setRole($this);
     }
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Filter the query by a related \ORM\RolePermission object
  *
  * @param \ORM\RolePermission|ObjectCollection $rolePermission  the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildRoleQuery The current query, for fluid interface
  */
 public function filterByPermission($rolePermission, $comparison = null)
 {
     if ($rolePermission instanceof \ORM\RolePermission) {
         return $this->addUsingAlias(RoleTableMap::COL_ID, $rolePermission->getId(), $comparison);
     } elseif ($rolePermission instanceof ObjectCollection) {
         return $this->usePermissionQuery()->filterByPrimaryKeys($rolePermission->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByPermission() only accepts arguments of type \\ORM\\RolePermission or Collection');
     }
 }
Exemplo n.º 4
0
 /**
  * Exclude object from result
  *
  * @param   ChildRolePermission $rolePermission Object to remove from the list of results
  *
  * @return $this|ChildRolePermissionQuery The current query, for fluid interface
  */
 public function prune($rolePermission = null)
 {
     if ($rolePermission) {
         $this->addUsingAlias(RolePermissionTableMap::COL_ID, $rolePermission->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }