Example #1
0
 /**
  * Fills up the model class with the given data
  * @param array $data The account data needed to fill the model
  */
 public function exchangeArray($data)
 {
     $this->id = !empty($data['id']) ? $data['id'] : null;
     $this->name = !empty($data['name']) ? $data['name'] : null;
     $this->password = !empty($data['password']) ? $data['password'] : null;
     $this->userhash = !empty($data['userhash']) ? $data['userhash'] : null;
     $this->email = !empty($data['email']) ? $data['email'] : null;
     $this->role = !empty($data['role']) ? $data['role'] : Role::NOT_ACTIVATED;
     $this->avatar = !empty($data['avatar']) ? $data['avatar'] : null;
     $this->mini = !empty($data['mini']) ? $data['mini'] : null;
     $date = new \DateTime();
     $this->date_registered = !empty($data['date_registered']) ? $data['date_registered'] : $date->format('Y-m-d H:i:s');
     if (array_key_exists('opted_out_date', $data)) {
         if (!$this->warstatus) {
             $this->warstatus = new Warstatus();
         }
         $this->warstatus->exchangeArray($data);
     }
 }
 public function editAction()
 {
     if (!PermissionChecker::check(Role::MEMBER)) {
         return $this->redirect()->toRoute('account', ['action' => 'noright']);
     }
     $session = new \Zend\Session\Container('user');
     $account = $this->getAccountTable()->getAccount($session->id);
     $warstatus = null;
     try {
         $warstatus = $this->getWarstatusTable()->getWarstatus((int) $account->getId());
     } catch (\Exception $e) {
         return $this->redirect()->toRoute('news');
     }
     if (!$warstatus) {
         $warstatus = new Warstatus($session->id);
         $warstatus->setOptedOutDate((new \DateTime())->format('Y-m-d'));
         $warstatus->setOptedOutDateMini((new \DateTime())->format('Y-m-d'));
     }
     $form = new WarstatusForm();
     //Prepare date for HTML 5 input
     $date = new \DateTime($warstatus->getOptedInDate());
     $date_mini = new \DateTime($warstatus->getOptedInDateMini());
     $warstatus->setOptedInDate($date->format('Y-m-d'));
     $warstatus->setOptedInDateMini($date_mini->format('Y-m-d'));
     $form->bind($warstatus);
     $has_mini = $account->getMini() ? true : false;
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter($warstatus->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $this->getWarstatusTable()->saveWarstatus($form->getData());
             return $this->redirect()->toRoute('account', ['action' => 'profile']);
         } else {
             $errors = $form->getMessages();
             return ['form' => $form, 'errors' => $errors, 'has_mini' => $has_mini];
         }
     }
     return ['form' => $form, 'has_mini' => $has_mini];
 }
 /**
  * Saves the given object ot the db
  * @param Warstatus $warstatus
  * @throws \Exception
  */
 public function saveWarstatus(Warstatus $warstatus)
 {
     $data = $warstatus->getArrayCopy();
     if ($warstatus->getId() == 0) {
         throw new \Exception('Id needed to save a warstatus');
     } else {
         if ($this->getWarstatus((int) $warstatus->getId())) {
             $this->tableGateway->update($data, ['id' => (int) $warstatus->getId()]);
         } else {
             $data['id'] = $warstatus->getId();
             $this->tableGateway->insert($data);
         }
     }
 }