/** * @brief Get data from database to pass it on to angular in JSON * @param * @returns $result: a json for the contacts and one for the groups */ function prepareRoster() { //Contacts $contactdao = new \Modl\ContactDAO(); $contacts = $contactdao->getRoster(); $capsarr = $this->getCaps(); $result = array(); $farray = array(); //final array if (isset($contacts)) { /* Init */ $c = array_shift($contacts); if ($c->groupname == '') { $c->groupname = $this->__('roster.ungrouped'); } $jid = $c->jid; $groupname = $c->groupname; $ac = $c->toRoster(); $this->prepareContact($ac, $c, $capsarr); $garray = array(); //group array $garray['agroup'] = $groupname; $garray['tombstone'] = false; $garray['agroupitems'] = array(); //group array of jids $jarray = array(); //jid array $jarray['ajid'] = $jid; $jarray['atruename'] = $ac['rosterview']['name']; $jarray['aval'] = $ac['value']; $jarray['tombstone'] = false; $jarray['ajiditems'] = $ac; //jid array of resources array_push($garray['agroupitems'], $jarray); foreach ($contacts as &$c) { /*jid has changed*/ if ($jid != $c->jid) { if ($c->groupname == '') { $c->groupname = $this->__('roster.ungrouped'); } $ac = $c->toRoster(); $this->prepareContact($ac, $c, $capsarr); if ($groupname != $c->groupname && $c->groupname != "") { //close group array_push($farray, $garray); //next group $groupname = $ac['groupname']; $garray = array(); $garray['agroup'] = $groupname; $garray['tombstone'] = false; $garray['agroupitems'] = array(); } //push new jid in group $jid = $ac['jid']; $jarray['ajid'] = $jid; $jarray['atruename'] = $ac['rosterview']['name']; $jarray['aval'] = $ac['value']; $jarray['tombstone'] = false; $jarray['ajiditems'] = $ac; //jid array of resources array_push($garray['agroupitems'], $jarray); } if ($c == $contacts[count($contacts) - 1]) { array_push($farray, $garray); } } } $result['contacts'] = json_encode($farray); //Groups $rd = new \Modl\RosterLinkDAO(); $groups = $rd->getGroups(); if (is_array($groups) && !in_array("Ungrouped", $groups)) { $groups[] = "Ungrouped"; } else { $groups = array(); } $groups = array_flip($groups); $result['groups'] = json_encode($groups); return $result; }
function prepareItems() { $cd = new \Modl\ContactDAO(); $this->user->reload(true); $view = $this->tpl(); $view->assign('contacts', $cd->getRoster()); $view->assign('offlineshown', $this->user->getConfig('roster')); $view->assign('presencestxt', getPresencesTxt()); return $view->draw('_roster_list', true); }