Exemple #1
0
 public function saveProductsOrderAction()
 {
     $ordersString = $this->getRequest()->getParam('order');
     $idGroup = $this->getRequest()->getParam('id');
     $products = explode(',', $ordersString);
     $arrayAll = array();
     //Needs_Tools::DeleteLegaturibyGroup( $groupId );
     $modelGroupAll = new Default_Model_ProductGroups();
     $selectAll = $modelGroupAll->getMapper()->getDbTable()->select()->where('idGroup = ?', $idGroup);
     $resultsAll = $modelGroupAll->fetchAll($selectAll);
     foreach ($resultsAll as $value) {
         $arrayAll[] = $value->getIdProduct();
         //all the products that are currently in the table
     }
     $resultDiff = array_diff($arrayAll, $products);
     foreach ($resultDiff as $deleteProd) {
         Needs_Tools::DeleteLegaturi($deleteProd);
         //here we delete the prods that were before in the table, but are not anymore in the new list of prods
     }
     foreach ($products as $key => $value) {
         $model = new Default_Model_ProductGroups();
         $select = $model->getMapper()->getDbTable()->select()->where('idProduct = ?', $value)->where('idGroup = ?', $idGroup);
         $model->fetchRow($select);
         if ($model->getId() != NULL) {
             $id = $model->getId();
             $model->find($id);
             $model->setOrder($key);
             $model->saveOrder();
         }
     }
 }