/**
  * Generates list of all available groups.
  *
  * @param Request $request Incoming request.
  * @return string Rendered page content.
  */
 public function indexAction(Request $request)
 {
     $operator = $this->getOperator();
     $page = array('errors' => array());
     $sort_by = $request->query->get('sortby');
     if (!in_array($sort_by, array('name', 'lastseen', 'weight'))) {
         $sort_by = 'name';
     }
     $sort['by'] = $sort_by;
     $sort['desc'] = $request->query->get('sortdirection', 'desc') == 'desc';
     // Load and prepare groups
     $groups = get_sorted_groups($sort);
     foreach ($groups as &$group) {
         $group['vclocalname'] = $group['vclocalname'];
         $group['vclocaldescription'] = $group['vclocaldescription'];
         $group['isOnline'] = group_is_online($group);
         $group['isAway'] = group_is_away($group);
         $group['lastTimeOnline'] = time() - ($group['ilastseen'] ? $group['ilastseen'] : time());
         $group['inumofagents'] = $group['inumofagents'];
     }
     unset($group);
     // Set values that are needed to build sorting block.
     $page['groups'] = $groups;
     $page['formsortby'] = $sort['by'];
     $page['formsortdirection'] = $sort['desc'] ? 'desc' : 'asc';
     $page['canmodify'] = is_capable(CAN_ADMINISTRATE, $operator);
     $page['availableOrders'] = array(array('id' => 'name', 'name' => getlocal('Name')), array('id' => 'lastseen', 'name' => getlocal('Last active')), array('id' => 'weight', 'name' => getlocal('Weight')));
     $page['availableDirections'] = array(array('id' => 'desc', 'name' => getlocal('descending')), array('id' => 'asc', 'name' => getlocal('ascending')));
     // Set other variables and render the response.
     $page['title'] = getlocal('Groups');
     $page['menuid'] = 'groups';
     $page = array_merge($page, prepare_menu($operator));
     $this->getAssetManager()->attachJs('js/compiled/groups.js');
     return $this->render('groups', $page);
 }
Beispiel #2
0
function setup_redirect_links(UrlGeneratorInterface $url_generator, $threadid, $operator, $token)
{
    $result = array();

    $operator_in_isolation = in_isolation($operator);

    $list_options = $operator_in_isolation
        ? array('isolated_operator_id' => $operator['operatorid'])
        : array();
    $operators = get_operators_list($list_options);
    $operators_count = count($operators);

    $groups_count = 0;
    $groups = array();
    if (Settings::get('enablegroups') == "1") {
        $groupslist = $operator_in_isolation
            ? get_groups_for_operator($operator, true)
            : get_groups(true);
        foreach ($groupslist as $group) {
            if ($group['inumofagents'] == 0) {
                continue;
            }
            $groups[] = $group;
        }
        $groups_count = count($groups);
    }

    $p = pagination_info(max($operators_count, $groups_count), 8);
    $result['pagination'] = $p;

    $operators = array_slice($operators, $p['start'], $p['end'] - $p['start']);
    $groups = array_slice($groups, $p['start'], $p['end'] - $p['start']);

    $agent_list = "";
    $params = array('thread_id' => $threadid, 'token' => $token);
    foreach ($operators as $agent) {
        $params['nextAgent'] = $agent['operatorid'];
        $status = $agent['time'] < Settings::get('online_timeout')
            ? ($agent['istatus'] == 0
                ? getlocal("(online)")
                : getlocal("(away)"))
            : "";
        $agent_list .= "<li><a href=\"" . $url_generator->generate('chat_operator_redirect', $params)
            . "\" title=\"" . get_operator_name($agent) . "\">"
            . get_operator_name($agent)
            . "</a> $status</li>";
    }
    $result['redirectToAgent'] = $agent_list;

    $group_list = "";
    if (Settings::get('enablegroups') == "1") {
        $params = array('thread_id' => $threadid, 'token' => $token);
        foreach ($groups as $group) {
            $params['nextGroup'] = $group['groupid'];
            $status = group_is_online($group)
                ? getlocal("(online)")
                : (group_is_away($group) ? getlocal("(away)") : "");
            $group_list .= "<li><a href=\"" . $url_generator->generate('chat_operator_redirect', $params)
                . "\" title=\"" . get_group_name($group) . "\">"
                . get_group_name($group)
                . "</a> $status</li>";
        }
    }
    $result['redirectToGroup'] = $group_list;

    return $result;
}
Beispiel #3
0
/**
 * Prepare groups list to build group select box.
 *
 * If $group_id specified groups list will consist of group with id equals to
 * $group_id and its children.
 *
 * @param int $group_id Id of selected group
 * @return array|boolean Array of groups info arrays or boolean false if there
 *   are no suitable groups.
 *   Group info array contain following keys:
 *    - 'id': int, group id;
 *    - 'name': string, group name;
 *    - 'description': string, group description;
 *    - 'online': boolean, indicates if group online;
 *    - 'selected': boolean, indicates if group selected by default.
 */
function prepare_groups_select($group_id)
{
    $show_groups = $group_id == '' ? true : group_has_children($group_id);
    if (!$show_groups) {
        return false;
    }
    $all_groups = get_groups(false);
    if (empty($all_groups)) {
        return false;
    }
    $groups_list = array();
    $selected_group_id = $group_id;
    foreach ($all_groups as $group) {
        $group_is_empty = (bool) ($group['inumofagents'] == 0);
        $group_related_with_specified = empty($group_id) || $group['parent'] == $group_id || $group['groupid'] == $group_id;
        if ($group_is_empty || !$group_related_with_specified) {
            continue;
        }
        if (group_is_online($group) && !$selected_group_id) {
            $selected_group_id = $group['groupid'];
        }
        $groups_list[] = array('id' => $group['groupid'], 'name' => get_group_name($group), 'description' => get_group_description($group), 'online' => group_is_online($group), 'selected' => (bool) ($group['groupid'] == $selected_group_id));
    }
    // One group must be selected by default
    if (!empty($groups_list)) {
        // Check if there is selected group
        $selected_group_present = false;
        foreach ($groups_list as $group) {
            if ($group['selected']) {
                $selected_group_present = true;
                break;
            }
        }
        // If there is no selected group select the first one
        if (!$selected_group_present) {
            $groups_list[0]['selected'] = true;
        }
    }
    return $groups_list;
}