public function searchAction() { $params = array_merge(array('page' => 1), array_intersect_key($_GET, Yadda_Model_Deal::$allowedSearchParams), array('count' => 5)); $this->view->results = Yadda_Model_Deal::search($params); $this->view->headTitle('yadda. - ' . $this->view->results['description'], 'SET'); $this->view->regions = Yadda_Model_Region::index(false); $this->view->priceRanges = Yadda_Model_Deal::$priceRanges; }
public function ajaxSearchAction() { $params = array_merge(array('page' => 1), array_intersect_key($_GET, Yadda_Model_Deal::$allowedSearchParams), array('count' => 15)); $deals = Yadda_Model_Deal::search($params); $html = array(); if ($deals['page'] == $deals['params']['page']) { foreach ($deals['results'] as $deal) { $html[] = $this->view->partial('deal/_deal.phtml', array('config' => $this->view->config, 'deal' => $deal)); } } $this->getResponse()->setHeader('Content-Type', 'application/json; charset=utf-8'); $this->getResponse()->setBody(Zend_Json::encode($html)); $this->getResponse()->sendResponse(); die; }
public function subscribeAction() { $form = new Www_Form_Subscribe(); if ($this->getRequest()->isPost()) { $this->view->params = array_intersect_key($_POST, Yadda_Model_Deal::$allowedSearchParams); $this->view->result = Yadda_Model_Deal::search($this->view->params); if ($form->isValid($_POST)) { $values = $form->getValues(); try { Yadda_Model_Subscription::subscribe($values); $this->getHelper('FlashMessenger')->addMessage('Your subscription has been set up.'); $this->_redirect($this->view->url(array(), 'search') . '?from=subscribe&' . http_build_query($this->view->params)); } catch (Yadda_Model_Exception $e) { $this->view->flashMessages[] = $e->getMessage(); } } } else { $this->view->params = array_intersect_key($_GET, Yadda_Model_Deal::$allowedSearchParams); $this->view->result = Yadda_Model_Deal::search($this->view->params); $form->populate($this->view->params); } $this->view->form = $form; $this->view->headLink()->appendStylesheet('/css/subscription/subscribe.css'); }
$config = Zend_Registry::get('config'); $router = new Www_Controller_Router(); $mailerUrl = 'http://' . $config->domain->www . $router->assemble(array(), 'mailer'); $unsubscribeUrl = 'http://' . $config->domain->www . $router->assemble(array(), 'unsubscribe'); // determine which subscriptions need to be sent $hour = (int) gmdate('H'); $subscriptionDb = Yadda_Db_Table::getInstance('subscription'); $select = $subscriptionDb->select()->setIntegrityCheck(false)->from('subscription')->joinLeft('user', 'subscription.user_id = user.id', array('user_email' => 'email'))->where('subscription.status = ?', 'active')->where('user.status = ?', 'active')->where('subscription.hour = ?', $hour)->order('id'); $subscriptions = $subscriptionDb->fetchAll($select); $since = gmdate('Y-m-d\\TH:00:00\\Z', strtotime('-24 hour')); foreach ($subscriptions as $subscription) { $logger->log('Subscription #' . $subscription->id, Zend_Log::DEBUG); // run the search $params = array('query' => $subscription->query, 'region' => $subscription->region_id, 'price' => $subscription->price, 'since' => $since, 'count' => 10); try { $result = Yadda_Model_Deal::search($params); } catch (Yadda_Model_Exception $e) { $logger->log('Error while searching: ' . $e->getMessage(), Zend_Log::ERR); $logger->log('Skipping...', Zend_Log::ERR); continue; } $total = $result['total']; $logger->log('Found ' . $total . ' result(s)', Zend_Log::DEBUG); if ($total == 0) { continue; } $logger->log('Sending ' . $total . ' deal(s) to ' . $subscription->user_email, Zend_Log::INFO); // fetch HTML try { $client = new Zend_Http_Client($mailerUrl, array('timeout' => 10, 'useragent' => 'send_subscriptions.php')); foreach ($params as $key => $value) {
public function listAction() { $params = array_merge(array('count' => 30), array_intersect_key($_GET, Yadda_Model_Deal::$allowedSearchParams)); $this->view->deals = Yadda_Model_Deal::search($params); }