/**
  * Get the associated Barang object
  *
  * @param PropelPDO $con Optional Connection object.
  * @param $doQuery Executes a query to get the object if required
  * @return Barang The associated Barang object.
  * @throws PropelException
  */
 public function getBarang(PropelPDO $con = null, $doQuery = true)
 {
     if ($this->aBarang === null && $this->id_barang !== null && $doQuery) {
         $this->aBarang = BarangQuery::create()->findPk($this->id_barang, $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->aBarang->addDetailBarangMasuks($this);
            */
     }
     return $this->aBarang;
 }
Example #2
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param PropelPDO $con
  * @return void
  * @throws PropelException
  * @throws Exception
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(BarangPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = BarangQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         // symfony_behaviors behavior
         foreach (sfMixer::getCallables('BaseBarang:delete:pre') as $callable) {
             if (call_user_func($callable, $this, $con)) {
                 $con->commit();
                 return;
             }
         }
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             // symfony_behaviors behavior
             foreach (sfMixer::getCallables('BaseBarang:delete:post') as $callable) {
                 call_user_func($callable, $this, $con);
             }
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this Kemasan is new, it will return
  * an empty collection; or if this Kemasan has previously
  * been saved, it will retrieve related Barangs from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in Kemasan.
  *
  * @param Criteria $criteria optional Criteria object to narrow the query
  * @param PropelPDO $con optional connection object
  * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
  * @return PropelObjectCollection|Barang[] List of Barang objects
  */
 public function getBarangsJoinProdusen($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $query = BarangQuery::create(null, $criteria);
     $query->joinWith('Produsen', $join_behavior);
     return $this->getBarangs($query, $con);
 }
 /**
  * Returns a new BarangQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param   BarangQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return BarangQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof BarangQuery) {
         return $criteria;
     }
     $query = new BarangQuery(null, null, $modelAlias);
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
 public function executeImportfile(sfWebRequest $request)
 {
     $allowed = array('xlsx', 'xls');
     $file = $request->getFiles('file');
     $fileSize = $file['size'];
     $fileType = $file['type'];
     $theFileName = $file['name'];
     $uploadDir = sfConfig::get("sf_upload_dir");
     $import = $uploadDir . '/import';
     if (!is_dir($import)) {
         mkdir($import, 0777);
     }
     $ext = pathinfo($theFileName, PATHINFO_EXTENSION);
     if (!in_array($ext, $allowed)) {
         $this->msg = 'file type not allowed. File Type Must ';
         $y = 0;
         foreach ($allowed as $x) {
             if ($y != count($allowed) - 1) {
                 $this->msg .= $x . " or ";
             } else {
                 $this->msg .= $x;
             }
             $y++;
         }
         $this->setTemplate('import');
     } else {
         move_uploaded_file($file['tmp_name'], "{$import}/{$theFileName}");
         $inputFileName = $uploadDir . '/import/' . $theFileName;
         try {
             $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
             $objReader = PHPExcel_IOFactory::createReader($inputFileType);
             $objPHPExcel = $objReader->load($inputFileName);
             $data = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
             for ($x = 3; $x <= count($data); $x++) {
                 $c = new Criteria();
                 $c->add(KategoriPeer::NAMA_KATEGORI, $data[$x]['C'], Criteria::EQUAL);
                 $kategori = $this->getIdColumn(KategoriPeer::doSelect($c));
                 $k = new Criteria();
                 $k->add(KemasanPeer::NAMA_KEMASAN, $data[$x]['E'], Criteria::EQUAL);
                 $kemasan = $this->getIdColumn(KemasanPeer::doSelect($k));
                 $p = new Criteria();
                 $p->add(ProdusenPeer::NAMA_PRODUSEN, $data[$x]['F'], Criteria::EQUAL);
                 $produsen = $this->getIdColumn(ProdusenPeer::doSelect($p));
                 $barang = BarangQuery::create()->findOneById($data[$x]['A']);
                 if (isset($barang)) {
                     $barang->setNamaBarang($data[$x]['B']);
                     $barang->setIdKategori("" . $kategori);
                     $barang->setStock($data[$x]['D']);
                     $barang->setIdKemasan("" . $kemasan);
                     $barang->setIdProdusen("" . $produsen);
                     $barang->setDescription($data[$x]['G']);
                     $barang->save();
                 } else {
                     $barang = new Barang();
                     $barang->setNamaBarang($data[$x]['B']);
                     $barang->setIdKategori("" . $kategori);
                     $barang->setStock($data[$x]['D']);
                     $barang->setIdKemasan("" . $kemasan);
                     $barang->setIdProdusen("" . $produsen);
                     $barang->setDescription($data[$x]['G']);
                     $barang->save();
                 }
             }
             unlink($inputFileName);
             $this->getUser()->setFlash('notice', $notice . ' You can add another one below.');
             $this->redirect('@barang');
         } catch (Exception $e) {
             die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
         }
     }
 }