示例#1
0
 public function indexAction()
 {
     $this->_helper->layout->setLayout('full');
     $event_id = $this->_getParam('id');
     if ($this->getRequest()->isGet()) {
         $proxy = new SxCms_Event_DataMapper();
         $event = $proxy->getEventById($event_id);
     }
     if ($this->getRequest()->isPost()) {
         $proxy = new SxCms_Event_DataMapper();
         $event = $proxy->getEventById($event_id);
         $subscription = array();
         $errors = array();
         foreach ($event->getFields() as $field) {
             if (!$this->_getParam($field->getName())) {
                 $errors[$field->getName()] = $field->getLabel();
             }
             $subscription[$field->getName()] = $this->_getParam($field->getName());
         }
         if (sizeof($errors) == 0) {
             $Subscription = new SxCms_Event_Subscription();
             $Subscription->setEventId($event_id);
             if ($event->isValidateIntern()) {
                 $Subscription->setStatus(0);
                 $sub_id = $Subscription->save();
             } else {
                 $Subscription->setStatus(1);
                 $sub_id = $Subscription->save();
                 $Subscription->sendConfirmation();
             }
             foreach ($event->getFields() as $field) {
                 if ($field->getType() == 'checkbox') {
                     $value = implode(';', $this->_getParam($field->getName()));
                 } else {
                     $value = $this->_getParam($field->getName());
                 }
                 $SubF = new SxCms_Event_Subscription_Field();
                 $SubF->setSubscriptionId($sub_id)->setFieldId($field->getId())->setName($field->getName())->setValue($value);
                 $SubF->save();
             }
             $this->view->result = true;
         } else {
             $this->view->errors = $errors;
         }
         $this->view->subscription = $subscription;
     }
     $mapperSub = new SxCms_Event_Subscription_DataMapper();
     $subscriptions = $mapperSub->getSubscriptionsForEvent($event_id);
     $now = strtotime(date('Y-m-d'));
     if (count($subscriptions) >= $event->getSubscriptionMax() || strtotime($event->getDateEnd()) < $now || strtotime($event->getDateStart()) > $now) {
         $event->setSubscriptionAllow(false);
     }
     $this->view->subscriptions = $subscriptions;
     $this->view->event = $event;
     $this->getResponse()->setHeader('Last-Modified', $event->getDateStart("%a, %d %b %Y %H:%I%S GMT"));
 }
 public function exportAction()
 {
     SxCms_Acl::requireAcl('subscriptions', 'subscription.export');
     $event_id = $this->_getParam('id');
     $eventMapper = new SxCms_Event_DataMapper();
     $event = $eventMapper->getEventById($event_id);
     $subProxy = new SxCms_Event_Subscription_DataMapper();
     $subscriptions = $subProxy->getValidSubscriptionsForEvent($event_id);
     $fieldProxy = new SxCms_Event_Field_DataMapper();
     $fields = $fieldProxy->getFieldsByEvent($event_id);
     $objPHPExcel = new PHPExcel();
     $objPHPExcel->createSheet("Event Subsciptions");
     $objPHPExcel->setActiveSheetIndex(0);
     $objPHPSheet = $objPHPExcel->getActiveSheet();
     $objPHPSheet->setCellValueByColumnAndRow(0, 1, $this->admin_tmx->_('subscriptionsforevent') . $event->getTitle());
     $i = 0;
     foreach ($fields as $field) {
         $objPHPSheet->setCellValueByColumnAndRow($i, 2, $field->getLabel());
         $i++;
     }
     $j = 3;
     foreach ($subscriptions as $subscription) {
         $i = 0;
         foreach ($fields as $field) {
             $objPHPSheet->setCellValueByColumnAndRow($i, $j, $subscription[$field->getName()]);
             $i++;
         }
         $j++;
     }
     $file = "sub_" . date("d_m_Y") . ".xls";
     header("Pragma: public");
     header("Expires: 0");
     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
     header("Content-Type: application/force-download");
     header("Content-Type: application/octet-stream");
     header("Content-Type: application/download");
     header("Content-Disposition: attachment; filename={$file}");
     header("Content-Transfer-Encoding: binary");
     error_reporting(0);
     $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
     $objWriter->setTempDir(APPLICATION_ROOT . '/tmp');
     $objWriter->save("php://output");
     die;
 }