Esempio n. 1
0
 /**
  * Returns a new ChildUnitQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildUnitQuery
  */
 public static function create($modelAlias = null, Criteria $criteria = null)
 {
     if ($criteria instanceof ChildUnitQuery) {
         return $criteria;
     }
     $query = new ChildUnitQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Esempio n. 2
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see Unit::setDeleted()
  * @see Unit::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(UnitTableMap::DATABASE_NAME);
     }
     $con->transaction(function () use($con) {
         $deleteQuery = ChildUnitQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $this->setDeleted(true);
         }
     });
 }
Esempio n. 3
0
 public static function unit($params, $currentUser, $con)
 {
     $units = UnitQuery::create()->filterByStatus('Active')->orderBy('name', 'ASC');
     if (isset($params->query)) {
         $units->where('Unit.Name like ?', "%{$params->query}%");
     }
     $units = $units->select(array('id', 'name'))->find($con);
     $data = [];
     foreach ($units as $unit) {
         $data[] = $unit;
     }
     $results['success'] = true;
     $results['data'] = $data;
     return $results;
 }
Esempio n. 4
0
 /**
  * Performs an INSERT on the database, given a Unit or Criteria object.
  *
  * @param mixed               $criteria Criteria or Unit 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(UnitTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Unit object
     }
     if ($criteria->containsKey(UnitTableMap::COL_ID) && $criteria->keyContainsValue(UnitTableMap::COL_ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . UnitTableMap::COL_ID . ')');
     }
     // Set the correct dbName
     $query = UnitQuery::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);
     });
 }
Esempio n. 5
0
 /**
  * Get the associated ChildUnit object
  *
  * @param  ConnectionInterface $con Optional Connection object.
  * @return ChildUnit The associated ChildUnit object.
  * @throws PropelException
  */
 public function getUnit(ConnectionInterface $con = null)
 {
     if ($this->aUnit === null && ($this->unit_id !== "" && $this->unit_id !== null)) {
         $this->aUnit = ChildUnitQuery::create()->findPk($this->unit_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->aUnit->addStocks($this);
            */
     }
     return $this->aUnit;
 }
Esempio n. 6
0
 public static function update($params, $currentUser, $con)
 {
     // check role's permission
     $permission = RolePermissionQuery::create()->select('update_unit')->findOneById($currentUser->role_id, $con);
     if (!$permission || $permission != 1) {
         throw new \Exception('Akses ditolak. Anda tidak mempunyai izin untuk melakukan operasi ini.');
     }
     // check whether unit is already exist
     $unit = UnitQuery::create()->filterByStatus('Active')->filterByName($params->name)->where('Unit.Id not like ?', $params->id)->count($con);
     if ($unit != 0) {
         throw new \Exception('Satuan ' . $params->name . ' sudah ada dalam data');
     }
     $unit = UnitQuery::create()->filterByStatus('Active')->findOneById($params->id, $con);
     if (!$unit) {
         throw new \Exception('Data tidak ditemukan');
     }
     $unit->setName($params->name)->save($con);
     $rowHistory = new RowHistory();
     $rowHistory->setRowId($params->id)->setData('unit')->setTime(time())->setOperation('update')->setUserId($currentUser->id)->save($con);
     $results['success'] = true;
     $results['data'] = $params;
     return $results;
 }