public function user() { try { $this->userModel = $this->loadModel('User'); $name = $this->getParams(); $user = $this->userModel->getUser($name[0]); if (empty($user)) { throw new NoUserFoundException($name[0]); } $user['mailHash'] = md5($user['mail']); $birthday = new \DateTime($user['birthday']); $today = new \DateTime(); $user['age'] = $birthday->diff($today)->format('%Y'); $registerDate = new \DateTime($user['registerdate']); $user['registerDateFormat'] = $registerDate->format('d/m/Y'); $user = array_merge($user, PrivacyCalculator::calculate($user['id'])); $this->getView()->render('admin/user', $user); } catch (MissingParamsException $e) { // TODO POPUP $this->getView()->render('/home/index'); } catch (NoUserFoundException $e) { // TODO POPUP $this->getView()->render('/home/index'); } }
public function accountPOST() { // HARDCODE $privacyValues = ['jobPrivacy' => 1, 'websitePrivacy' => 2, 'facebookuriPrivacy' => 4, 'skypePrivacy' => 8, 'twitterPrivacy' => 16, 'phonenumberPrivacy' => 32, 'mailPrivacy' => 64]; $input = new Input(); $toModify = $input->getPost(); try { if (!empty($params) && Authentication::getInstance()->getOptionOr('accessLevel', 0)) { $user = $this->userModel->getUser($toModify['id']); } else { $user = $this->userModel->getUser(Authentication::getInstance()->getUserId()); } if (empty($user)) { throw new NoUserFoundException(Authentication::getInstance()->getUserName()); } $privacyUser = PrivacyCalculator::calculate($user['id']); foreach ($privacyValues as $key => $value) { if (!isset($toModify[$key]) && $privacyUser[$key] == true) { $user['privacy'] -= $value; } else { if (isset($toModify[$key]) && $privacyUser[$key] == false) { $user['privacy'] += $value; } } if (isset($toModify[$key])) { unset($toModify[$key]); } } foreach ($toModify as $key => $value) { if ($user[$key] != $value) { $user[$key] = $value; } } $toModify['privacy'] = $user['privacy']; $toModify['id'] = $user['id']; $this->userModel->updateUser($toModify); $this->getView()->redirect('/user/profile/' . $toModify['username']); //$this->getView()->render('home/index'); } catch (NoUserFoundException $e) { $e->getMessage(); $this->getView()->render('/home/index'); } }