示例#1
0
 public function getThumbsAction()
 {
     $galleryModel = new GalleryModel();
     // width of html doc
     $screen_width = (int) $this->params()->fromQuery('screen_width');
     //width of browser viewport
     $width = (int) $this->params()->fromQuery('width');
     $height = (int) $this->params()->fromQuery('height');
     $direction = $this->params()->fromQuery('direction');
     $limit = $galleryModel->getLimit($width, $height);
     $page = (int) $this->params('page');
     $offset = 0;
     if ($page > 0) {
         $offset = $page * $limit;
     }
     $dateYMon = $this->params('date', false);
     if (!$dateYMon) {
         $dateYMon = date("Y-M");
     } else {
         // validate date
         $partsArr = explode("-", $dateYMon);
         if (date("Y") < $partsArr[0] || $this->getGalleryModel()->validateThreeLetterMonth($partsArr[1]) == false) {
             $dateYMon = date("Y-M");
         }
     }
     $cache = $this->getGalleryModel()->getThumbGalleryCache($dateYMon);
     $key = $offset . "_" . $limit;
     $jsonStr = $cache->getItem($key, $success);
     if ($this->disableCache || !$success) {
         // get previous and next month dates from monthly nav arr
         $navArr = $this->getMonthlyNav();
         $arr = $this->getGalleryModel()->getPrevAndNextDate($navArr, $dateYMon);
         $nextDateYMon = $arr['nextDateYMon'];
         $prevDateYMon = $arr['prevDateYMon'];
         $prevTotal = $arr['prevTotal'];
         $thumbArr = $this->getGalleryMapper()->fetchThumbArr($dateYMon, $offset, $limit, $prevDateYMon, $nextDateYMon, $prevTotal);
         printR($thumbArr);
         if (!$thumbArr) {
             $offset = 0;
             $dateYMon = 0;
             if ($direction == 'next' && $nextDateYMon) {
                 $dateYMon = $nextDateYMon;
             } elseif ($prevDateYMon) {
                 $dateYMon = $prevDateYMon;
             }
             if ($dateYMon) {
                 $arr = $this->getGalleryModel()->getPrevAndNextDate($navArr, $dateYMon);
                 $nextDateYMon = $arr['nextDateYMon'];
                 $prevDateYMon = $arr['prevDateYMon'];
                 $prevTotal = $arr['prevTotal'];
                 $thumbArr = $this->getGalleryMapper()->fetchThumbArr($dateYMon, $offset, $limit, $prevDateYMon, $nextDateYMon, $prevTotal);
             }
         }
         if ($thumbArr) {
             $cache->setItem($key, serialize($thumbArr));
         }
     } else {
         $thumbArr = unserialize($jsonStr);
     }
     $jsonModel = new JsonModel(array("result" => $thumbArr));
     $jsonModel->setTerminal(true);
     return $jsonModel;
 }
示例#2
0
 public function getPicture($id, $position)
 {
     $select = $this->sql->select();
     $id = (int) $id;
     if ($position == 'current') {
         $select->where(array('id' => $id, 'unpublish' => 0, 'media_url IS NOT NULL'));
     } elseif ($position == 'next') {
         $select->where(array("id < {$id}", 'unpublish' => 0, 'media_url IS NOT NULL'));
         $select->order('id DESC')->limit(1);
     } elseif ($position == 'prev') {
         $select->where(array("id > {$id}", 'unpublish' => 0, 'media_url IS NOT NULL'));
         $select->order('id ASC')->limit(1);
     }
     //echo "<br><br>".$select->getSqlString($this->dbAdapter->getPlatform());exit;
     $statement = $this->sql->prepareStatementForSqlObject($select);
     $result = $statement->execute();
     if ($result->count() == 0) {
         if ($position == 'prev') {
             return 'top reached';
         } elseif ($position == 'next') {
             return 'end reached';
         }
     }
     $socMediaModel = new GalleryModel();
     $socMediaModel->exchangeArray($result->current());
     return $socMediaModel;
 }