예제 #1
0
 /**
  * It handles the case in which a user that already used a free trial,
  * try to get another free trial (that is not allowed)
  *
  * It also set the pc_user.has_requested_free_trial field
  *
  * @param PcUser $user
  * @param PcSubscriptionType $subscriptionType
  * @param bool $isGift (=false)
  * @param bool $isAutomatic (=false)
  * @param string $paypalTransactionId (='')
  * @return bool - false if a user who requested a free trial tries to get it again, true otherwise
  */
 public static function createOrExtendSupporterAccount(PcUser $user, PcSubscriptionType $subscriptionType, $isGift = false, $isAutomatic = false, $paypalTransactionId = '')
 {
     if ($subscriptionType->getId() == PcSubscriptionTypePeer::FREE_TRIAL) {
         if ($user->getHasRequestedFreeTrial()) {
             return false;
         } else {
             $user->setHasRequestedFreeTrial(1)->save();
         }
     }
     // 3 situations can happen:
     // 1) the user is not an supporter -> we add the record
     // 2) the user is still a supporter -> we extend the subscription from the last day of the current subscription
     // 3) the user used to be a supporter (the record is still in the table) but the subscription has expired -> we
     //    start a new subscription from today
     $startDate = null;
     $today = date("Y-m-d");
     $c = new Criteria();
     $c->add(PcSupporterPeer::USER_ID, $user->getId());
     $supporterAccount = PcSupporterPeer::doSelectOne($c);
     if (!$supporterAccount) {
         $supporterAccount = new PcSupporter();
         $supporterAccount->setUserId($user->getId());
         $startDate = $today;
     } else {
         $supporterAccountExpiryDate = $supporterAccount->getExpiryDate();
         if ($today > $supporterAccountExpiryDate) {
             $startDate = $today;
         } else {
             $startDate = $supporterAccountExpiryDate;
         }
     }
     $newExpiryDateTimestamp = $supporterAccount->getNewExpiryDateAfterSubscription($subscriptionType, $startDate);
     $supporterAccount->setExpiryDate(date("Y-m-d", $newExpiryDateTimestamp))->save();
     // recording the subscription
     $subscription = new PcSubscription();
     $subscription->setUserId($user->getId())->setSubscriptionTypeId($subscriptionType->getId())->setWasGift($isGift)->setWasAutomatic($isAutomatic)->setPaypalTransactionId($paypalTransactionId)->save();
     // sending email
     $email = $user->getEmail();
     $from = sfConfig::get('app_emailAddress_contact');
     $subject = sfConfig::get('app_subscriptionSuccess_emailSubject');
     $body = sfConfig::get('app_subscriptionSuccess_emailBody');
     $replyTo = sfConfig::get('app_emailAddress_director');
     PcUtils::sendEmail($email, $subject, $body, $from, $replyTo);
     // creating task in the Inbox
     $user->addToInbox(__('ACCOUNT_SUBSCRIPTION_INBOX_MESSAGE') . ' ' . $supporterAccount->getExpiryDate('j F Y') . '.');
     return true;
 }
예제 #2
0
 /**
  *
  * @param PcUser $user
  * @param PcTask $task
  * @return boolean - return true if the entry has been actually added
  */
 public static function addEntry($user, $task)
 {
     if ($user == null) {
         return false;
     }
     if ($task == null) {
         return false;
     }
     $entry = self::retrieveByPK($user->getId(), $task->getId());
     if (is_object($entry)) {
         // the entry already exists
         return false;
     }
     $dirtyTask = new PcDirtyTask();
     $dirtyTask->setUserId($user->getId())->setTaskId($task->getId())->save();
     return true;
 }
 /**
  * Declares an association between this object and a PcUser object.
  *
  * @param      PcUser $v
  * @return     PcContactNote The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setPcUser(PcUser $v = null)
 {
     if ($v === null) {
         $this->setCreatorId(NULL);
     } else {
         $this->setCreatorId($v->getId());
     }
     $this->aPcUser = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the PcUser object, it will not be re-added.
     if ($v !== null) {
         $v->addPcContactNote($this);
     }
     return $this;
 }
예제 #4
0
 /**
  * Declares an association between this object and a PcUser object.
  *
  * @param      PcUser $v
  * @return     PcSupporter The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setPcUser(PcUser $v = null)
 {
     if ($v === null) {
         $this->setUserId(NULL);
     } else {
         $this->setUserId($v->getId());
     }
     $this->aPcUser = $v;
     // Add binding for other direction of this 1:1 relationship.
     if ($v !== null) {
         $v->setPcSupporter($this);
     }
     return $this;
 }
예제 #5
0
 /**
  * Checks the logged in user is the user $userToCheckAgainst (the legitimate user)
  *
  * @param PcUser $userToCheckAgainst
  * @return boolean
  */
 public static function checkLoggedInUserPermission(PcUser $userToCheckAgainst)
 {
     // we actually compare the ids to have a robust behaviour, safe from changes in PHP
     if (PcUserPeer::getLoggedInUser()->getId() != $userToCheckAgainst->getId()) {
         throw new sfException('User ' . $userToCheckAgainst->getId() . ' trying to access a resource illegitimately');
     }
 }
예제 #6
0
 /**
  * Sets the 'remember me' cookie and stores the hash in the db.
  *
  * @param myUser $userSf
  * @param PcUser $userApp - the user trying to login
  */
 private static function setRememberMeCookie(myUser $userSf, PcUser $userApp)
 {
     $secret = sfConfig::get('app_rememberMe_secret');
     $timeout = sfConfig::get('app_rememberMe_timeout');
     $cookieName = sfConfig::get('app_rememberMe_cookieName');
     $userId = $userSf->getAttribute('userid');
     if (!is_int($userId)) {
         throw new sfException('Couldn\'t set the rememberme cookie properly - userId invalid.');
     }
     $now = time();
     $cookieValue = md5($userApp->getId() . $secret . $now);
     $rememberMeEntry = new PcRemembermeKey();
     $rememberMeEntry->setUserId($userApp->getId())->setRemembermeKey($cookieValue)->save();
     $sfContext = sfContext::getInstance();
     $sfContext->getResponse()->setCookie($cookieName, $cookieValue, $now + $timeout);
 }
 /**
  *
  * @param PcUser $user
  * @return PcGoogleCalendar
  */
 public static function retrieveByUser(PcUser $user)
 {
     $c = new Criteria();
     $c->add(self::USER_ID, $user->getId());
     return self::doSelectOne($c);
 }
예제 #8
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      PcUser $value A PcUser object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(PcUser $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
예제 #9
0
 /**
  * Returns whether the user is the correct owner of the task
  *
  * @param PcUser $user
  * @return bool
  */
 public function validateOwner(PcUser $user)
 {
     $list = PcListPeer::retrieveByPK($this->getListId());
     return $list->getCreatorId() == $user->getId();
 }