コード例 #1
0
 /**
  * @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);
 }
コード例 #2
0
 /**
  * @before _secured, _admin
  */
 public function index()
 {
     $view = $this->getActionView();
     $users = App_Model_User::all(array('role <> ?' => 'role_superadmin'), array('id', 'firstname', 'lastname', 'email', 'role', 'active', 'created'), array('id' => 'asc'));
     $view->set('users', $users);
 }
コード例 #3
0
 /**
  * @before _secured, _admin
  */
 public function edit($id)
 {
     $view = $this->getActionView();
     $dog = App_Model_Dog::fetchDogById((int) $id);
     if ($dog === null) {
         $view->warningMessage(self::ERROR_MESSAGE_2);
         $this->_willRenderActionView = false;
         self::redirect('/admin/dog/');
     }
     $dogExams = $dog->exams;
     $dogExamIds = array();
     if (!empty($dogExams)) {
         foreach ($dogExams as $dogExam) {
             $dogExamIds[] = $dogExam->examId;
         }
     }
     $exams = App_Model_Exam::all(array('active = ?' => true));
     $users = App_Model_User::all(array('role = ?' => 'role_member'), array('id', 'firstname', 'lastname'));
     $view->set('dog', $dog)->set('exams', $exams)->set('dogexamids', $dogExamIds)->set('users', $users);
     if (RequestMethods::post('submitEditDog')) {
         if ($this->checkCSRFToken() !== true) {
             self::redirect('/admin/dog/');
         }
         $errors = array();
         $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));
         $imgMain = $imgThumb = '';
         if ($dog->imgMain == '') {
             $photoNameRaw = RequestMethods::post('user') . '-' . RequestMethods::post('dogname');
             $photoName = $this->_createUrlKey($photoNameRaw);
             $fileErrors = $fileManager->uploadBase64Image(RequestMethods::post('croppedimage'), $photoName, 'dog', time() . '_')->getUploadErrors();
             $files = $fileManager->getUploadedFiles();
             if (!empty($fileErrors)) {
                 $errors['croppedimage'] = $fileErrors;
             }
             if (!empty($files)) {
                 foreach ($files as $i => $file) {
                     if ($file instanceof \THCFrame\Filesystem\Image) {
                         $imgMain = trim($file->getFilename(), '.');
                         $imgThumb = trim($file->getThumbname(), '.');
                         break;
                     }
                 }
             }
         } else {
             $imgMain = $dog->imgMain;
             $imgThumb = $dog->imgThumb;
         }
         if ((int) RequestMethods::post('isactive') == 1) {
             App_Model_Dog::updateAll(array('isActive = ?' => true, 'userId = ?' => (int) RequestMethods::post('user')), array('isActive' => 0));
         }
         $dog->userId = RequestMethods::post('user');
         $dog->isActive = RequestMethods::post('isactive', 0);
         $dog->dogName = RequestMethods::post('dogname');
         $dog->race = RequestMethods::post('dograce');
         $dog->dob = RequestMethods::post('dogdob');
         $dog->information = RequestMethods::post('doginfo');
         $dog->active = RequestMethods::post('active');
         $dog->imgMain = $imgMain;
         $dog->imgThumb = $imgThumb;
         if (empty($errors) && $dog->validate()) {
             $dog->save();
             $examsArr = (array) RequestMethods::post('chexam');
             if ($examsArr[0] != '') {
                 $deleteStatus = App_Model_DogExam::deleteAll(array('dogId = ?' => (int) $dog->getId()));
                 if ($deleteStatus != -1) {
                     foreach ($examsArr as $exam) {
                         $de = new App_Model_DogExam(array('dogId' => (int) $dog->getId(), 'examId' => (int) $exam));
                         $de->save();
                         Event::fire('admin.log', array('success', 'Dog id: ' . $dog->getId() . ' has exam ' . $exam));
                     }
                 } else {
                     $errors['exams'] = array('Nastala chyba při ukládání zkoušek');
                 }
             }
             if (RequestMethods::post('uploadmorephotos') == '1') {
                 $fileErrors = $fileManager->newUpload()->uploadImage('secondfile', 'dog', time() . '_')->getUploadErrors();
                 $files = $fileManager->getUploadedFiles();
                 if (!empty($fileErrors)) {
                     $errors['secondfile'] = $fileErrors;
                 }
                 if (!empty($files)) {
                     foreach ($files as $i => $file) {
                         if ($file instanceof \THCFrame\Filesystem\Image) {
                             $info = $file->getOriginalInfo();
                             $photo = new App_Model_Photo(array('galleryId' => 2, 'imgMain' => trim($file->getFilename(), '.'), 'imgThumb' => trim($file->getThumbname(), '.'), 'description' => RequestMethods::post('description'), 'photoName' => pathinfo($file->getFilename(), PATHINFO_FILENAME), 'mime' => $info['mime'], 'format' => $info['format'], 'width' => $file->getWidth(), 'height' => $file->getHeight(), 'size' => $file->getSize()));
                             if ($photo->validate()) {
                                 $photoId = $photo->save();
                                 $dp = new App_Model_DogPhoto(array('dogId' => $dog->getId(), 'photoId' => $photoId));
                                 $dp->save();
                                 Event::fire('admin.log', array('success', 'Photo id: ' . $photoId));
                             } else {
                                 Event::fire('admin.log', array('fail'));
                                 $errors['secondfile'][] = $photo->getErrors();
                             }
                         }
                     }
                 }
                 if (empty($errors)) {
                     Event::fire('admin.log', array('success', 'Dog Id: ' . $id));
                     $view->successMessage(self::SUCCESS_MESSAGE_2);
                     self::redirect('/admin/dog/');
                 } else {
                     Event::fire('admin.log', array('fail'));
                     $view->set('errors', $errors)->set('dog', $dog);
                 }
             } else {
                 Event::fire('admin.log', array('success', 'Dog Id: ' . $id));
                 $view->successMessage(self::SUCCESS_MESSAGE_2);
                 self::redirect('/admin/dog/');
             }
         } else {
             Event::fire('admin.log', array('fail', 'Dog Id: ' . $dog->getId()));
             $view->set('errors', $errors + $dog->getErrors())->set('dog', $dog);
         }
     }
 }