Overview
Comment:CSV/ODS export of services/fees
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: f397e359883689b31145edfb4fbc85d3a98146f2
User & Date: bohwaz on 2020-11-09 19:39:35
Other Links: branch diff | manifest | tags
Context
2020-11-09
20:36
Use dynamic list for account journals check-in: 89f465c9b1 user: bohwaz tags: dev
19:39
CSV/ODS export of services/fees check-in: f397e35988 user: bohwaz tags: dev
02:07
Small UX improvements check-in: 613a2978e9 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/DynamicList.php from [1e9885b5f5] to [a6cc752b56].

5
6
7
8
9
10
11

12
13
14
15
16
17
18
..
24
25
26
27
28
29
30




31
32
33
34
35
36
37
..
54
55
56
57
58
59
60





















61
62
63
64
65
66
67
..
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
..
94
95
96
97
98
99
100
101
102




103
104
105
106
107
108





109
110
111
112
113
114
115
116
117
class DynamicList
{
	protected $columns;
	protected $tables;
	protected $conditions;
	protected $group;
	protected $order;

	protected $count = 'COUNT(*)';
	protected $desc = true;
	protected $per_page = 100;
	protected $page = 1;

	private $count_result;

................................................................................
		$this->order = key($columns);
	}

	public function __get($key)
	{
		return $this->$key;
	}





	public function setConditions(string $conditions)
	{
		$this->conditions = $conditions;
	}

	public function orderBy(string $key, bool $desc)
................................................................................
		if (null === $this->count_result) {
			$sql = sprintf('SELECT %s FROM %s WHERE %s;', $this->count, $this->tables, $this->conditions);
			$this->count_result = DB::getInstance()->firstColumn($sql);
		}

		return $this->count_result;
	}






















	public function paginationURL()
	{
		$query = array_merge($_GET, ['p' => '[ID]']);
		$url = Utils::getSelfURL($query);
		return $url;
	}
................................................................................
	}

	public function setCount(string $count)
	{
		$this->count = $count;
	}

	public function iterate()
	{
		$start = ($this->page - 1) * $this->per_page;
		$columns = [];

		foreach ($this->columns as $alias => $properties) {
			$select = isset($properties['select']) ? $properties['select'] : $alias;
			$columns[] = sprintf('%s AS %s', $select, $alias);
................................................................................

		if ($this->desc) {
			$order .= ' DESC';
		}

		$group = $this->group ? 'GROUP BY ' . $this->group : '';

		$sql = sprintf('SELECT %s FROM %s WHERE %s %s ORDER BY %s LIMIT %d,%d;',
			$columns, $this->tables, $this->conditions, $group, $order, $start, $this->per_page);





		return DB::getInstance()->iterate($sql);
	}

	public function loadFromQueryString()
	{





		if (!empty($_GET['o'])) {
			$this->orderBy($_GET['o'], !empty($_GET['d']));
		}

		if (!empty($_GET['p'])) {
			$this->page = (int)$_GET['p'];
		}
	}
}







>







 







>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







|
|
>
>
>
>






>
>
>
>
>









5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
..
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
..
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
...
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
...
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
class DynamicList
{
	protected $columns;
	protected $tables;
	protected $conditions;
	protected $group;
	protected $order;
	protected $title = 'Liste';
	protected $count = 'COUNT(*)';
	protected $desc = true;
	protected $per_page = 100;
	protected $page = 1;

	private $count_result;

................................................................................
		$this->order = key($columns);
	}

	public function __get($key)
	{
		return $this->$key;
	}

	public function setTitle(string $title) {
		$this->title = $title;
	}

	public function setConditions(string $conditions)
	{
		$this->conditions = $conditions;
	}

	public function orderBy(string $key, bool $desc)
................................................................................
		if (null === $this->count_result) {
			$sql = sprintf('SELECT %s FROM %s WHERE %s;', $this->count, $this->tables, $this->conditions);
			$this->count_result = DB::getInstance()->firstColumn($sql);
		}

		return $this->count_result;
	}

	public function export(string $name, string $format = 'csv')
	{
		$columns = [];

		foreach ($this->columns as $key => $column) {
			if (empty($column['label'])) {
				$columns[] = $key;
				continue;
			}

			$columns[] = $column['label'];
		}

		if ('csv' == $format) {
			CSV::toCSV($name, $this->iterate(false), $columns);
		}
		else if ('ods' == $format) {
			CSV::toODS($name, $this->iterate(false), $columns);
		}
	}

	public function paginationURL()
	{
		$query = array_merge($_GET, ['p' => '[ID]']);
		$url = Utils::getSelfURL($query);
		return $url;
	}
................................................................................
	}

	public function setCount(string $count)
	{
		$this->count = $count;
	}

	public function iterate(bool $paginate = true)
	{
		$start = ($this->page - 1) * $this->per_page;
		$columns = [];

		foreach ($this->columns as $alias => $properties) {
			$select = isset($properties['select']) ? $properties['select'] : $alias;
			$columns[] = sprintf('%s AS %s', $select, $alias);
................................................................................

		if ($this->desc) {
			$order .= ' DESC';
		}

		$group = $this->group ? 'GROUP BY ' . $this->group : '';

		$sql = sprintf('SELECT %s FROM %s WHERE %s %s ORDER BY %s',
			$columns, $this->tables, $this->conditions, $group, $order);

		if ($paginate) {
			$sql .= sprintf(' LIMIT %d,%d', $start, $this->per_page);
		}

		return DB::getInstance()->iterate($sql);
	}

	public function loadFromQueryString()
	{
		if (!empty($_GET['export'])) {
			$this->export($this->title, $_GET['export']);
			exit;
		}

		if (!empty($_GET['o'])) {
			$this->orderBy($_GET['o'], !empty($_GET['d']));
		}

		if (!empty($_GET['p'])) {
			$this->page = (int)$_GET['p'];
		}
	}
}

Modified src/templates/services/details.tpl from [d8f055dc74] to [8ad4e9ebd0].

3
4
5
6
7
8
9




10
11
12
13
14
15
16
{include file="services/_nav.tpl" current="index" current_service=$service service_page=$type}

<dl class="cotisation">
	<dt>Nombre de membres trouvés</dt>
	<dd>
		{$list->count()}
		<em class="help">(N'apparaît ici que l'inscription la plus récente de chaque membre.)</em>




	</dd>
</dl>

{include file="common/dynamic_list_head.tpl"}

	{foreach from=$list->iterate() item="row"}
		<tr>







>
>
>
>







3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{include file="services/_nav.tpl" current="index" current_service=$service service_page=$type}

<dl class="cotisation">
	<dt>Nombre de membres trouvés</dt>
	<dd>
		{$list->count()}
		<em class="help">(N'apparaît ici que l'inscription la plus récente de chaque membre.)</em>
		{if $session->canAccess('membres', Membres::DROIT_ADMIN)}
		{linkbutton href="%s&export=csv"|args:$self_url shape="export" label="Export CSV"}
		{linkbutton href="%s&export=ods"|args:$self_url shape="export" label="Export tableur"}
		{/if}
	</dd>
</dl>

{include file="common/dynamic_list_head.tpl"}

	{foreach from=$list->iterate() item="row"}
		<tr>

Modified src/templates/services/fees/details.tpl from [0a4a2f9ba2] to [b920f9c000].

3
4
5
6
7
8
9




10
11
12
13
14
15
16
{include file="services/_nav.tpl" current="index" current_service=$service service_page="index" current_fee=$fee fee_page=$type}

<dl class="cotisation">
	<dt>Nombre de membres trouvés</dt>
	<dd>
		{$list->count()}
		<em class="help">(N'apparaît ici que l'inscription la plus récente de chaque membre.)</em>




	</dd>
</dl>

{include file="common/dynamic_list_head.tpl"}

	{foreach from=$list->iterate() item="row"}
		<tr>







>
>
>
>







3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{include file="services/_nav.tpl" current="index" current_service=$service service_page="index" current_fee=$fee fee_page=$type}

<dl class="cotisation">
	<dt>Nombre de membres trouvés</dt>
	<dd>
		{$list->count()}
		<em class="help">(N'apparaît ici que l'inscription la plus récente de chaque membre.)</em>
		{if $session->canAccess('membres', Membres::DROIT_ADMIN)}
			{linkbutton href="%s&export=csv"|args:$self_url shape="export" label="Export CSV"}
			{linkbutton href="%s&export=ods"|args:$self_url shape="export" label="Export tableur"}
		{/if}
	</dd>
</dl>

{include file="common/dynamic_list_head.tpl"}

	{foreach from=$list->iterate() item="row"}
		<tr>

Modified src/templates/services/user.tpl from [ff212c7842] to [62816e927d].

21
22
23
24
25
26
27




28
29
30
31
32
33
34
	<dd>
		Aucune inscription.
	</dd>
	{/foreach}
	<dt>Nombre d'inscriptions pour ce membre</dt>
	<dd>
		{$list->count()}




	</dd>
</dl>

{include file="common/dynamic_list_head.tpl"}

	{foreach from=$list->iterate() item="row"}
		<tr>







>
>
>
>







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
	<dd>
		Aucune inscription.
	</dd>
	{/foreach}
	<dt>Nombre d'inscriptions pour ce membre</dt>
	<dd>
		{$list->count()}
		{if $session->canAccess('membres', Membres::DROIT_ADMIN)}
			{linkbutton href="%s&export=csv"|args:$self_url shape="export" label="Export CSV"}
			{linkbutton href="%s&export=ods"|args:$self_url shape="export" label="Export tableur"}
		{/if}
	</dd>
</dl>

{include file="common/dynamic_list_head.tpl"}

	{foreach from=$list->iterate() item="row"}
		<tr>

Modified src/www/admin/services/user.php from [fa552f3018] to [e3055067d1].

20
21
22
23
24
25
26

27
28
29
30
31
32
	}

	$su->paid = (bool)qg('paid');
	$su->save();
}, null, ADMIN_URL . 'services/user.php?id=' . $user->id);

$list = Services_User::perUserList($user->id);

$list->loadFromQueryString();

$tpl->assign('services', Services_User::listDistinctForUser($user->id));
$tpl->assign(compact('list', 'user'));

$tpl->display('services/user.tpl');







>






20
21
22
23
24
25
26
27
28
29
30
31
32
33
	}

	$su->paid = (bool)qg('paid');
	$su->save();
}, null, ADMIN_URL . 'services/user.php?id=' . $user->id);

$list = Services_User::perUserList($user->id);
$list->setTitle(sprintf('Inscriptions — %s', $user->identite));
$list->loadFromQueryString();

$tpl->assign('services', Services_User::listDistinctForUser($user->id));
$tpl->assign(compact('list', 'user'));

$tpl->display('services/user.tpl');