示例#1
0
 /**
  *
  * @param int $userId
  * @param string $description (='') - the description of the use
  * @return boolean - false is the user has got a personal api key already, true otherwise
  */
 public static function createPersonalApiApp($userId, $description = '')
 {
     $alreadyExisting = is_object(self::retrieveByUserId($userId));
     if ($alreadyExisting) {
         return false;
     }
     $apiKey = '';
     $safetyCounter = 0;
     // to avoid infinite loop under any circumstances
     do {
         $apiKey = PcUtils::generate40CharacterRandomHash();
         $c = new Criteria();
         $c->add(PcApiAppPeer::API_KEY, $apiKey);
         $alreadyExisting = PcApiAppPeer::doSelectOne($c);
         $safetyCounter++;
         if ($safetyCounter == 100) {
             throw new Exception("Detected possible infinite loop while creating API key");
         }
     } while (is_object($alreadyExisting));
     $personalApiApp = new PcApiApp();
     $personalApiApp->setUserId($userId)->setName('personal')->setApiKey($apiKey)->setApiSecret(PcUtils::generateRandomString(16))->setIsLimited(true)->setDescription($description)->save();
     $apiKeyStats = new PcApiAppStats();
     $apiKeyStats->setApiAppId($personalApiApp->getId())->setToday(date('Y-m-d'))->setLastHour(date('H'))->save();
     $userKey = PcUserKeyPeer::retrieveByPK($userId);
     if (!is_object($userKey)) {
         $userKey = new PcUserKey();
         $userKey->setUserId($userId)->setKey(PcUtils::generate32CharacterRandomHash())->save();
     }
     return true;
 }
 /**
  *
  * @param string $promoCode
  * @return pcPromotionCode|null
  */
 public static function getValidPromoCodeEntry($promoCode)
 {
     $c = new Criteria();
     $c->add(self::EXPIRY_DATE, PcUtils::getMysqlTimestamp(time()), Criteria::GREATER_EQUAL);
     $c->add(self::ID, $promoCode);
     return self::doSelectOne($c);
 }
 /**
  * N.B.: if the user passed as input is a supporter, the method prefix '1'
  * to the token, making it 41-character long, rather than 40
  *
  * @param PcApiApp $apiApp
  * @param int $userId
  * @return string
  */
 public static function createToken(PcApiApp $apiApp, $userId)
 {
     $apiAppId = $apiApp->getId();
     // if there is already a token entry for the application and the user, we delete it
     $c = new Criteria();
     $c->add(PcApiTokenPeer::API_APP_ID, $apiAppId);
     $c->add(PcApiTokenPeer::USER_ID, $userId);
     PcApiTokenPeer::doDelete($c);
     $apiTokenEntry = new PcApiToken();
     $tokenPrefix = PcUserPeer::retrieveByPK($userId)->isSupporter() ? '1' : '';
     // we want to be extra-sure the token is unique
     $token = '';
     $safetyCounter = 0;
     // to avoid infinite loop under any circumstances
     do {
         $token = $tokenPrefix . PcUtils::generate40CharacterRandomHash();
         $c = new Criteria();
         $c->add(PcApiTokenPeer::TOKEN, $token);
         $alreadyExisting = PcApiTokenPeer::doSelectOne($c);
         $safetyCounter++;
         if ($safetyCounter == 100) {
             throw new Exception("Detected possible infinite loop while creating API token");
         }
     } while (is_object($alreadyExisting));
     $apiTokenEntry->setToken($token)->setApiAppId($apiAppId)->setUserId($userId)->setExpiryTimestamp(time() + sfConfig::get('app_api_tokenValidity') * 3600)->save();
     return $token;
 }
 /**
  * @see sfTask
  */
 protected function executeTask($env, $arguments = array(), $options = array())
 {
     $sql = "SELECT ft.id AS id,\n                   ft.subject as title,\n                   ft.posted as posted\n            FROM forum_topics AS ft\n            WHERE ft.forum_id=3\n            ORDER BY ft.posted ASC";
     $connection = Propel::getConnection();
     $statement = $connection->prepare($sql);
     $statement->execute();
     while ($resultset = $statement->fetch(PDO::FETCH_ASSOC)) {
         $id = $resultset['id'];
         $title = $resultset['title'];
         $sql2 = "SELECT message AS description\n                FROM forum_posts\n                WHERE topic_id={$id}\n                ORDER BY posted DESC\n                LIMIT 0,1";
         $connection2 = Propel::getConnection();
         $statement2 = $connection2->prepare($sql2);
         $statement2->execute();
         $resultset2 = $statement2->fetch(PDO::FETCH_ASSOC);
         $description = nl2br($resultset2['description']);
         $description = preg_replace('!\\[url[^]]*\\]([^\\[]*)\\[/url\\]!', '<a href="\\1">\\1</a>', $description);
         $createdAt = date('Y-m-d H:i:s', $resultset['posted']);
         $forumUrl = "http://www.plancake.com/forums/topic/{$id}/" . PcUtils::slugify($title);
         $blogPost = new PcBlogPost();
         $blogPost->setTitle($title)->setContent($description)->setCreatedAt($createdAt)->setUserId(4)->setSlug(PcUtils::slugify($title))->setForumUrl($forumUrl)->save();
         $blogPostCategory = new PcBlogCategoriesPosts();
         $blogPostCategory->setPostId($blogPost->getId())->setCategoryId(1)->save();
         if (strpos($title, "Plancake will be down for scheduled maintenance of server") !== FALSE) {
             $blogPostCategory = new PcBlogCategoriesPosts();
             $blogPostCategory->setPostId($blogPost->getId())->setCategoryId(4)->save();
         }
     }
     echo "\nDone migration to 1.9.0 \n\n";
 }
 /**
  *
  * @param int $fromTimestamp (=null) - GMT
  * @param int $toTimestamp (=null) - GMT
  * @return array of PcRepetition
  */
 public static function retrieveUpdatedSince($fromTimestamp = null, $toTimestamp = null)
 {
     $c = new Criteria();
     if ($fromTimestamp !== null) {
         $c->add(self::UPDATED_AT, PcUtils::getMysqlTimestamp($fromTimestamp), Criteria::GREATER_EQUAL);
         $c->addAnd(self::UPDATED_AT, PcUtils::getMysqlTimestamp($toTimestamp), Criteria::LESS_THAN);
     }
     $c->addAscendingOrderByColumn(self::SORT_ORDER);
     return self::doSelect($c);
 }
 public function executeAddEdit(sfWebRequest $request)
 {
     $op = $request->getParameter('op');
     $contextId = $request->getParameter('id');
     $contextName = trim($request->getParameter('name'));
     $newContext = null;
     if ($contextName && strpos($contextName, ' ') !== FALSE) {
         die("ERROR: " . __('ACCOUNT_ERROR_TAG_CANT_HAVE_SPACE'));
     }
     $existingContexts = PcUserPeer::getLoggedInUser()->getContextsArray(true);
     if (count($existingContexts)) {
         if (in_array(strtolower($contextName), $existingContexts)) {
             die("ERROR: " . __('ACCOUNT_ERROR_TAG_ALREADY_EXIST'));
         }
     }
     if ($op == 'delete' && $contextId) {
         $contextToDelete = PcUsersContextsPeer::retrieveByPk($contextId);
         PcUtils::checkLoggedInUserPermission(PcUserPeer::retrieveByPk($contextToDelete->getUserId()));
         $contextToDelete->delete();
     } else {
         if ($op == 'edit' && $contextId && $contextName) {
             $contextToEdit = PcUsersContextsPeer::retrieveByPk($contextId);
             PcUtils::checkLoggedInUserPermission(PcUserPeer::retrieveByPk($contextToEdit->getUserId()));
             $contextToEdit->setContext($contextName)->save();
             // {{{
             // this lines to make sure the list details we sent back via AJAX
             // are the ones stored in the database
             $contextToEdit = PcUsersContextsPeer::retrieveByPk($contextId);
             // }}}
         } else {
             if ($op == 'add' && $contextName) {
                 // getting max sortOrder
                 $c = new Criteria();
                 $c->addDescendingOrderByColumn(PcUsersContextsPeer::SORT_ORDER);
                 $maxSortOrder = PcUsersContextsPeer::doSelectOne($c)->getSortOrder();
                 $context = new PcUsersContexts();
                 $context->setContext($contextName)->setPcUser(PcUserPeer::getLoggedInUser())->setSortOrder($maxSortOrder + 1)->save();
                 // {{{
                 // this lines to make sure the list details we sent back via AJAX
                 // are the ones stored in the database
                 $newContext = PcUsersContextsPeer::retrieveByPk($context->getId());
                 // }}}
             }
         }
     }
     $tag = isset($contextToEdit) && $contextToEdit ? $contextToEdit : $newContext;
     if ($request->isXmlHttpRequest()) {
         if ($tag) {
             $ret = array('id' => $tag->getId(), 'name' => $tag->getContext());
             return $this->renderJson($ret);
         } else {
             return $this->renderDefault();
         }
     }
 }
 private function deleteReferenceInTasks()
 {
     $contextId = $this->getId();
     $tasks = PcTaskPeer::getTasksByContextId($contextId);
     foreach ($tasks as $task) {
         $contextIdsString = $task->getContexts();
         $contextIds = PcUtils::explodeWithEmptyInputDetection(',', $contextIdsString);
         $contextIds = array_diff($contextIds, array($contextId));
         $task->setContexts(implode(',', $contextIds))->save();
     }
 }
 public function executeReorder(sfWebRequest $request)
 {
     $tagIds = $request->getParameter('tag');
     $i = 1;
     foreach ($tagIds as $tagId) {
         $tag = PcUsersContextsPeer::retrieveByPk($tagId);
         PcUtils::checkLoggedInUserPermission(PcUserPeer::retrieveByPK($tag->getUserId()));
         $tag->setSortOrder($i)->save();
         $i++;
     }
     return $this->renderDefault();
 }
 public function executeReorder(sfWebRequest $request)
 {
     $listIds = $request->getParameter('list');
     $i = 1;
     foreach ($listIds as $listId) {
         $list = PcListPeer::retrieveByPK($listId);
         PcUtils::checkLoggedInUserPermission($list->getCreator());
         $list->setSortOrder($i)->save();
         $i++;
     }
     return $this->renderDefault();
 }
 public function execute($filterChain)
 {
     $context = $this->getContext();
     $user = $context->getUser();
     if (!$user->getAttribute(self::ENTRY_POINT_SESSION_KEY)) {
         $user->setAttribute(self::ENTRY_POINT_SESSION_KEY, PcUtils::getCurrentURL());
     }
     if (!$user->getAttribute(self::REFERRAL_SESSION_KEY) && isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], 'www.plancake.com/openIdWrongLogin') === FALSE) {
         // added to prevent a lot of meaningless entries
         $user->setAttribute(self::REFERRAL_SESSION_KEY, $_SERVER['HTTP_REFERER']);
     }
     $filterChain->execute();
 }
示例#11
0
 public function save(PropelPDO $con = null)
 {
     if (!$this->getSlug()) {
         $this->setSlug(PcUtils::slugifyWithUniqueness($this->getTitle(), PcBlogPostPeer::SLUG));
     }
     // check whether the Italian URL has got a leading 'http://'
     $italianUrl = $this->getItalianUrl();
     if ($italianUrl && strpos($italianUrl, 'http:') === FALSE) {
         $italianUrl = 'http://' . $italianUrl;
         $this->setItalianUrl($italianUrl);
     }
     parent::save($con);
 }
示例#12
0
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
 public function executeIndex(sfWebRequest $request)
 {
     $this->form = new PcTestimonialForm();
     $this->showFeedback = false;
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter('testimonial'));
         if ($this->form->isValid()) {
             $fields = $request->getParameter('testimonial');
             $this->showFeedback = true;
             PcUtils::sendNotificationToAdmin("New testimonial");
             $this->form->save();
         }
     }
 }
示例#13
0
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
 public function executeIndex(sfWebRequest $request)
 {
     $user = PcUserPeer::getLoggedInUser();
     $this->getUser()->setCulture($user->getPreferredLanguage());
     // {{{ START: is this the first login?
     // We need to do this before calling refreshLastLogin()
     if ($user->getLastLogin('U') < mktime(0, 0, 0)) {
         $this->getUser()->setAttribute('user_first_login_of_the_day', 1);
     } else {
         $this->getUser()->setAttribute('user_first_login_of_the_day', 0);
     }
     // }}} END: is this the first login?
     $user->refreshLastLogin()->save();
     if (!$user->getHasDesktopAppBeenLoaded()) {
         $this->getUser()->setAttribute('user_still_to_load_desktop_app', 1);
     }
     // the action we are in is not called by the mobile app, but must by the desktop app
     $user->setHasDesktopAppBeenLoaded(true)->save();
     $this->updateAvailable = false;
     // check whether one day has passed from the last check
     $lastCheckForUpdates = PcUtils::getValue('last_check_for_updates', time());
     if (time() - $lastCheckForUpdates > 86400) {
         // time to do a new check
         //
         // we access the version file directly (and not the config value) to avoid cache
         $urlFriendlySiteVersion = str_replace('.', '-', file_get_contents(sfConfig::get('sf_root_dir') . '/version'));
         $updatesUrl = sfConfig::get('app_site_urlForUpdates') . '/' . $urlFriendlySiteVersion;
         // $updatesUrl may be something like this: http://updates.plancake.com/updates/1.8.6
         $updates = PcUtils::getFileContentOverInternet($updatesUrl, true);
         // $updates may be something like this:
         // 1--|--ffb524e371203966974750bf5c3a9a77--|--Reminder: Plancake will be down for maintenance in a few hours--|--http://tinyurl.com/34vwsq5
         $updatesParts = explode(sfConfig::get('app_site_updatesStringDivider'), $updates);
         $newReleaseAvailable = isset($updatesParts[0]) ? $updatesParts[0] : '';
         $lastUpdateSignature = isset($updatesParts[1]) ? $updatesParts[1] : '';
         $lastUpdateDescription = isset($updatesParts[2]) ? $updatesParts[2] : '';
         $lastUpdateLink = isset($updatesParts[3]) ? $updatesParts[3] : '';
         // we use this also in the hosted version (even if it is meant for installations)
         // to spot problems easily
         $this->updateAvailable = (bool) $newReleaseAvailable;
         if (defined('PLANCAKE_PUBLIC_RELEASE')) {
             // check whether the update is already in the system
             if (!is_object(PcUpdatePeer::retrieveBySignature($lastUpdateSignature))) {
                 $update = new PcUpdate();
                 $update->setUrl($lastUpdateLink)->setDescription($lastUpdateDescription)->setSignature($lastUpdateSignature)->setCreatedAt(time())->save();
                 PcUtils::broadcastUpdate($lastUpdateDescription, $lastUpdateLink);
             }
         }
         PcUtils::setValue('last_check_for_updates', time());
     }
 }
 /**
  * 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;
 }
示例#15
0
 public function executeReorder(sfWebRequest $request)
 {
     $taskIds = $request->getParameter('task_panel1');
     if (!$taskIds) {
         $taskIds = $request->getParameter('task_panel2');
     }
     $task = null;
     $taskIds = array_reverse($taskIds);
     $i = 1;
     foreach ($taskIds as $taskId) {
         // the action actually could have been deleted via AJAX
         if ($task = PcTaskPeer::retrieveByPk($taskId)) {
             PcUtils::checkLoggedInUserPermission($task->getList()->getCreator());
             $task->setSortOrder($i);
             $task->save();
             $i++;
         }
     }
     return $this->renderDefault();
 }
示例#16
0
 /**
  * @return string - a 32-character hash
  */
 public static function generateSignature()
 {
     return PcUtils::generate32CharacterRandomHash();
 }
示例#17
0
 public static function redirectToApp($action)
 {
     $urlForRedirect = 'http://' . sfConfig::get('app_site_url') . '/' . sfConfig::get('app_accountApp_frontController');
     if (PcUtils::isMobileBrowser()) {
         // we force https with mobile app so that
         // the cache manifest can have this entry:
         // https://www.plancake.com/account.php/mobile
         // and it is going to work for any user, not just Premium ones
         $urlForRedirect = 'https://' . sfConfig::get('app_site_url') . '/' . sfConfig::get('app_accountApp_frontController') . '/mobile';
     }
     $action->redirect($urlForRedirect);
 }
示例#18
0
 public function executeSubmitArticle(sfWebRequest $request)
 {
     $this->form = new SubmitArticleForm();
     $user = PcUserPeer::getLoggedInUser();
     $this->submitted = false;
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter('article'), $request->getFiles('article'));
         if ($this->form->isValid()) {
             $file = $this->form->getValue('file');
             $extension = $file->getExtension($file->getOriginalExtension());
             $fileFullPath = '/tmp/article_' . time('Y-m-d-H-i-s') . $extension;
             try {
                 $file->save($fileFullPath);
                 PcUtils::sendEmail(sfConfig::get('app_site_adminUserEmails'), 'New article', 'New article', sfConfig::get('app_site_adminUserEmails'), $user->getEmail(), $fileFullPath);
             } catch (Exception $e) {
                 unlink($fileFullPath);
                 throw $e;
             }
             unlink($fileFullPath);
             $this->submitted = true;
         }
     }
 }
示例#19
0
<?php 
if (!defined('PLANCAKE_PUBLIC_RELEASE')) {
    ?>
    <div id="pc_socialWidgets">
        <ul>
                <li>Spread the love</li>
                <li>
                <script type="text/javascript" charset="utf-8">
                tweetmeme_source = 'plancake';
                tweetmeme_url = '<?php 
    echo PcUtils::getCurrentURL();
    ?>
';
                </script>
                <script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script>
                </li>

                <li>

                      <a name="fb_share" type="box_count" href="http://www.facebook.com/sharer.php?u=<?php 
    echo PcUtils::getCurrentURL();
    ?>
">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>


                </li>
        </ul>
    </div>
<?php 
}
* Licensed under the AGPL version 3 license.                                         *                                                       *
* Danyuki Software Limited is registered in England and Wales (Company No. 07554549) *
**************************************************************************************
* Plancake is distributed in the hope that it will be useful,                        *
* but WITHOUT ANY WARRANTY; without even the implied warranty of                     *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                      *
* GNU Affero General Public License for more details.                                *
*                                                                                    *
* You should have received a copy of the GNU Affero General Public License           *
* along with this program.  If not, see <http://www.gnu.org/licenses/>.              *
*                                                                                    *
**************************************************************************************/
require_once dirname(__FILE__) . '/../../config/ProjectConfiguration.class.php';
$configuration = ProjectConfiguration::getApplicationConfiguration('account', 'prod', false);
$context = sfContext::createInstance($configuration);
$consumer = new PlancakeOpenIdConsumer(PlancakeOpenIdConsumer::PROVIDER_GOOGLE, 'http://www.plancake.com/openIdEndpoints/googleReceiveLogin.php', PlancakeOpenIdConsumer::MODE_LOGIN);
$consumer->receive($data);
$email = $data['http://axschema.org/contact/email'][0];
if (PcUserPeer::emailExist($email)) {
    $userToLogin = PcUserPeer::retrieveByEmailAddress($email);
    CustomAuth::login($context->getUser(), $userToLogin, false, false);
    if (PcUtils::isMobileBrowser()) {
        $redirectUrl = 'https://' . sfConfig::get('app_site_url') . "/account.php/mobile";
    } else {
        $redirectUrl = 'http://' . sfConfig::get('app_site_url') . "/account.php";
    }
} else {
    $encodedEmail = urlencode($email);
    $redirectUrl = 'http://' . sfConfig::get('app_site_url') . "/openIdWrongLogin?input_email={$encodedEmail}";
}
header("Location: {$redirectUrl}");
示例#21
0
 public function executeDelete(sfWebRequest $request)
 {
     $noteLabel = $request->getParameter('noteLabel');
     $noteLabelInfo = explode('_', $noteLabel);
     $note = PcNotePeer::retrieveByPk($noteLabelInfo[1]);
     PcUtils::checkLoggedInUserPermission($note->getCreator());
     $note->delete();
     if ($request->isXmlHttpRequest()) {
         return sfView::NONE;
     }
 }
示例#22
0
 /**
  * Checks whether the authentication by a user is correct and returns the
  * correct PcUser object in the case of correct authentication
  *
  * @param string $email - the email address
  * @param string $password - the plain password (no encryption)
  * @return boolean|PcUser, false if the details are not correct, the correct PcUser otherwise
  */
 public static function isCorrectAuthentication($email, $password)
 {
     // query to retrieve the salt, if the user exists
     $c = new Criteria();
     $c->add(PcUserPeer::EMAIL, $email, Criteria::EQUAL);
     $user = PcUserPeer::doSelectOne($c);
     if (!is_object($user)) {
         // the email address doesn't exist
         return false;
     }
     $salt = $user->getSalt();
     $c = new Criteria();
     $c->add(PcUserPeer::EMAIL, $email, Criteria::EQUAL);
     $c->add(PcUserPeer::ENCRYPTED_PASSWORD, PcUtils::createEncryptedPassword($password, $salt), Criteria::EQUAL);
     $user = PcUserPeer::doSelectOne($c);
     return is_object($user) ? $user : false;
 }
 public function executeSubscriptionContent()
 {
     $inputDiscountCode = trim($this->getContext()->getRequest()->getParameter('codeForDiscount'));
     $discount = PcPromotionCodePeer::getDiscountByCode($inputDiscountCode, $promotionErrorCode);
     $c = new Criteria();
     $c->add(PcPaypalProductPeer::SUBSCRIPTION_TYPE_ID, 3);
     $c->add(PcPaypalProductPeer::ITEM_PRICE_CURRENCY, 'USD');
     $this->oneYearUsdSubscription = PcPaypalProductPeer::doSelectOne($c);
     $c = new Criteria();
     $c->add(PcPaypalProductPeer::SUBSCRIPTION_TYPE_ID, 3);
     $c->add(PcPaypalProductPeer::ITEM_PRICE_CURRENCY, 'GBP');
     $this->oneYearGbpSubscription = PcPaypalProductPeer::doSelectOne($c);
     $c = new Criteria();
     $c->add(PcPaypalProductPeer::SUBSCRIPTION_TYPE_ID, 3);
     $c->add(PcPaypalProductPeer::ITEM_PRICE_CURRENCY, 'EUR');
     $this->oneYearEurSubscription = PcPaypalProductPeer::doSelectOne($c);
     $c = new Criteria();
     $c->add(PcPaypalProductPeer::SUBSCRIPTION_TYPE_ID, 3);
     $c->add(PcPaypalProductPeer::ITEM_PRICE_CURRENCY, 'JPY');
     $this->oneYearJpySubscription = PcPaypalProductPeer::doSelectOne($c);
     $c = new Criteria();
     $c->add(PcPaypalProductPeer::SUBSCRIPTION_TYPE_ID, 2);
     $c->add(PcPaypalProductPeer::ITEM_PRICE_CURRENCY, 'USD');
     $this->threeMonthUsdSubscription = PcPaypalProductPeer::doSelectOne($c);
     $c = new Criteria();
     $c->add(PcPaypalProductPeer::SUBSCRIPTION_TYPE_ID, 2);
     $c->add(PcPaypalProductPeer::ITEM_PRICE_CURRENCY, 'GBP');
     $this->threeMonthGbpSubscription = PcPaypalProductPeer::doSelectOne($c);
     $c = new Criteria();
     $c->add(PcPaypalProductPeer::SUBSCRIPTION_TYPE_ID, 2);
     $c->add(PcPaypalProductPeer::ITEM_PRICE_CURRENCY, 'EUR');
     $this->threeMonthEurSubscription = PcPaypalProductPeer::doSelectOne($c);
     $c = new Criteria();
     $c->add(PcPaypalProductPeer::SUBSCRIPTION_TYPE_ID, 2);
     $c->add(PcPaypalProductPeer::ITEM_PRICE_CURRENCY, 'JPY');
     $this->threeMonthJpySubscription = PcPaypalProductPeer::doSelectOne($c);
     $c = new Criteria();
     $c->add(PcPaypalProductPeer::ID, 7);
     $this->testSubscription = PcPaypalProductPeer::doSelectOne($c);
     $this->yearlyUsdSaving = $this->threeMonthUsdSubscription->getItemPrice() * 4 - $this->oneYearUsdSubscription->getItemPrice();
     $this->yearlyGbpSaving = $this->threeMonthGbpSubscription->getItemPrice() * 4 - $this->oneYearGbpSubscription->getItemPrice();
     $this->yearlyEurSaving = $this->threeMonthEurSubscription->getItemPrice() * 4 - $this->oneYearEurSubscription->getItemPrice();
     $this->yearlyJpySaving = $this->threeMonthJpySubscription->getItemPrice() * 4 - $this->oneYearJpySubscription->getItemPrice();
     $this->niceExpiryDate = '';
     $this->niceExpiryDateThreeMonthExtended = '';
     $this->niceExpiryDateOneYearExtended = '';
     $this->oneYearUsdDiscountedSubscription = null;
     $this->oneYearGbpDiscountedSubscription = null;
     $this->oneYearEurDiscountedSubscription = null;
     $this->oneYearJpyDiscountedSubscription = null;
     $loggedInUser = PcUserPeer::getLoggedInUser();
     $this->promotionErrorCode = $promotionErrorCode;
     $this->discount = $discount;
     $this->hasDiscountCodeBeenEntered = false;
     if ($inputDiscountCode) {
         $this->hasDiscountCodeBeenEntered = true;
     }
     $this->isDiscountCodeValid = false;
     if ($discount > 0) {
         $this->isDiscountCodeValid = true;
         if ($loggedInUser) {
             $loggedInUser->setLastPromotionalCodeInserted($inputDiscountCode)->save();
         }
         $c = new Criteria();
         $c->add(PcPaypalProductPeer::SUBSCRIPTION_TYPE_ID, 3);
         $c->add(PcPaypalProductPeer::ITEM_PRICE_CURRENCY, 'USD');
         $c->add(PcPaypalProductPeer::DISCOUNT_PERCENTAGE, $discount);
         $this->oneYearUsdDiscountedSubscription = PcPaypalProductPeer::doSelectOne($c);
         $c = new Criteria();
         $c->add(PcPaypalProductPeer::SUBSCRIPTION_TYPE_ID, 3);
         $c->add(PcPaypalProductPeer::ITEM_PRICE_CURRENCY, 'GBP');
         $c->add(PcPaypalProductPeer::DISCOUNT_PERCENTAGE, $discount);
         $this->oneYearGbpDiscountedSubscription = PcPaypalProductPeer::doSelectOne($c);
         $c = new Criteria();
         $c->add(PcPaypalProductPeer::SUBSCRIPTION_TYPE_ID, 3);
         $c->add(PcPaypalProductPeer::ITEM_PRICE_CURRENCY, 'EUR');
         $c->add(PcPaypalProductPeer::DISCOUNT_PERCENTAGE, $discount);
         $this->oneYearEurDiscountedSubscription = PcPaypalProductPeer::doSelectOne($c);
         $c = new Criteria();
         $c->add(PcPaypalProductPeer::SUBSCRIPTION_TYPE_ID, 3);
         $c->add(PcPaypalProductPeer::ITEM_PRICE_CURRENCY, 'JPY');
         $c->add(PcPaypalProductPeer::DISCOUNT_PERCENTAGE, $discount);
         $this->oneYearJpyDiscountedSubscription = PcPaypalProductPeer::doSelectOne($c);
     }
     $this->isSupporter = false;
     if ($loggedInUser) {
         $this->isSupporter = $loggedInUser->isSupporter();
         $supporterAccount = PcSupporterPeer::retrieveByPK($loggedInUser->getId());
         if ($this->isSupporter) {
             $this->niceExpiryDate = $supporterAccount->getExpiryDate('j') . ' ' . PcUtils::fromIndexToMonth($supporterAccount->getExpiryDate('n')) . ' ' . $supporterAccount->getExpiryDate('Y');
             $newExpiryTimestamp = $supporterAccount->getNewExpiryDateAfterSubscription(PcSubscriptionTypePeer::retrieveByPK(2), $supporterAccount->getExpiryDate('Y-m-d'));
             $this->niceExpiryDateThreeMonthExtended = date('j', $newExpiryTimestamp) . ' ' . PcUtils::fromIndexToMonth(date('n', $newExpiryTimestamp)) . ' ' . date('Y', $newExpiryTimestamp);
             $newExpiryTimestamp = $supporterAccount->getNewExpiryDateAfterSubscription(PcSubscriptionTypePeer::retrieveByPK(3), $supporterAccount->getExpiryDate('Y-m-d'));
             $this->niceExpiryDateOneYearExtended = date('j', $newExpiryTimestamp) . ' ' . PcUtils::fromIndexToMonth(date('n', $newExpiryTimestamp)) . ' ' . date('Y', $newExpiryTimestamp);
         }
     }
     $userCulture = $this->getUser()->getCulture();
     $this->cultureUrlPart = '';
     if ($userCulture != SfConfig::get('app_site_defaultLang')) {
         $this->cultureUrlPart = '/' . $userCulture;
     }
     $this->isOnRegistration = $this->getContext()->getRequest()->getParameter('onRegistration') == '1';
     /*
         if ($this->promoCode = $request->getParameter('promoCode'))
         {
        $this->hasPromoCodeBeenSubmitted = true;
     
        $promoCodeEntry = PcPromotionCodePeer::getValidPromoCodeEntry($this->promoCode);
     
        if (is_object($promoCodeEntry))
        {
            $this->isPromoCodeValid = true;
            $buttonCode = $promoCodeEntry->getPaypalButtonCode();
            $this->price *= 1 - ($promoCodeEntry->getDiscountPercentage() / 100);
        }
         }
     */
 }
示例#24
0
 /**
  * Sends an email to reset the password.
  * At this point we should be already sure the email address is valid
  *
  * @param string $email - the email address
  */
 public static function sendPasswordForgotten($email)
 {
     $requestingUser = PcUserPeer::getUserByEmail($email);
     if (!is_object($requestingUser)) {
         throw new Exception('Couldn\'t send the password forgotten email. Problems while creating the user object.');
     }
     // I need to use a token
     $token = '';
     $c = new Criteria();
     $c->add(PcPasswordResetTokenPeer::USER_ID, $requestingUser->getId(), Criteria::EQUAL);
     $tokenEntry = PcPasswordResetTokenPeer::doSelectOne($c);
     if (is_object($tokenEntry)) {
         $token = $tokenEntry->getToken();
     } else {
         $secret = sfConfig::get('app_forgottenPassword_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($requestingUser->getId() . $secret . time()), 0, 14);
         $tokenEntry = new PcPasswordResetToken();
         $tokenEntry->setUserId($requestingUser->getId());
         $tokenEntry->setToken($token);
         $tokenEntry->save();
     }
     // now we can send the email
     $link = sfContext::getInstance()->getController()->genUrl('@password-reset?t=' . $token, true);
     $from = sfConfig::get('app_emailAddress_contact');
     $subject = __('WEBSITE_FORGOTTEN_PSW_EMAIL_SUBJECT');
     $body = sprintf(__('WEBSITE_FORGOTTEN_PSW_EMAIL_BODY'), $link);
     PcUtils::sendEmail($email, $subject, $body, $from);
 }
示例#25
0
 /**
  * @return string (XML format)
  */
 public function getXmlString()
 {
     $dump = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
     $dump .= '<backup version="1" title="Plancake backup" link="http://www.plancake.com">' . "\n";
     $dump .= "\t<plancake_tasks>\n";
     // This Ids are to make the dump more portable:
     // tasks will be related to tags and lists via these "virtual" ids
     $tagLocalIds = array();
     $listLocalIds = array();
     $c = new Criteria();
     $c->add(PcUsersContextsPeer::USER_ID, $this->user->getId(), Criteria::EQUAL);
     $c->addDescendingOrderByColumn(PcUsersContextsPeer::SORT_ORDER);
     $c->addDescendingOrderByColumn(PcUsersContextsPeer::ID);
     $tags = PcUsersContextsPeer::doSelect($c);
     $dump .= "\t\t<tags>\n";
     $localId = 1;
     foreach ($tags as $tag) {
         $dump .= "\t\t\t<tag>\n";
         $dump .= "\t\t\t\t<localId>{$localId}</localId>\n";
         $dump .= "\t\t\t\t<id>{$tag->getId()}</id>\n";
         $dump .= "\t\t\t\t<name><![CDATA[{$tag->getContext()}]]></name>\n";
         $dump .= "\t\t\t\t<sortOrder>{$tag->getSortOrder()}</sortOrder>\n";
         $dump .= "\t\t\t\t<updatedAt>{$tag->getUpdatedAt()}</updatedAt>\n";
         $dump .= "\t\t\t\t<createdAt>{$tag->getCreatedAt()}</createdAt>\n";
         $dump .= "\t\t\t</tag>\n";
         $tagLocalIds[$tag->getId()] = $localId;
         $localId++;
     }
     $dump .= "\t\t</tags>\n\n";
     $c = new Criteria();
     $c->add(PcListPeer::CREATOR_ID, $this->user->getId(), Criteria::EQUAL);
     $c->addDescendingOrderByColumn(PcListPeer::SORT_ORDER);
     $c->addDescendingOrderByColumn(PcListPeer::ID);
     $lists = PcListPeer::doSelect($c);
     $dump .= "\t\t<lists>\n";
     $localId = 1;
     foreach ($lists as $list) {
         $listIsInbox = $list->getIsInbox() ? 1 : 0;
         $listIsTodo = $list->getIsTodo() ? 1 : 0;
         $listIsHeader = $list->getIsHeader() ? 1 : 0;
         $dump .= "\t\t\t<list>\n";
         $dump .= "\t\t\t\t<localId>{$localId}</localId>\n";
         $dump .= "\t\t\t\t<id>{$list->getId()}</id>\n";
         $dump .= "\t\t\t\t<name><![CDATA[{$list->getTitle()}]]></name>\n";
         $dump .= "\t\t\t\t<sortOrder>{$list->getSortOrder()}</sortOrder>\n";
         $dump .= "\t\t\t\t<isInbox>{$listIsInbox}</isInbox>\n";
         $dump .= "\t\t\t\t<isTodo>{$listIsTodo}</isTodo>\n";
         $dump .= "\t\t\t\t<isHeader>{$listIsHeader}</isHeader>\n";
         $dump .= "\t\t\t\t<updatedAt>{$list->getUpdatedAt()}</updatedAt>\n";
         $dump .= "\t\t\t\t<createdAt>{$list->getCreatedAt()}</createdAt>\n";
         $dump .= "\t\t\t</list>\n";
         $listLocalIds[$list->getId()] = $localId;
         $localId++;
     }
     $dump .= "\t\t</lists>\n";
     $tasks = $this->user->getTasksByMultipleCriteria();
     $c = new Criteria();
     $c->addJoin(PcTaskPeer::LIST_ID, PcListPeer::ID, Criteria::INNER_JOIN);
     $c->add(PcListPeer::CREATOR_ID, $this->user->getId());
     $c->addDescendingOrderByColumn(PcTaskPeer::LIST_ID);
     $c->addAscendingOrderByColumn(PcTaskPeer::SORT_ORDER);
     $c->addAscendingOrderByColumn(PcTaskPeer::ID);
     $tasks = PcTaskPeer::doSelect($c);
     $dump .= "\t\t<tasks>\n";
     $localId = 1;
     foreach ($tasks as $task) {
         $taskIsStarred = $task->getIsStarred() ? 1 : 0;
         $taskIsCompleted = $task->getIsCompleted() ? 1 : 0;
         $taskIsHeader = $task->getIsHeader() ? 1 : 0;
         $taskIsFromSystem = $task->getIsFromSystem() ? 1 : 0;
         $taskListId = $task->getListId();
         $taskListLocalId = $listLocalIds[$task->getListId()];
         $taskTagIds = $task->getContexts();
         // comma separated list of tagIds
         $taskTagIdsArray = PcUtils::explodeWithEmptyInputDetection(',', $taskTagIds);
         $taskTagLocalIdsArray = array();
         foreach ($taskTagIdsArray as $id) {
             $taskTagLocalIdsArray[] = $tagLocalIds[$id];
         }
         $taskTagLocalIds = implode(',', $taskTagLocalIdsArray);
         $dump .= "\t\t\t<task>\n";
         $dump .= "\t\t\t\t<id>{$task->getId()}</id>\n";
         $dump .= "\t\t\t\t<localId>{$localId}</localId>\n";
         $dump .= "\t\t\t\t<listName><![CDATA[{$task->getList()->getTitle()}]]></listName>\n";
         $dump .= "\t\t\t\t<listLocalId>{$taskListLocalId}</listLocalId>\n";
         $dump .= "\t\t\t\t<description><![CDATA[{$task->getDescription()}]]></description>\n";
         $dump .= "\t\t\t\t<sortOrder>{$list->getSortOrder()}</sortOrder>\n";
         $dump .= "\t\t\t\t<dueDate>{$task->getDueDate()}</dueDate>\n";
         $dump .= "\t\t\t\t<dueTime>{$task->getDueTime()}</dueTime>\n";
         $dump .= "\t\t\t\t<repetitionId>{$task->getRepetitionId()}</repetitionId>\n";
         $dump .= "\t\t\t\t<repetitionParam>{$task->getRepetitionParam()}</repetitionParam>\n";
         $dump .= "\t\t\t\t<isStarred>{$taskIsStarred}</isStarred>\n";
         $dump .= "\t\t\t\t<isCompleted>{$taskIsCompleted}</isCompleted>\n";
         $dump .= "\t\t\t\t<isHeader>{$taskIsHeader}</isHeader>\n";
         $dump .= "\t\t\t\t<isFromSystem>{$taskIsFromSystem}</isFromSystem>\n";
         $dump .= "\t\t\t\t<tagLocalIds>{$taskTagLocalIds}</tagLocalIds>\n";
         $dump .= "\t\t\t\t<note><![CDATA[{$task->getNote()}]]></note>\n";
         $dump .= "\t\t\t\t<completedAt>{$task->getCompletedAt()}</completedAt>\n";
         $dump .= "\t\t\t\t<updatedAt>{$task->getUpdatedAt()}</updatedAt>\n";
         $dump .= "\t\t\t\t<createdAt>{$task->getCreatedAt()}</createdAt>\n";
         $dump .= "\t\t\t</task>\n";
         $localId++;
     }
     $dump .= "\t\t</tasks>\n";
     $dump .= "\t</plancake_tasks>\n";
     $dump .= "\t<plancake_notes>\n";
     $c = new Criteria();
     $c->add(PcNotePeer::CREATOR_ID, $this->user->getId(), Criteria::EQUAL);
     $c->addDescendingOrderByColumn(PcNotePeer::ID);
     $notes = PcNotePeer::doSelect($c);
     $dump .= "\t\t<notes>\n";
     $localId = 1;
     foreach ($notes as $note) {
         $dump .= "\t\t\t<note>\n";
         $dump .= "\t\t\t\t<localId>{$localId}</localId>\n";
         $dump .= "\t\t\t\t<id>{$note->getId()}</id>\n";
         $dump .= "\t\t\t\t<title><![CDATA[{$note->getTitle()}]]></title>\n";
         $dump .= "\t\t\t\t<content><![CDATA[{$note->getContent()}]]></content>\n";
         $dump .= "\t\t\t\t<updatedAt>{$note->getUpdatedAt()}</updatedAt>\n";
         $dump .= "\t\t\t\t<createdAt>{$note->getCreatedAt()}</createdAt>\n";
         $dump .= "\t\t\t</note>\n";
         $localId++;
     }
     $dump .= "\t\t</notes>\n";
     $dump .= "\t</plancake_notes>";
     $dump .= "\n" . '</backup>';
     return $dump;
 }
示例#26
0
 public function executeGetRepetitionParamSelectTag(sfWebRequest $request)
 {
     $id = $request->getParameter('id');
     $value = $request->getParameter('value');
     if (!$id) {
         return $this->renderText('');
     }
     $summary = '';
     $tag = '';
     if ($repetition = PcRepetitionPeer::retrieveByPk($id)) {
         if ($repetition->needsParam()) {
             if ($repetition->getSpecial() == 'selected_wkdays') {
                 $weekdaysSelected = DateFormat::fromIntegerToWeekdaysSetForRepetition($value);
                 $selectedSun = $weekdaysSelected['sun'] ? "checked='checked'" : '';
                 $selectedMon = $weekdaysSelected['mon'] ? "checked='checked'" : '';
                 $selectedTue = $weekdaysSelected['tue'] ? "checked='checked'" : '';
                 $selectedWed = $weekdaysSelected['wed'] ? "checked='checked'" : '';
                 $selectedThu = $weekdaysSelected['thu'] ? "checked='checked'" : '';
                 $selectedFri = $weekdaysSelected['fri'] ? "checked='checked'" : '';
                 $selectedSat = $weekdaysSelected['sat'] ? "checked='checked'" : '';
                 $tag = "";
                 if (PcUserPeer::getLoggedInUser()->getWeekStart() == 0) {
                     $tag .= "<input type='checkbox' id='wdfr_sun' name='weekdaysForRepetition' value='sun' {$selectedSun} ><label for='wdfr_sun'>" . __('ACCOUNT_DOW_SUN') . "</label>";
                 }
                 $tag .= "<input type='checkbox' id='wdfr_mon' name='weekdaysForRepetition' value='mon' {$selectedMon} /><label for='wdfr_mon'>" . __('ACCOUNT_DOW_MON') . "</label>";
                 $tag .= "<input type='checkbox' id='wdfr_tue' name='weekdaysForRepetition' value='tue' {$selectedTue} /><label for='wdfr_tue'>" . __('ACCOUNT_DOW_TUE') . "</label>";
                 $tag .= "<input type='checkbox' id='wdfr_wed' name='weekdaysForRepetition' value='wed' {$selectedWed} /><label for='wdfr_wed'>" . __('ACCOUNT_DOW_WED') . "</label>";
                 $tag .= "<input type='checkbox' id='wdfr_thu' name='weekdaysForRepetition' value='thu' {$selectedThu} /><label for='wdfr_thu'>" . __('ACCOUNT_DOW_THU') . "</label>";
                 $tag .= "<input type='checkbox' id='wdfr_fri' name='weekdaysForRepetition' value='fri' {$selectedFri} /><label for='wdfr_fri'>" . __('ACCOUNT_DOW_FRI') . "</label>";
                 $tag .= "<input type='checkbox' id='wdfr_sat' name='weekdaysForRepetition' value='sat' {$selectedSat} /><label for='wdfr_sat'>" . __('ACCOUNT_DOW_SAT') . "</label>";
                 if (PcUserPeer::getLoggedInUser()->getWeekStart() == 1) {
                     $tag .= "<input type='checkbox' id='wdfr_sun' name='weekdaysForRepetition' value='sun' {$selectedSun} ><label for='wdfr_sun'>" . __('ACCOUNT_DOW_SUN') . "</label>";
                 }
                 $summary = $tag;
             } else {
                 $min = $repetition->getMinParam();
                 $max = $repetition->getMaxParam();
                 $tag = "<select name=\"repetitionParam\">";
                 for ($i = $min; $i <= $max; $i++) {
                     $selected = $value == $i ? 'selected="selected"' : '';
                     $label = $repetition->isParamCardinal() ? $i : PcUtils::getOrdinalFromCardinal($i);
                     $tag .= "<option value=\"{$i}\" {$selected}>{$label}</option>";
                 }
                 $tag .= "</select>";
                 $summary = str_replace(__('ACCOUNT_TASK_REPETITION_SELECT_LATER'), $tag, $repetition->getLocalizedHumanExpression());
             }
         }
     }
     return $this->renderText($summary);
 }
示例#27
0
 public function refreshLastLogin()
 {
     $this->setLastLogin(PcUtils::getMysqlTimestamp(time()));
     return $this;
 }
示例#28
0
 public function executePasswordReset(sfWebRequest $request)
 {
     $token = '';
     if ($request->getParameter('t')) {
         $token = $request->getParameter('t');
     } else {
         $param = $request->getParameter('passwordReset');
         $token = $param['t'];
     }
     $token = trim($token);
     // if the user is authenticated, they shouldn't get here
     PcUtils::redirectLoggedInUser($this->getUser(), $this);
     // Check the token is valid
     $c = new Criteria();
     $c->add(PcPasswordResetTokenPeer::TOKEN, $token, Criteria::EQUAL);
     $entry = PcPasswordResetTokenPeer::doSelectOne($c);
     if (!is_object($entry)) {
         // the token is not valid
         PcWatchdog::alert('Invalid Password Reset Token', 'This is the token ' . $token);
         $this->forward('customAuth', 'passwordResetInvalidToken');
     }
     $this->form = new PasswordResetForm(array('t' => $token));
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter('passwordReset'));
         if ($this->form->isValid()) {
             $fields = $request->getParameter('passwordReset');
             $user = CustomAuth::resetPassword($token, $fields['password1']);
             $this->redirect('/' . sfConfig::get('app_accountApp_frontController'));
         }
     }
 }
示例#29
0
 public function executeGenerateUserKey(sfWebRequest $request)
 {
     $userId = PcUserPeer::getLoggedInUser()->getId();
     $userKey = PcUserKeyPeer::retrieveByPK($userId);
     if (!is_object($userKey)) {
         $userKey = new PcUserKey();
         $userKey->setUserId($userId)->setKey(PcUtils::generate32CharacterRandomHash())->save();
     }
     $this->getUser()->setFlash('settingSuccess', __('ACCOUNT_SETTINGS_USER_KEY_SUCCESS'));
     $this->redirect(sfContext::getInstance()->getController()->genUrl('settings/index'));
 }
示例#30
0
 /**
  *
  * @param int $fromTs (=null) - GMT
  * @param int $toTs (=null) - GMT
  * @param int $taskId (=null)
  * @param int $listId (=null)
  * @param int $tagId (=null)
  * @param bool $completed (=false)
  * @param bool $onlyWithDueDate (=false)
  * @param bool $onlyWithoutDueDate (=false)
  * @param bool $onlyDueTodayOrTomorrow (=false)
  * @param bool $onlyStarred (=false)
  * @param string $byDate (=null)  - in the format yyyy-mm-dd
  * @param Criteria $c (=null)
  * @return array of PcTask
  */
 public static function getTasksByMultipleCriteria($fromTs = null, $toTs = null, $taskId = null, $listId = null, $tagId = null, $completed = false, $onlyWithDueDate = false, $onlyWithoutDueDate = false, $onlyDueTodayOrTomorrow = false, $onlyStarred = false, $byDate = null, Criteria $c = null)
 {
     $c = $c === null ? new Criteria() : $c;
     if ($byDate !== null && strlen($byDate) > 0) {
         return PcTaskPeer::getTasksByDate($byDate);
     } else {
         if ($taskId !== null) {
             // the request is for a specific task
             $c->add(self::ID, $taskId);
         } else {
             if ($fromTs !== null) {
                 $c->add(self::UPDATED_AT, PcUtils::getMysqlTimestamp($fromTs), Criteria::GREATER_EQUAL);
                 $c->addAnd(self::UPDATED_AT, PcUtils::getMysqlTimestamp($toTs), Criteria::LESS_THAN);
             }
             if ($listId !== null) {
                 $c->add(self::LIST_ID, $listId);
             }
             if ($tagId !== null) {
                 $c->addJoin(PcTasksContextsPeer::TASK_ID, self::ID);
                 $c->add(PcTasksContextsPeer::USERS_CONTEXTS_ID, $tagId);
             }
             $c->add(self::IS_COMPLETED, (int) $completed);
             if ($onlyWithDueDate) {
                 $c->add(self::DUE_DATE, null, Criteria::ISNOTNULL);
             }
             if ($onlyWithoutDueDate) {
                 $c->add(self::DUE_DATE, null, Criteria::ISNULL);
             }
             if ($onlyDueTodayOrTomorrow) {
                 $tomorrow = date('Y-m-d', strtotime('tomorrow'));
                 $c->add(self::DUE_DATE, $tomorrow, Criteria::LESS_EQUAL);
                 $c->addAscendingOrderByColumn(PcTaskPeer::DUE_DATE);
                 $c->addAscendingOrderByColumn(PcTaskPeer::DUE_TIME);
             }
             if ($onlyStarred) {
                 $c->add(self::IS_STARRED, 1);
             }
             if ($completed) {
                 $c->addDescendingOrderByColumn(PcTaskPeer::COMPLETED_AT);
             } else {
                 if ($onlyWithDueDate) {
                     $c->addAscendingOrderByColumn(PcTaskPeer::DUE_DATE);
                     $c->addAscendingOrderByColumn(PcTaskPeer::DUE_TIME);
                 } else {
                     $c->addDescendingOrderByColumn(PcTaskPeer::SORT_ORDER);
                 }
             }
         }
         return self::doSelect($c);
     }
 }