public function editAction() { $form = new Admin_Form_User(); $form->user_type->setMultioptions($this->userTypeService->getOptions()); $form->author->setMultioptions(array('' => getGS('None')) + $this->_helper->service('author')->getOptions()); $user = $this->getUser(); $form->setDefaultsFromEntity($user); $request = $this->getRequest(); if ($request->isPost() && $form->isValid($request->getPost())) { try { $this->userService->save($form->getValues(), $user); $this->_helper->flashMessenger(getGS("User saved")); $this->_helper->redirector('edit', 'user', 'admin', array('user' => $user->getId())); } catch (\InvalidArgumentException $e) { switch ($e->getMessage()) { case 'username_conflict': $form->username->addError(getGS('Username is used already')); break; case 'email_conflict': $form->email->addError(getGS('Email is used already')); break; } } } $this->view->form = $form; $this->view->user = $user; $this->view->image = $this->_helper->service('image')->getSrc('images/' . $user->getImage(), 80, 80, 'crop'); $this->view->actions = array(array('label' => getGS('Edit permissions'), 'module' => 'admin', 'controller' => 'acl', 'action' => 'edit', 'params' => array('user' => $user->getId(), 'role' => $user->getRoleId())), array('label' => getGS('Edit subscriptions'), 'module' => 'admin', 'controller' => 'subscription', 'action' => 'index', 'class' => 'iframe', 'params' => array('user' => $user->getId()))); }
public function editAction() { $translator = \Zend_Registry::get('container')->getService('translator'); $form = new Admin_Form_User(); $form->user_type->setMultioptions($this->userTypeService->getOptions()); $form->author->setMultioptions(array('' => $translator->trans('None', array(), 'users')) + $this->_helper->service('author')->getOptions()); $user = $this->getUser(); $form->setDefaultsFromEntity($user); $request = $this->getRequest(); if ($request->isPost() && $form->isValid($request->getPost())) { try { $values = $form->getValues(); $values['attributes']['is_featured'] = $values['is_featured']; $values['attributes']['is_verified'] = $values['is_verified']; unset($values['is_featured']); unset($values['is_verified']); $this->userService->save($values, $user); $cacheService = \Zend_Registry::get('container')->get('newscoop.cache'); $cacheService->getCacheDriver()->deleteAll(); $this->_helper->flashMessenger($translator->trans("User saved", array(), 'users')); $this->_helper->redirector('edit', 'user', 'admin', array('user' => $user->getId())); } catch (\InvalidArgumentException $e) { switch ($e->getMessage()) { case 'username_conflict': $form->username->addError($translator->trans('Username is used already', array(), 'users')); break; case 'email_conflict': $form->email->addError($translator->trans('Email is used already', array(), 'users')); break; } } } $requestSymfony = \Zend_Registry::get('container')->getService('request'); $zendRouter = \Zend_Registry::get('container')->getService('zend_router'); $publicationMetadata = $requestSymfony->attributes->get('_newscoop_publication_metadata'); $baseUrl = $requestSymfony->getScheme() . '://' . $publicationMetadata['alias']['name'] . $zendRouter->assemble(array('controller' => 'images'), 'default', true); $this->view->form = $form; $this->view->user = $user; $this->view->image = $this->_helper->service('image')->getSrc('images/' . $user->getImage(), 80, 80, 'crop'); $this->view->baseImage = $baseUrl . '/' . $user->getImage(); $this->view->originalImage = $user->getImage(); $this->view->actions = array(array('label' => $translator->trans('Edit geolocation', array(), 'users'), 'module' => 'admin', 'controller' => 'user', 'action' => 'geolocation', 'class' => 'iframe', 'params' => array('user' => $user->getId())), array('label' => $translator->trans('Edit permissions', array(), 'users'), 'module' => 'admin', 'controller' => 'acl', 'action' => 'edit', 'params' => array('user' => $user->getId(), 'role' => $user->getRoleId()))); }