Garradin Plugins

Check-in [0e6aea9cd9]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Réservations : ajout calendrier dans les input de type date pour les vieux navigateurs, correction bug pour les dates à plus d'une semaine dans le futur
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0e6aea9cd96abdeaefa2795f5699fa6ac4cfd627
User & Date: bohwaz 2020-05-03 22:57:25
Context
2020-05-06
22:10
Mise à jour : permettre d'ajouter des réservations à la place des adhérents check-in: 304e118766 user: bohwaz tags: trunk
2020-05-03
22:57
Réservations : ajout calendrier dans les input de type date pour les vieux navigateurs, correction bug pour les dates à plus d'une semaine dans le futur check-in: 0e6aea9cd9 user: bohwaz tags: trunk
2020-05-01
18:59
Permettre de supprimer les inscriptions check-in: 017f9adde8 user: bohwaz tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to reservations/garradin_plugin.ini.

1
2
3
4
5
6
7
8
nom="Réservations"
description="Permet de configurer des créneaux et permettre aux adhérents de s'y inscrire"
auteur="BohwaZ"
url="https://garradin.eu/"
version="0.1"
menu=1
config=1
min_version="0.9.6"




|



1
2
3
4
5
6
7
8
nom="Réservations"
description="Permet de configurer des créneaux et permettre aux adhérents de s'y inscrire"
auteur="BohwaZ"
url="https://garradin.eu/"
version="0.2"
menu=1
config=1
min_version="0.9.6"

Changes to reservations/lib/Reservations.php.

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
...
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
		$db = DB::getInstance();
		return $db->exec(sprintf('DELETE FROM plugin_reservations_creneaux WHERE %s;', $db->where('id', 'NOT IN', $ids)));
	}

	public function listUpcomingSlots()
	{
		$slots = DB::getInstance()->get('SELECT id, heure, maximum,
			CASE WHEN repetition = 1 THEN
				strftime(\'%s\', \'now\', strftime(\'weekday %w\', jour))
			ELSE
				strftime(\'%s\', jour)
			END AS date,
			(SELECT COUNT(*) FROM plugin_reservations_personnes prp WHERE creneau = prc.id AND prp.date = date) AS jauge
			FROM plugin_reservations_creneaux prc
			WHERE jour >= date() OR repetition = 1
			ORDER BY date, heure;');

		$date = null;
		foreach ($slots as &$slot) {
			if ($date !== $slot->date) {
				$slot->date_change = true;
				$date = $slot->date;
			}


			$slot->available = $slot->maximum - $slot->jauge;
		}

		return $slots;
	}

	public function deleteSlot(int $id)
................................................................................

		return $this->deleteBooking($id);
	}

	public function createUserBooking(string $slot_code, ?string $id_membre, ?string $nom)
	{
		$slot_id = (int)strtok($slot_code, '=');
		$date = (int)strtok('');

		try {
			$date = DateTime::createFromFormat('U', $date);
		}
		catch (\Exception $e) {
			$date = null;
		}

		if (!$slot_id || !$date) {
			throw new UserException('Erreur dans la date');







|
|

|













>







 







|


|







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
...
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
		$db = DB::getInstance();
		return $db->exec(sprintf('DELETE FROM plugin_reservations_creneaux WHERE %s;', $db->where('id', 'NOT IN', $ids)));
	}

	public function listUpcomingSlots()
	{
		$slots = DB::getInstance()->get('SELECT id, heure, maximum,
			CASE WHEN repetition = 1 AND jour < date() THEN
				date(\'now\', strftime(\'weekday %w\', jour))
			ELSE
				jour
			END AS date,
			(SELECT COUNT(*) FROM plugin_reservations_personnes prp WHERE creneau = prc.id AND prp.date = date) AS jauge
			FROM plugin_reservations_creneaux prc
			WHERE jour >= date() OR repetition = 1
			ORDER BY date, heure;');

		$date = null;
		foreach ($slots as &$slot) {
			if ($date !== $slot->date) {
				$slot->date_change = true;
				$date = $slot->date;
			}

			$slot->timestamp = DateTime::createFromFormat('Y-m-d', $slot->date)->getTimestamp();
			$slot->available = $slot->maximum - $slot->jauge;
		}

		return $slots;
	}

	public function deleteSlot(int $id)
................................................................................

		return $this->deleteBooking($id);
	}

	public function createUserBooking(string $slot_code, ?string $id_membre, ?string $nom)
	{
		$slot_id = (int)strtok($slot_code, '=');
		$date = strtok('');

		try {
			$date = DateTime::createFromFormat('Y-m-d', $date, new \DateTimeZone('UTC'));
		}
		catch (\Exception $e) {
			$date = null;
		}

		if (!$slot_id || !$date) {
			throw new UserException('Erreur dans la date');

Changes to reservations/templates/_form.tpl.

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
	<legend>Créneaux disponibles</legend>
	{if !count($slots)}
		<p class="alert">Aucun créneau disponible.
	{else}
		<dl class="slots">
			{foreach from=$slots item="slot"}
				{if $slot.date_change}
					<dt>{$slot.date|strftime_fr:"%A %e %B %Y"}</dt>
				{/if}
				<dd class="hour available_{$slot.available}">
					{if $slot.available && !$booking}
						<label><input type="radio" class="n-radio" name="slot" value="{$slot.id}={$slot.date}" /> {$slot.heure}</label>
					{else}
						{$slot.heure}
					{/if}







|







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
	<legend>Créneaux disponibles</legend>
	{if !count($slots)}
		<p class="alert">Aucun créneau disponible.
	{else}
		<dl class="slots">
			{foreach from=$slots item="slot"}
				{if $slot.date_change}
					<dt>{$slot.timestamp|strftime_fr:"%A %e %B %Y"}</dt>
				{/if}
				<dd class="hour available_{$slot.available}">
					{if $slot.available && !$booking}
						<label><input type="radio" class="n-radio" name="slot" value="{$slot.id}={$slot.date}" /> {$slot.heure}</label>
					{else}
						{$slot.heure}
					{/if}

Changes to reservations/templates/admin/config.tpl.

1
2
3
4
5
6
7
8
{include file="admin/_head.tpl" title="Configuration — %s"|args:$plugin.nom current="plugin_%s"|args:$plugin.id}

{form_errors}

{if $ok && !$form->hasErrors()}
	<p class="confirm">
		La configuration a bien été enregistrée.
	</p>
|







1
2
3
4
5
6
7
8
{include file="admin/_head.tpl" title="Configuration — %s"|args:$plugin.nom current="plugin_%s"|args:$plugin.id js=1}

{form_errors}

{if $ok && !$form->hasErrors()}
	<p class="confirm">
		La configuration a bien été enregistrée.
	</p>