示例#1
0
 /**
  * Export attendees list as csv.
  *
  * @return array|CsvModel|ViewModel
  */
 public function exportAttendeesAction()
 {
     $sm = $this->getServiceLocator();
     $userService = $sm->get('Stjornvisi\\Service\\User');
     $eventService = $sm->get('Stjornvisi\\Service\\Event');
     $authService = $sm->get('AuthenticationService');
     //EVENT FOUND
     //  an event with this ID was found
     if (($event = $eventService->get($this->params()->fromRoute('id', 0))) != false) {
         $groupIds = $this->extractGroupIds($event->groups);
         $access = $userService->getTypeByGroup($authService->hasIdentity() ? $authService->getIdentity()->id : null, $groupIds);
         //ACCESS GRANTED
         //  user has access
         if ($access->is_admin || $access->type >= 1) {
             $csv = new Csv();
             $csv->setHeader(['Nafn', 'Titill', 'Netfang', 'Dags.']);
             $csv->setName('maertingarlisti' . date('Y-m-d-H:i') . '.csv');
             foreach ($event->attenders as $item) {
                 $csv->add(['name' => $item->name, 'title' => $item->title, 'email' => $item->email, 'register_time' => $item->register_time->format('Y-m-d H:i')]);
             }
             $model = new CsvModel();
             $model->setData($csv);
             return $model;
         } else {
             $this->getResponse()->setStatusCode(401);
             $model = new ViewModel();
             $model->setTemplate('error/401');
             return $model;
         }
     } else {
         return $this->notFoundAction();
     }
 }
示例#2
0
 /**
  * Export events list in CSV
  *
  * @return array|CsvModel|ViewModel
  */
 public function exportEventsAction()
 {
     $sm = $this->getServiceLocator();
     $groupService = $sm->get('Stjornvisi\\Service\\Group');
     $userService = $sm->get('Stjornvisi\\Service\\User');
     $eventService = $sm->get('Stjornvisi\\Service\\Event');
     /** @var $eventService \Stjornvisi\Service\Event */
     //GROUP
     //  group found
     if (($group = $groupService->get($this->params()->fromRoute('id', 0))) != false) {
         $auth = new AuthenticationService();
         $access = $userService->getTypeByGroup($auth->hasIdentity() ? $auth->getIdentity()->id : null, $group->id);
         //ACCESS GRANTED
         //  user has access
         if ($access->is_admin || $access->type >= 1) {
             $server = isset($_SERVER['HTTP_HOST']) ? "http://" . $_SERVER['HTTP_HOST'] : 'http://0.0.0.0';
             $csv = new Csv();
             $csv->setHeader(['Nafn', 'Hópar', 'Dags.', 'Slóð']);
             $csv->setName('vidburdalistilisti' . date('Y-m-d-H:i') . '.csv');
             $events = $eventService->getByGroup($group->id);
             foreach ($events as $result) {
                 $csv->add(['name' => $result->subject, 'groups' => implode(', ', array_map(function ($item) {
                     return $item->name_short;
                 }, $result->groups)), 'date' => $result->event_date->format('Y-m-d'), 'url' => $server . $this->url()->fromRoute('vidburdir/index', ['id' => $result->id])]);
             }
             $model = new CsvModel();
             $model->setData($csv);
             return $model;
             //ACCESS DENIED
             //  user has no access
         } else {
             $this->getResponse()->setStatusCode(401);
             $model = new ViewModel();
             $model->setTemplate('error/401');
             return $model;
         }
         //NO GROUP
         //  group not found
         //TODO 404
     } else {
         return $this->notFoundAction();
     }
 }
示例#3
0
 /**
  * Export all companies as a CSV list file.
  *
  * @return CsvModel
  */
 public function exportAction()
 {
     $sm = $this->getServiceLocator();
     $companyService = $sm->get('Stjornvisi\\Service\\Company');
     $csv = new Csv();
     $csv->setHeader(['Nafn', 'Kennitala', 'Heimilisfang.', 'Póstnúmer', 'Stærð', 'Tegung', 'Stofnað']);
     $csv->setName('fyrirtaekjalisti-' . date('Y-m-d-H:i') . '.csv');
     $companies = $companyService->fetchAll([]);
     foreach ($companies as $result) {
         $csv->add(['name' => $result->name, 'ssn' => $result->ssn, 'address' => $result->address, 'zip' => $result->zip, 'number_of_employees' => $result->number_of_employees, 'business_type' => $result->business_type, 'created' => $result->created->format('Y-m-d')]);
     }
     $model = new CsvModel();
     $model->setData($csv);
     return $model;
 }