Esempio n. 1
0
 public function addCollectionAction()
 {
     if ($this->view->aclIsAllowed('newsletter', 'edit', true)) {
         $baseDir = $this->view->baseUrl();
         $returnUrl = "/newsletter/filter/list-collection/";
         $form = new FormNewsletterFilterCollection(array('cancelUrl' => "{$baseDir}{$returnUrl}"));
         $this->view->assign('form', $form);
         $filterOptionsSelect = new NewsletterFilterProfilesFields();
         $select = $filterOptionsSelect->select();
         $filterOptionsData = $filterOptionsSelect->fetchAll($select)->toArray();
         $cpt = count($filterOptionsData);
         for ($i = 0; $i < $cpt; $i++) {
             $filterOptionsData[$i]['name'] = $this->view->getCibleText('newsletter_send_filter_' . $filterOptionsData[$i]['NFPF_Name']);
         }
         $this->view->assign('filterOptionsData', $filterOptionsData);
         if ($this->_request->isPost()) {
             $formData = $this->_request->getPost();
             if (array_key_exists('filterSet', $formData)) {
                 $filterSetArray = $formData['filterSet'];
                 $i = 1;
                 foreach ($filterSetArray as $key => $filterSet) {
                     $y = 1;
                     foreach ($filterSet as $keyFilter => $filter) {
                         if ($filter['filterSet'] != '0') {
                             $element = Newsletter_FilterController::getNewElement($filter['filterSet'], $y, $i, $filter['filterValue']);
                             $filterSetArray[$key][$keyFilter]['element'] = $element;
                             $y++;
                         } else {
                             unset($filterSetArray[$key][$keyFilter]);
                         }
                     }
                     if (count($filterSetArray[$key]) == 0) {
                         unset($filterSetArray[$key]);
                     }
                     $i++;
                 }
             } else {
                 $filterSetArray = array();
             }
             if ($form->isValid($formData)) {
                 $collectionData = new NewsletterFilterCollectionsSet();
                 $collection = $collectionData->createRow();
                 $collection->NFCS_Name = $formData['collectionForm']['NFCS_Name'];
                 $collection->save();
                 $collectionID = $collection->NFCS_ID;
                 foreach ($filterSetArray as $filterSet) {
                     $filterSetData = new NewsletterFilterFiltersSet();
                     $filterSetCreate = $filterSetData->createRow();
                     $filterSetCreate->save();
                     $filterSetID = $filterSetCreate->NFFS_ID;
                     $collectionFilterSetData = new NewsletterFilterCollectionsFiltersSet();
                     $collectionFilterSet = $collectionFilterSetData->createRow();
                     $collectionFilterSet->NFCFS_CollectionSetID = $collectionID;
                     $collectionFilterSet->NFCFS_FilterSetID = $filterSetID;
                     $collectionFilterSet->save();
                     foreach ($filterSet as $filter) {
                         $filterData = new NewsletterFilterFilters();
                         $filterCreate = $filterData->createRow();
                         $filterCreate->NFF_ProfileFieldName = $filter['filterSet'];
                         $filterCreate->NFF_FilterSetID = $filterSetID;
                         $filterCreate->NFF_Value = $filter['filterValue'];
                         $filterCreate->save();
                     }
                 }
                 $this->_redirect($returnUrl);
             } else {
                 $this->view->assign('filterSetArray', $filterSetArray);
             }
         }
     }
 }