/** @inheritDoc */ public function translate($key, array $args = [], Locale $locale = null) { $locales = [$locale, $this->defaultLocale, Locale::parse('en')]; foreach ($locales as $locale) { if (!$locale) { continue; } $message = $this->messages->get($key, $locale); if ($message) { return $message->format($args); } } return $key; }
/** * Default header used by all View objects. * If necessary can be overwritten. * * @return void */ public function header() { $this->view->top_info = $this->html->divClosed('top-back'); $this->view->login_form = $this->getTemplate('login_form'); // verify if user exists in session if (isset($_SESSION['oUser']) && $_SESSION['oUser']) { // assign user object properties to the header template fields $this->view->user_id = $_SESSION['oUser']->getId(); $this->view->user_login = $_SESSION['oUser']->getLogin(); $this->view->user_firstname = $_SESSION['oUser']->getFirstname(); $this->view->user_lastname = $_SESSION['oUser']->getLastname(); // default woman (1) or man (2) avatar is assigned by default $this->view->user_avatar = URL_IMG . 'avatar-' . $_SESSION['oUser']->getGender() . EXT_PNG; // if user has avatar it's assigned to the user if ($_SESSION['oUser']->hasAvatar()) { $this->view->user_avatar = URL_PHOTOS . $_SESSION['oUser']->getId() . '/avatar' . EXT_JPG; } // after login the user menu will be shown if (!$this instanceof LoginView) { $this->view->user_menu = $this->buildUserMenu(); $this->view->user_menu_panel = $this->getTemplate('user_menu_panel'); $this->view->login_form = $this->getTemplate('welcome_avatar'); } } // gets a sum of registered users // $this->view->total_users = $this->html->liBegin() . $this->html->linkBegin(URL_LOGIN, '', '', '', 'text-decoration: blink; font-weight: bold;') . $this->view->total_users = $this->html->liBegin() . $this->html->linkBegin(URL_LOGIN, '', '', '', 'font-weight: bold;') . MessageBundle::getMessage('link.label.search.friends') . ' (' . $this->model->countAllUsers() . ')' . $this->html->linkEnd() . $this->html->liEnd(); // display the header template $this->view->show('header'); }
/** * Handles display and messages for new Photo. * * @return void * @author anza */ public function addPhoto() { // check if any key in request is of error type if ($this->request->hasKey(ErrorEnum::ERROR)) { // setting general error message and view style for a template $this->view->add_new_photo_message_class = ErrorEnum::ERROR; $this->view->add_new_photo_message = MessageBundle::getMessage('form.validation.field.addphoto.noimage.exists'); if ($this->request->hasKey(ErrorEnum::FILENOIMAGE)) { $this->view->add_new_photo_message = MessageBundle::getMessage('form.validation.field.addphoto.filenoimage'); } } $this->view->add_to_existing_album = $this->helper->getExistingAlbumsToForm(); $this->view->show('profile_gallery_add'); }
/** * Tests MessageBundle->getMessages() */ public function testGetMessages() { $this->assertEquals($this->Messages, $this->MessageBundle->getMessages()); }
/** * Retrieves request from controller and build priopriate view output. * @return void */ public function register() { // check if any key in request is of error type if ($this->request->hasKey(ErrorEnum::ERROR)) { // setting general error message and view style for a template $this->view->register_message = MessageBundle::getMessage('form.validation.field.incorrect'); $this->view->register_message_class = ErrorEnum::ERROR; // if error is regarding user inputs this clause is enetered if ($this->request->hasKey(ErrorEnum::USER)) { // is there a problem with login input... if ($this->request->hasKey(ErrorEnum::LOGIN)) { $this->view->register_message = MessageBundle::getMessage('form.validation.field.register.login.exists'); } else { if ($this->request->hasKey(ErrorEnum::EMAIL)) { $this->view->register_message = MessageBundle::getMessage('form.validation.field.register.email.exists'); } } } else { if ($this->request->hasKey(ErrorEnum::VALIDATION)) { echo 'KOKOO'; $this->view->register_message = MessageBundle::getMessage('form.validation.field.incorrect.values'); } } // registration form values processing foreach ($this->request->container as $key => $value) { // setting form values $this->view->{$key} = $value; // in case of empty value... if (empty($value)) { // ...form input is properly styled $errorStyle = $key . ErrorEnum::STYLE_SUFFIX; $this->view->{$errorStyle} = ErrorEnum::STYLE_COLOR; } // assign a hint to a form field $hintName = $key . '_hint'; $this->view->{$hintName} = MessageBundle::getMessage('form.validation.field.register.hint.' . $key); } } else { if ($this->request->hasKey('success')) { $this->view->register_message = MessageBundle::getMessage('form.validation.field.register.success'); $this->view->register_message_class = 'success'; } } // display template with the view assigned values $this->view->show($this->currentAction); }