}
/* Get the full, sorted task list. */
- $tasks = Nag::listTasks(null, null, null, $tasklists,
- Horde_Util::getFormData('exportTasks'));
- if (is_a($tasks, 'PEAR_Error')) {
- $notification->push($tasks);
- $error = true;
- } elseif (!$tasks->hasTasks()) {
- $notification->push(_("There were no tasks to export."), 'horde.message');
- $error = true;
- } else {
- $tasks->reset();
- switch ($exportID) {
- case Horde_Data::EXPORT_CSV:
- $data = array();
- while ($task = $tasks->each()) {
- $task = $task->toHash();
- unset($task['task_id']);
- $task['desc'] = str_replace(',', '', $task['desc']);
- unset($task['tasklist_id']);
- unset($task['parent']);
- unset($task['view_link']);
- unset($task['complete_link']);
- unset($task['edit_link']);
- unset($task['delete_link']);
- $data[] = $task;
- }
- $injector->getInstance('Horde_Core_Factory_Data')->create('Csv', array('cleanup' => '_cleanupData'))->exportFile(_("tasks.csv"), $data, true);
- exit;
+ try {
+ $tasks = Nag::listTasks(null, null, null, $tasklists,
+ Horde_Util::getFormData('exportTasks'));
+ if (!$tasks->hasTasks()) {
+ $notification->push(_("There were no tasks to export."), 'horde.message');
+ $error = true;
+ } else {
+ $tasks->reset();
+ switch ($exportID) {
+ case Horde_Data::EXPORT_CSV:
+ $data = array();
+ while ($task = $tasks->each()) {
+ $task = $task->toHash();
+ unset($task['task_id']);
+ $task['desc'] = str_replace(',', '', $task['desc']);
+ unset($task['tasklist_id']);
+ unset($task['parent']);
+ unset($task['view_link']);
+ unset($task['complete_link']);
+ unset($task['edit_link']);
+ unset($task['delete_link']);
+ $data[] = $task;
+ }
+ $injector->getInstance('Horde_Core_Factory_Data')->create('Csv', array('cleanup' => '_cleanupData'))->exportFile(_("tasks.csv"), $data, true);
+ exit;
- case Horde_Data::EXPORT_ICALENDAR:
- $iCal = new Horde_Icalendar();
- $iCal->setAttribute(
- 'PRODID',
- '-//The Horde Project//Nag ' . $registry->getVersion() . '//EN');
- while ($task = $tasks->each()) {
- $iCal->addComponent($task->toiCalendar($iCal));
+ case Horde_Data::EXPORT_ICALENDAR:
+ $iCal = new Horde_Icalendar();
+ $iCal->setAttribute(
+ 'PRODID',
+ '-//The Horde Project//Nag ' . $registry->getVersion() . '//EN');
+ while ($task = $tasks->each()) {
+ $iCal->addComponent($task->toiCalendar($iCal));
+ }
+ $data = $iCal->exportvCalendar();
+ $browser->downloadHeaders(_("tasks.ics"), 'text/calendar', false, strlen($data));
+ echo $data;
+ exit;
}
- $data = $iCal->exportvCalendar();
- $browser->downloadHeaders(_("tasks.ics"), 'text/calendar', false, strlen($data));
- echo $data;
- exit;
}
+ } catch (Nag_Exception $e) {
+ $notification->push($e->getMessage());
+ $error = true;
}
break;
}
}
- $result = $storage->add($row['name'], $row['desc'], $row['start'],
- $row['due'], $row['priority'],
- $row['estimate'], $row['completed'],
- $row['category'], $row['alarm'], $row['uid'],
- isset($row['parent']) ? $row['parent'] : '',
- $row['private'], $GLOBALS['registry']->getAuth(),
- $row['assignee']);
- if (is_a($result, 'PEAR_Error')) {
+ try {
+ $storage->add(
+ $row['name'], $row['desc'], $row['start'],
+ $row['due'], $row['priority'],
+ $row['estimate'], $row['completed'],
+ $row['category'], $row['alarm'], $row['uid'],
+ isset($row['parent']) ? $row['parent'] : '',
+ $row['private'], $GLOBALS['registry']->getAuth(),
+ $row['assignee']
+ );
+ } catch (Nag_Exception $e) {
+ $haveError = true;
+ $notification->push(sprintf(_("There was an error importing the data: %s"),
+ $result->getMessage()), 'horde.error');
break;
}
if (!count($next_step)) {
$notification->push(sprintf(_("The %s file didn't contain any tasks."),
$file_types[$session->get('horde', 'import_data/format')]), 'horde.error');
- } elseif (is_a($result, 'PEAR_Error')) {
- $notification->push(sprintf(_("There was an error importing the data: %s"),
- $result->getMessage()), 'horde.error');
- } else {
+ } elseif (empty($haveError)) {
$notification->push(sprintf(_("%s successfully imported"),
$file_types[$session->get('horde', 'import_data/format')]), 'horde.success');
}
public function addTasklist($name, $description = '', $color = '')
{
$tasklist = Nag::addTasklist(array('name' => $name, 'description' => $description, 'color' => $color));
- if (is_a($tasklist, 'PEAR_Error')) {
- return $tasklist;
- }
return $tasklist->getName();
}
public function deleteTasklist($id)
{
$tasklist = $GLOBALS['nag_shares']->getShare($id);
- if (is_a($tasklist, 'PEAR_Error')) {
- return $tasklist;
- }
return Nag::deleteTasklist($tasklist);
}
return PEAR::raiseError(_("Invalid tasklist requested."), 404);
}
$storage = Nag_Driver::singleton($parts[1]);
- $result = $storage->retrieve();
- if (is_a($result, 'PEAR_Error')) {
- $result->code = 500;
- return $result;
+ try {
+ $storage->retrieve();
+ } catch (Nag_Exception $e) {
+ throw new Nag_Exception($e->getMessage, 500);
}
-
$icon = Horde_Themes::img('nag.png');
$results = array();
$storage->tasks->reset();
// The only valid request left is for either a specific task item.
//
if (count($parts) == 3 &&
- array_key_exists($parts[1], Nag::listTasklists(false,
- Horde_Perms::READ))) {
- //
- // This request is for a specific item within a given task list.
- //
- /* Create a Nag storage instance. */
- $storage = Nag_Driver::singleton($parts[1]);
- if (is_a($storage, 'PEAR_Error')) {
- return PEAR::raiseError(sprintf(_("Connection failed: %s"), $storage->getMessage()));
- }
- $storage->retrieve();
+ array_key_exists($parts[1], Nag::listTasklists(false, Horde_Perms::READ))) {
+
+ //
+ // This request is for a specific item within a given task list.
+ //
+ /* Create a Nag storage instance. */
+ $storage = Nag_Driver::singleton($parts[1]);
+ $storage->retrieve();
+ try {
+ $storage->get($parts[2]);
+ } catch (Nag_Exception $e) {
+ throw new Nag_Exception($e->getMessage(), 500);
+ }
+ $result = array(
+ 'data' => $this->export($task->uid, 'text/calendar'),
+ 'mimetype' => 'text/calendar');
+ $modified = $this->modified($task->uid, $parts[1]);
+ if (!empty($modified)) {
+ $result['mtime'] = $modified;
+ }
+ return $result;
+ } elseif (count($parts) == 2 &&
+ substr($parts[1], -4) == '.ics' &&
+ array_key_exists(substr($parts[1], 0, -4), Nag::listTasklists(false, Horde_Perms::READ))) {
- $task = $storage->get($parts[2]);
- if (is_a($task, 'PEAR_Error')) {
- $task->code = 500;
- return $task;
- }
+ // ??
- $result = array('data' => $this->export($task->uid, 'text/calendar'),
- 'mimetype' => 'text/calendar');
- $modified = $this->modified($task->uid, $parts[1]);
- if (!empty($modified)) {
- $result['mtime'] = $modified;
- }
- return $result;
- } elseif (count($parts) == 2 &&
- substr($parts[1], -4) == '.ics' &&
- array_key_exists(substr($parts[1], 0, -4), Nag::listTasklists(false, Horde_Perms::READ))) {
- } else {
- //
- // All other requests are a 404: Not Found
- //
- return false;
- }
+ } else {
+ //
+ // All other requests are a 404: Not Found
+ //
+ return false;
+ }
}
}
* @param string $content The file content.
* @param string $content_type The file's content type.
*
- * @return array The event UIDs, or a PEAR_Error on failure.
+ * @return array The event UIDs
*/
public function put($path, $content, $content_type)
{
$content_type = 'text/calendar';
}
} else {
- return PEAR::raiseError(_("Invalid tasklist name supplied."), 403);
+ throw new Nag_Exception(_("Invalid tasklist name supplied."), 403);
}
if (!array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::EDIT))) {
// FIXME: Should we attempt to create a tasklist based on the filename
// in the case that the requested tasklist does not exist?
- return PEAR::raiseError(_("Tasklist does not exist or no permission to edit"), 403);
+ throw new Nag_Exception(_("Tasklist does not exist or no permission to edit"), 403);
}
// Store all currently existings UIDs. Use this info to delete UIDs not
$iCal = new Horde_Icalendar();
if (!($content instanceof Horde_Icalendar_Vtodo)) {
if (!$iCal->parsevCalendar($content)) {
- return PEAR::raiseError(_("There was an error importing the iCalendar data."), 400);
+ throw new Nag_Exception(_("There was an error importing the iCalendar data."), 400);
}
} else {
$iCal->addComponent($content);
$task = new Nag_Task();
$task->fromiCalendar($content);
$task->tasklist = $tasklist;
- if (isset($task->uid) &&
- !is_a(($existing = $storage->getByUID($task->uid)), 'PEAR_Error')) {
+ if (isset($task->uid)) {
+ $existing = $storage->getByUID($task->uid);
// Entry exists, remove from uids_remove list so we
// won't delete in the end.
if (isset($uids_remove[$task->uid])) {
// Don't change creator/owner.
$owner = $existing->owner;
$taskId = $existing->id;
- $result = $storage->modify(
- $taskId,
- isset($task->name) ? $task->name : $existing->name,
- isset($task->desc) ? $task->desc : $existing->desc,
- isset($task->start) ? $task->start : $existing->start,
- isset($task->due) ? $task->due : $existing->due,
- isset($task->priority) ? $task->priority : $existing->priority,
- isset($task->estimate) ? $task->estimate : 0,
- isset($task->completed) ? (int)$task->completed : $existing->completed,
- isset($task->category) ? $task->category : $existing->category,
- isset($task->alarm) ? $task->alarm : $existing->alarm,
- isset($task->parent_id) ? $task->parent_id : $existing->parent_id,
- isset($task->private) ? $task->private : $existing->private,
- $owner,
- isset($task->assignee) ? $task->assignee : $existing->assignee);
-
- if (is_a($result, 'PEAR_Error')) {
- $result->code = 500;
- return $result;
+ try {
+ $storage->modify(
+ $taskId,
+ isset($task->name) ? $task->name : $existing->name,
+ isset($task->desc) ? $task->desc : $existing->desc,
+ isset($task->start) ? $task->start : $existing->start,
+ isset($task->due) ? $task->due : $existing->due,
+ isset($task->priority) ? $task->priority : $existing->priority,
+ isset($task->estimate) ? $task->estimate : 0,
+ isset($task->completed) ? (int)$task->completed : $existing->completed,
+ isset($task->category) ? $task->category : $existing->category,
+ isset($task->alarm) ? $task->alarm : $existing->alarm,
+ isset($task->parent_id) ? $task->parent_id : $existing->parent_id,
+ isset($task->private) ? $task->private : $existing->private,
+ $owner,
+ isset($task->assignee) ? $task->assignee : $existing->assignee
+ );
+ } catch (Nag_Exception $e) {
+ throw new Nag_Exception($e->getMessage(), 500);
}
$ids[] = $task->uid;
} else {
- $newTask = $storage->add(
- isset($task->name) ? $task->name : '',
- isset($task->desc) ? $task->desc : '',
- isset($task->start) ? $task->start : 0,
- isset($task->due) ? $task->due : 0,
- isset($task->priority) ? $task->priority : 3,
- isset($task->estimate) ? $task->estimate : 0,
- !empty($task->completed),
- isset($task->category) ? $task->category : '',
- isset($task->alarm) ? $task->alarm : 0,
- isset($task->uid) ? $task->uid : null,
- isset($task->parent_id) ? $task->parent_id : '',
- !empty($task->private),
- $GLOBALS['registry']->getAuth(),
- isset($task->assignee) ? $task->assignee : null);
- if (is_a($newTask, 'PEAR_Error')) {
- $newtask->code = 500;
- return $newTask;
+ try {
+ $newTask = $storage->add(
+ isset($task->name) ? $task->name : '',
+ isset($task->desc) ? $task->desc : '',
+ isset($task->start) ? $task->start : 0,
+ isset($task->due) ? $task->due : 0,
+ isset($task->priority) ? $task->priority : 3,
+ isset($task->estimate) ? $task->estimate : 0,
+ !empty($task->completed),
+ isset($task->category) ? $task->category : '',
+ isset($task->alarm) ? $task->alarm : 0,
+ isset($task->uid) ? $task->uid : null,
+ isset($task->parent_id) ? $task->parent_id : '',
+ !empty($task->private),
+ $GLOBALS['registry']->getAuth(),
+ isset($task->assignee) ? $task->assignee : null);
+ } catch (Nag_Exception $e) {
+ throw new Nag_Exception($e->getMessage(), 500);
}
// use UID rather than ID
$ids[] = $newTask[1];
break;
default:
- return PEAR::raiseError(sprintf(_("Unsupported Content-Type: %s"), $content_type), 400);
+ throw new Nag_Exception(sprintf(_("Unsupported Content-Type: %s"), $content_type), 400);
}
if (array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::DELETE))) {
*
* @param string $path The path to the file.
*
- * @return mixed The event's UID, or a PEAR_Error on failure.
+ * @return string The event's UID
+ * @throws Nag_Exception
*/
public function path_delete($path)
{
// Allow users to delete tasklists but not create them via WebDAV will
// be more confusing than helpful. They are, however, still able to
// delete individual task items within the tasklist folder.
- return PEAR::raiseError(_("Deleting entire tasklists is not supported."), 403);
+ throw Nag_Exception(_("Deleting entire tasklists is not supported."), 403);
// To re-enable the functionality just remove this if {} block.
}
if (!(count($parts) == 2 || count($parts) == 3) ||
!array_key_exists($tasklistID, Nag::listTasklists(false, Horde_Perms::DELETE))) {
- return PEAR::raiseError(_("Tasklist does not exist or no permission to delete"), 403);
- }
- /* Create a Nag storage instance. */
- $storage = Nag_Driver::singleton($tasklistID);
- if (is_a($storage, 'PEAR_Error')) {
- return PEAR::raiseError(sprintf(_("Connection failed: %s"), $storage->getMessage()), 500);
- }
- $retrieved = $storage->retrieve();
- if (is_a($retrieved, 'PEAR_Error')) {
- $retrieved->code = 500;
- return $retrieved;
+ throw new Nag_Exception(_("Tasklist does not exist or no permission to delete"), 403);
}
+ /* Create a Nag storage instance. */
+ try {
+ $storage = Nag_Driver::singleton($tasklistID);
+ $storage->retrieve();
+ } catch (Nag_Exception $e) {
+ throw new Nag_Exception(sprintf(_("Connection failed: %s"), $e->getMessage()), 500);
+ }
if (count($parts) == 3) {
// Delete just a single entry
return $storage->delete($parts[2]);
} else {
// Delete the entire task list
- $result = $storage->deleteAll();
- if (is_a($result, 'PEAR_Error')) {
- return PEAR::raiseError(sprintf(_("Unable to delete tasklist \"%s\": %s"), $tasklistID, $result->getMessage()), 500);
- } else {
- // Remove share and all groups/permissions.
- $share = $GLOBALS['nag_shares']->getShare($tasklistID);
- try {
- $GLOBALS['nag_shares']->removeShare($share);
- } catch (Horde_Share_Exception $e) {
- throw new Nag_Exception($e->getMessage());
- }
+ try {
+ $storage->deleteAll();
+ } catch (Nag_Exception $e) {
+ throw new Nag_Exception(sprintf(_("Unable to delete tasklist \"%s\": %s"), $tasklistID, $e->getMessage()), 500);
+ }
+
+ // Remove share and all groups/permissions.
+ $share = $GLOBALS['nag_shares']->getShare($tasklistID);
+ try {
+ $GLOBALS['nag_shares']->removeShare($share);
+ } catch (Horde_Share_Exception $e) {
+ throw new Nag_Exception($e->getMessage());
}
}
}
* Returns an array of UIDs for all tasks that the current user is authorized
* to see.
*
- * @param variant $tasklist The tasklist or an array of taskslists to list.
+ * @param mixed $tasklist The tasklist or an array of taskslists to list.
*
* @return array An array of UIDs for all tasks
* the user can access.
+ *
+ * @throws Horde_Exception_PermissionDenied
+ * @throws Nag_Exception
*/
public function listUids($tasklist = null)
{
if (!isset($GLOBALS['conf']['storage']['driver'])) {
- return PEAR::raiseError(_("Not configured"));
+ throw new Nag_Exception(_("Not configured"));
}
-
if ($tasklist === null) {
$tasklist = Nag::getDefaultTasklist(Horde_Perms::READ);
}
-
- if (!array_key_exists($tasklist,
- Nag::listTasklists(false, Horde_Perms::READ))) {
- return PEAR::raiseError(_("Permission Denied"));
- }
-
- $tasks = Nag::listTasks(null, null, null, $tasklist, 1);
- if (is_a($tasks, 'PEAR_Error')) {
- return $tasks;
+ if (!array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::READ))) {
+ throw new Horde_Exception_PermissionDenied(_("Permission Denied"));
}
-
+ $tasks = Nag::listTasks(null, null, null, $tasklist, 1);
$uids = array();
$tasks->reset();
while ($task = $tasks->each()) {
$tasklist = Nag::getDefaultTasklist(Horde_Perms::READ);
}
- if (!array_key_exists($tasklist,
- Nag::listTasklists(false, Horde_Perms::READ))) {
- return PEAR::raiseError(_("Permission Denied"));
+ if (!array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::READ))) {
+ throw new Horde_Exception_PermissionDenied(_("Permission Denied"));
}
$filter = array(array('op' => '=', 'field' => 'action', 'value' => $action));
if (!empty($end)) {
$filter[] = array('op' => '<', 'field' => 'ts', 'value' => $end);
}
- $histories = $GLOBALS['injector']->getInstance('Horde_History')->getByTimestamp('>', $timestamp, $filter, 'nag:' . $tasklist);
+ $histories = $GLOBALS['injector']
+ ->getInstance('Horde_History')
+ ->getByTimestamp('>', $timestamp, $filter, 'nag:' . $tasklist);
// Strip leading nag:username:.
return preg_replace('/^([^:]*:){2}/', '', array_keys($histories));
* @return integer The timestamp for this action.
*
* @throws InvalidArgumentException
+ * @throws Horde_Exception_PermissionDenied
+ * @thorws Horde_History_Exception
*/
public function getActionTimestamp($uid, $action, $tasklist = null)
{
$tasklist = Nag::getDefaultTasklist(Horde_Perms::READ);
}
- if (!array_key_exists($tasklist,
- Nag::listTasklists(false, Horde_Perms::READ))) {
- return PEAR::raiseError(_("Permission Denied"));
- }
+ if (!array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::READ))) {
+ throw new Horde_Exception_PermissionDenied(_("Permission Denied"));
+ }
- return $GLOBALS['injector']->getInstance('Horde_History')->getActionTimestamp('nag:' . $tasklist . ':' . $uid, $action);
+ return $GLOBALS['injector']
+ ->getInstance('Horde_History')
+ ->getActionTimestamp('nag:' . $tasklist . ':' . $uid, $action);
}
/**
* tasklist will be used.
*
* @return string The new UID on one import, an array of UIDs on multiple imports,
- * or PEAR_Error on failure.
*/
public function import($content, $contentType, $tasklist = null)
{
}
if (!array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::EDIT))) {
- return PEAR::raiseError(_("Permission Denied"));
+ throw new Horde_Exception_PermissionDenied(_("Permission Denied"));
}
/* Create a Nag_Driver instance. */
$iCal = new Horde_Icalendar();
if (!($content instanceof Horde_Icalendar_Vtodo)) {
if (!$iCal->parsevCalendar($content)) {
- return PEAR::raiseError(_("There was an error importing the iCalendar data."));
+ throw new Nag_Exception(_("There was an error importing the iCalendar data."));
}
} else {
$iCal->addComponent($content);
$components = $iCal->getComponents();
if (count($components) == 0) {
- return PEAR::raiseError(_("No iCalendar data was found."));
+ throw new Nag_Exception(_("No iCalendar data was found."));
}
$ids = array();
if ($content instanceof Horde_Icalendar_Vtodo) {
$task = new Nag_Task();
$task->fromiCalendar($content);
- if (isset($task->uid) &&
- !is_a(($existing = $storage->getByUID($task->uid)), 'PEAR_Error')) {
- $taskId = $existing->id;
- $result = $storage->modify(
- $taskId,
- isset($task->name) ? $task->name : $existing->name,
- isset($task->desc) ? $task->desc : $existing->desc,
- isset($task->start) ? $task->start : $existing->start,
- isset($task->due) ? $task->due : $existing->due,
- isset($task->priority) ? $task->priority : $existing->priority,
- isset($task->estimate) ? $task->estimate : 0,
- isset($task->completed) ? (int)$task->completed : $existing->completed,
- isset($task->category) ? $task->category : $existing->category,
- isset($task->alarm) ? $task->alarm : $existing->alarm,
- isset($task->parent_id) ? $task->parent_id : $existing->parent_id,
- isset($task->private) ? $task->private : $existing->private,
- isset($task->owner) ? $task->owner : $existing->owner,
- isset($task->assignee) ? $task->assignee : $existing->assignee);
-
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- }
- $ids[] = $task->uid;
- } else {
- $newTask = $storage->add(
- isset($task->name) ? $task->name : '',
- isset($task->desc) ? $task->desc : '',
- isset($task->start) ? $task->start : 0,
- isset($task->due) ? $task->due : 0,
- isset($task->priority) ? $task->priority : 3,
- isset($task->estimate) ? $task->estimate : 0,
- !empty($task->completed),
- isset($task->category) ? $task->category : '',
- isset($task->alarm) ? $task->alarm : 0,
- isset($task->methods) ? $task->methods : null,
- isset($task->uid) ? $task->uid : null,
- isset($task->parent_id) ? $task->parent_id : '',
- !empty($task->private),
- $GLOBALS['registry']->getAuth(),
- isset($task->assignee) ? $task->assignee : null);
- if (is_a($newTask, 'PEAR_Error')) {
- return $newTask;
- }
- // use UID rather than ID
- $ids[] = $newTask[1];
- }
+ if (isset($task->uid)) {
+ $existing = $storage->getByUID($task->uid);
+ $taskId = $existing->id;
+ $result = $storage->modify(
+ $taskId,
+ isset($task->name) ? $task->name : $existing->name,
+ isset($task->desc) ? $task->desc : $existing->desc,
+ isset($task->start) ? $task->start : $existing->start,
+ isset($task->due) ? $task->due : $existing->due,
+ isset($task->priority) ? $task->priority : $existing->priority,
+ isset($task->estimate) ? $task->estimate : 0,
+ isset($task->completed) ? (int)$task->completed : $existing->completed,
+ isset($task->category) ? $task->category : $existing->category,
+ isset($task->alarm) ? $task->alarm : $existing->alarm,
+ isset($task->parent_id) ? $task->parent_id : $existing->parent_id,
+ isset($task->private) ? $task->private : $existing->private,
+ isset($task->owner) ? $task->owner : $existing->owner,
+ isset($task->assignee) ? $task->assignee : $existing->assignee
+ );
+ $ids[] = $task->uid;
+ } else {
+ $newTask = $storage->add(
+ isset($task->name) ? $task->name : '',
+ isset($task->desc) ? $task->desc : '',
+ isset($task->start) ? $task->start : 0,
+ isset($task->due) ? $task->due : 0,
+ isset($task->priority) ? $task->priority : 3,
+ isset($task->estimate) ? $task->estimate : 0,
+ !empty($task->completed),
+ isset($task->category) ? $task->category : '',
+ isset($task->alarm) ? $task->alarm : 0,
+ isset($task->methods) ? $task->methods : null,
+ isset($task->uid) ? $task->uid : null,
+ isset($task->parent_id) ? $task->parent_id : '',
+ !empty($task->private),
+ $GLOBALS['registry']->getAuth(),
+ isset($task->assignee) ? $task->assignee : null
+ );
+ // use UID rather than ID
+ $ids[] = $newTask[1];
+ }
}
}
if (count($ids) == 0) {
- return PEAR::raiseError(_("No iCalendar data was found."));
+ throw Nag_Exception(_("No iCalendar data was found."));
} else if (count($ids) == 1) {
return $ids[0];
}
$task = new Nag_Task();
$task->fromASTask($content);
$results = $storage->add(
- isset($task->name) ? $task->name : '',
- isset($task->desc) ? $task->desc : '',
- isset($task->start) ? $task->start : 0,
- isset($task->due) ? $task->due : 0,
- isset($task->priority) ? $task->priority : 3,
- isset($task->estimate) ? $task->estimate : 0,
- !empty($task->completed),
- isset($task->category) ? $task->category : '',
- isset($task->alarm) ? $task->alarm : 0,
- isset($task->methods) ? $task->methods : null,
- isset($task->uid) ? $task->uid : null,
- isset($task->parent_id) ? $task->parent_id : '',
- !empty($task->private),
- $GLOBALS['registry']->getAuth(),
- isset($task->assignee) ? $task->assignee : null);
+ isset($task->name) ? $task->name : '',
+ isset($task->desc) ? $task->desc : '',
+ isset($task->start) ? $task->start : 0,
+ isset($task->due) ? $task->due : 0,
+ isset($task->priority) ? $task->priority : 3,
+ isset($task->estimate) ? $task->estimate : 0,
+ !empty($task->completed),
+ isset($task->category) ? $task->category : '',
+ isset($task->alarm) ? $task->alarm : 0,
+ isset($task->methods) ? $task->methods : null,
+ isset($task->uid) ? $task->uid : null,
+ isset($task->parent_id) ? $task->parent_id : '',
+ !empty($task->private),
+ $GLOBALS['registry']->getAuth(),
+ isset($task->assignee) ? $task->assignee : null
+ );
/* array index 0 is id, 1 is uid */
return $results[1];
}
- return PEAR::raiseError(sprintf(_("Unsupported Content-Type: %s"), $contentType));
+ throw new Nag_Exception(sprintf(_("Unsupported Content-Type: %s"), $contentType));
}
/**
* Adds a task.
*
* @param array $task A hash with overwriting task information.
+ *
+ * @throws Horde_Exception_PermissionDenied
*/
- public function addTask($task)
+ public function addTask(array $task)
{
if (!$GLOBALS['registry']->isAdmin() &&
!array_key_exists($task['tasklist'],
Nag::listTasklists(false, Horde_Perms::EDIT))) {
- return PEAR::raiseError(_("Permission Denied"));
+ throw new Horde_Exception_PermissionDenied(_("Permission Denied"));
}
$storage = Nag_Driver::singleton($task['tasklist']);
-
return $storage->add(
isset($task['name']) ? $task['name'] : '',
isset($task['desc']) ? $task['desc'] : '',
isset($task['parent_id']) ? $task['parent_id'] : '',
!empty($task['private']),
$GLOBALS['registry']->getAuth(),
- isset($task['assignee']) ? $task['assignee'] : null);
+ isset($task['assignee']) ? $task['assignee'] : null
+ );
}
/**
* tasklist will be used.
*
* @return array The UIDs of all tasks that were added.
+ * @throws Horde_Exception_PermissionDenied
*/
public function quickAdd($text, $tasklist = null)
{
$tasklist = Nag::getDefaultTasklist(Horde_Perms::EDIT);
}
if (!array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::EDIT))) {
- return PEAR::raiseError(_("Permission Denied"));
+ throw new Horde_Exception_PermissionDenied(_("Permission Denied"));
}
return Nag::createTasksFromText($text, $tasklist);
*/
public function toggleCompletion($task_id, $tasklist_id)
{
- if (!array_key_exists($tasklist_id,
- Nag::listTasklists(false, Horde_Perms::EDIT))) {
- return PEAR::raiseError(_("Permission Denied"));
- }
+ if (!array_key_exists($tasklist_id, Nag::listTasklists(false, Horde_Perms::EDIT))) {
+ throw new Horde_Exception_PermissionDenied(_("Permission Denied"));
+ }
try {
$share = $GLOBALS['nag_shares']->getShare($tasklist_id);
throw new Nag_Exception($e);
}
$task = Nag::getTask($tasklist_id, $task_id);
- if ($task instanceof PEAR_Error) {
- return $task;
- }
-
$task->completed = !$task->completed;
if ($task->completed) {
$task->completed_date = time();
{
$storage = Nag_Driver::singleton();
$task = $storage->getByUID($uid);
- if (is_a($task, 'PEAR_Error')) {
- return $task;
- }
-
- if (!array_key_exists($task->tasklist,
- Nag::listTasklists(false, Horde_Perms::READ))) {
- return PEAR::raiseError(_("Permission Denied"));
+ if (!array_key_exists($task->tasklist, Nag::listTasklists(false, Horde_Perms::READ))) {
+ throw new Horde_Exception_PermimssionDenied(_("Permission Denied"));
}
$version = '2.0';
case 'activesync':
return $task->toASTask();
default:
- return PEAR::raiseError(sprintf(_("Unsupported Content-Type: %s"), $contentType));
+ throw new Nag_Exception(sprintf(_("Unsupported Content-Type: %s"), $contentType));
}
}
*/
public function getTask($tasklist, $id)
{
- if (!array_key_exists($tasklist,
- Nag::listTasklists(false, Horde_Perms::READ))) {
- return PEAR::raiseError(_("Permission Denied"));
+ if (!array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::READ))) {
+ throw new Horde_Exception_PermimssionDenied(_("Permission Denied"));
}
$storage = Nag_Driver::singleton($tasklist);
*/
public function exportTasklist($tasklist, $contentType)
{
- if (!array_key_exists($tasklist,
- Nag::listTasklists(false, Horde_Perms::READ))) {
- return PEAR::raiseError(_("Permission Denied"));
- }
+ if (!array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::READ))) {
+ throw new Horde_Exception_PermimssionDenied(_("Permission Denied"));
+ }
$tasks = Nag::listTasks(null, null, null, array($tasklist), 1);
return $iCal->exportvCalendar();
}
- return PEAR::raiseError(sprintf(_("Unsupported Content-Type: %s"), $contentType));
+ throw new Nag_Exception(sprintf(_("Unsupported Content-Type: %s"), $contentType));
}
*/
public function delete($uid)
{
- // Handle an arrray of UIDs for convenience of deleting multiple tasks at
- // once.
+ // Handle an arrray of UIDs for convenience
if (is_array($uid)) {
foreach ($uid as $g) {
$result = $this->delete($g);
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- }
}
return true;
$storage = Nag_Driver::singleton();
$task = $storage->getByUID($uid);
- if (is_a($task, 'PEAR_Error')) {
- return $task;
- }
if (!$GLOBALS['registry']->isAdmin() &&
- !array_key_exists($task->tasklist,
- Nag::listTasklists(false, Horde_Perms::DELETE))) {
- return PEAR::raiseError(_("Permission Denied"));
+ !array_key_exists($task->tasklist, Nag::listTasklists(false, Horde_Perms::DELETE))) {
+
+ throw new Horde_Exception_PermimssionDenied(_("Permission Denied"));
}
return $storage->delete($task->id);
public function deleteTask($tasklist, $id)
{
if (!$GLOBALS['registry']->isAdmin() &&
- !array_key_exists($tasklist,
- Nag::listTasklists(false, Horde_Perms::DELETE))) {
- return PEAR::raiseError(_("Permission Denied"));
+ !array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::DELETE))) {
+
+ throw new Horde_Exception_PermimssionDenied(_("Permission Denied"));
}
$storage = Nag_Driver::singleton($tasklist);
{
$storage = Nag_Driver::singleton();
$existing = $storage->getByUID($uid);
- if (is_a($existing, 'PEAR_Error')) {
- return $existing;
- }
$taskId = $existing->id;
-
if (!array_key_exists($existing->tasklist, Nag::listTasklists(false, Horde_Perms::EDIT))) {
- return PEAR::raiseError(_("Permission Denied"));
+ throw new Horde_Exception_PermimssionDenied(_("Permission Denied"));
}
switch ($contentType) {
if (!($content instanceof Horde_Icalendar_Vtodo)) {
$iCal = new Horde_Icalendar();
if (!$iCal->parsevCalendar($content)) {
- return PEAR::raiseError(_("There was an error importing the iCalendar data."));
+ throw new Nag_Exception(_("There was an error importing the iCalendar data."));
}
$components = $iCal->getComponents();
foreach ($components as $content) {
if ($content instanceof Horde_Icalendar_Vtodo) {
if ($component !== null) {
- return PEAR::raiseError(_("Multiple iCalendar components found; only one vTodo is supported."));
+ throw new Nag_Exception(_("Multiple iCalendar components found; only one vTodo is supported."));
}
$component = $content;
}
}
if ($component === null) {
- return PEAR::raiseError(_("No iCalendar data was found."));
+ throw new Nag_Exception(_("No iCalendar data was found."));
}
}
isset($task->parent_id) ? $task->parent_id : $existing->parent_id,
isset($task->private) ? $task->private : $existing->private,
isset($task->owner) ? $task->owner : $existing->owner,
- isset($task->assignee) ? $task->assignee : $existing->assignee);
-
+ isset($task->assignee) ? $task->assignee : $existing->assignee
+ );
break;
case 'activesync':
isset($task->parent_id) ? $task->parent_id : $existing->parent_id,
isset($task->private) ? $task->private : $existing->private,
isset($task->owner) ? $task->owner : $existing->owner,
- isset($task->assignee) ? $task->assignee : $existing->assignee);
+ isset($task->assignee) ? $task->assignee : $existing->assignee
+ );
break;
default:
- return PEAR::raiseError(sprintf(_("Unsupported Content-Type: %s"), $contentType));
+ throw new Nag_Exception(sprintf(_("Unsupported Content-Type: %s"), $contentType));
}
return $result;
public function updateTask($tasklist, $id, $task)
{
if (!$GLOBALS['registry']->isAdmin() &&
- !array_key_exists($tasklist,
- Nag::listTasklists(false, Horde_Perms::EDIT))) {
- return PEAR::raiseError(_("Permission Denied"));
+ !array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::EDIT))) {
+
+ throw new Horde_Exception_PermimssionDenied(_("Permission Denied"));
}
$storage = Nag_Driver::singleton($tasklist);
$existing = $storage->get($id);
- if (is_a($existing, 'PEAR_Error')) {
- return $existing;
- }
return $storage->modify(
$id,
isset($task['owner']) ? $task['owner'] : $existing->owner,
isset($task['assignee']) ? $task['assignee'] : $existing->assignee,
$task['completed'] && !$existing->completed ? date() : $existing->completed_date,
- isset($task['tasklist']) ? $task['tasklist'] : $existing->tasklist);
+ isset($task['tasklist']) ? $task['tasklist'] : $existing->tasklist
+ );
}
/**
* @param array $timeobject A time object hash.
* @throws Nag_Exception
*/
- public function saveTimeObject($timeobject)
+ public function saveTimeObject(array $timeobject)
{
$storage = Nag_Driver::singleton();
$existing = $storage->get($timeobject['id']);
- if (is_a($existing, 'PEAR_Error')) {
- throw new Nag_Exception($existing->getMessage());
- }
- if (!array_key_exists($existing->tasklist,
- Nag::listTasklists(false, Horde_Perms::EDIT))) {
- throw new Horde_Exception_PermissionDenied(_("Permission Denied"));
+ if (!array_key_exists($existing->tasklist, Nag::listTasklists(false, Horde_Perms::EDIT))) {
+ throw new Horde_Exception_PermimssionDenied(_("Permission Denied"));
}
$storage = Nag_Driver::singleton($existing->tasklist);
-
if (isset($timeobject['start'])) {
$due = new Horde_Date($timeobject['start']);
$due = $due->timestamp();
$existing->owner,
$existing->assignee,
$existing->completed_date,
- $existing->tasklist);
+ $existing->tasklist
+ );
}
/**
{
if ((empty($user) || $user != $GLOBALS['registry']->getAuth()) &&
!$GLOBALS['registry']->isAdmin()) {
- return PEAR::raiseError(_("Permission Denied"));
+
+ throw new Horde_Exception_PermimssionDenied(_("Permission Denied"));
}
$storage = Nag_Driver::singleton();
$group = $GLOBALS['injector']->getInstance('Horde_Group');
$alarm_list = array();
- $tasklists = is_null($user) ? array_keys($GLOBALS['nag_shares']->listAllShares()) : $GLOBALS['display_tasklists'];
+ $tasklists = is_null($user) ?
+ array_keys($GLOBALS['nag_shares']->listAllShares()) :
+ $GLOBALS['display_tasklists'];
$alarms = Nag::listAlarms($time, $tasklists);
- if ($alarms instanceof PEAR_Error) {
- return $alarms;
- }
-
foreach ($alarms as $alarm) {
try {
$share = $GLOBALS['nag_shares']->getShare($alarm->tasklist);
/* Get the list of all tasks */
$tasks = Nag::listTasks(null, null, null, $user, 1);
- if ($tasks instanceof PEAR_Error) {
- Horde::logMessage($tasks, 'ERR');
- throw new Nag_Exception(sprintf(_("There was an error removing tasks for %s. Details have been logged."), $user));
- } else {
- $uids = array();
- $tasks->reset();
- while ($task = $tasks->each()) {
- $uids[] = $task->uid;
- }
+ $uids = array();
+ $tasks->reset();
+ while ($task = $tasks->each()) {
+ $uids[] = $task->uid;
+ }
- /* ... and delete them. */
- foreach ($uids as $uid) {
- $this->delete($uid);
- }
+ /* ... and delete them. */
+ foreach ($uids as $uid) {
+ $this->delete($uid);
}
+
/* ...and finally, delete the actual share */
if (!empty($share)) {
try {
// Get any alarms in the next hour.
$now = time();
$alarms = Nag::listAlarms($now);
- if ($alarms instanceof PEAR_Error) {
- return;
- }
-
$alarmCount = 0;
$horde_alarm = $GLOBALS['injector']->getInstance('Horde_Alarm');
-
foreach ($alarms as $taskId => $task) {
if ($horde_alarm->isSnoozed($task->uid, $registry->getAuth())) {
continue;
if (!empty($this->_params['show_alarms'])) {
$messages = array();
- $alarmList = Nag::listAlarms($now);
- if (is_a($alarmList, 'PEAR_Error')) {
- return '<em>' . htmlspecialchars($alarmList->getMessage())
+ try {
+ $alarmList = Nag::listAlarms($now);
+ } catch (Nag_Exception $e) {
+ return '<em>' . htmlspecialchars($e->getMessage())
. '</em>';
}
foreach ($alarmList as $task) {
}
$i = 0;
- $tasks = Nag::listTasks(
- null, null, null,
- isset($this->_params['show_tasklists'])
- ? $this->_params['show_tasklists']
- : array_keys(Nag::listTasklists(false, Horde_Perms::READ)),
- empty($this->_params['show_completed']) ? 0 : 1);
- if (is_a($tasks, 'PEAR_Error')) {
- return '<em>' . htmlspecialchars($tasks->getMessage()) . '</em>';
+ try {
+ $tasks = Nag::listTasks(
+ null, null, null,
+ isset($this->_params['show_tasklists']) ?
+ $this->_params['show_tasklists'] :
+ array_keys(Nag::listTasklists(false, Horde_Perms::READ)),
+ empty($this->_params['show_completed']) ?
+ 0 :
+ 1
+ );
+ } catch (Nag_Exception $e) {
+ return '<em>' . htmlspecialchars($e->getMessage()) . '</em>';
}
$tasks->reset();
*
* @var Nag_Task
*/
- var $tasks;
+ public $tasks;
/**
* String containing the current tasklist.
*
* @var string
*/
- var $_tasklist = '';
+ protected $_tasklist = '';
/**
* Hash containing connection parameters.
*
* @var array
*/
- var $_params = array();
+ protected $_params = array();
/**
* An error message to throw when something is wrong.
*
* @var string
*/
- var $_errormsg;
+ protected $_errormsg;
/**
* Constructor - just store the $params in our newly-created
* object. All other work is done by initialize().
*
- * @param array $params Any parameters needed for this driver.
+ * @param array $params Any parameters needed for this driver.
+ * @param string $errormsg Custom error message
+ *
+ * @return Nag_Driver
*/
- function Nag_Driver($params = array(), $errormsg = null)
+ public function __construct(array $params = array(), $errormsg = null)
{
$this->tasks = new Nag_Task();
$this->_params = $params;
*
* @return array An array of tasks that have alarms that match.
*/
- function listAlarms($date)
+ public function listAlarms($date)
{
if (!$this->tasks->count()) {
$result = $this->retrieve(0);
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- }
}
$alarms = array();
$this->tasks->reset();
* @return mixed The newly created concrete Nag_Driver instance, or
* false on an error.
*/
- function factory($tasklist = '', $driver = null, $params = null)
+ static public function factory($tasklist = '', $driver = null, $params = null)
{
if (is_null($driver)) {
$driver = $GLOBALS['conf']['storage']['driver'];
}
-
$driver = ucfirst(basename($driver));
-
if (is_null($params)) {
$params = Horde::getDriverConfig('storage', $driver);
}
-
- require_once dirname(__FILE__) . '/Driver/' . $driver . '.php';
$class = 'Nag_Driver_' . $driver;
if (class_exists($class)) {
- $nag = new $class($tasklist, $params);
- $result = $nag->initialize();
- if (is_a($result, 'PEAR_Error')) {
- $nag = new Nag_Driver($params, sprintf(_("The Tasks backend is not currently available: %s"), $result->getMessage()));
+ try {
+ $nag = new $class($tasklist, $params);
+ } catch (Nag_Exception $e) {
+ $nag = new Nag_Driver($params, sprintf(_("The Tasks backend is not currently available: %s"), $e->getMessage()));
}
} else {
$nag = new Nag_Driver($params, sprintf(_("Unable to load the definition of %s."), $class));
* @return mixed The created concrete Nag_Driver instance, or false
* on error.
*/
- function &singleton($tasklist = '', $driver = null, $params = null)
+ static public function &singleton($tasklist = '', $driver = null, array $params = null)
{
static $instances = array();
*
* @return array array(ID,UID) of new task
*/
- function add($name, $desc, $start = 0, $due = 0, $priority = 0,
+ public function add($name, $desc, $start = 0, $due = 0, $priority = 0,
$estimate = 0.0, $completed = 0, $category = '', $alarm = 0,
- $methods = null, $uid = null, $parent = '', $private = false,
+ array $methods = null, $uid = null, $parent = '', $private = false,
$owner = null, $assignee = null)
{
if (is_null($uid)) {
$taskId = $this->_add($name, $desc, $start, $due, $priority, $estimate,
$completed, $category, $alarm, $methods, $uid,
$parent, $private, $owner, $assignee);
- if (is_a($taskId, 'PEAR_Error')) {
- return $taskId;
- }
+
$task = $this->get($taskId);
$task->process();
/* Notify users about the new event. */
$result = Nag::sendNotification('add', $task);
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, 'ERR');
- }
/* Add an alarm if necessary. */
if (!empty($alarm) &&
* @param string $assignee The assignee of the event.
* @param integer $completed_date The task's completion date.
* @param string $tasklist The new tasklist.
+ *
+ * @throws Nag_Exception
*/
- function modify($taskId, $name, $desc, $start = 0, $due = 0, $priority = 0,
+ public function modify($taskId, $name, $desc, $start = 0, $due = 0, $priority = 0,
$estimate = 0.0, $completed = 0, $category = '',
- $alarm = 0, $methods = null, $parent = '', $private = false,
+ $alarm = 0, array $methods = null, $parent = '', $private = false,
$owner = null, $assignee = null, $completed_date = null,
$tasklist = null)
{
/* Retrieve unmodified task. */
$task = $this->get($taskId);
- if (is_a($task, 'PEAR_Error')) {
- return $task;
- }
/* Avoid circular reference. */
if ($parent == $taskId) {
$parent = '';
}
-
$modify = $this->_modify($taskId, $name, $desc, $start, $due,
$priority, $estimate, $completed, $category,
$alarm, $methods, $parent, $private, $owner,
$assignee, $completed_date);
- if (is_a($modify, 'PEAR_Error')) {
- return $modify;
- }
$new_task = $this->get($task->id);
$log_tasklist = $this->_tasklist;
}
$moved = $this->_move($task->id, $tasklist);
- if ($moved instanceof PEAR_Error) {
- return $moved;
- }
$new_storage = Nag_Driver::singleton($tasklist);
$new_task = $new_storage->get($task->id);
}
/* Notify users about the changed event. */
- $result = Nag::sendNotification('edit', $new_task, $task);
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, 'ERR');
+ try {
+ $result = Nag::sendNotification('edit', $new_task, $task);
+ } catch (Nag_Exception $e) {
+ Horde::logMessage($e, 'ERR');
}
return true;
*
* @param string $taskId The task to delete.
*/
- function delete($taskId)
+ public function delete($taskId)
{
/* Get the task's details for use later. */
$task = $this->get($taskId);
- if ($task instanceof PEAR_Error) {
- return $task;
- }
-
$delete = $this->_delete($taskId);
- if (is_a($delete, 'PEAR_Error')) {
- return $delete;
- }
/* Log the deletion of this item in the history log. */
if (!empty($task->uid)) {
}
/* Notify users about the deleted event. */
- $result = Nag::sendNotification('delete', $task);
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, 'ERR');
+ try {
+ $result = Nag::sendNotification('delete', $task);
+ } catch (Nag_Exception $e) {
+ Horde::logMessage($e, 'ERR');
}
/* Delete alarm if necessary. */
if (!empty($task->alarm)) {
$GLOBALS['injector']->getInstance('Horde_Alarm')->delete($task->uid);
}
-
- return true;
}
/**
* Retrieves tasks from the database.
*
- * @return mixed True on success, PEAR_Error on failure.
+ * @throws Nag_Exception
*/
- function retrieve()
+ public function retrieve()
{
- return PEAR::raiseError($this->_errormsg);
+ throw new Nag_Exception($this->_errormsg);
}
/**
* @param string $parentId The parent id for the sub-tasks to retrieve.
*
* @return array List of sub-tasks.
+ * @throws Nag_Exception
*/
- function getChildren($parentId)
+ public function getChildren($parentId)
{
- return PEAR::raiseError($this->_errormsg);
+ throw new Nag_Exception($this->_errormsg);
}
/**
* @param string $taskId The id of the task to retrieve.
*
* @return Nag_Task A Nag_Task object.
+ * @throws Nag_Exception
*/
- function get($taskId)
+ public function get($taskId)
{
- return PEAR::raiseError($this->_errormsg);
+ throw new Nag_Exception($this->_errormsg);
}
/**
* @param string $uid The UID of the task to retrieve.
*
* @return Nag_Task A Nag_Task object.
+ * @throws Nag_Exception
*/
- function getByUID($uid)
+ public function getByUID($uid)
{
- return PEAR::raiseError($this->_errormsg);
+ throw new Nag_Exception($this->_errormsg);
}
}
* @author Jon Parise <jon@horde.org>
* @package Nag
*/
-class Nag_Driver_Sql extends Nag_Driver {
-
+class Nag_Driver_Sql extends Nag_Driver
+{
/**
* Handle for the current database connection.
*
* @var Horde_Db_Adapter
*/
- var $_db;
+ protected $_db;
/**
* Constructs a new SQL storage object.
{
$this->_tasklist = $tasklist;
$this->_params = $params;
+ if (!isset($this->_params['table'])) {
+ $this->_params['table'] = 'nag_tasks';
+ }
+
+ // @TODO: Use a bound factory for Nag_Driver and inject this from there.
+ $this->_db = $GLOBALS['injector']
+ ->getInstance('Horde_Core_Factory_Db')
+ ->create('nag', 'storage');
}
/**
* @param string $taskId The id of the task to retrieve.
*
* @return Nag_Task A Nag_Task object.
+ * @throws Horde_Exception_NotFound
+ * @throws Nag_Exception
*/
- function get($taskId)
+ public function get($taskId)
{
- /* Build the SQL query. */
$query = sprintf('SELECT * FROM %s WHERE task_id = ?',
$this->_params['table']);
$values = array($taskId);
-
try {
$row = $this->_db->selectOne($query, $values);
} catch (Horde_Db_Exception $e) {
- return PEAR::raiseError($e->getMessage());
+ throw new Nag_Exception($e);
}
-
if (!$row) {
- return PEAR::raiseError(_("Task not found"));
+ throw new Horde_Exception_NotFound("Task not found");
}
- /* Decode and return the task. */
+ // Decode and return the task.
return new Nag_Task($this->_buildTask($row));
}
* @param string $uid The UID of the task to retrieve.
*
* @return Nag_Task A Nag_Task object.
+ * @throws Horde_Exception_NotFound
+ * @throws Nag_Exception
*/
- function getByUID($uid)
+ public function getByUID($uid)
{
- /* Build the SQL query. */
$query = sprintf('SELECT * FROM %s WHERE task_uid = ?',
$this->_params['table']);
$values = array($uid);
-
try {
$row = $this->_db->selectOne($query, $values);
} catch (Horde_Db_Exception $e) {
- return PEAR::raiseError($e->getMessage());
+ throw new Nag_Exception($e->getMessage());
}
-
if (!$row) {
- return PEAR::raiseError(_("Task UID not found"));
+ throw new Horde_Exception_NotFound(_("Task UID not found"));
}
-
- /* Decode and return the task. */
$this->_tasklist = $row['task_owner'];
+ // Decode and return the task.
return new Nag_Task($this->_buildTask($row));
}
* @param string $assignee The assignee of the event.
*
* @return string The Nag ID of the new task.
+ * @throws Nag_Exception
*/
- function _add($name, $desc, $start = 0, $due = 0, $priority = 0,
+ protected function _add($name, $desc, $start = 0, $due = 0, $priority = 0,
$estimate = 0.0, $completed = 0, $category = '', $alarm = 0,
- $methods = null, $uid = null, $parent = '', $private = false,
+ array $methods = null, $uid = null, $parent = '', $private = false,
$owner = null, $assignee = null)
{
$taskId = strval(new Horde_Support_Randomid());
try {
$this->_db->insert($query, $values);
} catch (Horde_Db_Exception $e) {
- return PEAR::raiseError($e->getMessage());
+ throw new Nag_Exception($e->getMessage());
}
return $taskId;
* @param string $owner The owner of the event.
* @param string $assignee The assignee of the event.
* @param integer $completed_date The task's completion date.
+ *
+ * @throws Nag_Exception
*/
- function _modify($taskId, $name, $desc, $start = 0, $due = 0,
+ protected function _modify($taskId, $name, $desc, $start = 0, $due = 0,
$priority = 0, $estimate = 0.0, $completed = 0,
- $category = '', $alarm = 0, $methods = null,
+ $category = '', $alarm = 0, array $methods = null,
$parent = '', $private = false, $owner = null,
$assignee = null, $completed_date = null)
{
try {
$this->_db->update($query, $values);
} catch (Horde_Db_Exception $e) {
- return PEAR::raiseError($e->getMessage());
+ throw new Nag_Exception($e->getMessage());
}
return true;
*
* @param string $taskId The task to move.
* @param string $newTasklist The new tasklist.
+ *
+ * @throws Nag_Exception
*/
- function _move($taskId, $newTasklist)
+ protected function _move($taskId, $newTasklist)
{
$query = sprintf('UPDATE %s SET task_owner = ? WHERE task_owner = ? AND task_id = ?',
$this->_params['table']);
try {
$this->_db->update($query, $values);
} catch (Horde_Db_Exception $e) {
- return PEAR::raiseError($e->getMessage());
+ throw new Nag_Exception($e->getMessage());
}
-
- return true;
}
/**
* Deletes a task from the backend.
*
* @param string $taskId The task to delete.
+ *
+ * @throws Nag_Exception
*/
- function _delete($taskId)
+ protected function _delete($taskId)
{
/* Get the task's details for use later. */
$task = $this->get($taskId);
try {
$this->_db->delete($query, $values);
} catch (Horde_Db_Exception $e) {
- return PEAR::raiseError($e->getMessage());
+ throw Nag_Exception($e->getMessage());
}
-
- return true;
}
/**
* Deletes all tasks from the backend.
*
- * @return mixed True on success, PEAR_Error on failure.
+ * @throws Nag_Exception
*/
- function deleteAll()
+ public function deleteAll()
{
$query = sprintf('DELETE FROM %s WHERE task_owner = ?',
$this->_params['table']);
try {
$this->_db->delete($query, $values);
} catch (Horde_Db_Exception $e) {
- return PEAR::raiseError($e->getMessage());
+ throw new Nag_Exception($e->getMessage());
}
-
- return true;
}
/**
* 0 = incomplete tasks, 2 = complete tasks,
* 3 = future tasks, 4 = future and incomplete
* tasks).
- *
- * @return mixed True on success, PEAR_Error on failure.
+ * @throws Nag_Exception
*/
function retrieve($completed = Nag::VIEW_ALL)
{
try {
$result = $this->_db->selectAll($query, $values);
} catch (Horde_Db_Exception $e) {
- return PEAR::raiseError($e->getMessage());
+ throw new Nag_Exception($e->getMessage());
}
/* Store the retrieved values in a fresh task list. */
$this->tasks->add($dict[$key]);
}
}
-
- return true;
}
/**
* @param string $parentId The parent id for the sub-tasks to retrieve.
*
* @return array List of sub-tasks.
+ * @throws Nag_Exception
*/
- function getChildren($parentId)
+ public function getChildren($parentId)
{
- /* Build the SQL query. */
+ // Build the SQL query.
$query = sprintf('SELECT * FROM %s WHERE task_owner = ? AND task_parent = ?',
$this->_params['table']);
$values = array($this->_tasklist, $parentId);
try {
$result = $this->_db->selectAll($query, $values);
} catch (Horde_Db_Exception $e) {
- return PEAR::raiseError($e->getMessage());
+ throw new Nag_Exception($e->getMessage());
}
- /* Store the retrieved values in a fresh task list. */
+ // Store the retrieved values in a fresh task list.
$tasks = array();
foreach ($result as $row) {
$task = new Nag_Task($this->_buildTask($row));
$children = $this->getChildren($task->id);
- if ($children instanceof PEAR_Error) {
- return $children;
- }
$task->mergeChildren($children);
$tasks[] = $task;
}
* @param integer $date The unix epoch time to check for alarms.
*
* @return array An array of tasks that have alarms that match.
+ * @throws Nag_Exception
*/
- function listAlarms($date)
+ public function listAlarms($date)
{
$q = 'SELECT * FROM ' . $this->_params['table'] .
' WHERE task_owner = ?' .
try {
$result = $this->_db->selectAll($q, $values);
} catch (Horde_Db_Exception $e) {
- return PEAR::raiseError($e->getMessage());
+ throw new Nag_Exception($e->getMessage());
}
$tasks = array();
/**
*/
- function _buildTask($row)
+ protected function _buildTask($row)
{
- /* Make sure tasks always have a UID. */
+ // Make sure tasks always have a UID.
if (empty($row['task_uid'])) {
$row['task_uid'] = strval(new Horde_Support_Guid());
);
}
- /**
- * Attempts to open a connection to the SQL server.
- *
- * @return boolean True on success, PEAR_Error on failure.
- */
- function initialize()
- {
- if (!isset($this->_params['table'])) {
- $this->_params['table'] = 'nag_tasks';
- }
-
- $this->_db = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Db')->create('nag', 'storage');
-
- return true;
- }
-
}
--- /dev/null
+<?php
+/**
+ * Horde_Form for creating task lists.
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @package Nag
+ */
+/**
+ * The Nag_CreateTaskListForm class provides the form for
+ * creating a task list.
+ *
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @package Nag
+ */
+class Nag_Form_CreateTaskList extends Horde_Form
+{
+ public function __construct($vars)
+ {
+ parent::__construct($vars, _("Create Task List"));
+
+ $this->addVariable(_("Name"), 'name', 'text', true);
+ $this->addVariable(_("Color"), 'color', 'colorpicker', false);
+ $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60));
+ if ($GLOBALS['registry']->isAdmin()) {
+ $this->addVariable(
+ _("System Task List"), 'system', 'boolean', false, false,
+ _("System task lists don't have an owner. Only administrators can change the task list settings and permissions."));
+ }
+
+ $this->setButtons(array(_("Create")));
+ }
+
+ public function execute()
+ {
+ $info = array();
+ foreach (array('name', 'color', 'description', 'system') as $key) {
+ $info[$key] = $this->_vars->get($key);
+ }
+ return Nag::addTasklist($info);
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * Horde_Form for deleting task lists.
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @package Nag
+ */
+/**
+ * The Nag_DeleteTaskListForm class provides the form for
+ * deleting a task list.
+ *
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @package Nag
+ */
+class Nag_Form_DeleteTaskList extends Horde_Form
+{
+ /**
+ * Task list being deleted.
+ *
+ * @var Horde_Share_Object
+ */
+ protected $_tasklist;
+
+ /**
+ *
+ * @param array $vars
+ * @param Horde_Share_Object $tasklist
+ */
+ public function __construct($vars, Horde_Share_Object $tasklist)
+ {
+ $this->_tasklist = $tasklist;
+ parent::__construct($vars, sprintf(_("Delete %s"), $tasklist->get('name')));
+ $this->addHidden('', 't', 'text', true);
+ $this->addVariable(
+ sprintf(_("Really delete the task list \"%s\"? This cannot be undone and all data on this task list will be permanently removed."),
+ $this->_tasklist->get('name')), 'desc', 'description', false
+ );
+ $this->setButtons(array(_("Delete"), _("Cancel")));
+ }
+
+ public function execute()
+ {
+ // If cancel was clicked, return false.
+ if ($this->_vars->get('submitbutton') == _("Cancel")) {
+ return false;
+ }
+
+ return Nag::deleteTasklist($this->_tasklist);
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * Horde_Form for editing task lists.
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @package Nag
+ */
+/**
+ * The Nag_EditTaskListForm class provides the form for
+ * editing a task list.
+ *
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @package Nag
+ */
+class Nag_Form_EditTaskList extends Horde_Form
+{
+ /**
+ * Task list being edited
+ *
+ *
+ * @var Horde_Share_Object
+ */
+ protected $_tasklist;
+
+ /**
+ *
+ * @param array $vars
+ * @param Horde_Share_Object $tasklist
+ */
+ public function __construct($vars, Horde_Share_Object $tasklist)
+ {
+ $this->_tasklist = $tasklist;
+ parent::__construct($vars, sprintf(_("Edit %s"), $tasklist->get('name')));
+ $this->addHidden('', 't', 'text', true);
+ $this->addVariable(_("Task List Name"), 'name', 'text', true);
+ $this->addVariable(_("Task List Description"), 'description', 'longtext', false, false, null, array(4, 60));
+ if ($GLOBALS['registry']->isAdmin()) {
+ $this->addVariable(
+ _("System Task List"), 'system', 'boolean', false, false,
+ _("System task lists don't have an owner. Only administrators can change the task list settings and permissions.")
+ );
+ }
+ $this->setButtons(array(_("Save")));
+ }
+
+ public function execute()
+ {
+ $info = array();
+ foreach (array('name', 'color', 'description', 'system') as $key) {
+ $info[$key] = $this->_vars->get($key);
+ }
+ return Nag::updateTasklist($this->_tasklist, $info);
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * This file contains all Horde_Form extensions required for editing tasks.
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @package Nag
+ */
+/**
+ * The Nag_TaskForm class provides the form for adding and editing a task.
+ *
+ * @author Jan Schneider <jan@horde.org>
+ * @package Nag
+ */
+class Nag_Form_Renderer_Task extends Horde_Form_Renderer
+{
+ public $delete;
+
+ /**
+ *
+ * @param array $params
+ * @param boolean $delete
+ */
+ public function __construct($params = array(), $delete = false)
+ {
+ parent::__construct($params);
+ $this->delete = $delete;
+ }
+
+ /**
+ *@TODO: visibility needs to be public until Horde_Form refactored
+ */
+ public function _renderSubmit($submit, $reset)
+ {
+ ?><div class="control" style="padding:1em;">
+ <input class="button leftFloat" name="submitbutton" type="submit" value="<?php echo _("Save") ?>" />
+ <?php if ($this->delete): ?>
+ <input class="button rightFloat" name="submitbutton" type="submit" value="<?php echo _("Delete this task") ?>" />
+ <?php endif; ?>
+ <div class="clear"></div>
+ </div>
+ <?php
+ }
+
+}
\ No newline at end of file
--- /dev/null
+<?php
+/**
+ * The Horde_Form_Type_nag_alarm class provides a form field for editing task
+ * alarms.
+ *
+ * @author Jan Schneider <jan@horde.org>
+ * @package Nag
+ */
+class Nag_Form_Type_NagAlarm extends Horde_Form_Type
+{
+ public function getInfo(&$vars, &$var, &$info)
+ {
+ $info = $var->getValue($vars);
+ if (!$info['on']) {
+ $info = 0;
+ } else {
+ $value = $info['value'];
+ $unit = $info['unit'];
+ if ($value == 0) {
+ $value = $unit = 1;
+ }
+ $info = $value * $unit;
+ }
+ }
+
+ public function isValid(&$var, &$vars, $value, &$message)
+ {
+ if ($value['on']) {
+ if ($vars->get('due_type') == 'none') {
+ $message = _("A due date must be set to enable alarms.");
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public function getTypeName()
+ {
+ return 'NagAlarm';
+ }
+
+}
\ No newline at end of file
--- /dev/null
+<?php
+/**
+ * The Horde_Form_Type_nag_due class provides a form field for editing
+ * task due dates.
+ *
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @package Nag
+ */
+class Nag_Form_Type_NagDue extends Horde_Form_Type
+{
+ public function getInfo(&$vars, &$var, &$info)
+ {
+ $due_type = $vars->get('due_type');
+ $due = $vars->get('due');
+ if (is_array($due)) {
+ $due_day = !empty($due['day']) ? $due['day'] : null;
+ $due_month = !empty($due['month']) ? $due['month'] : null;
+ $due_year = !empty($due['year']) ? $due['year'] : null;
+ $due_hour = Horde_Util::getFormData('due_hour');
+ $due_minute = Horde_Util::getFormData('due_minute');
+ if (!$GLOBALS['prefs']->getValue('twentyFour')) {
+ $due_am_pm = Horde_Util::getFormData('due_am_pm');
+ if ($due_am_pm == 'pm') {
+ if ($due_hour < 12) {
+ $due_hour = $due_hour + 12;
+ }
+ } else {
+ // Adjust 12:xx AM times.
+ if ($due_hour == 12) {
+ $due_hour = 0;
+ }
+ }
+ }
+
+ $due = (int)strtotime("$due_month/$due_day/$due_year $due_hour:$due_minute");
+ }
+
+ $info = strcasecmp($due_type, 'none') ? $due : 0;
+ }
+
+ public function isValid(&$var, &$vars, $value, &$message)
+ {
+ return true;
+ }
+
+ public function getTypeName()
+ {
+ return 'NagDue';
+ }
+
+}
\ No newline at end of file
--- /dev/null
+<?php
+/**
+ * The Horde_Form_Type_nag_method class provides a form field for editing
+ * notification methods for a task alarm.
+ *
+ * @TODO: Need to refactor these to be named as Nag_Form_Type... once Horde_Form
+ * is refactored and no longer needs
+ *
+ * @author Alfonso Marin <almarin@um.es>
+ * @package Nag
+ */
+class Nag_Form_Type_NagMethod extends Horde_Form_Type
+{
+ public function getInfo(&$vars, &$var, &$info)
+ {
+ $info = $var->getValue($vars);
+ if (empty($info['on'])) {
+ $info = array();
+ return;
+ }
+
+ $types = $vars->get('task_alarms');
+ $info = array();
+ if (!empty($types)) {
+ foreach ($types as $type) {
+ $info[$type] = array();
+ switch ($type){
+ case 'notify':
+ $info[$type]['sound'] = $vars->get('task_alarms_sound');
+ break;
+ case 'mail':
+ $info[$type]['email'] = $vars->get('task_alarms_email');
+ break;
+ case 'popup':
+ break;
+ }
+ }
+ }
+ }
+
+ public function isValid(&$var, &$vars, $value, &$message)
+ {
+ $alarm = $vars->get('alarm');
+ if ($value['on'] && !$alarm['on']){
+ $message = _("An alarm must be set to specify a notification method");
+ return false;
+ }
+ return true;
+ }
+
+ public function getTypeName()
+ {
+ return 'NagMethod';
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * The Horde_Form_Type_nag_start class provides a form field for editing
+ * task delayed start dates.
+ *
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @package Nag
+ */
+class Nag_Form_Type_NagStart extends Horde_Form_Type
+{
+ public function getInfo(&$vars, &$var, &$info)
+ {
+ $start_type = $vars->get('start_date');
+ $start = $vars->get('start');
+ if (is_array($start)) {
+ $start_day = !empty($start['day']) ? $start['day'] : null;
+ $start_month = !empty($start['month']) ? $start['month'] : null;
+ $start_year = !empty($start['year']) ? $start['year'] : null;
+ $start = (int)strtotime("$start_month/$start_day/$start_year");
+ }
+
+ $info = strcasecmp($start_type, 'none') ? $start : 0;
+ }
+
+ public function isValid(&$var, &$vars, $value, &$message)
+ {
+ return true;
+ }
+
+ public function getTypeName()
+ {
+ return 'NagStart';
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * This file contains all Horde_Form extensions required for editing tasks.
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @package Nag
+ */
+
+/**
+ * The Nag_TaskForm class provides the form for adding and editing a task.
+ *
+ * @author Jan Schneider <jan@horde.org>
+ * @package Nag
+ */
+class Nag_Form_Task extends Horde_Form
+{
+ public $delete;
+
+ public function __construct($vars, $title = '', $delete = false)
+ {
+ parent::__construct($vars, $title);
+ $this->delete = $delete;
+ $tasklists = Nag::listTasklists(false, Horde_Perms::EDIT);
+ $tasklist_enums = array();
+ foreach ($tasklists as $tl_id => $tl) {
+ if ($tl->get('owner') != $GLOBALS['registry']->getAuth() &&
+ !empty($GLOBALS['conf']['share']['hidden']) &&
+ !in_array($tl->getName(), $GLOBALS['display_tasklists'])) {
+ continue;
+ }
+ $tasklist_enums[$tl_id] = $tl->get('name');
+ }
+ $tasklist = $vars->get('tasklist_id');
+ if (empty($tasklist)) {
+ reset($tasklist_enums);
+ $tasklist = key($tasklist_enums);
+ }
+ $tasks = Nag::listTasks(null, null, null, array($tasklist), Nag::VIEW_FUTURE_INCOMPLETE);
+ $task_enums = array('' => _("No parent task"));
+ $tasks->reset();
+ while ($task = $tasks->each()) {
+ if ($vars->get('task_id') == $task->id) {
+ continue;
+ }
+ $task_enums[htmlspecialchars($task->id)] = str_repeat(' ', $task->indent * 4) . htmlentities($task->name);
+ }
+ $users = array();
+ $share = $GLOBALS['nag_shares']->getShare($tasklist);
+ $users = $share->listUsers(Horde_Perms::READ);
+ $groups = $share->listGroups(Horde_Perms::READ);
+ if (count($groups)) {
+ $horde_group = $GLOBALS['injector']->getInstance('Horde_Group');
+ foreach ($groups as $group) {
+ $users = array_merge($users,
+ $horde_group->listAllUsers($group));
+ }
+ }
+ $users = array_flip($users);
+
+ if (count($users)) {
+ foreach (array_keys($users) as $user) {
+ $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($user);
+ $fullname = $identity->getValue('fullname');
+ $users[$user] = strlen($fullname) ? $fullname : $user;
+ }
+ }
+ $priorities = array(
+ 1 => '1 ' . _("(highest)"),
+ 2 => 2,
+ 3 => 3,
+ 4 => 4,
+ 5 => '5 ' . _("(lowest)")
+ );
+ $this->addHidden('', 'actionID', 'text', true);
+ $this->addHidden('', 'task_id', 'text', false);
+ $this->addHidden('', 'old_tasklist', 'text', false);
+ $this->addHidden('', 'url', 'text', false);
+ $this->addVariable(_("Name"), 'name', 'text', true);
+ if (!$GLOBALS['prefs']->isLocked('default_tasklist') &&
+ count($tasklist_enums) > 1) {
+ $v = $this->addVariable(
+ _("Task List"), 'tasklist_id', 'enum', true, false, false,
+ array($tasklist_enums));
+ $v->setAction(Horde_Form_Action::factory('reload'));
+ }
+ $v = $this->addVariable(
+ _("Parent task"), 'parent', 'enum', false, false, false, array($task_enums));
+ $v->setOption('htmlchars', true);
+
+ if (class_exists('Horde_Form_Type_category')) {
+ $this->addVariable(_("Category"), 'category', 'category', false);
+ } else {
+ $values = Horde_Array::valuesToKeys(Horde_Prefs_CategoryManager::get());
+ $this->addVariable(
+ _("Category"), 'category', 'enum', false, false, false,
+ array($values, _("Unfiled")));
+ }
+
+ $this->addVariable(_("Assignee"), 'assignee', 'enum', false, false,
+ null, array($users, _("None")));
+ $this->addVariable(_("Private?"), 'private', 'boolean', false);
+ $this->addVariable(_("Due By"), 'due', 'Nag:NagDue', false);
+ $this->addVariable(_("Delay Start Until"), 'start', 'Nag:NagStart', false);
+ $this->addVariable(_("Alarm"), 'alarm', 'Nag:NagAlarm', false);
+
+ $v = $this->addVariable(_("Notification"), 'methods', 'Nag:NagMethod', false);
+ $v->setAction(Horde_Form_Action::factory('reload'));
+
+ $v = $this->addVariable(_("Priority"), 'priority', 'enum', false, false, false, array($priorities));
+ $v->setDefault(3);
+
+ $this->addVariable(_("Estimated Time"), 'estimate', 'number', false);
+ $this->addVariable(_("Completed?"), 'completed', 'boolean', false);
+
+ try {
+ $description = Horde::callHook('description_help', array(), 'nag');
+ } catch (Horde_Exception_HookNotSet $e) {
+ $description = '';
+ }
+ $this->addVariable(_("Description"), 'desc', 'longtext', false, false, $description);
+
+ $buttons = array(_("Save"));
+ if ($delete) {
+ $buttons[] = _("Delete this task");
+ }
+ $this->setButtons($buttons);
+ }
+
+ public function renderActive()
+ {
+ return parent::renderActive(new Nag_Form_Renderer_Task(array('varrenderer_driver' => array('nag', 'nag')), $this->delete), $this->_vars, 'task.php', 'post');
+ }
+
+}
+++ /dev/null
-<?php
-/**
- * Horde_Form for creating task lists.
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @package Nag
- */
-
-/** Horde_Form */
-require_once 'Horde/Form.php';
-
-/** Horde_Form_Renderer */
-require_once 'Horde/Form/Renderer.php';
-
-/**
- * The Nag_CreateTaskListForm class provides the form for
- * creating a task list.
- *
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @package Nag
- */
-class Nag_CreateTaskListForm extends Horde_Form {
-
- function Nag_CreateTaskListForm(&$vars)
- {
- parent::Horde_Form($vars, _("Create Task List"));
-
- $this->addVariable(_("Name"), 'name', 'text', true);
- $this->addVariable(_("Color"), 'color', 'colorpicker', false);
- $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60));
- if ($GLOBALS['registry']->isAdmin()) {
- $this->addVariable(_("System Task List"), 'system', 'boolean', false, false, _("System task lists don't have an owner. Only administrators can change the task list settings and permissions."));
- }
-
- $this->setButtons(array(_("Create")));
- }
-
- function execute()
- {
- $info = array();
- foreach (array('name', 'color', 'description', 'system') as $key) {
- $info[$key] = $this->_vars->get($key);
- }
- return Nag::addTasklist($info);
- }
-
-}
+++ /dev/null
-<?php
-/**
- * Horde_Form for deleting task lists.
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @package Nag
- */
-
-/** Horde_Form */
-require_once 'Horde/Form.php';
-
-/** Horde_Form_Renderer */
-require_once 'Horde/Form/Renderer.php';
-
-/**
- * The Nag_DeleteTaskListForm class provides the form for
- * deleting a task list.
- *
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @package Nag
- */
-class Nag_DeleteTaskListForm extends Horde_Form {
-
- /**
- * Task list being deleted
- */
- var $_tasklist;
-
- function Nag_DeleteTaskListForm(&$vars, &$tasklist)
- {
- $this->_tasklist = &$tasklist;
- parent::Horde_Form($vars, sprintf(_("Delete %s"), $tasklist->get('name')));
-
- $this->addHidden('', 't', 'text', true);
- $this->addVariable(sprintf(_("Really delete the task list \"%s\"? This cannot be undone and all data on this task list will be permanently removed."), $this->_tasklist->get('name')), 'desc', 'description', false);
-
- $this->setButtons(array(_("Delete"), _("Cancel")));
- }
-
- function execute()
- {
- // If cancel was clicked, return false.
- if ($this->_vars->get('submitbutton') == _("Cancel")) {
- return false;
- }
-
- return Nag::deleteTasklist($this->_tasklist);
- }
-
-}
+++ /dev/null
-<?php
-/**
- * Horde_Form for editing task lists.
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @package Nag
- */
-
-/** Horde_Form */
-require_once 'Horde/Form.php';
-
-/** Horde_Form_Renderer */
-require_once 'Horde/Form/Renderer.php';
-
-/**
- * The Nag_EditTaskListForm class provides the form for
- * editing a task list.
- *
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @package Nag
- */
-class Nag_EditTaskListForm extends Horde_Form {
-
- /**
- * Task list being edited
- */
- var $_tasklist;
-
- function Nag_EditTaskListForm(&$vars, &$tasklist)
- {
- $this->_tasklist = &$tasklist;
- parent::Horde_Form($vars, sprintf(_("Edit %s"), $tasklist->get('name')));
-
- $this->addHidden('', 't', 'text', true);
- $this->addVariable(_("Task List Name"), 'name', 'text', true);
- $this->addVariable(_("Task List Description"), 'description', 'longtext', false, false, null, array(4, 60));
- if ($GLOBALS['registry']->isAdmin()) {
- $this->addVariable(_("System Task List"), 'system', 'boolean', false, false, _("System task lists don't have an owner. Only administrators can change the task list settings and permissions."));
- }
-
- $this->setButtons(array(_("Save")));
- }
-
- function execute()
- {
- $info = array();
- foreach (array('name', 'color', 'description', 'system') as $key) {
- $info[$key] = $this->_vars->get($key);
- }
- return Nag::updateTasklist($this->_tasklist, $info);
- }
-
-}
+++ /dev/null
-<?php
-/**
- * This file contains all Horde_Form extensions required for editing tasks.
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @package Nag
- */
-
-/**
- * The Nag_TaskForm class provides the form for adding and editing a task.
- *
- * @author Jan Schneider <jan@horde.org>
- * @package Nag
- */
-class Nag_TaskForm extends Horde_Form {
-
- var $delete;
-
- function Nag_TaskForm(&$vars, $title = '', $delete = false)
- {
- parent::Horde_Form($vars, $title);
- $this->delete = $delete;
-
- $tasklists = Nag::listTasklists(false, Horde_Perms::EDIT);
- $tasklist_enums = array();
- foreach ($tasklists as $tl_id => $tl) {
- if ($tl->get('owner') != $GLOBALS['registry']->getAuth() &&
- !empty($GLOBALS['conf']['share']['hidden']) &&
- !in_array($tl->getName(), $GLOBALS['display_tasklists'])) {
- continue;
- }
- $tasklist_enums[$tl_id] = $tl->get('name');
- }
-
- $tasklist = $vars->get('tasklist_id');
- if (empty($tasklist)) {
- reset($tasklist_enums);
- $tasklist = key($tasklist_enums);
- }
- $tasks = Nag::listTasks(null, null, null, array($tasklist), Nag::VIEW_FUTURE_INCOMPLETE);
- $task_enums = array('' => _("No parent task"));
- $tasks->reset();
- while ($task = $tasks->each()) {
- if ($vars->get('task_id') == $task->id) {
- continue;
- }
- $task_enums[htmlspecialchars($task->id)] = str_repeat(' ', $task->indent * 4) . htmlentities($task->name);
- }
- $users = array();
- $share = $GLOBALS['nag_shares']->getShare($tasklist);
- $users = $share->listUsers(Horde_Perms::READ);
- $groups = $share->listGroups(Horde_Perms::READ);
- if (count($groups)) {
- $horde_group = $GLOBALS['injector']->getInstance('Horde_Group');
- foreach ($groups as $group) {
- $users = array_merge($users,
- $horde_group->listAllUsers($group));
- }
- }
- $users = array_flip($users);
-
- if (count($users)) {
- foreach (array_keys($users) as $user) {
- $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($user);
- $fullname = $identity->getValue('fullname');
- $users[$user] = strlen($fullname) ? $fullname : $user;
- }
- }
- $priorities = array(1 => '1 ' . _("(highest)"), 2 => 2, 3 => 3,
- 4 => 4, 5 => '5 ' . _("(lowest)"));
-
- $this->addHidden('', 'actionID', 'text', true);
- $this->addHidden('', 'task_id', 'text', false);
- $this->addHidden('', 'old_tasklist', 'text', false);
- $this->addHidden('', 'url', 'text', false);
-
- $this->addVariable(_("Name"), 'name', 'text', true);
- if (!$GLOBALS['prefs']->isLocked('default_tasklist') &&
- count($tasklist_enums) > 1) {
- $v = &$this->addVariable(_("Task List"), 'tasklist_id', 'enum', true, false, false, array($tasklist_enums));
- $v->setAction(Horde_Form_Action::factory('reload'));
- }
-
- $v = &$this->addVariable(_("Parent task"), 'parent', 'enum', false, false, false, array($task_enums));
- $v->setOption('htmlchars', true);
-
- if (class_exists('Horde_Form_Type_category')) {
- $this->addVariable(_("Category"), 'category', 'category', false);
- } else {
- $values = Horde_Array::valuesToKeys(Horde_Prefs_CategoryManager::get());
- $this->addVariable(_("Category"), 'category', 'enum', false, false, false, array($values, _("Unfiled")));
- }
-
- $this->addVariable(_("Assignee"), 'assignee', 'enum', false, false,
- null, array($users, _("None")));
- $this->addVariable(_("Private?"), 'private', 'boolean', false);
- $this->addVariable(_("Due By"), 'due', 'nag_due', false);
- $this->addVariable(_("Delay Start Until"), 'start', 'nag_start', false);
- $this->addVariable(_("Alarm"), 'alarm', 'nag_alarm', false);
- $v = &$this->addVariable(_("Notification"), 'methods', 'nag_method', false);
- $v->setAction(Horde_Form_Action::factory('reload'));
-
- $v = &$this->addVariable(_("Priority"), 'priority', 'enum', false, false, false, array($priorities));
- $v->setDefault(3);
-
- $this->addVariable(_("Estimated Time"), 'estimate', 'number', false);
- $this->addVariable(_("Completed?"), 'completed', 'boolean', false);
-
- try {
- $description = Horde::callHook('description_help', array(), 'nag');
- } catch (Horde_Exception_HookNotSet $e) {
- $description = '';
- }
- $this->addVariable(_("Description"), 'desc', 'longtext', false, false, $description);
-
- $buttons = array(_("Save"));
- if ($delete) {
- $buttons[] = _("Delete this task");
- }
- $this->setButtons($buttons);
- }
-
- function renderActive()
- {
- return parent::renderActive(new Nag_TaskForm_Renderer(array('varrenderer_driver' => array('nag', 'nag')), $this->delete), $this->_vars, 'task.php', 'post');
- }
-
-}
-
-class Nag_TaskForm_Renderer extends Horde_Form_Renderer {
-
- var $delete;
-
- function Nag_TaskForm_Renderer($params = array(), $delete = false)
- {
- parent::Horde_Form_Renderer($params);
- $this->delete = $delete;
- }
-
- function _renderSubmit($submit, $reset)
- {
-?><div class="control" style="padding:1em;">
- <input class="button leftFloat" name="submitbutton" type="submit" value="<?php echo _("Save") ?>" />
-<?php if ($this->delete): ?>
- <input class="button rightFloat" name="submitbutton" type="submit" value="<?php echo _("Delete this task") ?>" />
-<?php endif; ?>
- <div class="clear"></div>
-</div>
-<?php
- }
-
-}
-/**
- * The Horde_Form_Type_nag_method class provides a form field for editing
- * notification methods for a task alarm.
- *
- * @author Alfonso Marin <almarin@um.es>
- * @package Nag
- */
-class Horde_Form_Type_nag_method extends Horde_Form_Type {
-
- function getInfo(&$vars, &$var, &$info)
- {
- $info = $var->getValue($vars);
- if (empty($info['on'])) {
- $info = array();
- return;
- }
-
- $types = $vars->get('task_alarms');
- $info = array();
- if (!empty($types)) {
- foreach ($types as $type) {
- $info[$type] = array();
- switch ($type){
- case 'notify':
- $info[$type]['sound'] = $vars->get('task_alarms_sound');
- break;
- case 'mail':
- $info[$type]['email'] = $vars->get('task_alarms_email');
- break;
- case 'popup':
- break;
- }
- }
- }
- }
-
- function isValid(&$var, &$vars, $value, &$message)
- {
- $alarm = $vars->get('alarm');
- if ($value['on'] && !$alarm['on']){
- $message = _("An alarm must be set to specify a notification method");
- return false;
- }
- return true;
- }
-
-}
-
-/**
- * The Horde_Form_Type_nag_alarm class provides a form field for editing task
- * alarms.
- *
- * @author Jan Schneider <jan@horde.org>
- * @package Nag
- */
-class Horde_Form_Type_nag_alarm extends Horde_Form_Type {
-
- function getInfo(&$vars, &$var, &$info)
- {
- $info = $var->getValue($vars);
- if (!$info['on']) {
- $info = 0;
- } else {
- $value = $info['value'];
- $unit = $info['unit'];
- if ($value == 0) {
- $value = $unit = 1;
- }
- $info = $value * $unit;
- }
- }
-
- function isValid(&$var, &$vars, $value, &$message)
- {
- if ($value['on']) {
- if ($vars->get('due_type') == 'none') {
- $message = _("A due date must be set to enable alarms.");
- return false;
- }
- }
-
- return true;
- }
-
-}
-
-/**
- * The Horde_Form_Type_nag_due class provides a form field for editing
- * task due dates.
- *
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @package Nag
- */
-class Horde_Form_Type_nag_due extends Horde_Form_Type {
-
- function getInfo(&$vars, &$var, &$info)
- {
- $due_type = $vars->get('due_type');
- $due = $vars->get('due');
- if (is_array($due)) {
- $due_day = !empty($due['day']) ? $due['day'] : null;
- $due_month = !empty($due['month']) ? $due['month'] : null;
- $due_year = !empty($due['year']) ? $due['year'] : null;
- $due_hour = Horde_Util::getFormData('due_hour');
- $due_minute = Horde_Util::getFormData('due_minute');
- if (!$GLOBALS['prefs']->getValue('twentyFour')) {
- $due_am_pm = Horde_Util::getFormData('due_am_pm');
- if ($due_am_pm == 'pm') {
- if ($due_hour < 12) {
- $due_hour = $due_hour + 12;
- }
- } else {
- // Adjust 12:xx AM times.
- if ($due_hour == 12) {
- $due_hour = 0;
- }
- }
- }
-
- $due = (int)strtotime("$due_month/$due_day/$due_year $due_hour:$due_minute");
- }
-
- $info = strcasecmp($due_type, 'none') ? $due : 0;
- }
-
- function isValid(&$var, &$vars, $value, &$message)
- {
- return true;
- }
-
-}
-
-/**
- * The Horde_Form_Type_nag_start class provides a form field for editing
- * task delayed start dates.
- *
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @package Nag
- */
-class Horde_Form_Type_nag_start extends Horde_Form_Type {
-
- function getInfo(&$vars, &$var, &$info)
- {
- $start_type = $vars->get('start_date');
- $start = $vars->get('start');
- if (is_array($start)) {
- $start_day = !empty($start['day']) ? $start['day'] : null;
- $start_month = !empty($start['month']) ? $start['month'] : null;
- $start_year = !empty($start['year']) ? $start['year'] : null;
- $start = (int)strtotime("$start_month/$start_day/$start_year");
- }
-
- $info = strcasecmp($start_type, 'none') ? $start : 0;
- }
-
- function isValid(&$var, &$vars, $value, &$message)
- {
- return true;
- }
-
-}
*/
const VIEW_FUTURE_INCOMPLETE = 4;
+ /**
+ *
+ * @param integer $seconds
+ *
+ * @return string
+ */
public static function secondsToString($seconds)
{
$hours = floor($seconds / 3600);
public static function listTasks($sortby = null,
$sortdir = null,
$altsortby = null,
- $tasklists = null,
+ array $tasklists = null,
$completed = null)
{
global $prefs, $registry;
/* Retrieve the tasklist from storage. */
$result = $storage->retrieve($completed);
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- }
$tasks->mergeChildren($storage->tasks->children);
}
foreach ($apps as $app) {
if ($app != 'nag' &&
$registry->hasMethod('getListTypes', $app)) {
- $types = $registry->callByPackage($app, 'getListTypes');
- if (is_a($types, 'PEAR_Error')) {
+ try {
+ $types = $registry->callByPackage($app, 'getListTypes');
+ } catch (Horde_Exception $e) {
continue;
}
if (!empty($types['taskHash'])) {
- $newtasks = $registry->callByPackage($app, 'listAs', array('taskHash'));
- if (is_a($newtasks, 'PEAR_Error')) {
- Horde::logMessage($newtasks, 'ERR');
- } else {
- foreach ($newtasks as $task) {
+ try {
+ $newtasks = $registry->callByPackage($app, 'listAs', array('taskHash'));
+ foreach ($newtasks as $task) {
$task['tasklist_id'] = '**EXTERNAL**';
$task['tasklist_name'] = $registry->get('name', $app);
$tasks->add(new Nag_Task($task));
}
+ } catch (Horde_Exception $e) {
+ Horde::logMessage($newtasks, 'ERR');
}
}
}
{
$storage = Nag_Driver::singleton($tasklist);
$task = $storage->get($task);
- if (is_a($task, 'PEAR_Error')) {
- return $task;
- }
$task->process();
return $task;
}
return $count;
}
- $tasklists = Nag::listTasklists(true, Horde_Perms::ALL);
+ $tasklists = self::listTasklists(true, Horde_Perms::ALL);
$count = 0;
foreach (array_keys($tasklists) as $tasklist) {
public static function createTasksFromText($text, $tasklist = null)
{
if ($tasklist === null) {
- $tasklist = Nag::getDefaultTasklist(Horde_Perms::EDIT);
+ $tasklist = self::getDefaultTasklist(Horde_Perms::EDIT);
}
- if (!array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::EDIT))) {
+ if (!array_key_exists($tasklist, self::listTasklists(false, Horde_Perms::EDIT))) {
return PEAR::raiseError(_("Permission Denied"));
}
} else {
$newTask = $storage->add($name, '', 0, $due, 3);
}
- if (is_a($newTask, 'PEAR_Error')) {
- return $newTask;
- }
$uids[] = $newTask[1];
$task['id'] = $newTask[0];
}
/**
* Returns all the alarms active right on $date.
*
- * @param integer $date The unix epoch time to check for alarms.
+ * @param integer $date The unix epoch time to check for alarms.
+ * @param array $tasklists An array of tasklists
*
* @return array The alarms (taskId) active on $date.
*/
- public static function listAlarms($date, $tasklists = null)
+ public static function listAlarms($date, array $tasklists = null)
{
if (is_null($tasklists)) {
$tasklists = $GLOBALS['display_tasklists'];
/* Retrieve the alarms for the task list. */
$newtasks = $storage->listAlarms($date);
- if (is_a($newtasks, 'PEAR_Error')) {
- return $newtasks;
- }
/* Don't show an alarm for complete tasks. */
foreach ($newtasks as $taskID => $task) {
* Filters data based on permissions.
*
* @param array $in The data we want filtered.
- * @param string $filter What type of data we are filtering.
* @param integer $permission The Horde_Perms::* constant we will filter
* on.
*
* @return array The filtered data.
*/
- public static function permissionsFilter($in, $permission = Horde_Perms::READ)
+ public static function permissionsFilter(array $in, $permission = Horde_Perms::READ)
{
// FIXME: Must find a way to check individual tasklists for
// permission. Can't specify attributes as it does not check for the
/**
* Returns the default tasklist for the current user at the specified
* permissions level.
+ *
+ * @param integer $permission The permission to require.
+ *
+ * @return mixed The default tasklist or false if none.
*/
public static function getDefaultTasklist($permission = Horde_Perms::SHOW)
{
global $prefs;
$default_tasklist = $prefs->getValue('default_tasklist');
- $tasklists = Nag::listTasklists(false, $permission);
+ $tasklists = self::listTasklists(false, $permission);
if (isset($tasklists[$default_tasklist])) {
return $default_tasklist;
*
* @return Horde_Share The new share.
*/
- public static function addTasklist($info)
+ public static function addTasklist(array $info)
{
try {
$tasklist = $GLOBALS['nag_shares']->newShare($GLOBALS['registry']->getAuth(), strval(new Horde_Support_Randomid()));
/**
* Updates an existing share.
*
- * @param Horde_Share $share The share to update.
- * @param array $info Hash with task list information.
+ * @param Horde_Share_Object $tasklist The share to update.
+ * @param array $info Hash with task list information.
*
* @throws Horde_Exception_PermissionDenied
* @throws Nag_Exception
*/
- public static function updateTasklist($tasklist, $info)
+ public static function updateTasklist(Horde_Share_Object $tasklist, array $info)
{
if (!$GLOBALS['registry']->getAuth() ||
($tasklist->get('owner') != $GLOBALS['registry']->getAuth() &&
/**
* Deletes a task list.
*
- * @param Horde_Share $tasklist The task list to delete.
+ * @param Horde_Share_Object $tasklist The task list to delete.
+ * @throws Nag_Exception
+ * @throws Horde_Exception_PermissionDenied
*/
- public static function deleteTasklist($tasklist)
+ public static function deleteTasklist(Horde_Share_Object $tasklist)
{
if (!$GLOBALS['registry']->getAuth() ||
($tasklist->get('owner') != $GLOBALS['registry']->getAuth() &&
// Delete the task list.
$storage = &Nag_Driver::singleton($tasklist->getName());
$result = $storage->deleteAll();
- if ($result instanceof PEAR_Error) {
- throw new Nag_Exception(sprintf(_("Unable to delete \"%s\": %s"), $tasklist->get('name'), $result->getMessage()));
- }
// Remove share and all groups/permissions.
try {
/**
* Returns the string representation of the given completion status.
*
- * @param int $completed The completion value.
+ * @param integer $completed The completion value.
*
* @return string The HTML representation of $completed.
*/
/**
* Returns a colored representation of a priority.
*
- * @param int $priority The priority level.
+ * @param integer $priority The priority level.
*
* @return string The HTML representation of $priority.
*/
/**
* Returns the string matching the given alarm value.
*
- * @param int $value The alarm value in minutes.
+ * @param integer $value The alarm value in minutes.
*
* @return string The formatted alarm string.
*/
// Make sure all task lists exist now, to save on checking later.
$_temp = $GLOBALS['display_tasklists'];
- $GLOBALS['all_tasklists'] = Nag::listTasklists();
+ $GLOBALS['all_tasklists'] = self::listTasklists();
$GLOBALS['display_tasklists'] = array();
foreach ($_temp as $id) {
if (isset($GLOBALS['all_tasklists'][$id])) {
/* If the user doesn't own a task list, create one. */
if (!empty($GLOBALS['conf']['share']['auto_create']) &&
$GLOBALS['registry']->getAuth() &&
- !count(Nag::listTasklists(true))) {
+ !count(self::listTasklists(true))) {
$identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create();
$share = $GLOBALS['nag_shares']->newShare($GLOBALS['registry']->getAuth(), strval(new Horde_Support_Randomid()));
$share->set('name', sprintf(_("Task list of %s"), $identity->getName()));
if (empty($GLOBALS['conf']['alarms']['driver'])) {
// Get any alarms in the next hour.
$now = time();
- $alarmList = Nag::listAlarms($now);
- if (is_a($alarmList, 'PEAR_Error')) {
- Horde::logMessage($alarmList, 'ERR');
- $notification->push($alarmList, 'horde.error');
- } else {
+ try {
+ $alarmList = self::listAlarms($now);
$messages = array();
foreach ($alarmList as $task) {
$differential = $task->due - $now;
$messages[$key] = array(sprintf(_("%s is due now."), $task->name), 'horde.alarm');
} elseif ($differential >= 60) {
$messages[$key] = array(sprintf(_("%s is due in %s"), $task->name,
- Nag::secondsToString($differential)), 'horde.alarm');
+ self::secondsToString($differential)), 'horde.alarm');
}
}
foreach ($messages as $message) {
$notification->push($message[0], $message[1]);
}
+ } catch (Nag_Exception $e) {
+ Horde::logMessage($e, 'ERR');
+ $notification->push($e->getMessage(), 'horde.error');
}
}
// Check here for guest task lists so that we don't get multiple
// messages after redirects, etc.
- if (!$GLOBALS['registry']->getAuth() && !count(Nag::listTasklists())) {
+ if (!$GLOBALS['registry']->getAuth() && !count(self::listTasklists())) {
$notification->push(_("No task lists are available to guests."));
}
* "delete".
* @param Nag_Task $task The changed task.
* @param Nag_Task $old_task The original task if $action is "edit".
+ *
+ * @throws Nag_Exception
*/
public static function sendNotification($action, $task, $old_task = null)
{
if (!in_array($action, array('add', 'edit', 'delete'))) {
- return PEAR::raiseError('Unknown event action: ' . $action);
+ throw new Nag_Exception('Unknown event action: ' . $action);
}
try {
$owner = $share->get('owner');
if (strlen($owner)) {
- $recipients[$owner] = Nag::_notificationPref($owner, 'owner');
+ $recipients[$owner] = self::_notificationPref($owner, 'owner');
}
foreach ($share->listUsers(Horde_Perms::READ) as $user) {
if (empty($recipients[$user])) {
- $recipients[$user] = Nag::_notificationPref($user, 'read', $task->tasklist);
+ $recipients[$user] = self::_notificationPref($user, 'read', $task->tasklist);
}
}
foreach ($share->listGroups(Horde_Perms::READ) as $group) {
foreach ($group_users as $user) {
if (empty($recipients[$user])) {
- $recipients[$user] = Nag::_notificationPref($user, 'read', $task->tasklist);
+ $recipients[$user] = self::_notificationPref($user, 'read', $task->tasklist);
}
}
}
}
if ($old_task->parent_id != $task->parent_id) {
$old_parent = $old_task->getParent();
- $parent = $task->getParent();
- if (!is_a($parent, 'PEAR_Error')) {
+ try {
+ $parent = $task->getParent();
$notification_message .= "\n - "
. sprintf(_("Changed parent task from \"%s\" to \"%s\""),
$old_parent ? $old_parent->name : _("no parent"),
$parent ? $parent->name : _("no parent"));
+ } catch (Tag_Exception $e) {
}
-
}
if ($old_task->category != $task->category) {
$notification_message .= "\n - "
if ($old_task->due != $task->due) {
$notification_message .= "\n - "
. sprintf(_("Changed due date from %s to %s"),
- $old_task->due ? Nag::formatDate($old_task->due) : _("no due date"),
- $task->due ? Nag::formatDate($task->due) : _("no due date"));
+ $old_task->due ? self::formatDate($old_task->due) : _("no due date"),
+ $task->due ? self::formatDate($task->due) : _("no due date"));
}
if ($old_task->start != $task->start) {
$notification_message .= "\n - "
. sprintf(_("Changed start date from %s to %s"),
- $old_task->start ? Nag::formatDate($old_task->start) : _("no start date"),
- $task->start ? Nag::formatDate($task->start) : _("no start date"));
+ $old_task->start ? self::formatDate($old_task->start) : _("no start date"),
+ $task->start ? self::formatDate($task->start) : _("no start date"));
}
if ($old_task->alarm != $task->alarm) {
$notification_message .= "\n - "
. sprintf(_("Changed alarm from %s to %s"),
- Nag::formatAlarm($old_task->alarm), Nag::formatAlarm($task->alarm));
+ self::formatAlarm($old_task->alarm), self::formatAlarm($task->alarm));
}
if ($old_task->priority != $task->priority) {
$notification_message .= "\n - "
/**
* Returns the real name, if available, of a user.
+ *
+ * @param string $uid The userid of the user to retrieve
+ *
+ * @return string The fullname of the user.
*/
public static function getUserName($uid)
{
* @author Jan Schneider <jan@horde.org>
* @package Nag
*/
-class Nag_Task {
-
+class Nag_Task
+{
/**
* The task id.
*
* @var string
*/
- var $id;
+ public $id;
/**
* This task's tasklist id.
*
* @var string
*/
- var $tasklist;
+ public $tasklist;
/**
* The task uid.
*
* @var string
*/
- var $uid;
+ public $uid;
/**
* The task owner.
*
* @var string
*/
- var $owner;
+ public $owner;
/**
* The task assignee.
*
* @var string
*/
- var $assignee;
+ public $assignee;
/**
* The task title.
*
* @var string
*/
- var $name;
+ public $name;
/**
* The task decription.
*
* @var string
*/
- var $desc;
+ public $desc;
/**
* The start date timestamp.
*
* @var integer
*/
- var $start;
+ public $start;
/**
* The due date timestamp.
*
* @var integer
*/
- var $due;
+ public $due;
/**
* The task priority.
*
* @var integer
*/
- var $priority;
+ public $priority;
/**
* The estimated task length.
*
* @var float
*/
- var $estimate;
+ public $estimate;
/**
* Whether the task is completed.
*
* @var boolean
*/
- var $completed;
+ public $completed;
/**
* The completion date timestamp.
*
* @var integer
*/
- var $completed_date;
+ public $completed_date;
/**
* The task category
*
* @var string
*/
- var $category;
+ public $category;
/**
* The task alarm threshold.
*
* @var integer
*/
- var $alarm;
+ public $alarm;
/**
* The particular alarm methods overridden for this task.
*
* @var array
*/
- var $methods;
+ public $methods;
/**
* Whether the task is private.
*
* @var boolean
*/
- var $private;
+ public $private;
/**
* URL to view the task.
*
* @var string
*/
- var $view_link;
+ public $view_link;
/**
* URL to complete the task.
*
* @var string
*/
- var $complete_link;
+ public $complete_link;
/**
* URL to edit the task.
*
* @var string
*/
- var $edit_link;
+ public $edit_link;
/**
* URL to delete the task.
*
* @var string
*/
- var $delete_link;
+ public $delete_link;
/**
* The parent task's id.
*
* @var string
*/
- var $parent_id = '';
+ public $parent_id = '';
/**
* The parent task.
*
* @var Nag_Task
*/
- var $parent;
+ public $parent;
/**
* The sub-tasks.
*
* @var array
*/
- var $children = array();
+ public $children = array();
/**
* This task's idention (child) level.
*
* @var integer
*/
- var $indent = 0;
+ public $indent = 0;
/**
* Whether this is the last sub-task.
*
* @var boolean
*/
- var $lastChild;
+ public $lastChild;
/**
* Internal flag.
* @var boolean
* @see each()
*/
- var $_inlist = false;
+ protected $_inlist = false;
/**
* Internal pointer.
* @var integer
* @see each()
*/
- var $_pointer;
+ protected $_pointer;
/**
* Task id => pointer dictionary.
*
* @var array
*/
- var $_dict = array();
+ protected $_dict = array();
/**
* Constructor.
*
* @param array $task A task hash.
*/
- function Nag_Task($task = null)
+ public function __construct(array $task = null)
{
if ($task) {
$this->merge($task);
*
* @param array $task A task hash.
*/
- function merge($task)
+ public function merge(array $task)
{
foreach ($task as $key => $val) {
if ($key == 'tasklist_id') {
/**
* Saves this task in the storage backend.
*/
- function save()
+ public function save()
{
$storage = Nag_Driver::singleton($this->tasklist);
return $storage->modify($this->id,
/**
* Returns the parent task of this task, if one exists.
*
- * @return Nag_Task The parent task, null if none exists, PEAR_Error on
- * failure.
+ * @return mixed The parent task, null if none exists
*/
- function getParent()
+ public function getParent()
{
if (!$this->parent_id) {
return null;
*
* @param Nag_Task $task A sub task.
*/
- function add($task)
+ public function add(Nag_Task $task)
{
$this->_dict[$task->id] = count($this->children);
$task->parent = $this;
/**
* Loads all sub-tasks.
*/
- function loadChildren()
+ public function loadChildren()
{
$storage = Nag_Driver::singleton($this->tasklist);
- $children = $storage->getChildren($this->id);
- if (!is_a($children, 'PEAR_Error')) {
- $this->children = $children;
- }
+ try {
+ $this->children = $storage->getChildren($this->id);
+ } catch (Nag_Exception $e) {}
}
/**
* @param array $children A list of Nag_Tasks.
*
*/
- function mergeChildren($children)
+ public function mergeChildren(array $children)
{
for ($i = 0, $c = count($children); $i < $c; ++$i) {
$this->add($children[$i]);
*
* @return Nag_Task The searched task or null.
*/
- function get($key)
+ public function get($key)
{
- if (isset($this->_dict[$key])) {
- $task = $this->children[$this->_dict[$key]];
- } else {
- $task = null;
- }
- return $task;
+ return isset($this->_dict[$key]) ?
+ $this->children[$this->_dict[$key]] :
+ null;
}
/**
*
* @return boolean True if this is a task or has sub tasks.
*/
- function hasTasks()
+ public function hasTasks()
{
- if ($this->id) {
- return true;
- }
- return $this->hasSubTasks();
+ return ($this->id) ? true : $this->hasSubTasks();
}
/**
*
* @return boolean True if this task has sub tasks.
*/
- function hasSubTasks()
+ public function hasSubTasks()
{
foreach ($this->children as $task) {
if ($task->hasTasks()) {
*
* @return boolean True if all sub tasks are completed.
*/
- function childrenCompleted()
+ public function childrenCompleted()
{
foreach ($this->children as $task) {
if (!$task->completed || !$task->childrenCompleted()) {
*
* @return integer The number of tasks and sub tasks.
*/
- function count()
+ public function count()
{
$count = $this->id ? 1 : 0;
foreach ($this->children as $task) {
*
* @return integer The estimated length sum.
*/
- function estimation()
+ public function estimation()
{
$estimate = $this->estimate;
foreach ($this->children as $task) {
*
* @return string
*/
- function getFormattedDescription()
+ public function getFormattedDescription()
{
- $desc = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($this->desc, 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO));
+ $desc = $GLOBALS['injector']
+ ->getInstance('Horde_Core_Factory_TextFilter')
+ ->filter($this->desc,
+ 'text2html',
+ array('parselevel' => Horde_Text_Filter_Text2html::MICRO));
try {
return Horde::callHook('format_description', array($desc), 'nag');
} catch (Horde_Exception_HookNotSet $e) {
*
* @see each()
*/
- function reset()
+ public function reset()
{
foreach (array_keys($this->children) as $key) {
$this->children[$key]->reset();
*
* @see reset()
*/
- function each()
+ public function each()
{
if ($this->id && !$this->_inlist) {
$this->_inlist = true;
*
* @param integer $indent The indention level of the tasks.
*/
- function process($indent = 0)
+ public function process($indent = 0)
{
/* Link cache. */
static $view_url_list, $task_url_list;
*
* @return string The HTML code for necessary tree icons.
*/
- function treeIcons()
+ public function treeIcons()
{
$html = '';
* (Nag::SORT_ASCEND, Nag::SORT_DESCEND).
* @param string $altsortby The secondary sort field.
*/
- function sort($sortby, $sortdir, $altsortby)
+ public function sort($sortby, $sortdir, $altsortby)
{
/* Sorting criteria for the task list. */
$sort_functions = array(
*
* @return array A task hash.
*/
- function toHash()
+ public function toHash()
{
return array('tasklist_id' => $this->tasklist,
'task_id' => $this->id,
*
* @return object A simple object.
*/
- function toJson($full = false, $time_format = 'H:i')
+ public function toJson($full = false, $time_format = 'H:i')
{
$json = new stdClass;
$json->l = $this->tasklist;
*
* @return array Alarm hash or null.
*/
- function toAlarm($user = null, $prefs = null)
+ public function toAlarm($user = null, $prefs = null)
{
if (empty($this->alarm) || $this->completed) {
return;
*
* @return Horde_Icalendar_Vtodo A vtodo component of this task.
*/
- function toiCalendar($calendar)
+ public function toiCalendar(Horde_Icalendar $calendar)
{
$vTodo = Horde_Icalendar::newComponent('vtodo', $calendar);
$v1 = $calendar->getAttribute('VERSION') == '1.0';
/**
* Create an AS message from this task
*
+ * @return Horde_ActiveSync_Message_Task
*/
function toASTask()
{
*
* @param Horde_Icalendar_Vtodo $vTodo The iCalendar data to update from.
*/
- function fromiCalendar($vTodo)
+ function fromiCalendar(Horde_Icalendar_Vtodo $vTodo)
{
try {
$name = $vTodo->getAttribute('SUMMARY');
foreach ($relations as $id => $relation) {
if (empty($params[$id]['RELTYPE']) ||
Horde_String::upper($params[$id]['RELTYPE']) == 'PARENT') {
- $storage = Nag_Driver::singleton($this->tasklist);
+ $storage = Nag_Driver::singleton($this->tasklist);
$parent = $storage->getByUID($relation);
- if (!is_a($parent, 'PEAR_Error')) {
- $this->parent_id = $parent->id;
- }
+ $this->parent_id = $parent->id;
break;
}
}
/**
* Create a nag Task object from an activesync message
*
+ * @param Horde_ActiveSync_Message_Task $message The task object
*/
function fromASTask(Horde_ActiveSync_Message_Task $message)
{
*/
class Horde_Core_Ui_VarRenderer_Nag extends Horde_Core_Ui_VarRenderer_Html
{
- protected function _renderVarInput_nag_method($form, $var, $vars)
+ protected function _renderVarInput_NagMethod($form, $var, $vars)
{
$varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
$varvalue = $var->getValue($vars);
}
}
- protected function _renderVarInput_nag_start($form, $var, $vars)
+ protected function _renderVarInput_NagStart($form, $var, $vars)
{
$var->type->getInfo($vars, $var, $task_start);
$start_date = ($task_start == 0)
}
}
- protected function _renderVarInput_nag_due($form, $var, $vars)
+ protected function _renderVarInput_NagDue($form, $var, $vars)
{
$var->type->getInfo($vars, $var, $task_due);
if ($task_due == 0) {
<?php
}
- protected function _renderVarInput_nag_alarm($form, $var, $vars)
+ protected function _renderVarInput_NagAlarm($form, $var, $vars)
{
$varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
$value = $var->getValue($vars);
$vars->set('show_completed', $search_completed);
/* Get the full, sorted task list. */
- $tasks = Nag::listTasks($prefs->getValue('sortby'),
- $prefs->getValue('sortdir'),
- $prefs->getValue('altsortby'),
- null,
- $search_completed);
- if (is_a($tasks, 'PEAR_Error')) {
+ try {
+ $tasks = Nag::listTasks(
+ $prefs->getValue('sortby'),
+ $prefs->getValue('sortdir'),
+ $prefs->getValue('altsortby'),
+ null,
+ $search_completed
+ );
+ } catch (Nag_Exception $e) {
$notification->push($tasks, 'horde.error');
$tasks = new Nag_Task();
}
default:
/* Get the full, sorted task list. */
- $tasks = Nag::listTasks($prefs->getValue('sortby'),
- $prefs->getValue('sortdir'),
- $prefs->getValue('altsortby'));
- if (is_a($tasks, 'PEAR_Error')) {
+ try {
+ $tasks = Nag::listTasks(
+ $prefs->getValue('sortby'),
+ $prefs->getValue('sortdir'),
+ $prefs->getValue('altsortby')
+ );
+ } catch (Nag_Exception $e) {
$notification->push($tasks, 'horde.error');
$tasks = new Nag_Task();
}
$title = _("My Tasks");
/* Get the full, sorted task list. */
-$tasks = Nag::listTasks($prefs->getValue('sortby'),
- $prefs->getValue('sortdir'),
- $prefs->getValue('altsortby'));
-if (is_a($tasks, 'PEAR_Error')) {
+try {
+ $tasks = Nag::listTasks(
+ $prefs->getValue('sortby'),
+ $prefs->getValue('sortdir'),
+ $prefs->getValue('altsortby')
+ );
+} catch (Nag_Exception $e) {
$notification->push($tasks, 'horde.error');
$tasks = new Nag_Task();
}
-
require $registry->get('templates', 'horde') . '/common-header-mobile.inc';
-
?>
<style type="text/css">
.ui-icon-nag-unchecked {
Horde_Registry::appInit('nag');
if ($quickText = Horde_Util::getPost('quickText')) {
- $result = Nag::createTasksFromText($quickText, Nag::getDefaultTasklist(Horde_Perms::EDIT));
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result);
- } elseif ($result) {
+ try {
+ $result = Nag::createTasksFromText($quickText, Nag::getDefaultTasklist(Horde_Perms::EDIT));
+ } catch (Nag_Exception $e) {
+ $notification->push($e->getMessage());
+ }
+ if ($result) {
$notification->push(sprintf(ngettext("Added %d task", "Added %d tasks", count($result)), count($result)), 'horde.success');
} else {
$notification->push(_("No tasks have been added."), 'horde.warning');
Horde_Auth::setAuth($user, array());
// Import data.
-$result = $registry->call('tasks/import',
- array($vtodo, 'text/calendar', $tasklist));
-if (is_a($result, 'PEAR_Error')) {
+try {
+ $result = $registry->tasks->import($vtodo, 'text/calendar', $tasklist);
+} catch (Horde_Exception $e) {
$cli->fatal($result->toString());
}
-
$cli->message('Imported successfully ' . count($result) . ' tasks', 'cli.success');
function usage()
function _delete($task_id, $tasklist_id)
{
if (!empty($task_id)) {
- $task = Nag::getTask($tasklist_id, $task_id);
- if ($task instanceof PEAR_Error) {
- $GLOBALS['notification']->push(
- sprintf(_("Error deleting task: %s"),
- $task->getMessage()), 'horde.error');
- } else {
+ try {
+ $task = Nag::getTask($tasklist_id, $task_id);
try {
$share = $GLOBALS['nag_shares']->getShare($tasklist_id);
} catch (Horde_Share_Exception $e) {
$GLOBALS['notification']->push(sprintf(_("Deleted %s."), $task->name),
'horde.success');
}
+ } catch (Nag_Exception $e) {
+ $GLOBALS['notification']->push(
+ sprintf(_("Error deleting task: %s"),
+ $e->getMessage()), 'horde.error');
}
}
require_once dirname(__FILE__) . '/lib/Application.php';
Horde_Registry::appInit('nag');
-require_once NAG_BASE . '/lib/Forms/task.php';
$vars = Horde_Variables::getDefaultVariables();
/* Redirect to the task list if no action has been requested. */
if (!$vars->exists('tasklist_id')) {
$vars->set('tasklist_id', Nag::getDefaultTasklist(Horde_Perms::EDIT));
}
- $form = new Nag_TaskForm($vars, _("New Task"));
+ $form = new Nag_Form_Task($vars, _("New Task"));
break;
case 'modify_task':
$vars->set('actionID', 'save_task');
$vars->set('old_tasklist', $task->tasklist);
$vars->set('url', Horde_Util::getFormData('url'));
- $form = new Nag_TaskForm($vars, sprintf(_("Edit: %s"), $task->name), $share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE));
+ $form = new Nag_Form_Task($vars, sprintf(_("Edit: %s"), $task->name), $share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE));
break;
}
}
_delete($vars->get('task_id'), $vars->get('old_tasklist'));
}
- $form = new Nag_TaskForm($vars, $vars->get('task_id') ? sprintf(_("Edit: %s"), $vars->get('name')) : _("New Task"));
+ $form = new Nag_Form_Task($vars, $vars->get('task_id') ? sprintf(_("Edit: %s"), $vars->get('name')) : _("New Task"));
if (!$form->validate($vars)) {
break;
}
/* Creating a new task. */
$storage = Nag_Driver::singleton($info['tasklist_id']);
- $result = $storage->add($info['name'], $info['desc'], $info['start'],
- $info['due'], $info['priority'],
- (float)$info['estimate'],
- (int)$info['completed'],
- $info['category']['value'],
- $info['alarm'], $info['methods'], null,
- $info['parent'], (int)$info['private'],
- $GLOBALS['registry']->getAuth(), $info['assignee']);
+ try {
+ $storage->add(
+ $info['name'], $info['desc'], $info['start'],
+ $info['due'], $info['priority'],
+ (float)$info['estimate'],
+ (int)$info['completed'],
+ $info['category']['value'],
+ $info['alarm'], $info['methods'], null,
+ $info['parent'], (int)$info['private'],
+ $GLOBALS['registry']->getAuth(), $info['assignee']
+ );
+ } catch (Nag_Exception $e) {
+ $notification->push(sprintf(_("There was a problem saving the task: %s."), $result->getMessage()), 'horde.error');
+ Horde::url('list.php', true)->redirect();
+ }
}
/* Check our results. */
- if ($result instanceof PEAR_Error) {
- $notification->push(sprintf(_("There was a problem saving the task: %s."), $result->getMessage()), 'horde.error');
- } else {
- $notification->push(sprintf(_("Saved %s."), $info['name']), 'horde.success');
- /* Return to the last page or to the task list. */
- if ($url = Horde_Util::getFormData('url')) {
- header('Location: ' . $url);
- exit;
- }
- Horde::url('list.php', true)->redirect();
+ $notification->push(sprintf(_("Saved %s."), $info['name']), 'horde.success');
+ /* Return to the last page or to the task list. */
+ if ($url = Horde_Util::getFormData('url')) {
+ header('Location: ' . $url);
+ exit;
}
-
+ Horde::url('list.php', true)->redirect();
break;
case 'delete_task':
} else {
$task->completed_date = null;
}
- $result = $task->save();
- if ($result instanceof PEAR_Error) {
+ try {
+ $result = $task->save();
+ } catch (Nag_Exception $e) {
$notification->push(sprintf(_("There was a problem completing %s: %s"),
- $task->name, $result->getMessage()), 'horde.error');
+ $task->name, $e->getMessage()), 'horde.error');
+ }
+ if ($task->completed) {
+ $notification->push(sprintf(_("Completed %s."), $task->name), 'horde.success');
} else {
- if ($task->completed) {
- $notification->push(sprintf(_("Completed %s."), $task->name), 'horde.success');
- } else {
- $notification->push(sprintf(_("%s is now incomplete."), $task->name), 'horde.success');
- }
+ $notification->push(sprintf(_("%s is now incomplete."), $task->name), 'horde.success');
}
+
}
}
$prefs->getValue('sortdir'),
$prefs->getValue('altsortby'),
null,
- 1);
-if ($tasks instanceof PEAR_Error) {
- throw new Nag_Exception($tasks);
-}
-
+ 1
+);
$search_pattern = '/^' . preg_quote($search, '/') . '/i';
$search_results = new Nag_Task();
$tasks->reset();
* UID first. */
if ($uid = Horde_Util::getFormData('uid')) {
$storage = Nag_Driver::singleton();
- $task = $storage->getByUID($uid);
- if ($task instanceof PEAR_Error) {
+ try {
+ $task = $storage->getByUID($uid);
+ } catch (Nag_Exception $e) {
Horde::url('list.php', true)->redirect();
}
-
$task_id = $task->id;
$tasklist_id = $task->tasklist;
} else {