X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=sidebyside;f=modules%2Fevents.php;h=b4400e0d40b22d3519a3f0abfb52061f241e8d81;hb=3084c5dee14509f0a13b451b8db006157e8adc0f;hp=9c4f0796b93c63178fc751670a0f74a18fc2a8a8;hpb=067dd0d8a18ddb782aa90db3986983465cb33320;p=platal.git
diff --git a/modules/events.php b/modules/events.php
index 9c4f079..b4400e0 100644
--- a/modules/events.php
+++ b/modules/events.php
@@ -1,6 +1,6 @@
Nous t\'invitons à faire un tour d\'horizon des '
. 'nouveautés.
'
. 'Tu peux également retrouver ces informations sur '
- . 'les fora, ou sur la liste exhaustive des modifications.',
+ . 'les forums, ou sur la liste exhaustive des modifications.',
'priorite' => 255,
'promo_min' => 0,
'promo_max' => 0,
@@ -81,57 +81,20 @@ class EventsModule extends PLModule
return $res->fetchOneAssoc();
}
- private function get_events($where, $order, array &$array, $name)
- {
- // affichage des evenements
- // annonces promos triées par présence d'une limite sur les promos
- // puis par dates croissantes d'expiration
- $promo = S::v('promo');
- $uid = S::i('uid');
- $sql = "SELECT e.id,e.titre, ev.user_id IS NULL AS nonlu
- FROM evenements AS e
- LEFT JOIN evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?})
- WHERE FIND_IN_SET('valide', e.flags) AND peremption >= NOW()
- AND (e.promo_min = 0 || e.promo_min <= {?})
- AND (e.promo_max = 0 || e.promo_max >= {?})
- AND $where
- ORDER BY $order";
- $sum = XDB::iterator($sql, $uid, $promo, $promo);
- if (!$sum->total()) {
- return false;
- }
- $sql = "SELECT e.id,e.titre,e.texte,e.post_id,a.user_id,a.nom,a.prenom,a.promo,l.alias AS forlife,
- p.x, p.y, p.attach IS NOT NULL AS img, FIND_IN_SET('wiki', e.flags) AS wiki
- FROM evenements AS e
- LEFT JOIN evenements_photo AS p ON (e.id = p.eid)
- INNER JOIN auth_user_md5 AS a ON e.user_id=a.user_id
- INNER JOIN aliases AS l ON ( a.user_id=l.id AND l.type='a_vie' )
- LEFT JOIN evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?})
- WHERE FIND_IN_SET('valide', e.flags) AND peremption >= NOW()
- AND (e.promo_min = 0 || e.promo_min <= {?})
- AND (e.promo_max = 0 || e.promo_max >= {?})
- AND ev.user_id IS NULL
- AND $where
- ORDER BY $order";
- $evt = XDB::iterator($sql, $uid, $promo, $promo);
- $array[$name] = array('events' => $evt, 'summary' => $sum);
- return true;
- }
-
private function upload_image(PlatalPage &$page, PlUpload &$upload)
{
if (@!$_FILES['image']['tmp_name'] && !Env::v('image_url')) {
return true;
}
if (!$upload->upload($_FILES['image']) && !$upload->download(Env::v('image_url'))) {
- $page->trig('Impossible de télécharger l\'image');
+ $page->trigError('Impossible de télécharger l\'image');
return false;
} elseif (!$upload->isType('image')) {
- $page->trig('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG.');
+ $page->trigError('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG.');
$upload->rm();
return false;
} elseif (!$upload->resizeImage(200, 300, 100, 100, 32284)) {
- $page->trig('Impossible de retraiter l\'image');
+ $page->trigError('Impossible de retraiter l\'image');
return false;
}
return true;
@@ -198,18 +161,41 @@ class EventsModule extends PLModule
}
$array = array();
- $this->get_events('FIND_IN_SET(\'important\', e.flags)', 'e.creation_date DESC', $array, 'important');
- $this->get_events('e.creation_date > DATE_SUB(CURDATE(), INTERVAL 2 DAY)
- AND NOT FIND_IN_SET(\'important\', e.flags)',
- 'e.creation_date DESC', $array, 'news');
- $this->get_events('e.peremption < DATE_ADD(CURDATE(), INTERVAL 2 DAY)
- AND e.creation_date <= DATE_SUB(CURDATE(), INTERVAL 2 DAY)
- AND NOT FIND_IN_SET(\'important\', e.flags)',
- 'e.peremption, e.creation_date DESC', $array, 'end');
- $this->get_events('e.peremption >= DATE_ADD(CURDATE(), INTERVAL 2 DAY)
- AND e.creation_date <= DATE_SUB(CURDATE(), INTERVAL 2 DAY)
- AND NOT FIND_IN_SET(\'important\', e.flags)',
- 'e.peremption, e.creation_date DESC', $array, 'body');
+ $it = XDB::iterator("SELECT e.id,e.titre,e.texte,e.post_id,a.user_id,a.nom,a.prenom,a.promo,l.alias AS forlife,
+ p.x, p.y, p.attach IS NOT NULL AS img, FIND_IN_SET('wiki', e.flags) AS wiki,
+ FIND_IN_SET('important', e.flags) AS important,
+ e.creation_date > DATE_SUB(CURDATE(), INTERVAL 2 DAY) AS news,
+ e.peremption < DATE_ADD(CURDATE(), INTERVAL 2 DAY) AS end,
+ ev.user_id IS NULL AS nonlu
+ FROM evenements AS e
+ LEFT JOIN evenements_photo AS p ON (e.id = p.eid)
+ INNER JOIN auth_user_md5 AS a ON e.user_id=a.user_id
+ INNER JOIN aliases AS l ON ( a.user_id=l.id AND l.type='a_vie' )
+ LEFT JOIN evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?})
+ WHERE FIND_IN_SET('valide', e.flags) AND peremption >= NOW()
+ AND (e.promo_min = 0 || e.promo_min <= {?})
+ AND (e.promo_max = 0 || e.promo_max >= {?})
+ ORDER BY important DESC, news DESC, end DESC, e.peremption, e.creation_date DESC",
+ S::i('uid'), S::i('promo'), S::i('promo'));
+ $cats = array('important', 'news', 'end', 'body');
+ $body = $it->next();
+ foreach ($cats as $cat) {
+ $data = array();
+ if (!$body) {
+ continue;
+ }
+ do {
+ if ($cat == 'body' || $body[$cat]) {
+ $data[] = $body;
+ } else {
+ break;
+ }
+ $body = $it->next();
+ } while ($body);
+ if (!empty($data)) {
+ $array[$cat] = $data;
+ }
+ }
$page->assign_by_ref('events', $array);
}
@@ -253,7 +239,8 @@ class EventsModule extends PLModule
$rss = XDB::iterator(
'SELECT e.id, e.titre, e.texte, e.creation_date, e.post_id, p.attachmime IS NOT NULL AS photo,
- IF(u2.nom_usage = "", u2.nom, u2.nom_usage) AS nom, u2.prenom, u2.promo
+ IF(u2.nom_usage = "", u2.nom, u2.nom_usage) AS nom, u2.prenom, u2.promo,
+ FIND_IN_SET(\'wiki\', e.flags) AS wiki
FROM auth_user_md5 AS u
INNER JOIN evenements AS e ON ( (e.promo_min = 0 || e.promo_min <= u.promo)
AND (e.promo_max = 0 || e.promo_max >= u.promo) )
@@ -302,7 +289,7 @@ class EventsModule extends PLModule
($promo_min != 0 && ($promo_min <= 1900 || $promo_min >= 2020)) ||
($promo_max != 0 && ($promo_max <= 1900 || $promo_max >= 2020)))
{
- $page->trig("L'intervalle de promotions n'est pas valide");
+ $page->trigError("L'intervalle de promotions n'est pas valide");
$action = null;
}
@@ -319,7 +306,7 @@ class EventsModule extends PLModule
$upload->rm();
$page->assign('action', false);
} elseif ($action && (!trim($texte) || !trim($titre))) {
- $page->trig("L'article doit avoir un titre et un contenu");
+ $page->trigError("L'article doit avoir un titre et un contenu");
} elseif ($action) {
require_once 'validations.inc.php';
$evtreq = new EvtReq($titre, $texte, $promo_min, $promo_max,
@@ -386,7 +373,7 @@ class EventsModule extends PLModule
if (($promo_min != 0 && ($promo_min <= 1900 || $promo_min >= 2020)) ||
($promo_max != 0 && ($promo_max <= 1900 || $promo_max >= 2020 || $promo_max < $promo_min)))
{
- $page->trig("L'intervalle de promotions $promo_min -> $promo_max n'est pas valide");
+ $page->trigError("L'intervalle de promotions $promo_min -> $promo_max n'est pas valide");
$action = 'edit';
} else {
$res = XDB::query('SELECT flags FROM evenements WHERE id = {?}', $eid);
@@ -486,7 +473,7 @@ class EventsModule extends PLModule
FIND_IN_SET('valide', e.flags) AS fvalide,
FIND_IN_SET('archive', e.flags) AS farch,
u.promo, u.nom, u.prenom, a.alias AS forlife,
- FIND_IN_SET('wiki', flags) AS wiki
+ FIND_IN_SET('wiki', e.flags) AS wiki
FROM evenements AS e
INNER JOIN auth_user_md5 AS u ON(e.user_id = u.user_id)
INNER JOIN aliases AS a ON (u.user_id = a.id AND a.type='a_vie')