Example #1
0
 public static function role($params, $currentUser, $con)
 {
     $roles = RoleQuery::create()->filterByStatus('Active')->orderBy('name', 'ASC');
     if (isset($params->query)) {
         $roles->where('Role.Name like ?', "%{$params->query}%");
     }
     $roles = $roles->select(array('id', 'name'))->find($con);
     $data = [];
     foreach ($roles as $role) {
         $data[] = $role;
     }
     $results['success'] = true;
     $results['data'] = $data;
     return $results;
 }
Example #2
0
 public static function update($params, $currentUser, $con)
 {
     // check role's permission
     $permission = RolePermissionQuery::create()->select('update_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)->where('Role.Id not like ?', $params->id)->count($con);
     if ($role != 0) {
         throw new \Exception('Jabatan ' . $params->name . ' sudah ada dalam data');
     }
     $role = RoleQuery::create()->filterByStatus('Active')->findOneById($params->id, $con);
     if (!$role) {
         throw new \Exception('Data tidak ditemukan');
     }
     $role->setName($params->name)->save($con);
     $rowHistory = new RowHistory();
     $rowHistory->setRowId($params->id)->setData('role')->setTime(time())->setOperation('update')->setUserId($currentUser->id)->save($con);
     $results['success'] = true;
     $results['data'] = $params;
     return $results;
 }
Example #3
0
 /**
  * Get the associated ChildRole object
  *
  * @param  ConnectionInterface $con Optional Connection object.
  * @return ChildRole The associated ChildRole object.
  * @throws PropelException
  */
 public function getRole(ConnectionInterface $con = null)
 {
     if ($this->aRole === null && ($this->id !== "" && $this->id !== null)) {
         $this->aRole = ChildRoleQuery::create()->findPk($this->id, $con);
         // Because this foreign key represents a one-to-one relationship, we will create a bi-directional association.
         $this->aRole->setPermission($this);
     }
     return $this->aRole;
 }
Example #4
0
 /**
  * Returns a new ChildRoleQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildRoleQuery
  */
 public static function create($modelAlias = null, Criteria $criteria = null)
 {
     if ($criteria instanceof ChildRoleQuery) {
         return $criteria;
     }
     $query = new ChildRoleQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Example #5
0
 public function onMessage(ConnectionInterface $from, $msg)
 {
     $event = $from->event = 'anonymous';
     $data = [];
     // if message did not exist then deny access
     if (!isset($msg) || $msg == '') {
         throw new Exception('Wrong turn buddy');
     }
     // if event or data did not exist then deny access
     $msg = json_decode($msg);
     if (!$msg || !isset($msg->event) || !isset($msg->data)) {
         throw new Exception('Wrong turn buddy');
     }
     // store baby store em to variables
     $event = $from->event = $msg->event;
     $params = $msg->data;
     // if user not loged in yet then deny access
     if ($from->Session->get('pos/state') != 1) {
         throw new Exception('Akses ditolak. Anda belum login.');
     }
     // initiating propel orm
     require_once 'propel-config.php';
     Propel::disableInstancePooling();
     $con = Propel::getConnection('pos');
     // if user don't have role assigned then deny access
     $role = RoleQuery::create()->findOneById($from->Session->get('pos/current_user')->role_id);
     if (!$role) {
         throw new Exception('Akses ditolak. Anda belum punya Jabatan.');
     }
     // uh... decoding event to get requested module and method
     $decode = explode('/', $event);
     // if decoded array length is not 2 then deny access
     if (count($decode) != 2) {
         throw new Exception('Wrong turn buddy');
     }
     // store baby store em to variables... again
     $module = $decode[0];
     $method = $decode[1];
     // list of all module that can be requested
     $registeredModule = array('chart', 'combo', 'credit', 'customer', 'debit', 'notification', 'option', 'populate', 'product', 'purchase', 'report', 'role', 'sales', 'secondParty', 'stock', 'supplier', 'unit', 'user');
     // if requested module is not registered then deny access
     if (!in_array($module, $registeredModule)) {
         throw new Exception('Wrong turn buddy');
     }
     // you know it.. begin transaction
     $con->beginTransaction();
     // this is where magic begins..
     // route to requested module
     $data = $this->{$module}($method, $params, $from, $con);
     // commit transaction
     $con->commit();
     // store to results variable before spitting it out back to client
     $results['event'] = $event;
     $results['data'] = $data;
     // errmmmmm
     $from->send(json_encode($results));
     // followup action
     if ($event == 'purchase/create' || $event == 'purchase/destroy' || $event == 'purchase/update') {
         // get update of last 30 Days transaction's data
         $data = $this->chart('last30DaysTransaction', new \stdClass(), $from, $con);
         $last30DaysTransaction['event'] = 'chart/last30DaysTransaction';
         $last30DaysTransaction['data'] = $data;
         // iterate through all connected client
         foreach ($this->clients as $client) {
             // get notification update of each client
             $data = $this->notification('read', new \stdClass(), $client, $con);
             $results['event'] = 'notification/read';
             $results['data'] = $data;
             // push notification to each client
             $client->send(json_encode($results));
             // push last 30 Days transaction's data to each client
             $client->send(json_encode($last30DaysTransaction));
         }
     } elseif ($event == 'sales/create' || $event == 'sales/destroy' || $event == 'sales/update') {
         // get update of last 30 Days transaction's data
         $data = $this->chart('last30DaysTransaction', new \stdClass(), $from, $con);
         $last30DaysTransaction['event'] = 'chart/last30DaysTransaction';
         $last30DaysTransaction['data'] = $data;
         // iterate through all connected client
         foreach ($this->clients as $client) {
             // push last 30 Days transaction's data to each client
             $client->send(json_encode($last30DaysTransaction));
         }
     }
     // finish
     return;
 }
Example #6
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see Role::setDeleted()
  * @see Role::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(RoleTableMap::DATABASE_NAME);
     }
     $con->transaction(function () use($con) {
         $deleteQuery = ChildRoleQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $this->setDeleted(true);
         }
     });
 }
Example #7
0
 /**
  * Performs an INSERT on the database, given a Role or Criteria object.
  *
  * @param mixed               $criteria Criteria or Role 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(RoleTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Role object
     }
     if ($criteria->containsKey(RoleTableMap::COL_ID) && $criteria->keyContainsValue(RoleTableMap::COL_ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . RoleTableMap::COL_ID . ')');
     }
     // Set the correct dbName
     $query = RoleQuery::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);
     });
 }
Example #8
0
 /**
  * Get the associated ChildRole object
  *
  * @param  ConnectionInterface $con Optional Connection object.
  * @return ChildRole The associated ChildRole object.
  * @throws PropelException
  */
 public function getRole(ConnectionInterface $con = null)
 {
     if ($this->aRole === null && ($this->role_id !== "" && $this->role_id !== null)) {
         $this->aRole = ChildRoleQuery::create()->findPk($this->role_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->aRole->addNotificationOptions($this);
            */
     }
     return $this->aRole;
 }