/**
* Returns a simple object suitable for json transport representing this
* task.
*
* @param boolean $full Whether to return all task details.
* @param string $time_format The date() format to use for time formatting.
*
* @return object A simple object.
*/
public function toJson($full = false, $time_format = 'H:i')
{
$json = new stdClass();
$json->l = $this->tasklist;
$json->p = $this->parent_id;
$json->i = $this->indent;
$json->n = $this->name;
if ($this->desc) {
//TODO: Get the proper amount of characters, and cut by last
//whitespace
$json->sd = Horde_String::substr($this->desc, 0, 80);
}
$json->cp = (bool) $this->completed;
if ($this->due && ($due = $this->getNextDue())) {
$json->du = $due->toJson();
}
if ($this->start && ($start = $this->getNextStart())) {
$json->s = $start->toJson();
}
$json->pr = (int) $this->priority;
if ($this->recurs()) {
$json->r = $this->recurrence->getRecurType();
}
$json->t = array_values($this->tags);
if ($full) {
// @todo: do we really need all this?
$json->id = $this->id;
$json->de = $this->desc;
if ($this->due) {
$date = new Horde_Date($this->due);
$json->dd = $date->strftime('%x');
$json->dt = $date->format($time_format);
}
$json->as = $this->assignee;
if ($this->estimate) {
$json->e = $this->estimate;
}
/*
$json->o = $this->owner;
if ($this->completed_date) {
$date = new Horde_Date($this->completed_date);
$json->cd = $date->toJson();
}
*/
$json->a = (int) $this->alarm;
$json->m = $this->methods;
//$json->pv = (boolean)$this->private;
if ($this->recurs()) {
$json->r = $this->recurrence->toJson();
}
if ($this->tasklist == '**EXTERNAL**') {
$json->vl = (string) $this->view_link;
$json->cl = (string) $this->complete_link;
$json->pe = $json->pd = false;
} else {
try {
$share = $GLOBALS['nag_shares']->getShare($this->tasklist);
} catch (Horde_Share_Exception $e) {
Horde::log($e->getMessage(), 'ERR');
throw new Nag_Exception($e);
}
$json->pe = $share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT);
$json->pd = $share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE);
}
}
return $json;
}