Пример #1
0
 public function showAction()
 {
     $this->view->userRole = $this->_helper->checkUserRole->check();
     $id = $this->_request->getParam('id');
     $model = new Model_Ad();
     //check if the ad exists in memcached
     $oBackend = new Zend_Cache_Backend_Memcached(array('servers' => array(array('host' => '127.0.0.1', 'port' => '11211')), 'compression' => true));
     // configure caching frontend strategy
     $oFrontend = new Zend_Cache_Core(array('lifetime' => 3600 * 24 * 7, 'caching' => true, 'cache_id_prefix' => 'singleAd', 'logging' => false, 'write_control' => true, 'automatic_serialization' => true, 'ignore_user_abort' => true));
     // build a caching object
     $cacheAd = Zend_Cache::factory($oFrontend, $oBackend);
     $cacheTest = $cacheAd->test((int) $id);
     if ($cacheTest == false) {
         //if not exists in cache lets query to db
         $this->view->ad = $model->getAd((int) $id);
         $cacheAd->save($this->view->ad, (int) $id);
     } else {
         //load ad from memcached
         $this->view->ad = $cacheAd->load((int) $id);
     }
     //lets count the comments number and update
     $modelComments = new Model_Comment();
     $this->view->checkCountAd = $count = $modelComments->countCommentsAd((int) $id);
     //let's increment +1 the ad view counter
     $model->updateReadedAd($id);
     $this->view->countReadedAd = $model->countReadedAd($id);
     if ($this->view->checkCountAd > 0) {
         $modelComments->updateCommentsAd($id, $count);
     }
     if ($this->view->ad != null) {
         // if the id ad exists then render the ad and comments
         if ($this->view->ad['type'] == 1) {
             $this->view->page_title .= $this->view->translate('give') . ' ' . $this->view->translate('second hand') . ' ';
         }
         if ($this->view->ad['type'] == 2) {
             $this->view->page_title .= $this->view->translate('want') . ' ' . $this->view->translate('second hand') . ' ';
         }
         $this->view->comments = $model->getComments($id);
         $this->view->woeidName = $this->_helper->woeid->name($this->view->ad['woeid_code'], $this->lang);
         $this->view->page_title .= $this->view->ad['title'];
         $this->view->page_title .= ' ' . $this->view->translate('free') . ' ';
         $this->view->page_title .= ' ' . $this->view->woeidName;
         //add meta description to head
         $this->view->metaDescription = $this->view->page_title . '. ' . $this->view->ad['body'];
         //add link rel canonical , better seo
         $this->view->canonicalUrl = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $this->lang . '/ad/' . $id . '/' . $this->view->slugTitle($this->view->ad['title']);
         //if user logged in, show the comment form, if not show the login link
         $auth = Zend_Auth::getInstance();
         if (!$auth->hasIdentity()) {
             $this->view->createcomment = '<a href="/' . $this->lang . '/auth/login">' . $this->view->translate('login to post a comment') . '</a> ';
         } else {
             require_once APPLICATION_PATH . '/forms/Comment.php';
             $form = new Form_Comment();
             $form->setAction('/' . $this->lang . '/comment/create/ad_id/' . $id);
             $this->view->createcomment = $form;
         }
     } else {
         $urlChunks = explode('/', $_SERVER['REQUEST_URI']);
         $urlChunks = str_replace('.html', '', $urlChunks);
         $urlChunks = str_replace('-', ' ', $urlChunks);
         //redir to search
         $this->_redirect('/' . $this->lang . '/search/?q=' . $urlChunks[sizeof($urlChunks) - 1] . '&ad_type=1&woeid=' . $this->location, array('code' => 301));
     }
 }
Пример #2
0
 public function contestmoreAction()
 {
     $uid = Zend_Registry::get('uid');
     $id = $this->_request->getParam('id');
     $this->view->dugaar = $id;
     $q = $this->_request->getParam('q');
     if ($q == 'signup') {
         $this->view->is = 'signup';
     }
     if ($q == 'rating') {
         $this->view->is = 'rating';
     }
     if ($q == 'davaa') {
         $this->view->is = 'davaa';
     }
     $tmp = 0;
     $davaas = new Model_DbTable_Davaa();
     $this->view->davaa = $davaas->fetchAll($davaas->select()->where('fantasy_id =' . $id . ' AND active =' . $tmp));
     $tmp = 1;
     $this->view->davaaduussan = $davaas->fetchAll($davaas->select()->where('fantasy_id =' . $id . ' AND active =' . $tmp));
     $fantasys = new Model_DbTable_Fantasy();
     $fantasy = $fantasys->fetchAll($fantasys->select()->where('id=' . $id));
     foreach ($fantasy as $key => $value) {
         $this->view->fantasyname = $value['name'];
     }
     $users = new Model_DbTable_Users();
     $this->view->user = $users->fetchAll($users->select());
     $gals = new Model_DbTable_Gal();
     $this->view->galuud = $gals->fetchAll($gals->select());
     $this->view->gal = $gals->fetchAll($gals->select()->where('ezen_id =' . $uid));
     $gald = $gals->fetchAll($gals->select()->where('ezen_id =' . $uid));
     $gid = 0;
     foreach ($gald as $key => $value) {
         $gid = $value['id'];
     }
     $scores = new Model_DbTable_Score();
     $this->view->rating = $scores->fetchAll($scores->select()->where('fantasyid =' . $id)->order('total_score DESC'));
     $this->view->score = $scores->fetchAll($scores->select()->where('galid =' . $gid . ' AND fantasyid=' . $id));
     $form = new Form_Comment();
     $request = $this->getRequest();
     if ($request->isPost()) {
         if ($form->isValid($this->_request->getPost())) {
             $content = $this->_request->getParam('commentbody');
             $content = $this->check($content);
             $uid = Zend_Registry::get('uid');
             $date = date("Y-m-d H:i:s");
             $uri = 'index/index/id/' . $id;
             $comments = new Model_DbTable_Comment();
             $comments->insert(array('uri' => $uri, 'content' => $content, 'uid' => $uid, 'date' => $date));
             $this->_redirect('news/more/id/' . $id);
         }
     }
     $form->setAction('../../index/index');
     $this->view->form = $form;
     $news = new Model_DbTable_News();
     $this->view->news = $news->fetchAll($news->select()->where('isactive = 1')->order('isping DESC')->order('date DESC'));
     $this->view->news1 = $news->fetchAll($news->select()->where('isactive = 0')->order('date DESC'));
     $page = 0;
     if ($this->_request->getParam("page") != null) {
         $page = $this->_request->getParam("page");
     }
     $this->view->page = $page;
     $q = $news->fetchAll($news->select()->where('isactive = 1')->order('isping DESC')->order('date DESC'));
     $id = $this->_request->getParam('id');
     $this->view->dugaar = $id;
     $paginator = Zend_Paginator::factory($q);
     $paginator->setItemCountPerPage("6")->setCurrentPageNumber($this->_getParam('page', 1));
     $this->view->medee = $paginator;
     $comments = new Model_DbTable_Comment();
     $this->view->comment = $comments->fetchAll($comments->select()->order('date DESC'));
 }