*/ /** * Klasa stSoteshopXmlExportBackendActions * * @package stsoteshopPlugin * @subpackage actions */ class stSoteshopXmlBackendActions extends autostSoteshopXmlBackendActions { public function initialize($context) { $result = parent::initialize($context); $this->checkSubscriptionTypes('stSoteshopXmlPlugin', [stCommunication::SUBSCRIPTION_STANDARD, stCommunication::SUBSCRIPTION_PRO, stCommunication::SUBSCRIPTION_VIP], [ 'block_actions' => ['addAll', 'deleteAll', 'generateCustom'], 'install_version' => '7.4.4' ]); return $result; } public function executeProductEnable() { $ids = $this->getRequestParameter('soteshop_xml[selected]', array()); foreach ($ids as $id) { $c = new Criteria(); $c->add(SoteshopXmlPeer::PRODUCT_ID, $id); $soteshop = SoteshopXmlPeer::doSelectOne($c); if (null === $soteshop) { $soteshop = new SoteshopXml(); $soteshop->setProductId($id); } $soteshop->setActive(true); $soteshop->save(); } return $this->redirect('stSoteshopXmlBackend/list?page=' . $this->getRequestParameter('page', 1)); } public function executeProductDisable() { $ids = $this->getRequestParameter('soteshop_xml[selected]', array()); /** * @var soteshop $soteshop */ foreach (SoteshopXmlPeer::retrieveByPKs(array_values($ids)) as $soteshop){ $soteshop->delete(); } return $this->redirect('stSoteshopXmlBackend/list?page=' . $this->getRequestParameter('page', 1)); } protected function addFiltersCriteria($c) { if (isset($this->filters['code_is_empty'])) { $criterion = $c->getNewCriterion(ProductPeer::CODE, ''); $criterion->addOr($c->getNewCriterion(ProductPeer::CODE, null, Criteria::ISNULL)); $c->add($criterion); } else if (isset($this->filters['code']) && $this->filters['code'] !== '') { if (method_exists($this, 'filterCriteriaByProductCode')) { $filter_anyway = !$this->filterCriteriaByProductCode($c, $this->filters['code']); } else { $filter_anyway = true; } if ($filter_anyway) { $c->add(ProductPeer::CODE, '%' . $this->filters['code'] . '%', Criteria::LIKE); } } if (isset($this->filters['product_is_empty'])) { $criterion = $c->getNewCriterion(ProductPeer::OPT_NAME, ''); $criterion->addOr($c->getNewCriterion(ProductPeer::OPT_NAME, null, Criteria::ISNULL)); $c->add($criterion); } else if (isset($this->filters['product']) && $this->filters['product'] !== '') { if (method_exists($this, 'filterCriteriaByProductOptName')) { $filter_anyway = !$this->filterCriteriaByProductOptName($c, $this->filters['product']); } else { $filter_anyway = true; } if ($filter_anyway) { $c->add(ProductPeer::OPT_NAME, '%' . $this->filters['product'] . '%', Criteria::LIKE); } } if (isset($this->filters['active_is_empty'])){ $criterion = $c->getNewCriterion(SoteshopXmlPeer::ACTIVE, ''); $criterion->addOr($c->getNewCriterion(SoteshopXmlPeer::ACTIVE, null, Criteria::ISNULL)); $c->add($criterion); } else if (isset($this->filters['active']) && $this->filters['active'] !== '') { if ($this->filters['active'] == null || $this->filters['active'] == 0){ $criterion = $c->getNewCriterion(SoteshopXmlPeer::ACTIVE, ''); $criterion->addOr($c->getNewCriterion(SoteshopXmlPeer::ACTIVE, null, Criteria::ISNULL)); $c->add($criterion); } if ($this->filters['active'] == 1){ $c->add(SoteshopXmlPeer::ACTIVE, $this->filters['active']); } } if ($this->filters){ $c->add(SoteshopXmlPeer::PRODUCT_ID, 0, Criteria::NOT_EQUAL); } $this->getDispatcher()->notify(new sfEvent($this, 'autostSoteshopXmlBackendActions.addFiltersCriteria', array('criteria' => $c))); } public function executeAddAll() { SoteshopXmlPeer::doDeleteAll(); $con = Propel::getConnection(); $con->executeQuery(sprintf( "INSERT INTO %s(%s, %s) (SELECT %s, 1 FROM %s)", SoteshopXmlPeer::TABLE_NAME, SoteshopXmlPeer::PRODUCT_ID, SoteshopXmlPeer::ACTIVE, ProductPeer::ID, ProductPeer::TABLE_NAME )); return $this->redirect('stSoteshopXmlBackend/list?page=' . $this->getRequestParameter('page', 1)); } public function executeDeleteAll() { SoteshopXmlPeer::doDeleteAll(); return $this->redirect('stSoteshopXmlBackend/list?page=' . $this->getRequestParameter('page', 1)); } protected function getSoteshopXmlOrCreate($id = 'id') { $soteshop = SoteshopXmlPeer::retrieveByProduct($this->related_object); if (null === $soteshop) { if ($this->hasRequestParameter('id')){ return $this->redirect('@stSoteshopXmlPlugin?action=create&product_id=' . $this->related_object->getId().'&view=default'); } else { $soteshop = new SoteshopXml(); $soteshop->setProduct($this->related_object); } } return $soteshop; } public function executeGenerateCustom() { parent::executeGenerateCustom(); $i18n = $this->getContext()->getI18n(); $this->getBreadcrumbsBuilder()->getDefaultBreadcrumbs()->add($i18n->__('Generowanie pliku')); } }