aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Widget/Privacygroups.php
blob: a6b16c5521804036525ffa12cdfd436f6872f993 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php

namespace Zotlabs\Widget;

use Zotlabs\Lib\AccessList;

class Privacygroups {

	function widget($arr) {

		$o = '';

		$groups = q("SELECT id, gname FROM pgrp WHERE deleted = 0 AND uid = %d ORDER BY gname ASC",
			intval(local_channel())
		);

		if (!$groups) {
			return $o;
		}

		$menu_items = [];
		$z_root = z_root();
		$active = argv(1) ?? '';

		foreach($groups as $group) {
			$menu_items[] = [
				'href' => $z_root . '/group/' . $group['id'],
				'label' => $group['gname'],
				'title' => '',
				'active' => ($active === $group['id']),
				'count' => count(AccessList::members(local_channel(), $group['id']))
			];
		}

		if ($active) {
			$menu_items[] = [
				'href' => $z_root . '/group',
				'label' => '<i class="fa fa-plus"></i> &nbsp;' . t('Add new group'),
				'title' => '',
				'active' => '',
				'count' => ''
			];
		}

		$tpl = get_markup_template("widget_menu_count.tpl");
		$o .= replace_macros($tpl, [
			'$title' => t('Privacy groups'),
			'$menu_items' => $menu_items,

		]);

		return $o;

	}
}