/**
  *
  * @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;
 }
 /**
  * Get the associated PcUser object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     PcUser The associated PcUser object.
  * @throws     PropelException
  */
 public function getPcUser(PropelPDO $con = null)
 {
     if ($this->aPcUser === null && $this->user_id !== null) {
         $this->aPcUser = PcUserPeer::retrieveByPk($this->user_id);
         // Because this foreign key represents a one-to-one relationship, we will create a bi-directional association.
         $this->aPcUser->setPcSupporter($this);
     }
     return $this->aPcUser;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
Example #5
0
 /**
  * Sets the date format
  *
  * @param PcUser $user
  */
 private static function setDateFormat(PcUser $user)
 {
     $forumTablesPrefix = sfConfig::get('app_forum_tablePrefix');
     $connection = Propel::getConnection();
     $userId = $user->getForumId();
     $query = sprintf("UPDATE " . $forumTablesPrefix . "users SET date_format=%d WHERE id=%d", (int) $user->getDateFormat(true), (int) $userId);
     $statement = $connection->prepare($query);
     $statement->execute();
 }
Example #6
0
 /**
  * @param PcUser $loggedInUser
  * @param int $forcedTimeFormatId
  * @return string
  */
 public function getHumanFriendlyTime(PcUser $loggedInUser, $forcedTimeFormatId = null)
 {
     if ($this->integerValue === NULL) {
         return '';
     }
     list($hour, $minute) = $this->getDueTimeHourAndMinute();
     $timeFormat = $forcedTimeFormatId !== null ? $forcedTimeFormatId : $loggedInUser->getTimeFormat();
     if ($timeFormat == 1) {
         if (strlen($minute) == 1) {
             $minute = '0' . $minute;
         }
         return $hour . ':' . $minute;
     } else {
         // see http://en.wikipedia.org/wiki/24-hour_clock
         $pm = null;
         if ($hour > 12) {
             $hour -= 12;
             $pm = true;
         } else {
             if ($hour == 12) {
                 $pm = true;
             } else {
                 if ($hour == 0) {
                     $hour = 12;
                 }
                 $pm = false;
             }
         }
         if (strlen($minute) == 1) {
             $minute = '0' . $minute;
         }
         return $hour . ':' . $minute . ($pm ? 'pm' : 'am');
     }
 }
Example #7
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');
     }
 }
Example #8
0
 /**
  * Register a new user
  *
  * @param string $email - the email address
  * @param string $password - the plain password (no encryption)
  * @param string $lang - if it is null or empty, the language will be detected from the header of the request
  * @param string $preferredLang - this should be a 2-char abbreviation of the lang the user wants,
  *         among the ones in the main app.yml config file
  * @param string $tzLabel - a timezone label as in the PcTimezone db table
  * @param integer $dstOn (1 or 0) - whether or not the dst for the user is on
  * @param boolen $joinNewsletter(=false) - whether the user decided to join our newsletter
  * @param boolen $sendActivationEmail(=true) - whether to send the activation email  
  * @return boolean|PcUser false is a user with that email already exists, the PcUser object otherwise
  */
 public static function registerNewUser($email, $password, $lang, $preferredLang, $tzLabel, $dstOn, $joinNewsletter = false, $sendActivationEmail = true)
 {
     if (self::emailExist($email)) {
         return false;
     }
     $newUser = new PcUser();
     $newUser->setEmail($email);
     $newUser->setPassword($password);
     $newUser->setAwaitingActivation(1);
     if ($joinNewsletter) {
         $newUser->setNewsletter(1);
     }
     $newUser->save();
     // Dealing with timezone
     $newUser->setDstActive($dstOn);
     $c = new Criteria();
     $c->add(PcTimezonePeer::LABEL, $tzLabel, Criteria::EQUAL);
     $timezone = PcTimezonePeer::doSelectOne($c);
     if (!is_object($timezone)) {
         // set to a default one
         $timezone = PcTimezonePeer::retrieveByPK(21);
     }
     $newUser->setTimezoneId($timezone->getId());
     // Dealing with formats
     // _ time format: the countries with the majority of our users are using the
     //   12H format, thus we can leave the default
     // _ for the date format we check whether they are in USA
     // _ for the first day of the week, we check whether they are in USA
     $dateFormatId = 3;
     $weekStart = 1;
     // from Monday
     $tzOffset = $timezone->getOffset();
     if ($tzOffset <= -300 && $tzOffset >= -450) {
         $dateFormatId = 4;
         $weekStart = 0;
         // from Sunday
     }
     $newUser->setDateFormat($dateFormatId);
     $newUser->setWeekStart($weekStart);
     if ($lang != null && $lang !== '') {
         $newUser->setLanguage($lang);
     } else {
         $newUser->setLanguage(PcUtils::getVisitorAcceptLanguage());
     }
     $availableLangs = PcLanguagePeer::getAvailableLanguageAbbreviations();
     if (in_array($preferredLang, $availableLangs)) {
         $newUser->setPreferredLanguage($preferredLang);
     } else {
         $newUser->setPreferredLanguage(SfConfig::get('app_site_defaultLang'));
     }
     $newUser->setIpAddress(PcUtils::getVisitorIPAddress());
     if ($sessionEntryPoint = sfContext::getInstance()->getUser()->getAttribute('session_entry_point')) {
         $newUser->setSessionEntryPoint($sessionEntryPoint);
     }
     if ($sessionReferral = sfContext::getInstance()->getUser()->getAttribute('session_referral')) {
         $newUser->setSessionReferral($sessionReferral);
     }
     $newUser->save();
     // Creating system lists
     $inboxList = new PcList();
     $inboxList->setIsInbox(1)->setTitle(__('ACCOUNT_LISTS_INBOX'))->setCreator($newUser)->save();
     $todoList = new PcList();
     $todoList->setIsTodo(1)->setTitle(__('ACCOUNT_LISTS_TODO'))->setCreator($newUser)->save();
     // Creating default contexts
     $context = new PcUsersContexts();
     $context->setPcUser($newUser)->setContext(__('ACCOUNT_TAGS_DEFAULT_HOME'))->save();
     $context = new PcUsersContexts();
     $context->setPcUser($newUser)->setContext(__('ACCOUNT_TAGS_DEFAULT_ERRANDS'))->save();
     $context = new PcUsersContexts();
     $context->setPcUser($newUser)->setContext(__('ACCOUNT_TAGS_DEFAULT_COMPUTER'))->save();
     // Creating some tasks for the inbox
     $newUser->addToInbox(__('ACCOUNT_MISC_WELCOME_TASK'));
     // creating Plancake email address
     $newUser->generateAndStorePlancakeEmailAddress();
     // I need to use a token for the activation of their account
     $token = '';
     $c = new Criteria();
     $c->add(PcActivationTokenPeer::USER_ID, $newUser->getId(), Criteria::EQUAL);
     $tokenEntry = PcActivationTokenPeer::doSelectOne($c);
     if (is_object($tokenEntry)) {
         $token = $tokenEntry->getToken();
     } else {
         $secret = sfConfig::get('app_registration_secret');
         // token doesn't need to be 32-char long. It is better to keep it short
         // so there will be less chance the email client will break the link into 2 lines
         $token = substr(md5($newUser->getId() . $secret . time()), 0, 14);
         $tokenEntry = new PcActivationToken();
         $tokenEntry->setUserId($newUser->getId());
         $tokenEntry->setToken($token);
         $tokenEntry->save();
     }
     // now we can send the email
     if ($sendActivationEmail) {
         $link = sfContext::getInstance()->getController()->genUrl('@activation?t=' . $token, true);
         $from = sfConfig::get('app_emailAddress_contact');
         $subject = 'Plancake - ' . __('WEBSITE_REGISTRATION_EMAIL_SUBJECT');
         $body = sprintf(__('WEBSITE_REGISTRATION_EMAIL_BODY'), $link);
         PcUtils::sendEmail($email, $subject, $body, $from);
     }
     $newUser->refreshLatestBlogAccess();
     sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($newUser, 'user.sign_up', array('user' => $newUser, 'plainPassword' => $password)));
     return $newUser;
 }
Example #9
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);
 }
 /**
  * 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;
     }
 }
Example #12
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();
 }