Exemplo n.º 1
0
 public function indexAction()
 {
     $this->view->headMeta()->setName('description', 'Yadda (yet another daily deal aggregator) gathers into one space the daily deals and specials offered by South Africa\'s popular group buying websites.');
     $this->view->headLink()->appendStylesheet('/css/index/index.css');
     $this->view->regions = Yadda_Model_Region::index(false);
     $this->view->sites = Yadda_Model_Site::all();
     $this->view->featured = Yadda_Model_Deal::featured(3);
 }
Exemplo n.º 2
0
 public function deleteAction()
 {
     $id = $this->_getParam('id');
     try {
         Yadda_Model_Site::delete($id);
         $this->getHelper('FlashMessenger')->addMessage('Site deleted.');
     } catch (Yadda_Model_Exception $e) {
         $this->getHelper('FlashMessenger')->addMessage('Error: ' . $e->getMessage());
     }
     $this->_redirect($this->getHelper('ReturnUrl')->getUrl('/site/edit/id/' . $id));
 }
Exemplo n.º 3
0
 public function __construct($deal)
 {
     parent::__construct();
     $this->setAction('/deal/edit/id/' . $deal['id']);
     $this->addElements(array('title' => array('type' => 'text', 'options' => array('label' => 'Title')), 'description' => array('type' => 'textarea', 'options' => array('label' => 'Description', 'rows' => 10, 'cols' => 60)), 'site' => array('type' => 'select', 'options' => array('label' => 'Site', 'multiOptions' => Yadda_Model_Site::index(true))), 'region' => array('type' => 'select', 'options' => array('label' => 'Region', 'multiOptions' => Yadda_Model_Region::index(true))), 'price' => array('type' => 'text', 'options' => array('label' => 'Price (R)', 'class' => 'short')), 'value' => array('type' => 'text', 'options' => array('label' => 'Value (R)', 'class' => 'short')), 'discount' => array('type' => 'text', 'options' => array('label' => 'Discount (%)', 'class' => 'short')), 'lat' => array('type' => 'text', 'options' => array('label' => 'Latitude', 'class' => 'short')), 'long' => array('type' => 'text', 'options' => array('label' => 'Longitude', 'class' => 'short')), 'submit' => array('type' => 'submit', 'options' => array('label' => 'Submit'))));
 }
Exemplo n.º 4
0
 /**
  * Updates a deal.
  * 
  * @param int $id
  * @param array $values
  * @throws Yadda_Model_Exception
  * @return void
  */
 public static function update($id, array $values)
 {
     $deal = self::find($id);
     $update = array();
     $where = array('id = ?' => $deal['id']);
     // validate - title
     if (isset($values['title'])) {
         if (empty($values['title'])) {
             throw new Yadda_Model_Exception('Please provide a title for the deal.');
         } else {
             $update['title'] = trim($values['title']);
         }
     }
     // validate - description
     if (isset($values['description'])) {
         $update['description'] = empty($values['description']) ? null : trim($values['description']);
     }
     // validate - site
     if (isset($values['site'])) {
         $site = Yadda_Model_Site::find($values['site']);
         $update['site_id'] = $site['id'];
     }
     // validate - region
     if (isset($values['region'])) {
         $region = Yadda_Model_Region::find($values['region']);
         $update['region_id'] = $region['id'];
     }
     // validate - price
     if (isset($values['price'])) {
         if (empty($values['price'])) {
             $update['price'] = null;
         } else {
             $update['price'] = (double) $values['price'];
         }
     }
     // validate - value
     if (isset($values['value'])) {
         if (empty($values['value'])) {
             $update['value'] = null;
         } else {
             $update['value'] = (double) $values['value'];
         }
     }
     // validate - discount
     if (isset($values['discount'])) {
         if (empty($values['discount'])) {
             $update['discount'] = null;
         } else {
             $update['discount'] = (double) $values['discount'];
         }
     }
     // validate - lat
     if (isset($values['lat'])) {
         if (preg_match('/^\\s*$/', $values['lat'])) {
             $update['lat'] = null;
         } else {
             $lat = (double) $values['lat'];
             if ($lat <= -180 || $lat >= 180) {
                 throw new Yadda_Model_Exception('Please provide a valid latitude.');
             }
             $update['lat'] = $lat;
         }
     }
     // validate - long
     if (isset($values['long'])) {
         if (preg_match('/^\\s*$/', $values['long'])) {
             $update['long'] = null;
         } else {
             $long = (double) $values['long'];
             if ($long <= -180 || $long >= 180) {
                 throw new Yadda_Model_Exception('Please provide a valid longitude.');
             }
             $update['long'] = $long;
         }
     }
     // check if there's anything to do?
     if (sizeof($update) == 0) {
         return;
     }
     // do the update
     $dealDb = Yadda_Db_Table::getInstance('deal');
     $dealDb->getAdapter()->beginTransaction();
     try {
         $update['modified'] = Yadda_Db::now();
         $dealDb->update($update, $where);
         $dealDb->getAdapter()->commit();
     } catch (Exception $e) {
         $dealDb->getAdapter()->rollBack();
         throw $e;
     }
 }
Exemplo n.º 5
0
 public function __construct()
 {
     parent::__construct();
     $this->setAction('/feed/new');
     $this->addElements(array('site' => array('type' => 'select', 'options' => array('label' => 'Site', 'multiOptions' => Yadda_Model_Site::index(true))), 'region' => array('type' => 'select', 'options' => array('label' => 'Region', 'multiOptions' => Yadda_Model_Region::index(true))), 'engine' => array('type' => 'select', 'options' => array('label' => 'Engine', 'multiOptions' => array('' => '') + Yadda_Model_Feed::$engines)), 'url' => array('type' => 'text', 'options' => array('label' => 'URL', 'attribs' => array('placeholder' => 'http://'))), 'submit' => array('type' => 'submit', 'options' => array('label' => 'Submit'))));
 }
Exemplo n.º 6
0
 /**
  * Updates a feed.
  * 
  * @param int $id
  * @param array $values
  * @throws Yadda_Model_Exception
  * @return void
  */
 public static function update($id, array $values)
 {
     $feed = self::find($id);
     $update = array();
     $where = array('id = ?' => $feed['id']);
     // validate - site
     if (isset($values['site'])) {
         $site = Yadda_Model_Site::find($values['site']);
         $update['site_id'] = $site['id'];
     }
     // validate - region
     if (isset($values['region'])) {
         $region = Yadda_Model_Region::find($values['region']);
         $update['region_id'] = $region['id'];
     }
     // validate - engine
     if (isset($values['engine'])) {
         if (!isset(self::$engines[$values['engine']])) {
             throw new Yadda_Model_Exception('Please select a valid engine.');
         }
         $update['engine'] = $values['engine'];
     }
     // validate - url
     if (isset($values['url'])) {
         if (empty($values['url'])) {
             throw new Yadda_Model_Exception('Please supply a URL for this feed.');
         } else {
             try {
                 $uri = Zend_Uri::factory($values['url']);
                 $update['url'] = $values['url'];
             } catch (Zend_Uri_Exception $e) {
                 throw new Yadda_Model_Exception('Please supply a valid URL for this feed.');
             }
         }
     }
     // check if there's anything to do?
     if (sizeof($update) == 0) {
         return;
     }
     // do the update
     $feedDb = Yadda_Db_Table::getInstance('feed');
     $feedDb->getAdapter()->beginTransaction();
     try {
         $feedDb->update($update + array('modified' => Yadda_Db::now()), $where);
         $feedDb->getAdapter()->commit();
     } catch (Exception $e) {
         $feedDb->getAdapter()->rollBack();
         throw new Yadda_Model_Exception('Database error: ' . $e->getMessage());
     }
 }