Esempio n. 1
0
 public static function create($params, $currentUser, $con)
 {
     // check role's permission
     $permission = RolePermissionQuery::create()->select('create_user')->findOneById($currentUser->role_id, $con);
     if (!$permission || $permission != 1) {
         throw new \Exception('Akses ditolak. Anda tidak mempunyai izin untuk melakukan operasi ini.');
     }
     // check if picked username is already used by anyone
     $user = UserQuery::create()->filterByUser($params->user)->count($con);
     if ($user != 0) {
         throw new \Exception('User ID sudah terpakai. Pilih User ID lainnya.');
     }
     // create new user
     $user = new User();
     $user->setUser($params->user)->setPassword(hash('sha512', $params->user))->setRoleId($params->role_id)->setStatus('Active')->save($con);
     // create user detail
     $userDetail = new UserDetail();
     $userDetail->setId($user->getId())->setName($params->name)->setAddress($params->address)->setPhone($params->phone)->save($con);
     // insert into row_history table
     $rowHistory = new RowHistory();
     $rowHistory->setRowId($user->getId())->setData('user')->setTime(time())->setOperation('create')->setUserId($currentUser->id)->save($con);
     $results['success'] = true;
     $results['id'] = $user->getId();
     return $results;
 }
Esempio n. 2
0
 /**
  * Declares an association between this object and a ChildUser object.
  *
  * @param  ChildUser $v
  * @return $this|\ORM\UserDetail The current object (for fluent API support)
  * @throws PropelException
  */
 public function setUser(ChildUser $v = null)
 {
     if ($v === null) {
         $this->setId(NULL);
     } else {
         $this->setId($v->getId());
     }
     $this->aUser = $v;
     // Add binding for other direction of this 1:1 relationship.
     if ($v !== null) {
         $v->setDetail($this);
     }
     return $this;
 }
Esempio n. 3
0
 /**
  * Exclude object from result
  *
  * @param   ChildUser $user Object to remove from the list of results
  *
  * @return $this|ChildUserQuery The current query, for fluid interface
  */
 public function prune($user = null)
 {
     if ($user) {
         $this->addUsingAlias(UserTableMap::COL_ID, $user->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Esempio n. 4
0
 /**
  * Filter the query by a related \ORM\User object
  *
  * @param \ORM\User|ObjectCollection $user The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildUserDetailQuery The current query, for fluid interface
  */
 public function filterByUser($user, $comparison = null)
 {
     if ($user instanceof \ORM\User) {
         return $this->addUsingAlias(UserDetailTableMap::COL_ID, $user->getId(), $comparison);
     } elseif ($user instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(UserDetailTableMap::COL_ID, $user->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByUser() only accepts arguments of type \\ORM\\User or Collection');
     }
 }
Esempio n. 5
0
 /**
  * Declares an association between this object and a ChildUser object.
  *
  * @param  ChildUser $v
  * @return $this|\ORM\NotificationOnUser The current object (for fluent API support)
  * @throws PropelException
  */
 public function setUser(ChildUser $v = null)
 {
     if ($v === null) {
         $this->setUserId(NULL);
     } else {
         $this->setUserId($v->getId());
     }
     $this->aUser = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the ChildUser object, it will not be re-added.
     if ($v !== null) {
         $v->addNotification($this);
     }
     return $this;
 }