/**
  * @throws Zend_Controller_Action_Exception
  */
 public function planInfoAction()
 {
     //Get user
     $identity = Zend_Auth::getInstance()->getIdentity();
     $userId = $identity->id;
     //Get current subscription
     $subscriptionManager = new Subscriptions_Model_Subscription_Manager();
     $currentSubscription = $subscriptionManager->getCurrentSubscription($userId);
     if ($currentSubscription) {
         $subscriptionPlansTable = new Subscriptions_Model_SubscriptionPlans_Table();
         $subscriptionPlan = $subscriptionPlansTable->getById($currentSubscription->subscriptionPlanId);
         $this->view->currentSubscription = $currentSubscription;
         $this->view->subscriptionPlan = $subscriptionPlan;
     } else {
         throw new Zend_Controller_Action_Exception('Page not found');
     }
 }
 public function testCreateActionByUserNotTrialPlan()
 {
     //POST
     //Save fake user to DB
     $account = new Users_Model_User();
     $account->avatar = null;
     $account->login = '******' . date('YmdHis');
     $account->email = 'testCreateActionByUserNotTrialPlan' . time() . '@example.org';
     $account->password = md5('password');
     $account->role = Users_Model_User::ROLE_USER;
     $account->status = Users_Model_User::STATUS_ACTIVE;
     $account->save();
     //Login
     Zend_Auth::getInstance()->getStorage()->write($account);
     //Get plan
     $subscriptionPlansTable = new Subscriptions_Model_SubscriptionPlans_Table();
     $subscriptionPlan = $subscriptionPlansTable->getByType(Subscriptions_Model_SubscriptionPlan::PLAN_TYPE_MONTHLY);
     $this->request->setMethod('POST')->setPost(array('id' => $subscriptionPlan->id));
     $this->dispatch('/subscriptions/index/create');
     $this->assertModule('subscriptions');
     $this->assertController('index');
     $this->assertAction('create');
 }
Exemple #3
0
 /**
  * Get expiration date
  * If null - plan with unlimited period
  *
  * @param $userId
  * @param $planId
  * @return bool|null|string
  */
 public function getExpirationDate($userId, $planId)
 {
     //Get subscription plan
     $subscriptionPlansTable = new Subscriptions_Model_SubscriptionPlans_Table();
     $subscriptionPlan = $subscriptionPlansTable->getById($planId);
     //If plan have period
     if ($subscriptionPlan->period > 0) {
         $select = $this->getDbTable()->select()->from(array('subscriptions'), array('expirationDate'))->where('userId =?', $userId)->where('subscriptionPlanId =?', $planId)->where('status =?', Subscriptions_Model_Subscription::STATUS_ACTIVE)->where('expirationDate > ?', date('Y-m-d H:i:s'))->order('expirationDate DESC');
         $subscriptionRow = $this->getDbTable()->fetchRow($select);
         if ($subscriptionRow && $subscriptionRow->expirationDate) {
             $seconds = (int) $subscriptionPlan->period * 86400;
             return $expirationDate = date('Y-m-d H:i:s', strtotime($subscriptionRow->expirationDate) + $seconds);
         } else {
             //If is first subscription this type
             return $expirationDate = date('Y-m-d H:i:s', mktime(date("H"), date("i"), date("s"), date("m"), date("d") + (int) $subscriptionPlan->period, date("Y")));
         }
     }
     //Plan with unlimited period
     return null;
 }
Exemple #4
0
 public function testGetExpirationDate()
 {
     //Create user
     $account = new Users_Model_User();
     $account->avatar = null;
     $account->login = '******' . date('YmdHis');
     $account->email = 'testGetExpirationDate' . time() . '@example.org';
     $account->password = md5('password');
     $account->role = Users_Model_User::ROLE_USER;
     $account->status = Users_Model_User::STATUS_ACTIVE;
     $account->save();
     //Get subscription plan
     $subscriptionPlansTable = new Subscriptions_Model_SubscriptionPlans_Table();
     $subscriptionManager = new Subscriptions_Model_Subscription_Manager();
     //Get plan with infinite subscription
     $subscriptionPlan = $subscriptionPlansTable->getByType(Subscriptions_Model_SubscriptionPlan::PLAN_TYPE_INFINITE);
     $expirationDate = $subscriptionManager->getExpirationDate($account->id, $subscriptionPlan->id);
     $this->assertNull($expirationDate);
     //Get plan with monthly subscription
     $subscriptionPlan = $subscriptionPlansTable->getByType(Subscriptions_Model_SubscriptionPlan::PLAN_TYPE_MONTHLY);
     $expirationDate = $subscriptionManager->getExpirationDate($account->id, $subscriptionPlan->id);
     $this->assertEquals(date('Y-m-d H:i:s', mktime(date("H"), date("i"), date("s"), date("m"), date("d") + 30, date("Y"))), $expirationDate);
 }