Example #1
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);
     }
 }