/** * * @param string $query * @return array of integers - taskIds */ public static function searchTasks($query) { $fieldWeights = array('description' => 10, 'note' => 6); $indexName = 'plancake_tasks'; $client = new SphinxClient(); // $client->SetServer (sfConfig::get('app_sphinx_host'), sfConfig::get('app_sphinx_port')); $client->SetFilter("author_id", array(PcUserPeer::getLoggedInUser()->getId())); $client->SetConnectTimeout(1); $client->SetMatchMode(SPH_MATCH_ANY); $client->SetSortMode(SPH_SORT_RELEVANCE); $client->SetRankingMode(SPH_RANK_PROXIMITY_BM25); $client->SetArrayResult(true); $client->SetFieldWeights($fieldWeights); $client->setLimits(0, 100); $results = $client->query($client->EscapeString($query), $indexName); if ($results === false) { $error = "Sphinx Error - " . $client->GetLastError(); sfErrorNotifier::alert($error); } $ids = array(); if (isset($results['matches']) && count($results['matches'])) { foreach ($results['matches'] as $match) { $ids[] = $match['id']; } } return PcTaskPeer::retrieveByPKs($ids); }
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(); } }
/** * @see sfTask */ protected function executeTask($env, $arguments = array(), $options = array()) { $tasks = PcTaskPeer::doSelect(new Criteria()); foreach ($tasks as $task) { $contextsBlob = $task->getContexts(); if (strlen($contextsBlob) > 0) { $contextIds = explode(',', $contextsBlob); foreach ($contextIds as $contextId) { // checking the context exists $context = PcUsersContextsPeer::retrieveByPK($contextId); if (is_object($context)) { $tasksContextsEntry = new PcTasksContexts(); $tasksContextsEntry->setTaskId($task->getId())->setUsersContextsId($contextId)->save(); } } } } echo "\nDone migration to 1.6.7 \n\n"; }
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(); }
public static function cleanDirtyTasks(PcUser $user) { if ($user == null) { return; } $c = new Criteria(); $c->add(self::USER_ID, $user->getId()); $taskEntriesToClean = self::doSelect($c); foreach ($taskEntriesToClean as $taskEntryToClean) { $task = PcTaskPeer::retrieveByPK($taskEntryToClean->getTaskId()); if ($task != null) { $cacheManager = sfContext::getInstance()->getViewCacheManager(); if (is_object($cacheManager)) { $cacheManager->remove('@sf_cache_partial?module=task&action=_incompletedTask&sf_cache_key=' . $task->getCacheKey(true)); $cacheManager->remove('@sf_cache_partial?module=task&action=_completedTask&sf_cache_key=' . $task->getCacheKey(false)); } } $taskEntryToClean->delete(); } }
/** * Updates the corresponding Plancake task. * If there is not a corresponding Plancake task, * we create a new one. * * @param -Google Calendar Event- $event */ private function updatePlancakeTask($event) { $eventId = $this->getEventId($event); // retrieving the Plancake task: we use this method, rather than the EVENT_EXTENDED_PROPERTY_TASK_ID // extended property, because it should be more reliable $task = PcTaskPeer::getTaskByGoogleCalendarEventId($eventId); // {{{ PATCH: we have this problem something Google was trying to send us back some events that // had been either completed or deleted on the Plancake side. // This is the reason why we have decided to use an extended property to keep a record of the link // CalendarEvent<-->PlancakeTask $taskIdFromExtendedProperty = $this->getExtendedProperty($event, self::EVENT_EXTENDED_PROPERTY_TASK_ID); if ($taskIdFromExtendedProperty) { $taskFromExtendedProperty = PcTaskPeer::retrieveByPK($taskIdFromExtendedProperty); if ($taskFromExtendedProperty && $taskFromExtendedProperty->isCompleted()) { $taskFromExtendedProperty->removeGoogleCalendarEventId(); return; } if (PcTrashbinTaskPeer::retrieveByPK($taskIdFromExtendedProperty)) { return; } } // }}} // end PATCH // {{{ checking whether the event has been deleted if ($this->hasEventBeenDeleted($event)) { // event has been deleted if (is_object($task)) { if (SfConfig::get('app_gcal_debug')) { error_log('Deleting Plancake task ' . $task->getId() . ' ' . $task->getDescription()); } $task->removeGoogleCalendarEventId(); // In order to avoid potential disasters, we disable the possibility // for GCal to delete tasks // $task->delete(); return; } } // }}} $eventDescription = $event->title->text; $eventNote = $event->content->text; $eventDueDate = ''; $eventDueTime = ''; $eventRepetitionId = 0; $eventRepetitionParam = 0; $eventIsRecurrent = true; foreach ($event->when as $when) { $startTime = $when->startTime; $eventIsRecurrent = false; if (strlen($startTime) == 10) { $eventDueDate = $startTime; $eventDueTime = ''; } else { preg_match('!([^T]+)T([0-9]{2}):([0-9]{2}):.*!', $startTime, $matches); $eventDueDate = $matches[1]; $eventDueTime = $matches[2] . $matches[3]; $eventDueTime = (int) $eventDueTime; } break; // getting just the first due date } if ($eventIsRecurrent) { $recurrentData = $event->recurrence->text; // $recurrentData is something like: // DTSTART;VALUE=DATE:20110215 DTEND;VALUE=DATE:20110216 RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=TU // DTSTART:20110228T110000Z DTEND:20110228T120000Z RRULE:FREQ=WEEKLY;BYDAY=MO list($eventDueDate, $eventDueTime, $eventRepetitionId, $eventRepetitionParam) = DateFormat::fromICalRecurrentStringToInternalParams($recurrentData); } foreach ($event->when as $when) { break; // we only consider the first 'when' parameter } list($eventLocalDueDate, $eventLocalDueTime) = DateFormat::fromGmtDateAndTime2LocalDateAndTime($eventDueDate, $eventDueTime); if (is_object($task)) { $task->edit($eventDescription, null, null, null, $eventNote, $eventLocalDueDate, $eventLocalDueTime, null, $eventRepetitionId, $eventRepetitionParam, 'gcal'); if (SfConfig::get('app_gcal_debug')) { error_log('Updated Plancake task ' . $task->getId() . ' ' . $task->getDescription()); } } else { $dbEntry = PcGoogleCalendarPeer::retrieveByUser($this->user); if (!is_object($dbEntry)) { throw new Exception("You need a session token in order to create a new task."); } // we have to create a new Plancake task $task = PcTaskPeer::createOrEdit($eventDescription, null, 0, '', false, $eventNote, $eventLocalDueDate, $eventLocalDueTime, 0, $eventRepetitionId, $eventRepetitionParam, 0, 'gcal', 'Y-m-d'); if (SfConfig::get('app_gcal_debug')) { error_log('Created Plancake task ' . $task->getId() . ' ' . $task->getDescription()); } } $task->setGoogleCalendarEventId($eventId); }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this PcRepetition is new, it will return * an empty collection; or if this PcRepetition has previously * been saved, it will retrieve related PcTasks from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in PcRepetition. */ public function getPcTasksJoinPcList($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { if ($criteria === null) { $criteria = new Criteria(PcRepetitionPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collPcTasks === null) { if ($this->isNew()) { $this->collPcTasks = array(); } else { $criteria->add(PcTaskPeer::REPETITION_ID, $this->id); $this->collPcTasks = PcTaskPeer::doSelectJoinPcList($criteria, $con, $join_behavior); } } else { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(PcTaskPeer::REPETITION_ID, $this->id); if (!isset($this->lastPcTaskCriteria) || !$this->lastPcTaskCriteria->equals($criteria)) { $this->collPcTasks = PcTaskPeer::doSelectJoinPcList($criteria, $con, $join_behavior); } } $this->lastPcTaskCriteria = $criteria; return $this->collPcTasks; }
/** * Get the associated PcTask object * * @param PropelPDO Optional Connection object. * @return PcTask The associated PcTask object. * @throws PropelException */ public function getPcTask(PropelPDO $con = null) { if ($this->aPcTask === null && $this->task_id !== null) { $this->aPcTask = PcTaskPeer::retrieveByPk($this->task_id); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aPcTask->addPcDirtyTasks($this); */ } return $this->aPcTask; }
public function import($xml) { $originalMaxExecutionTime = ini_get('max_execution_time'); ini_set('max_execution_time', 120); proc_nice(1); $tagLocalIds = array(); $listLocalIds = array(); $newTagIds = array(); $newListIds = array(); $newTaskIds = array(); $newNoteIds = array(); $tags = $xml->plancake_tasks->tags->tag; foreach ($tags as $tag) { $isNewTag = false; $tagId = (int) $tag->id > 0 ? $tag->id : null; $tagLocalId = (int) $tag->localId; $tagName = (string) $tag->name; $tagSortOrder = (int) $tag->sortOrder; $tagObj = null; if ($tagId && !in_array($tagId, $newTagIds)) { $tagObj = PcUsersContextsPeer::retrieveByPK($tagId); } if ($tagObj) { if ($tagObj->getUserId() != $this->user->getId()) { die("Hacking attempt."); } } else { // tags are unique by name, thus // we check whether the tag is already in the instance // we are importing the dump to. $c = new Criteria(); $c->add(PcUsersContextsPeer::CONTEXT, $tagName); $tagObj = PcUsersContextsPeer::doSelectOne($c); if (!is_object($tagObj)) { $tagObj = new PcUsersContexts(); $isNewTag = true; } } $tagObj->setUserId($this->user->getId())->setContext($tagName)->setSortOrder($tagSortOrder)->save(); $tagLocalIds[$tagLocalId] = $tagObj->getId(); if ($isNewTag) { $newTagIds[] = $tagObj->getId(); } } $lists = $xml->plancake_tasks->lists->list; foreach ($lists as $list) { $isNewList = false; $listId = (int) $list->id > 0 ? $list->id : null; $listLocalId = (int) $list->localId; $listName = (string) $list->name; $listSortOrder = (int) $list->sortOrder; $listIsInbox = (int) $list->isInbox == 1 ? true : false; $listIsTodo = (int) $list->isTodo == 1 ? true : false; $listIsHeader = (int) $list->isHeader == 1 ? true : false; $listObj = null; if ($listId && !in_array($listId, $newListIds)) { $listObj = PcListPeer::retrieveByPK($listId); } if ($listObj) { if ($listObj->getCreatorId() != $this->user->getId()) { die("Hacking attempt."); } } else { if ($listIsInbox) { $listObj = $this->user->getInbox(); } else { if ($listIsTodo) { $listObj = $this->user->getTodo(); } else { $listObj = new PcList(); $isNewList = true; } } } $listObj->setCreatorId($this->user->getId())->setTitle($listName)->setSortOrder($listSortOrder)->setIsInbox($listIsInbox)->setIsTodo($listIsTodo)->setIsHeader($listIsHeader)->save(); $listLocalIds[$listLocalId] = $listObj->getId(); if ($isNewList) { $newListIds[] = $listObj->getId(); } } $tasks = $xml->plancake_tasks->tasks->task; foreach ($tasks as $task) { $isNewTask = false; $taskId = (int) $task->id > 0 ? $task->id : 0; $taskListLocalId = (int) $task->listLocalId; $taskDescription = (string) $task->description; $taskSortOrder = (int) $task->sortOrder; $taskDueDate = (string) $task->dueDate; $taskDueTime = strlen($task->dueTime) > 0 ? (int) $task->dueTime : ''; $taskRepetitionId = (int) $task->repetitionId; $taskRepetitionParam = (int) $task->repetitionParam; $taskIsStarred = (int) $task->isStarred == 1 ? true : false; $taskIsCompleted = (int) $task->isCompleted == 1 ? true : false; $taskIsHeader = (int) $task->isHeader == 1 ? true : false; $taskIsFromSystem = (int) $task->isFromSystem == 1 ? true : false; $taskTagLocalIds = (string) $task->tagLocalIds; $taskNote = (string) $task->note; $taskListId = $listLocalIds[$taskListLocalId]; $taskTagIdsArray = array(); $taskTagLocalIdsArray = PcUtils::explodeWithEmptyInputDetection(',', $taskTagLocalIds); foreach ($taskTagLocalIdsArray as $id) { $taskTagIdsArray[] = $tagLocalIds[$id]; } $taskTagIds = ''; if (count($taskTagIdsArray)) { $taskTagIds = implode(',', $taskTagIdsArray); } $taskFromDb = null; if ($taskId && !in_array($taskId, $newTaskIds)) { $taskFromDb = PcTaskPeer::retrieveByPK($taskId); } if (!is_object($taskFromDb)) { // if the task doesn't exist (even if the dump contains a taskId) // we want to add it. $taskId = 0; $isNewTask = true; } $newTask = PcTaskPeer::createOrEdit($taskDescription, $taskListId, $taskId, $taskTagIds, $taskIsHeader, $taskNote, $taskDueDate, $taskDueTime, $taskIsStarred, $taskRepetitionId, $taskRepetitionParam, 0, '', 'd-m-Y', false); if ($taskIsCompleted) { $newTask->setIsCompleted(1); $newTask->setCompletedAt($task->completedAt); $newTask->save(); } if ($isNewTask) { $newTaskIds[] = $newTask->getId(); } if (!$taskId) { $newTask->deleteDirtyEntry(); } } $notes = $xml->plancake_notes->notes->note; foreach ($notes as $note) { $isNewNote = false; $noteId = (int) $note->id > 0 ? $note->id : null; $noteTitle = (string) $note->title; $noteContent = (string) $note->content; $noteObj = null; if ($noteId && !in_array($noteId, $newNoteIds)) { $noteObj = PcNotePeer::retrieveByPK($noteId); } if ($noteObj) { if ($noteObj->getCreatorId() != $this->user->getId()) { die("Hacking attempt."); } } else { $noteObj = new PcNote(); $isNewNote = true; } $noteObj->setCreatorId($this->user->getId())->setTitle($noteTitle)->setContent($noteContent)->save(); if ($isNewNote) { $newNoteIds[] = $noteObj->getId(); } } ini_set('max_execution_time', $originalMaxExecutionTime); }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(PcTaskPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(PcTaskPeer::DATABASE_NAME); $criteria->add(PcTaskPeer::ID, $pks, Criteria::IN); $objs = PcTaskPeer::doSelect($criteria, $con); } return $objs; }
/** * * @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 * @return array of PcTask */ public function getTasksByMultipleCriteria($fromTs = null, $toTs = null, $taskId = null, $listId = null, $tagId = null, $completed = false, $onlyWithDueDate = false, $onlyWithoutDueDate = false, $onlyDueTodayOrTomorrow = false, $onlyStarred = false, $byDate = null) { $c = new Criteria(); $c->addJoin(PcTaskPeer::LIST_ID, PcListPeer::ID, Criteria::INNER_JOIN); $c->add(PcListPeer::CREATOR_ID, $this->getId()); return PcTaskPeer::getTasksByMultipleCriteria($fromTs, $toTs, $taskId, $listId, $tagId, $completed, $onlyWithDueDate, $onlyWithoutDueDate, $onlyDueTodayOrTomorrow, $onlyStarred, $byDate, $c); }
/** * Get the associated PcTask object * * @param PropelPDO Optional Connection object. * @return PcTask The associated PcTask object. * @throws PropelException */ public function getPcTask(PropelPDO $con = null) { if ($this->aPcTask === null && $this->task_id !== null) { $this->aPcTask = PcTaskPeer::retrieveByPk($this->task_id); // Because this foreign key represents a one-to-one relationship, we will create a bi-directional association. $this->aPcTask->setPcGoogleCalendarEvent($this); } return $this->aPcTask; }
/** * Selects a collection of PcGoogleCalendarEvent objects pre-filled with all related objects. * * @param Criteria $criteria * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of PcGoogleCalendarEvent objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $criteria = clone $criteria; // Set the correct dbName if it has not been overridden if ($criteria->getDbName() == Propel::getDefaultDB()) { $criteria->setDbName(self::DATABASE_NAME); } PcGoogleCalendarEventPeer::addSelectColumns($criteria); $startcol2 = PcGoogleCalendarEventPeer::NUM_COLUMNS - PcGoogleCalendarEventPeer::NUM_LAZY_LOAD_COLUMNS; PcTaskPeer::addSelectColumns($criteria); $startcol3 = $startcol2 + (PcTaskPeer::NUM_COLUMNS - PcTaskPeer::NUM_LAZY_LOAD_COLUMNS); $criteria->addJoin(PcGoogleCalendarEventPeer::TASK_ID, PcTaskPeer::ID, $join_behavior); // symfony_behaviors behavior foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook) { call_user_func($sf_hook, 'BasePcGoogleCalendarEventPeer', $criteria, $con); } $stmt = BasePeer::doSelect($criteria, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = PcGoogleCalendarEventPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = PcGoogleCalendarEventPeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://propel.phpdb.org/trac/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $cls = PcGoogleCalendarEventPeer::getOMClass(false); $obj1 = new $cls(); $obj1->hydrate($row); PcGoogleCalendarEventPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined PcTask rows $key2 = PcTaskPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = PcTaskPeer::getInstanceFromPool($key2); if (!$obj2) { $cls = PcTaskPeer::getOMClass(false); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); PcTaskPeer::addInstanceToPool($obj2, $key2); } // if obj2 loaded // Add the $obj1 (PcGoogleCalendarEvent) to the collection in $obj2 (PcTask) $obj1->setPcTask($obj2); } // if joined row not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * Overrides the delete method to delete the associated tasks and the sharings * * @see parent::delete() * @param PropelPDO Optional Connection object. * @return PcList */ public function delete(PropelPDO $con = null) { // deleting all the tasks related to the list $tasksCriteria = new Criteria(); $tasksCriteria->add(PcTaskPeer::LIST_ID, $this->getId(), Criteria::EQUAL); $tasks = PcTaskPeer::doSelect($tasksCriteria); foreach ($tasks as $task) { $task->delete(); } // deleting all the sharing related to the list $sharingsCriteria = new Criteria(); $sharingsCriteria->add(PcTaskPeer::LIST_ID, $this->getId(), Criteria::EQUAL); $sharings = PcTaskPeer::doSelect($sharingsCriteria); foreach ($sharings as $sharing) { $sharing->delete(); } $this->clearRelevantCache(); $con = Propel::getConnection(); $ret = null; try { $con->beginTransaction(); $this->copyObjectToTrashBin(); $ret = parent::delete($con); $con->commit(); } catch (Exception $e) { $con->rollback(); throw $e; } return $ret; }
public function executeEdit(sfWebRequest $request) { $allowedOps = array('delete', 'edit'); $op = $request->getParameter('op'); if (!in_array($op, $allowedOps)) { return false; } $taskId = (int) $request->getParameter('taskId'); $task = PcTaskPeer::retrieveByPk($taskId); if (!is_object($task)) { die("ERROR: " . __('ACCOUNT_ERROR_ERROR_OCCURRED_PLEASE_RETRY')); } PcUtils::checkLoggedInUserPermission($task->getList()->getCreator()); if ($op == "delete") { $task->delete(); return $this->renderDefault(); } if ($op == "edit") { // the 'add' action will manage also the edit action return $this->executeAdd($request); } return sfView::NONE; }
* 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); require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Gdata'); Zend_Loader::loadClass('Zend_Gdata_AuthSub'); Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); Zend_Loader::loadClass('Zend_Gdata_Calendar'); $redirectUrl = ''; try { $googleCalender = new GoogleCalendarInterface(PcUserPeer::getLoggedInUser()); $googleCalender->init(); $googleCalender->import(PcTaskPeer::getIncompletedTasksWithDate()); $configuration->loadHelpers('Url'); $redirectUrl = 'http://' . sfConfig::get('app_site_url') . '/' . sfConfig::get('app_accountApp_frontController') . '/googleCalendarIntegration/step4'; } catch (Exception $e) { sfErrorNotifier::alert("Google Calendar Import: " . $e->getMessage()); error_log("Google Calendar Import: " . $e->getMessage()); $configuration->loadHelpers('Url'); $redirectUrl = 'http://' . sfConfig::get('app_site_url') . '/' . sfConfig::get('app_accountApp_frontController') . '/googleCalendarIntegration/step4Error'; } header("Location: {$redirectUrl}");
/** * Returns tasks scheduled for that day and the next 6 (including multiple occurrences of recurrent tasks) * * @param string $date - in the format yyyy-mm-dd (e.g.: 2011-12-25) * @return array|null - array of PcTask */ public static function getTasksByDate($date) { if ($date == null || strlen($date) <= 0) { return null; } $date = trim($date); $tasksToReturn = array(); $c = new Criteria(); $c->add(PcTaskPeer::DUE_DATE, null, Criteria::ISNOTNULL); // N.B.: the following criteria would be a mistake because it would take out recurrent tasks // $c->addAnd(PcTaskPeer::DUE_DATE, date('Y-m-d', strtotime($date)), Criteria::GREATER_EQUAL); $c->add(PcTaskPeer::IS_COMPLETED, 0); $c->addJoin(PcTaskPeer::LIST_ID, PcListPeer::ID); $c->add(PcListPeer::CREATOR_ID, PcUserPeer::getLoggedInUser()->getId()); $c->addAscendingOrderByColumn(PcTaskPeer::DUE_TIME); $tasksWithDueDate = PcTaskPeer::doSelect($c); $tmpDate = $date; for ($i = 0; $i < 7; $i++) { foreach ($tasksWithDueDate as $taskWithDueDate) { if ($taskWithDueDate->isOnThisDay($tmpDate)) { $taskWithDueDate->extra = date('D', strtotime($tmpDate)); $tasksToReturn[] = clone $taskWithDueDate; } } $tmpDate = date('Y-m-d', strtotime("+1 day", strtotime($tmpDate))); } return $tasksToReturn; }
/** * @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; }
/** * @see sfTask */ protected function executeTask($env, $arguments = array(), $options = array()) { /** * Getting the directory where the emails are stored */ $inboxUser = sfConfig::get('app_emailToInbox_inboxUser'); $emailDomain = sfConfig::get('app_emailToInbox_mailServerDomain'); $newEmailPath = $arguments['emailFileAbsolutePath']; // there are some regular Plancake inbox email address that are // use just for spam $spamAccounts = array(); $spamAccounts[] = 'niki_5436'; // this will be interpreted as inbox_niki_5436@plancakebox.com $spamAccounts[] = 'niki.jones_15c522'; $this->log(''); $this->log(''); $this->log("parsing the email at " . $newEmailPath); $mailParser = new PlancakeEmailParser(file_get_contents($newEmailPath)); $plancakeSubjectOK = false; $plancakeRecipientOK = false; $emailTo = array(); $emailSubject = ''; $emailCc = $mailParser->getCc(); try { $emailTo = $mailParser->getTo(); } catch (Exception $e) { $this->handleFault("couldn't retrieve the 'to' header of the email", $newEmailPath); return; } try { $emailSubject = $mailParser->getSubject(); $plancakeSubjectOK = true; $this->log("got the subject of the email: " . $emailSubject); } catch (Exception $e) { $this->handleFault("couldn't retrieve the subject of the email", $newEmailPath); return; } $emailRecipients = array_merge($emailTo, $emailCc); $emailRecipients = implode(', ', $emailRecipients); $deliveredToHeader = $mailParser->getHeader('Delivered-To'); $emailRecipients = $deliveredToHeader . ', ' . $emailRecipients; $this->log("all recipients of the email: " . $emailRecipients); $internalEmail = false; // to flag an email sent to the catchall address $spamEmail = false; if (preg_match('/' . $inboxUser . "@{$emailDomain}/", $emailRecipients, $matches)) { $internalEmail = true; $this->log("discarding the email as it is an internal one"); if (is_file($newEmailPath)) { unlink($newEmailPath); } return; } if (preg_match("/inbox_([^@]+)@{$emailDomain}/i", $emailRecipients, $matches)) { // found Plancake Inbox address! $plancakeInbox = $matches[1]; if (in_array($plancakeInbox, $spamAccounts)) { $spamEmail = true; $this->handleFault("discarding the email because it is from a spammer", $newEmailPath); return; } else { $emailRecipient = 'inbox_' . $plancakeInbox . "@{$emailDomain}"; $plancakeRecipientOK = true; $this->log("got the Plancake recipient of the email: " . $emailRecipient); } } else { $this->handleFault("couldn't find a Plancake recipient for the email", $newEmailPath); return; } /** * Sorting the email into the database */ if ($plancakeRecipientOK && $plancakeSubjectOK) { $this->log('well done. For this email we got both the recipient and the subject. I can now create the task for the user.'); $emailRecipientWithoutDomain = str_replace("@{$emailDomain}", '', $emailRecipient); $c = new Criteria(); $c->add(PcPlancakeEmailAddressPeer::EMAIL, $emailRecipientWithoutDomain, Criteria::EQUAL); $plancakeEmail = PcPlancakeEmailAddressPeer::doSelectOne($c); if (is_object($plancakeEmail)) { // everything's OK $userId = $plancakeEmail->getUserId(); $user = PcUserPeer::retrieveByPk($userId); PcUserPeer::setLoggedInUser($user); // check whether there is a note for the task $note = $this->extractNote($mailParser->getPlainBody()); if (strlen($note)) { $this->log("note: {$note}"); } if (!strlen($emailSubject)) { $emailSubject = 'Something went wrong with a task you sent via email. Please contact us.'; } PcTaskPeer::createOrEdit($emailSubject, $user->getInbox()->getId(), 0, '', false, $note); $this->log('the email has successfully become a task for the user.'); } else { // something wrong $this->handleFault('no email user', $newEmailPath); $this->log('couldn\'t create a task from the email - the Plancake address is not in the system :-(.'); } } else { if ((!$plancakeRecipientOK || !$plancakeSubjectOK) && !$internalEmail && !$spamEmail) { // something wrong $this->handleFault('email parsing', $newEmailPath); $this->log("counldn't find both the recipient and the subject of the email. Nothing to do."); } } $this->log("deleting the email from the hard disk."); if (is_file($newEmailPath)) { unlink($newEmailPath); } $this->log(''); $this->log(''); }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = PcTaskPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setListId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setDescription($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setSortOrder($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setDueDate($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setDueTime($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setRepetitionId($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setRepetitionParam($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setIsStarred($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { $this->setIsCompleted($arr[$keys[9]]); } if (array_key_exists($keys[10], $arr)) { $this->setIsHeader($arr[$keys[10]]); } if (array_key_exists($keys[11], $arr)) { $this->setIsFromSystem($arr[$keys[11]]); } if (array_key_exists($keys[12], $arr)) { $this->setSpecialFlag($arr[$keys[12]]); } if (array_key_exists($keys[13], $arr)) { $this->setNote($arr[$keys[13]]); } if (array_key_exists($keys[14], $arr)) { $this->setContexts($arr[$keys[14]]); } if (array_key_exists($keys[15], $arr)) { $this->setContactId($arr[$keys[15]]); } if (array_key_exists($keys[16], $arr)) { $this->setCompletedAt($arr[$keys[16]]); } if (array_key_exists($keys[17], $arr)) { $this->setUpdatedAt($arr[$keys[17]]); } if (array_key_exists($keys[18], $arr)) { $this->setCreatedAt($arr[$keys[18]]); } }
/** * Edit anything in a task * Only the input parameters that are not null will be changed. * * @param string $description (=null) * @param integer $listId (=null) * @param string $contexts (=null) (comma separated list) * @param boolean $isHeader * @param string $note (=null) * @param string $dueDate in the PHP date() format 'Y-m-d' * @param string $dueTime - formatted as an integer, ie: 0753 * @param integer $repetitionId * @param integer $repetitionParam * @param integer $taskAboveId * @param string $callerContext - can be either 'ajax' or 'email' * @return PcTask - the object that has been created */ public function edit($description = null, $listId = null, $contexts = null, $isHeader = null, $note = null, $dueDate = null, $dueTime = null, $isStarred = null, $repetitionId = null, $repetitionParam = null, $callerContext = '') { $description = $description === null ? $this->getDescription() : $description; $listId = $listId === null ? $this->getListId() : $listId; $contexts = $contexts === null ? $this->getContexts() : $contexts; $note = $note === null ? $this->getNote() : $note; $isHeader = $isHeader === null ? $this->isHeader() : $isHeader; $dueDate = $dueDate === null ? $this->getDueDate('Y-m-d') : $dueDate; $dueTime = $dueTime === null ? $this->getDueTime() : $dueTime; $isStarred = $isStarred === null ? $this->isStarred() : $isStarred; $repetitionId = $repetitionId === null ? $this->getRepetitionId() : $repetitionId; $repetitionParam = $repetitionParam === null ? $this->getRepetitionParam() : $repetitionParam; $taskId = $this->getId(); PcTaskPeer::createOrEdit($description, $listId, $taskId, $contexts, $isHeader, $note, $dueDate, $dueTime, $isStarred, $repetitionId, $repetitionParam, 0, $callerContext, 'Y-m-d'); }