/** * @before _secured, _admin */ public function index() { $view = $this->getActionView(); $latestnews = App_Model_News::all(array('active = ?' => true), array('author', 'title', 'shortBody', 'created'), array('created' => 'DESC'), 8); $latestgallery = App_Model_Gallery::all(array('active = ?' => true), array('title', 'created', 'isPublic'), array('created' => 'DESC'), 10); $latestmembers = App_Model_User::all(array('active = ?' => true, 'role = ?' => 'role_member'), array('firstname', 'lastname', 'imgThumb', 'created'), array('created' => 'DESC'), 10); $latestdogs = App_Model_Dog::fetchAllLimit(); $view->set('latestnews', $latestnews)->set('latestgallery', $latestgallery)->set('latestmembers', $latestmembers)->set('latestdogs', $latestdogs); }
/** * * @return array */ public static function fetchAllLimit() { $query = App_Model_Dog::getQuery(array('do.*'))->leftjoin('tb_user', 'do.userId = us.id', 'us', array('us.firstname', 'us.lastname'))->where('do.active = ?', true)->order('do.created', 'DESC')->limit(10); $dogs = App_Model_Dog::initialize($query); return $dogs; }
/** * @before _secured, _admin * @param type $id */ public function edit($id) { $view = $this->getActionView(); $user = App_Model_User::first(array('id = ?' => (int) $id)); if (NULL === $user) { $view->warningMessage(self::ERROR_MESSAGE_2); $this->_willRenderActionView = false; self::redirect('/admin/user/'); } elseif ($user->role == 'role_superadmin' && $this->getUser()->getRole() != 'role_superadmin') { $view->warningMessage(self::ERROR_MESSAGE_4); $this->_willRenderActionView = false; self::redirect('/admin/user/'); } $dogs = App_Model_Dog::fetchAllDogsByUserId($user->getId()); $view->set('user', $user)->set('dogs', $dogs); if (RequestMethods::post('submitEditUser')) { if ($this->checkCSRFToken() !== true) { self::redirect('/admin/user/'); } $errors = array(); if (RequestMethods::post('password') !== RequestMethods::post('password2')) { $errors['password2'] = array('Hesla se neshodují'); } if (RequestMethods::post('email') != $user->email) { $email = App_Model_User::first(array('email = ?' => RequestMethods::post('email', $user->email)), array('email')); if ($email) { $errors['email'] = array('Tento email je již použit'); } } $pass = RequestMethods::post('password'); if ($pass === null || $pass == '') { $salt = $user->getSalt(); $hash = $user->getPassword(); } else { $salt = PasswordManager::createSalt(); $hash = PasswordManager::hashPassword($pass, $salt); } if ($user->imgMain == '') { $cfg = Registry::get('configuration'); $fileManager = new FileManager(array('thumbWidth' => $cfg->thumb_width, 'thumbHeight' => $cfg->thumb_height, 'thumbResizeBy' => $cfg->thumb_resizeby, 'maxImageWidth' => $cfg->photo_maxwidth, 'maxImageHeight' => $cfg->photo_maxheight)); $photoNameRaw = RequestMethods::post('firstname') . '-' . RequestMethods::post('lastname'); $photoName = $this->_createUrlKey($photoNameRaw); $fileErrors = $fileManager->uploadBase64Image(RequestMethods::post('croppedimage'), $photoName, 'members', time() . '_')->getUploadErrors(); $files = $fileManager->getUploadedFiles(); if (!empty($files)) { foreach ($files as $i => $file) { if ($file instanceof \THCFrame\Filesystem\Image) { $imgMain = trim($file->getFilename(), '.'); $imgThumb = trim($file->getThumbname(), '.'); break; } } } else { $errors['croppedimage'] = $fileErrors; } } else { $imgMain = $user->imgMain; $imgThumb = $user->imgThumb; } $user->firstname = RequestMethods::post('firstname'); $user->lastname = RequestMethods::post('lastname'); $user->email = RequestMethods::post('email'); $user->password = $hash; $user->salt = $salt; $user->imgMain = $imgMain; $user->imgThumb = $imgThumb; $user->role = RequestMethods::post('role', $user->getRole()); $user->active = RequestMethods::post('active'); if (empty($errors) && $user->validate()) { $user->save(); Event::fire('admin.log', array('success', 'User id: ' . $id)); $view->successMessage(self::SUCCESS_MESSAGE_2); self::redirect('/admin/user/'); } else { Event::fire('admin.log', array('fail', 'User id: ' . $id)); $view->set('errors', $errors + $user->getErrors()); } } }
/** * @before _secured, _admin * @param type $id */ public function deleteMainPhoto($id) { $this->willRenderActionView = false; $this->willRenderLayoutView = false; if ($this->checkCSRFToken()) { $dog = App_Model_Dog::first(array('id = ?' => (int) $id)); if (NULL === $dog) { echo self::ERROR_MESSAGE_2; } else { @unlink($dog->getUnlinkPath()); @unlink($dog->getUnlinkThumbPath()); $dog->imgMain = ''; $dog->imgThumb = ''; if ($dog->validate()) { $dog->save(); Event::fire('admin.log', array('success', 'Dog Id: ' . $id)); echo 'success'; } else { Event::fire('admin.log', array('fail', 'Dog Id: ' . $id)); echo self::ERROR_MESSAGE_1; } } } else { echo self::ERROR_MESSAGE_1; } }
/** * * @return \App_Model_User */ public function getUserById() { $this->_activeDog = App_Model_Dog::fetchActiveDogByUserId($this->getId()); $this->_allDogs = App_Model_Dog::fetchOtherDogsByUserId($this->getId()); return $this; }