/** * @see Zend_Validate_Interface::isValid() * * @param mixed $value * @return boolean */ public function isValid($value) { // permitted roles $roles = UserRow::getRoles(); if (in_array($value, $roles)) { return true; } $this->_error('invalid', $value); return false; }
/** * Update the user information * @param $data array * @param $user - the user to update */ public function updateUser(array $data) { $roles = UserRow::getRoles(); $data['role'] = $roles[$data['role']]; try { $row = $this->fetchRow(array('email = ?' => $data['email'])); if (!$row) { throw new Zend_Exception('Fails to update - no such registered user ' . $data['email']); } $row->role = $data['role']; $row->save(); } catch (Exception $e) { throw new Zend_Exception('Fails to update' . $e->getMessage()); } }
/** * The default action - show the registration form */ public function adminAction() { $this->authenticate(); // check if admin $identity = Zend_Auth::getInstance()->getIdentity(); if ($identity['role'] != 'admin') { $this->_helper->getHelper('Redirector')->goto('view', 'portal'); } if ($this->getRequest()->isPost()) { // submitting form $data = $this->_request->getParams(); // update the user try { $this->users->updateUser($data); } catch (Exception $e) { $this->view->message = $e->getMessage(); } } // show form $this->view->roles = UserRow::getRoles(); }