X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fcarnet.php;h=afd1a315d3641d6198adf7f9e0aed5ba40dc7a74;hb=b270577e919c58455a3629a4d9d61bd38ea49e11;hp=7c656cc6c570ed580ab131d5f6de7ed45fdd572d;hpb=19550958a5a575ef8251f4f1ba34f41d6e190836;p=platal.git diff --git a/modules/carnet.php b/modules/carnet.php index 7c656cc..afd1a31 100644 --- a/modules/carnet.php +++ b/modules/carnet.php @@ -1,6 +1,6 @@ date('Y')) { + if (!(is_int($promo) || ctype_digit($promo)) || $promo < 1920 || $promo > date('Y')) { $page->trigError('Promotion invalide : ' . $promo . '.'); return null; } @@ -255,7 +255,7 @@ class CarnetModule extends PLModule $this->_add_rss_link($page); $uid = S::i('uid'); - $user = Env::v('user'); + $user = S::user(); // For XSRF protection, checks both the normal xsrf token, and the special RSS token. // It allows direct linking to contact adding in the RSS feed. @@ -284,7 +284,10 @@ class CarnetModule extends PLModule break; } -/* $search = false; + $search = false; + + require_once 'userset.inc.php'; + if ($action == 'search') { $action = $subaction; $subaction = $ssaction; @@ -292,18 +295,12 @@ class CarnetModule extends PLModule } if ($search && trim(Env::v('quick'))) { $base = 'carnet/contacts/search'; - - Platal::load('search', 'classes.inc.php'); - ThrowError::$throwHook = array($this, 'searchErrorHandler'); - $view = new SearchSet(true, false, "INNER JOIN contacts AS c2 ON (u.user_id = c2.contact)", "c2.uid = $uid"); + $view = new SearchSet(true, false, new UFC_Contact($user)); } else { $base = 'carnet/contacts'; - $view = new UserSet("INNER JOIN contacts AS c2 ON (u.user_id = c2.contact)", " c2.uid = $uid "); - }*/ + $view = new ProfileSet(new UFC_Contact($user)); + } - require_once 'userset.inc.php'; - $user = S::user(); - $view = new UserSet(new UFC_Contact($user)); $view->addMod('minifiche', 'Mini-fiches', true); $view->addMod('trombi', 'Trombinoscope', false, array('with_admin' => false, 'with_promo' => true)); // TODO: Reactivate when the new map is completed. @@ -317,32 +314,23 @@ class CarnetModule extends PLModule function handler_pdf(&$page, $arg0 = null, $arg1 = null) { $this->load('contacts.pdf.inc.php'); - require_once 'user.func.inc.php'; + $user = S::user(); Platal::session()->close(); - $sql = "SELECT a.alias - FROM aliases AS a - INNER JOIN auth_user_md5 AS u ON ( a.id = u.user_id ) - INNER JOIN contacts AS c ON ( a.id = c.contact ) - WHERE c.uid = {?} AND a.type='a_vie'"; + $order = array(new UFO_Name(Profile::LASTNAME), new UFO_Name(Profile::FIRSTNAME)); if ($arg0 == 'promo') { - $sql .= ' ORDER BY u.promo, u.nom, u.prenom'; + $order = array_unshift($order, new UFO_Promo()); } else { - $sql .= ' ORDER BY u.nom, u.prenom, u.promo'; + $order[] = new UFO_Promo(); } + $filter = new UserFilter(new UFC_Contact($user), $order); - $citer = XDB::iterRow($sql, S::v('uid')); $pdf = new ContactsPDF(); - while (list($alias) = $citer->next()) { - $user = get_user_details($alias); - foreach ($user as &$value) { - if (is_utf8($value)) { - $value = utf8_decode($value); - } - } - $pdf = ContactsPDF::addContact($pdf, $user, $arg0 == 'photos' || $arg1 == 'photos'); + $it = $filter->iterProfiles(); + while ($p = $it->next()) { + $pdf = ContactsPDF::addContact($pdf, $p, $arg0 == 'photos' || $arg1 == 'photos'); } $pdf->Output(); @@ -356,6 +344,20 @@ class CarnetModule extends PLModule return $feed->run($page, $user, $hash); } + function buildBirthRef(Profile $profile) + { + $date = strtotime($profile->birthdate); + $tomorrow = $date + 86400; + return array( + 'timestamp' => $date, + 'date' => date('Ymd', $date), + 'tomorrow' => date('Ymd', $tomorrow), + 'hruid' => $profile->hrid(), + 'summary' => 'Anniversaire de ' . $profile->fullName(true) + ); + } + + function handler_ical(&$page, $alias = null, $hash = null) { $user = Platal::session()->tokenAuth($alias, $hash); @@ -372,31 +374,17 @@ class CarnetModule extends PLModule $page->register_function('display_ical', 'display_ical'); $filter = new UserFilter(new UFC_Contact($user)); - $annivs = Array(); - foreach ($filter->getUsers() as $u) { - $profile = $u->profile(); - $date = strtotime($profile->birthdate); - $tomorrow = $date + 86400; - $annivs[] = array( - 'timestamp' => strtotime($user->registration_date), - 'date' => date('Ymd', $date), - 'tomorrow' => date('Ymd', $tomorrow), - 'hruid' => $profile->hrid(), - 'summary' => 'Anniversaire de ' . $profile->fullName(true) - ); - } - $page->assign('events', $annivs); + $profiles = $filter->iterProfiles(); + $page->assign('events', PlIteratorUtils::map($profiles, array($this, 'buildBirthRef'))); pl_content_headers("text/calendar"); } function handler_vcard(&$page, $photos = null) { - $res = XDB::query('SELECT contact - FROM contacts - WHERE uid = {?}', S::v('uid')); + $pf = new ProfileFilter(new UFC_Contact(S::user())); $vcard = new VCard($photos == 'photos'); - $vcard->addUsers($res->fetchColumn()); + $vcard->addProfiles($pf->getProfiles()); $vcard->show(); } }