public function indexAction() { //users cannot register as advertisers $session = new Zend_Session_Namespace('user'); if ($session->user != null) { $this->_redirect('/user'); return; } //redirect the user to the login page if they are not logged in $session = new Zend_Session_Namespace('advertiser'); if ($session->advertiser == null) { $this->_redirect('/advertiser/login'); return; } $form = new Advert_Models_Forms_Create(); if ($this->getRequest()->isPost()) { if ($form->isValid($_POST)) { $advertDetails = array('advertiserID' => $session->advertiser->accountID, 'status' => 'pending'); $advertDetails = array_merge($_POST, $advertDetails); $advert = new Advert_Models_Advert($advertDetails); $advert->save(); return; } } $this->view->form = $form; }
public function indexAction() { //users cannot register as advertisers $session = new Zend_Session_Namespace('user'); if ($session->user != null) { $this->_redirect('/user'); return; } //check if the advertiser is logged in again $session = new Zend_Session_Namespace('advertiser'); if ($session->advertiser != null) { $this->_redirect('/advertiser'); return; } $form = new User_Models_Forms_Login(); $form->setAction('/advertiser/login'); if ($this->getRequest()->isPost()) { if ($form->isValid($_POST)) { $advertiser = Advertiser_Models_Advertiser::login($_POST['username'], $_POST['password']); if (get_class($advertiser) != 'Advertiser_Models_Advertiser') { $this->view->formErrors = array($advertiser); } else { $session = new Zend_Session_Namespace('advertiser'); $session->advertiser = $advertiser; $session->advertiser->adverts = Advert_Models_Advert::getAdvertisersAds($session->advertiser->accountID); $this->_redirect('/advertiser'); return; } } } $this->view->form = $form; }
public function indexAction() { //make sure the user is logged in $session = new Zend_Session_Namespace('user'); if ($session->user == null) { $this->_redirect('/user'); return; } //get and assign user adverts if they already haven't been assigned if ($session->adverts == null) { //get available adverts $adverts = Advert_Models_Advert::getAdvertsForDisplay(4); //assigned the adverts to the user $session->adverts = $adverts; //log that the adverts were assigned to this user but have not been click yet foreach ($adverts as $advert) { $log = array('advertID' => $advert->advertID, 'userID' => $session->user->accountID, 'assignedDate' => date('Y-m-d')); $history = new Advert_Models_AdvertHistory($log); for ($i = 0; $i < $advert->display; $i++) { $history->save(); } } } //make adverts accessible in the view $this->view->adverts = $session->adverts; }