From 8eb6931f1ce4c88f1086859d9d46afd4793d87e4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Wed, 11 Aug 2010 11:19:27 +0200 Subject: [PATCH] Improve the PlView code, adding comments. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- include/userset.inc.php | 80 ++++++++++++++++++++++++++++++++++++------------- modules/search.php | 34 ++++++++++----------- 2 files changed, 77 insertions(+), 37 deletions(-) diff --git a/include/userset.inc.php b/include/userset.inc.php index 8d65239..e4631a2 100644 --- a/include/userset.inc.php +++ b/include/userset.inc.php @@ -51,7 +51,7 @@ class SearchSet extends ProfileSet private $score = null; private $quick = false; - public function __construct($quick = false, $no_search = false, PlFilterCondition $cond = null) + public function __construct($quick = false, PlFilterCondition $cond = null) { if ($no_search) { return; @@ -60,21 +60,24 @@ class SearchSet extends ProfileSet $this->quick = $quick; if (is_null($cond)) { - $this->conds = new PFC_And(); + $conds = new PFC_And(); } else if ($cond instanceof PFC_And) { - $this->conds = $cond; + $conds = $cond; } else { - $this->conds = new PFC_And($cond); + $conds = new PFC_And($cond); } if ($quick) { - $this->getQuick(); + $this->getQuick($conds); } else { - $this->getAdvanced(); + $this->getAdvanced($conds); } } - private function getQuick() + /** Sets up the conditions for a Quick Search + * @param $conds Additional conds (as a PFC_And) + */ + private function getQuick($conds) { if (!S::logged()) { Env::kill('with_soundex'); @@ -88,21 +91,24 @@ class SearchSet extends ProfileSet } $ufc = $ufb->getUFC(); - $this->conds->addChild($ufc); + $conds->addChild($ufc); $orders = $ufb->getOrders(); if (S::logged() && Env::has('nonins')) { - $this->conds = new PFC_And($this->conds, + $conds = new PFC_And($conds, new PFC_Not(new UFC_Dead()), new PFC_Not(new UFC_Registered()) ); } - parent::__construct($this->conds, $orders); + parent::__construct($conds, $orders); } - private function getAdvanced() + /** Sets up the conditions for an Advanced Search + * @param $conds Additional conds (as a PFC_And) + */ + private function getAdvanced($conds) { $this->advanced = true; require_once 'ufbuilder.inc.php'; @@ -112,7 +118,12 @@ class SearchSet extends ProfileSet return; } - $this->conds->addChild($ufb->getUFC()); + $ufc = $ufb->getUFC(); + $conds->addChild($ufc); + + $orders = $ufb->getOrders(); + + parent::__construct($conds, $orders); } protected function &getFilterResults(PlFilter &$pf, PlLimit $limit) @@ -122,6 +133,8 @@ class SearchSet extends ProfileSet } } +/** Simple set based on an array of User objects + */ class ArraySet extends ProfileSet { public function __construct(array $users) @@ -136,6 +149,9 @@ class ArraySet extends ProfileSet } } +/** A multipage view for profiles + * Allows the display of bounds when sorting by name or promo. + */ abstract class ProfileView extends MultipageView { protected function getBoundValue($obj) @@ -172,11 +188,21 @@ abstract class ProfileView extends MultipageView } } +/** An extended multipage view for profiles, as minifiches. + * Allows to sort by: + * - score (for a search query) + * - name + * - promo + * - latest modification + * + * Paramaters for this view are: + * - with_score: whether to allow ordering by score (set only for a quick search) + * - starts_with: show only names beginning with the given letter + */ class MinificheView extends ProfileView { - public function __construct(PlSet &$set, $data, array $params) + public function __construct(PlSet &$set, array $params) { - require_once 'education.func.inc.php'; global $globals; $this->entriesPerPage = $globals->search->per_page; if (@$params['with_score']) { @@ -200,7 +226,21 @@ class MinificheView extends ProfileView new UFO_Promo(UserFilter::DISPLAY, true), new UFO_Name(Profile::DN_SORT), ), 'dernière modification')); - parent::__construct($set, $data, $params); + parent::__construct($set, $params); + } + + public function apply(PlPage &$page) + { + if (array_key_exists('starts_with', $this->params) + && $this->params['starts_with'] != "" + && $this->params['starts_with'] != null) { + + $this->set->addCond( + new UFC_Name(Profile::LASTNAME, + $this->params['starts_with'], UFC_Name::PREFIX) + ); + } + return parent::apply($page); } public function templateName() @@ -211,7 +251,7 @@ class MinificheView extends ProfileView class MentorView extends ProfileView { - public function __construct(PlSet &$set, $data, array $params) + public function __construct(PlSet &$set, array $params) { $this->entriesPerPage = 10; $this->addSort(new PlViewOrder('rand', array(new PFO_Random(S::i('uid'))), 'aléatoirement')); @@ -225,7 +265,7 @@ class MentorView extends ProfileView new UFO_Promo(UserFilter::DISPLAY, true), new UFO_Name(Profile::DN_SORT), ), 'dernière modification')); - parent::__construct($set, $data, $params); + parent::__construct($set, $params); } public function templateName() @@ -236,7 +276,7 @@ class MentorView extends ProfileView class TrombiView extends ProfileView { - public function __construct(PlSet &$set, $data, array $params) + public function __construct(PlSet &$set, array $params) { $this->entriesPerPage = 24; $this->defaultkey = 'name'; @@ -254,7 +294,7 @@ class TrombiView extends ProfileView new UFO_Promo(UserFilter::DISPLAY, true), new UFO_Name(Profile::DN_SORT), ), 'promotion')); - parent::__construct($set, $data, $params); + parent::__construct($set, $params); } public function templateName() @@ -274,7 +314,7 @@ class TrombiView extends ProfileView class GadgetView implements PlView { - public function __construct(PlSet &$set, $data, array $params) + public function __construct(PlSet &$set, array $params) { $this->set =& $set; } diff --git a/modules/search.php b/modules/search.php index 67b4ba3..cc12371 100644 --- a/modules/search.php +++ b/modules/search.php @@ -43,11 +43,15 @@ class SearchModule extends PLModule Platal::page()->assign('formulaire',1); } - function handler_quick(&$page, $action = null, $subaction = null) + /** + * $model: The way of presenting the results: minifiche, trombi, geoloc. + * $byletter: Show only names beginning with this letter + */ + function handler_quick(&$page, $model = null, $byletter = null) { global $globals; - if (Env::has('quick') || $action == 'geoloc') { + if (Env::has('quick') || $model == 'geoloc') { $quick = Env::t('quick'); if (S::logged() && !Env::has('page')) { S::logger()->log('search', 'quick=' . $quick); @@ -110,20 +114,17 @@ class SearchModule extends PLModule $page->assign('formulaire', 0); require_once 'userset.inc.php'; - $view = new SearchSet(true, $action == 'geoloc' && substr($subaction, -3) == 'swf'); - $view->addMod('minifiche', 'Mini-fiches', true, array('with_score' => true)); + $view = new SearchSet(true); + $view->addMod('minifiche', 'Mini-fiches', true, array('with_score' => true, 'starts_with' => $byletter)); if (S::logged() && !Env::i('nonins')) { $view->addMod('trombi', 'Trombinoscope', false, array('with_promo' => true, 'with_score' => true)); // TODO: Reactivate when the new map is completed. // $view->addMod('geoloc', 'Planisphère', false, array('with_annu' => 'search/adv')); } - $view->apply('search', $page, $action, $subaction); + $view->apply('search', $page, $model); $nb_tot = $view->count(); $page->assign('search_results_nb', $nb_tot); - if ($subaction) { - return; - } if (!S::logged() && $nb_tot > $globals->search->public_max) { $page->trigError('Votre recherche a généré trop de résultats pour un affichage public.'); } elseif ($nb_tot > $globals->search->private_max) { @@ -140,14 +141,16 @@ class SearchModule extends PLModule $page->setTitle('Annuaire'); } - function handler_advanced(&$page, $action = null, $subaction = null) + /** $model is the way of presenting the results: minifiche, trombi, geoloc. + */ + function handler_advanced(&$page, $model = null, $byletter = null) { global $globals; require_once 'geocoding.inc.php'; $page->assign('advanced',1); $page->addJsLink('jquery.autocomplete.js'); - if (!Env::has('rechercher') && $action != 'geoloc') { + if (!Env::has('rechercher') && $model != 'geoloc') { $this->form_prepare(); } else { if (!Env::has('page')) { @@ -155,16 +158,13 @@ class SearchModule extends PLModule } require_once 'userset.inc.php'; - $view = new SearchSet(false, $action == 'geoloc' && substr($subaction, -3) == 'swf'); - $view->addMod('minifiche', 'Mini-fiches', true); + $view = new SearchSet(false); + $view->addMod('minifiche', 'Mini-fiches', true, array('starts_with' => $byletter)); $view->addMod('trombi', 'Trombinoscope', false, array('with_promo' => true)); // TODO: Reactivate when the new map is completed. // $view->addMod('geoloc', 'Planisphère', false, array('with_annu' => 'search/adv')); - $view->apply('search/adv', $page, $action, $subaction); + $view->apply('search/adv', $page, $model); - if ($subaction) { - return; - } $nb_tot = $view->count(); if ($nb_tot > $globals->search->private_max) { $this->form_prepare(); @@ -175,7 +175,7 @@ class SearchModule extends PLModule } } - $page->changeTpl('search/index.tpl', $action == 'mini' ? SIMPLE : SKINNED); + $page->changeTpl('search/index.tpl', $model == 'mini' ? SIMPLE : SKINNED); $page->addJsLink('ajax.js'); $page->assign('public_directory',0); } -- 2.1.4