private function setModel($row) { $model = new Application_Model_Subscribe(); $model->setId($row->id)->setUserId($row->user_id)->setItem($row->item)->setFirstName($row->first_name)->setLastName($row->last_name)->setSex($row->sex)->setEmail($row->email)->setStatus($row->status)->setAddedon($row->addedon)->setUpdatedon($row->updatedon); return $model; }
/** * @Created By : Mahipal Singh Adhikari * @Created On : 18-Jan-2011 * @Description : Unsubscribe user from newsletter service */ public function newsletterUnsubscribeAction() { $user_id = $this->_getParam('user_id'); $user_id = base64_decode($user_id); if ($user_id == "" || !is_numeric($user_id) || $user_id == 0) { $this->view->errorMsg = "Invalid request: No user fond, please make sure that you are addressing correct page URL."; } else { $userM = new Application_Model_User(); $userRes = $userM->find($user_id); if ($userRes) { //get user subscription info $subscribeM = new Application_Model_Subscribe(); $subscribeRes = $subscribeM->fetchRow("user_id={$user_id}"); //if($userRes->getNewsletter()!="" && $userRes->getNewsletter()=="yes") if ($subscribeRes) { $dbRes = $userM->newsletterSubscribe($user_id, 0); //$dbRes = $subscribeM->delete("user_id={$user_id}"); if ($dbRes) { $this->view->errorMsg = "Sorry to see you go. You have been successfully unsubscribed."; } else { $this->view->errorMsg = "Error occured, please try again later."; } } else { $this->view->errorMsg = "You've already unsubscribed from our newsletter service."; } } else { $this->view->errorMsg = "Invalid request: No user fond, please make sure that you are addressing correct page URL."; } } //else }
/** * @Created By : Mahipal Singh Adhikari * @Created On : 17-Jan-2011 * @Description : Update user newsletter status * @Input : $user_id (int) , $status->string * @Return : none */ public function newsletterSubscribe($user_id, $status = 1) { $user_id = trim($user_id); if (is_numeric($user_id)) { $db = Zend_Registry::get("db"); //Update user's newsletter status //$sSQL = "UPDATE user SET newsletter='{$status}' WHERE id=".$user_id; $item = "news"; $status = $status; $addedon = time(); //Check if user record already exists in database table $subscribeM = new Application_Model_Subscribe(); $subscribeRes = $subscribeM->fetchRow("user_id={$user_id}"); if ($subscribeRes) { $sSQL = "UPDATE subscribe SET status={$status}, updatedon={$addedon} WHERE user_id={$user_id}"; } else { $sSQL = "INSERT INTO subscribe (user_id, item, status, addedon) values({$user_id}, '{$item}', {$status}, {$addedon})"; } $db->query($sSQL); return true; } else { return false; } }