コード例 #1
0
ファイル: UserController.php プロジェクト: bix0r/Stjornvisi
 /**
  * Export all users as CSV file
  *
  * @return CsvModel|ViewModel
  */
 public function exportAction()
 {
     $auth = new AuthenticationService();
     if ($auth->hasIdentity()) {
         $type = $this->params('type', 'allir');
         $server = isset($_SERVER['HTTP_HOST']) ? "http://" . $_SERVER['HTTP_HOST'] : 'http://0.0.0.0';
         $sm = $this->getServiceLocator();
         $userService = $sm->get('Stjornvisi\\Service\\User');
         /** @var  $userService \Stjornvisi\Service\User */
         $csv = new Csv();
         switch ($this->params('type', 'allir')) {
             case 'formenn':
                 $users = $userService->fetchGroupMembers([2]);
                 break;
             case 'stjornendur':
                 $users = $userService->fetchGroupMembers([1, 2]);
                 break;
             default:
                 $users = $userService->fetchAll();
                 break;
         }
         if ($this->params('type', 'allir') == 'formenn' || $this->params('type', 'allir') == 'stjornendur') {
             $csv->setHeader(['Nafn', 'Titill', 'Netfang', 'Hópur', 'Fyrirtæki', 'Staða'])->setName('notendalisti' . date('Y-m-d-h:i') . '.csv');
             foreach ($users as $user) {
                 $csv->add([$user->name, $user->title, $user->email, $user->group_name, $user->company_name, $user->type == 2 ? 'Formaður' : 'Stjórnandi']);
             }
         } else {
             $csv->setHeader(['Nafn', 'Netfang', 'Fyrirtæki', 'Lykilstarfsmaður fyrirtækis', 'Stofna', 'Seinast innskráðu(ur)', 'Tíðni innskráninga', 'Kerfisstjóri', 'Slóð'])->setName('notendalisti' . date('Y-m-d-h:i') . '.csv');
             foreach ($users as $user) {
                 $csv->add([$user->name, $user->email, $user->company_name, $user->key_user ? 'já' : 'nei', $user->created_date->format('Y-m-d'), $user->modified_date->format('Y-m-d'), $user->frequency, $user->is_admin ? 'já' : 'nei', $server . $this->url()->fromRoute('notandi/index', ['id' => $user->id])]);
             }
         }
         $model = new CsvModel();
         $model->setData($csv);
         return $model;
     } else {
         $this->getResponse()->setStatusCode(401);
         $model = new ViewModel();
         $model->setTemplate('error/401');
         return $model;
     }
 }
コード例 #2
0
ファイル: EventController.php プロジェクト: bix0r/Stjornvisi
 /**
  * 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();
     }
 }
コード例 #3
0
ファイル: GroupController.php プロジェクト: bix0r/Stjornvisi
 /**
  * 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();
     }
 }
コード例 #4
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;
 }