/**
  * Show and update user profile information
  * @return array
  */
 public function indexAction()
 {
     //Get current user id and data from db
     $user = new Container('user');
     $userId = $user->identity->getId();
     $currentUser = $this->getObjectManager()->getRepository('Application\\Entity\\User')->findOneBy(array('id' => $userId));
     $formManager = $this->serviceLocator->get('FormElementManager');
     $form = $formManager->get('profileForm');
     $form->setInputFilter(new Form\ProfileFilter($this->getObjectManager()));
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             //Update user profile information
             $currentUser->setEmail($request->getPost('email'));
             $currentUser->setCompany($request->getPost('company'));
             $currentUser->setFirstName($request->getPost('first_name'));
             $currentUser->setLastName($request->getPost('last_name'));
             $currentUser->setAddress($request->getPost('address'));
             $currentUser->setZipcode($request->getPost('zipcode'));
             $currentUser->setCity($request->getPost('city'));
             $currentUser->setCountry($request->getPost('country'));
             $currentUser->setPhone($request->getPost('phone'));
             $currentUser->setLastModified(new \DateTime("now"));
             $bcrypt = new Bcrypt();
             $securePass = $bcrypt->create($request->getPost('password'));
             $currentUser->setPassword($securePass);
             $user->identity = $currentUser;
             //Track activity
             $activity = new Activity();
             $activity->setUserId($userId);
             $activity->setDescription('Updated profile');
             $activity->setUri($request->getUriString());
             $activity->setQuery(var_export($request->getQuery(), true));
             $activity->setPost(var_export($request->getPost(), true));
             $activity->setObject(var_export($currentUser, true));
             $activity->setCreated(new \DateTime("now"));
             $this->getObjectManager()->persist($activity);
             //Store user profile information do db
             $this->getObjectManager()->persist($currentUser);
             $this->getObjectManager()->flush();
             //REDIRECT TO PROFILE PAGE
             return $this->redirect()->toRoute('profile');
         }
     } else {
         //Prepare data to fill the form
         $formData = array();
         $formData['id'] = $currentUser->getId();
         $formData['email'] = $currentUser->getEmail();
         $formData['company'] = $currentUser->getCompany();
         $formData['first_name'] = $currentUser->getFirstName();
         $formData['last_name'] = $currentUser->getLastName();
         $formData['address'] = $currentUser->getAddress();
         $formData['zipcode'] = $currentUser->getZipcode();
         $formData['city'] = $currentUser->getCity();
         $formData['country'] = $currentUser->getCountry();
         $formData['phone'] = $currentUser->getPhone();
         $form->setData($formData);
     }
     return array('form' => $form);
 }
 /**
  * Delete existing News entry
  * @return array
  */
 public function deleteAction()
 {
     $user = new Container('user');
     $userId = $user->identity->getId();
     $currentUser = $this->getObjectManager()->getRepository('Application\\Entity\\User')->findOneBy(array('id' => $userId));
     $id = $this->getRequest()->getQuery('id');
     if (empty($id)) {
         $id = $this->getRequest()->getPost('id');
     }
     $formManager = $this->serviceLocator->get('FormElementManager');
     $form = $formManager->get('newsForm');
     $form->setInputFilter(new Form\NewsFilter($this->getObjectManager()));
     $request = $this->getRequest();
     if ($id > 0) {
         $news = $this->getObjectManager()->getRepository('Application\\Entity\\News')->findOneBy(array('id' => $id));
         if (is_object($news)) {
             $activity = new Activity();
             $activity->setUserId($userId);
             $activity->setDescription('Added News');
             $activity->setUri($request->getUriString());
             $activity->setQuery(var_export($request->getQuery(), true));
             $activity->setPost(var_export($request->getPost(), true));
             $activity->setObject(var_export($news, true));
             $activity->setCreated(new \DateTime("now"));
             $this->getObjectManager()->persist($activity);
             $this->getObjectManager()->remove($news);
             $this->getObjectManager()->flush();
         }
     }
     return $this->redirect()->toRoute('news');
 }