, Paweł Byszewski */ /** * Akcje grupy produktów. * * @package stProductGroup * @author Krzysztof Bebło , Paweł Byszewski */ class stProductGroupActions extends autostProductGroupActions { protected $configGroup; public function executeDelete() { ProductGroupPeer::cleanCache(); parent::executeDelete(); } public function executeProductAddGroup() { try { parent::executeProductAddGroup(); } catch (sfStopException $e) { ProductGroupPeer::cleanCache(); throw $e; } } public function executeProductRemoveGroup() { try { parent::executeProductRemoveGroup(); } catch (sfStopException $e) { ProductGroupPeer::cleanCache(); throw $e; } } public function addProductFiltersCriteria($c) { parent::addProductFiltersCriteria($c); if (isset($this->filters['list_image']) && $this->filters['list_image'] !== '') { $c->add(ProductPeer::OPT_IMAGE, null, $this->filters['list_image'] ? Criteria::ISNOTNULL : Criteria::ISNULL); } if (isset($this->filters['list_assigned']) && $this->filters['list_assigned'] !== '') { $c->addJoin(ProductPeer::ID, sprintf("%s AND %s = %d", ProductGroupHasProductPeer::PRODUCT_ID, ProductGroupHasProductPeer::PRODUCT_GROUP_ID, $this->forward_parameters['product_group_id']), Criteria::LEFT_JOIN); if ($this->filters['list_assigned']) { $c->add(ProductGroupHasProductPeer::ID, null, Criteria::ISNOTNULL); } else { $c->add(ProductGroupHasProductPeer::ID, null, Criteria::ISNULL); } } } protected function saveConfig() { parent::saveConfig(); stFastCacheManager::clearCache(); } protected function saveProductGroup($product_group) { if (!$this->getRequest()->hasErrors() && $this->hasRequestParameter('product_group[delete_image]')) { $currentFile = sfConfig::get('sf_upload_dir') . "/product_group/" . $product_group->getImage(); $product_group->setImage(''); if (is_file($currentFile)) { unlink($currentFile); } } if (!$this->getRequest()->hasErrors() && $this->hasRequestParameter('product_group[label]')) { $product_group->setLabel($this->getRequestParameter('product_group[label]')); } parent::saveProductGroup($product_group); $this->saveProductGroupImage($product_group); ProductGroupPeer::cleanCache(); stFastCacheManager::clearCache(); } protected function saveProductGroupImage($product_group) { if ($this->getRequest()->getFileError('product_group[image]') == UPLOAD_ERR_OK) { $filename = $this->getRequest()->getFileName('product_group[image]'); // dodaj zdjecie if (!$this->getRequest()->hasErrors() && $this->getRequest()->getFileSize('product_group[image]')) { $currentFile = sfConfig::get('sf_upload_dir') . "/product_group/" . $filename; if (is_file($currentFile)) { unlink($currentFile); } $this->getRequest()->moveFile('product_group[image]', sfConfig::get('sf_upload_dir') . "/product_group/" . $filename); $product_group->setImage($filename); } $product_group->save(); } } public function executeFixOptProductGroup() { } protected function addFiltersCriteria($c) { $c->add(ProductGroupPeer::FROM_BASKET_VALUE, null, Criteria::ISNULL); parent::addFiltersCriteria($c); } protected function getProductGroupOrCreate($id = 'id') { $productGroup = parent::getProductGroupOrCreate($id); if ($productGroup->getProductGroup() != 'NEW') { $this->hideField('new_type'); $this->hideField('new_product_date'); } return $productGroup; } }