/** * Given the task typed by a user (i.e.: pay electricity bill %%27-05-2009 %%money), * it returns an array with the information embedded in the task description: * _ the first element is null, or the id or the inbox or the todo list of the user * _ an array of context Ids * _ an array of potential due date expressions (thay could actual be illegal wrong contexts) * _ null or a PcTime object as potential due time * * The task description passed as input is cleared from the shortcuts * * @param string $taskDescription (passed by reference) the task text to evaluate and parse * @return array */ public function extractInfoFromTaskDescription(&$taskDescription) { preg_match('!@([0-9]+)([\\.:]([0-9]+))? ?([ap]m\\b)?!i', $taskDescription, $matches); $potentialDueTime = null; if (count($matches)) { $potentialDueTime = new PcTime(); $potentialDueTime->createFromParts(isset($matches[1]) ? $matches[1] : null, isset($matches[3]) ? $matches[3] : 0, isset($matches[4]) ? trim($matches[4]) : ''); // removing the shortcut from the description $taskDescription = str_replace($matches[0], '', $taskDescription); } $taskDescriptionParts = explode('%%', $taskDescription); $taskDescription = $taskDescriptionParts[0]; $potentialInfo = array_slice($taskDescriptionParts, 1); // the first part is the actual // task description $existingContextsLowercase = PcUserPeer::getLoggedInUser()->getContextsArray(true); $listId = null; $contextIds = array(); $potentialDueDates = array(); foreach ($potentialInfo as $info) { $info = trim($info); // searching for listId if (strtolower($info) == 'inbox') { $listId = PcUserPeer::getLoggedInUser()->getInbox()->getId(); } else { if (strtolower($info) == 'todo') { $listId = PcUserPeer::getLoggedInUser()->getTodo()->getId(); } else { if (in_array(strtolower($info), $existingContextsLowercase)) { $contextIds[] = array_search(strtolower($info), $existingContextsLowercase); } else { $potentialDueDates[] = strtolower($info); } } } } return array($listId, $contextIds, $potentialDueDates, $potentialDueTime); }