public static function create($params, $currentUser, $con) { // check role's permission $permission = RolePermissionQuery::create()->select('create_product')->findOneById($currentUser->role_id, $con); if (!$permission || $permission != 1) { throw new \Exception('Akses ditolak. Anda tidak mempunyai izin untuk melakukan operasi ini.'); } // check whether picked code is already used $product = ProductQuery::create()->filterByCode($params->code)->count($con); if ($product != 0) { throw new \Exception('Kode produk sudah terpakai. Pilih kode lainnya.'); } // create new record $product = new Product(); $product->setCode($params->code)->setName($params->name)->setStatus('Active')->save($con); // log history $rowHistory = new RowHistory(); $rowHistory->setRowId($product->getId())->setData('product')->setTime(time())->setOperation('create')->setUserId($currentUser->id)->save($con); $params->id = $product->getId(); $results['success'] = true; $results['data'] = $params; return $results; }
/** * Declares an association between this object and a ChildProduct object. * * @param ChildProduct $v * @return $this|\ORM\Stock The current object (for fluent API support) * @throws PropelException */ public function setProduct(ChildProduct $v = null) { if ($v === null) { $this->setProductId(NULL); } else { $this->setProductId($v->getId()); } $this->aProduct = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the ChildProduct object, it will not be re-added. if ($v !== null) { $v->addStock($this); } return $this; }
/** * Exclude object from result * * @param ChildProduct $product Object to remove from the list of results * * @return $this|ChildProductQuery The current query, for fluid interface */ public function prune($product = null) { if ($product) { $this->addUsingAlias(ProductTableMap::COL_ID, $product->getId(), Criteria::NOT_EQUAL); } return $this; }
/** * Filter the query by a related \ORM\Product object * * @param \ORM\Product|ObjectCollection $product 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 filterByProduct($product, $comparison = null) { if ($product instanceof \ORM\Product) { return $this->addUsingAlias(StockTableMap::COL_PRODUCT_ID, $product->getId(), $comparison); } elseif ($product instanceof ObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this->addUsingAlias(StockTableMap::COL_PRODUCT_ID, $product->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { throw new PropelException('filterByProduct() only accepts arguments of type \\ORM\\Product or Collection'); } }