public static function updateBiodata($params, $currentUser, $con) { $userDetail = UserDetailQuery::create()->filterById($currentUser->id)->findOne($con); if (!$userDetail) { throw new \Exception('Anda tidak terdaftar sebagai user!'); } $userDetail->setName($params->name)->setAddress($params->address)->setPhone($params->phone)->save($con); $results['success'] = true; $results['data'] = 'Yay'; return $results; }
public static function cashier($params, $currentUser, $con) { $cashiers = UserDetailQuery::create()->useUserQuery()->filterByStatus('Active')->endUse()->orderBy('name', 'ASC'); if (isset($params->query)) { $cashiers->where('UserDetail.Name like ?', "%{$params->query}%"); } $cashiers = $cashiers->select(array('id', 'name'))->limit(20)->find($con); $data = []; foreach ($cashiers as $cashier) { $data[] = $cashier; } $results['success'] = true; $results['data'] = $data; return $results; }
/** * Performs an INSERT on the database, given a UserDetail or Criteria object. * * @param mixed $criteria Criteria or UserDetail object containing data that is used to create the INSERT statement. * @param ConnectionInterface $con the ConnectionInterface connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(UserDetailTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from UserDetail object } // Set the correct dbName $query = UserDetailQuery::create()->mergeWith($criteria); // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) return $con->transaction(function () use($con, $query) { return $query->doInsert($con); }); }
/** * Get the associated ChildUserDetail object * * @param ConnectionInterface $con Optional Connection object. * @return ChildUserDetail The associated ChildUserDetail object. * @throws PropelException */ public function getUserDetail(ConnectionInterface $con = null) { if ($this->aUserDetail === null && ($this->user_id !== "" && $this->user_id !== null)) { $this->aUserDetail = ChildUserDetailQuery::create()->findPk($this->user_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aUserDetail->addHistories($this); */ } return $this->aUserDetail; }
public static function update($params, $currentUser, $con) { // check role's permission $permission = RolePermissionQuery::create()->select('update_user')->findOneById($currentUser->role_id, $con); if (!$permission || $permission != 1) { throw new \Exception('Akses ditolak. Anda tidak mempunyai izin untuk melakukan operasi ini.'); } if ($params->id == 1 && $params->user != 'admin') { throw new \Exception('User ID Default Admin tidak boleh diubah.'); } if ($params->id == 1 && $params->role_id != 1) { throw new \Exception('Role Default Admin tidak boleh diubah.'); } // check whether picked username is already taken $user = UserQuery::create()->filterByUser($params->user)->where("User.Id not like ?", $params->id)->count($con); if ($user != 0) { throw new \Exception('User ID sudah terpakai. Pilih User ID lainnya.'); } $user = UserQuery::create()->findOneById($params->id, $con); $detail = UserDetailQuery::create()->findOneById($params->id, $con); if (!$user || !$detail) { throw new \Exception('Data tidak ditemukan'); } $user->setUser($params->user)->setRoleId($params->role_id)->save($con); $detail->setName($params->name)->setAddress($params->address)->setPhone($params->phone)->save($con); $rowHistory = new RowHistory(); $rowHistory->setRowId($params->id)->setData('user')->setTime(time())->setOperation('update')->setUserId($currentUser->id)->save($con); $results['success'] = true; $results['id'] = $params->id; return $results; }
/** * Removes this object from datastore and sets delete attribute. * * @param ConnectionInterface $con * @return void * @throws PropelException * @see UserDetail::setDeleted() * @see UserDetail::isDeleted() */ public function delete(ConnectionInterface $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getServiceContainer()->getWriteConnection(UserDetailTableMap::DATABASE_NAME); } $con->transaction(function () use($con) { $deleteQuery = ChildUserDetailQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $this->setDeleted(true); } }); }
/** * Returns a new ChildUserDetailQuery object. * * @param string $modelAlias The alias of a model in the query * @param Criteria $criteria Optional Criteria to build the query from * * @return ChildUserDetailQuery */ public static function create($modelAlias = null, Criteria $criteria = null) { if ($criteria instanceof ChildUserDetailQuery) { return $criteria; } $query = new ChildUserDetailQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
/** * Gets a single ChildUserDetail object, which is related to this object by a one-to-one relationship. * * @param ConnectionInterface $con optional connection object * @return ChildUserDetail * @throws PropelException */ public function getDetail(ConnectionInterface $con = null) { if ($this->singleDetail === null && !$this->isNew()) { $this->singleDetail = ChildUserDetailQuery::create()->findPk($this->getPrimaryKey(), $con); } return $this->singleDetail; }