Backport
[platal.git] / include / search / classes.inc.php
index 4b5718a..c164852 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2004 Polytechnique.org                              *
+ *  Copyright (C) 2003-2006 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -439,6 +439,37 @@ class RefSField extends SField
 }
 
 // }}}
+
+// {{{ class RefSFieldMultipleTable
+class MapSField extends RefSField
+{
+       var $mapId;
+       
+    function MapSField($_fieldFormName, $_fieldDbName='', $_refTable, $_refAlias, $_refCondition, $_mapId=false)
+    {
+        if ($_mapId === false)
+            $this->mapId = Env::get($_fieldFormName, '');
+        else
+            $this->mapId = $_mapId;
+        $this->RefSField($_fieldFormName, $_fieldDbName, $_refTable, $_refAlias, $_refCondition, true, false);
+    }
+    function get_select_statement()
+    {
+        if ($this->mapId === '') return false;
+        $res = implode(' OR ', array_filter(array_map(array($this, 'get_single_match_statement'), $this->fieldDbName)));
+        foreach ($this->refTable as $i => $refT)
+            $last = $i;
+        $inner = "";
+        foreach ($this->refTable as $i => $refT)
+            $inner .= " INNER JOIN {$refT} AS {$this->refAlias[$i]} ON ({$this->refCondition[$i]} ".(($i == $last)?"AND ($res) ":"").")";
+        return $inner;
+    }
+    function get_request()
+    {
+        $this->value = $this->mapId;
+    }
+}
+
 // {{{ class RefWithSoundexSField                       [ ??? ]
 
 class RefWithSoundexSField extends RefSField
@@ -777,4 +808,5 @@ class SFieldGroup
 
 // }}}
 
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
 ?>