public static function create($params, $currentUser, $con) { // check role's permission $permission = RolePermissionQuery::create()->select('create_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)->count($con); if ($unit != 0) { throw new \Exception('Satuan ' . $params->name . ' sudah ada dalam data'); } // create new record $unit = new Unit(); $unit->setName($params->name)->setStatus('Active')->save($con); // log history $rowHistory = new RowHistory(); $rowHistory->setRowId($unit->getId())->setData('unit')->setTime(time())->setOperation('create')->setUserId($currentUser->id)->save($con); $params->id = $unit->getId(); $results['success'] = true; $results['data'] = $params; return $results; }
/** * Declares an association between this object and a ChildUnit object. * * @param ChildUnit $v * @return $this|\ORM\Stock The current object (for fluent API support) * @throws PropelException */ public function setUnit(ChildUnit $v = null) { if ($v === null) { $this->setUnitId(NULL); } else { $this->setUnitId($v->getId()); } $this->aUnit = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the ChildUnit object, it will not be re-added. if ($v !== null) { $v->addStock($this); } return $this; }
/** * Filter the query by a related \ORM\Unit object * * @param \ORM\Unit|ObjectCollection $unit The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildStockQuery The current query, for fluid interface */ public function filterByUnit($unit, $comparison = null) { if ($unit instanceof \ORM\Unit) { return $this->addUsingAlias(StockTableMap::COL_UNIT_ID, $unit->getId(), $comparison); } elseif ($unit instanceof ObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this->addUsingAlias(StockTableMap::COL_UNIT_ID, $unit->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { throw new PropelException('filterByUnit() only accepts arguments of type \\ORM\\Unit or Collection'); } }
/** * Exclude object from result * * @param ChildUnit $unit Object to remove from the list of results * * @return $this|ChildUnitQuery The current query, for fluid interface */ public function prune($unit = null) { if ($unit) { $this->addUsingAlias(UnitTableMap::COL_ID, $unit->getId(), Criteria::NOT_EQUAL); } return $this; }