GalleryController.php 7.23 KB
<?php
class GalleryController extends QLib_Controller_Default_Action
{
    private $maxSize = 200;

    public function indexAction()
    {
        $this->view->windowOpen = $windowOpen = $this->helpGquery('windowOpen', 0);
        if ($windowOpen == 1) {
            $this->_helper->layout()->setLayout('notheard');
        }
        $this->QLayoutScript()->offsetSetFile(2, $this->_js('jquery.wookmark'))
            //->appendFile($this->_js('modernizr-transitions'))
            ->appendFile($this->_js('jquery.infinitescroll'))
            ->appendFile($this->_js('jquery.lazyload.mini'));

        $this->QLayoutLink()->offsetSetStylesheet(20, $this->_css('style_css'))
            ->appendStylesheet($this->_css('style_css'))
            ->appendStylesheet($this->_css('photogallery'));

        $title = 'YOHO!有货潮品型录 最新最全的人气潮品集合';
        $keywords = '2012新品,2012超人气单品,2012热销TEE,2012热销短裤,2012最新潮鞋,2012经典,潮流小物集合';
        $description = '2012最新最全潮流单品集合,品牌授权,100%正品保证';
        $this->setMetaInfo($title, $keywords, $description);

        $this->view->marking = $marking = $this->helpGquery('page', 1);
        $total = QCGallery_Models_Client::getGalleryTotalView();
        $this->view->paging = $paging = $this->helpPaging()->setTotal($total)->setSize($this->maxSize);
        $galleryList = QCGallery_Models_Client::getGalleryListView($paging->getOffset(), 40, $marking);
        $galleryListKey = array_keys($galleryList);
        $this->view->pageData = implode(',', $galleryListKey);
        $this->view->galleryList = $galleryList;


    }

    public function showAction()
    {
        $this->QLayoutLink()->offsetSetStylesheet(20, $this->_css('style_css'))
            ->appendStylesheet($this->_css('style_css'))
            ->appendStylesheet($this->_css('photogallery'));
        $gallery_id = (int)$this->helpGparam('gallery_id');
        $this->view->page_data = $page_data = $this->helpGquery('page_data');
        $this->view->galleryInfo = $galleryInfo = QCGallery_Models_Client::getOne($gallery_id);
        $product = array();
        if (!empty($galleryInfo['product'])) {
            foreach ($galleryInfo['product'] as $infokey => $infoval) {
                if (!empty($infoval['storage'])) {
                    $product = $infoval;
                    break;
                }
            }
        }
        if (empty($product) && !empty($galleryInfo['product'])) {
            $product = array_shift($galleryInfo['product']);
        }
        $title = $product['product_name'] . ' | YOHO!有货 100%正品保证';
        $keywords = $product['style'];
        $description = empty($product['phrase']) ? $product['product_name'] : $product['phrase'];

        $this->setMetaInfo($title, $keywords, $description);

        if (empty($galleryInfo)) {
            $this->helpGo('/gallery');
        }
        $pageData = explode(',', $page_data);
        $leftGalleryID = 0;
        $rightGalleryID = 0;
        $hitGalleryId = 0;
        foreach ($pageData as $gallery_id_key) {
            if ($hitGalleryId > 0) {
                $rightGalleryID = $gallery_id_key;
                break;
            }
            if ($gallery_id == $gallery_id_key) {
                $hitGalleryId = $gallery_id_key;
                continue;
            }
            $leftGalleryID = $gallery_id_key;
        }
        $this->view->isLike = 0;
        $this->view->isFavorite = 0;
        if ($this->uid > 0) {
            $this->view->isLike = QCGallery_Models_Favorite_Client::checkUserFavorite($gallery_id, $this->uid, 2);
            $this->view->isFavorite = QCGallery_Models_Favorite_Client::checkUserFavorite($gallery_id, $this->uid, 1);
        }
        $this->view->leftGalleryID = $leftGalleryID;
        $this->view->rightGalleryID = $rightGalleryID;
    }

    public function nextAction()
    {
        $this->_helper->layout()->disableLayout();
        $galleryList = array();
        $galleryListKey = array();
        $total = QCGallery_Models_Client::getGalleryTotalView();
        $paging = $this->helpPaging()->setTotal($total)->setSize(20);
        if ($paging->getOffset() < $this->maxSize) {
            $page = $this->helpGquery('page', 1);
            $marking = (int)Q_Utils_Function::base64_url_decode($this->helpGquery('marking'));
            if ($page <= $paging->getPageNum()) {
                $offset = $paging->getOffset();
                if ($marking > 1) {
                    $markingPage = $this->helpPaging()->setTotal($total)->setSize($this->maxSize)->setCurrent($marking);
                    $offset = $markingPage->getOffset() + $paging->getOffset();
                }
                $galleryList = QCGallery_Models_Client::getGalleryListView($offset, $paging->getSize(), $marking);
            }
            $galleryListKey = array_keys($galleryList);
        }
        $this->view->pageData = implode(',', $galleryListKey);
        $this->view->galleryList = $galleryList;
    }

    public function mouseoverAction()
    {
        $this->_helper->layout()->disableLayout();
        $gallery_id = (int)$this->helpGquery('gallery_id');
        $uid = (int)$this->helpIsLogin();
        $data = array(
            'like' => 0,
            'favorite' => 0
        );
        if ($uid > 0) {
            $data = array(
                //1是收藏2是喜欢,pd里有写
                'like' => QCGallery_Models_Favorite_Client::checkUserFavorite($gallery_id, $uid, 2),
                'favorite' => QCGallery_Models_Favorite_Client::checkUserFavorite($gallery_id, $uid, 1),
                'likeNum' => QCGallery_Models_Favorite_Client::getGalleryFavoriteCount($gallery_id, 2),
                'favoriteNum' => QCGallery_Models_Favorite_Client::getGalleryFavoriteCount($gallery_id)
            );
        }
        $this->helpJsonResult(200, 'mouseover action', $data);
    }

    public function clickAction()
    {
        $type = $this->helpGquery('type');
        if ($type != 1 && $type != 2) {
            $this->helpJsonResult('400', '点击错误.');
        }
        $gallery_id = $this->helpGquery('gallery_id');
        $uid = (int)$this->helpIsLogin();
        if ($uid < 1) {
            $this->helpJsonResult('500', '请登陆后在点击.');
        }
        $checkTotal = QCGallery_Models_Favorite_Client::checkUserFavorite($gallery_id, $uid, $type);
        if ($checkTotal > 0) {
            $this->helpJsonResult('201', '', array('click' => 0));
        }
        QCGallery_Models_Favorite_Client::setGalleryFavorete($gallery_id, $uid, $type);
        $this->helpJsonResult('200', 'click gallery', array('click' => 1));
    }

    public function updateattrAction()
    {
        set_time_limit(0);
        $galleryList = QCGallery_Models_Client::getAttrIsNull(100);
        foreach ($galleryList as $key => $val) {
            $image = QLib_Images_Client::QFSFImages($val['image_url'], 'yohopin', '200x600');
            $imagesAr = @getimagesize($image);
            if ($imagesAr == false) {
                echo $key . "<br />";
                continue;
            }
            list($width, $height, $type, $attr) = $imagesAr;
            if (!empty($attr)) {
                QCGallery_Models_Client::updateAttr($attr, $val['id']);
            }
        }
        die('ok');
    }
}