1<?php
2/*
3    +-----------------------------------------------------------------------------+
4    | ILIAS open source                                                           |
5    +-----------------------------------------------------------------------------+
6    | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
7    |                                                                             |
8    | This program is free software; you can redistribute it and/or               |
9    | modify it under the terms of the GNU General Public License                 |
10    | as published by the Free Software Foundation; either version 2              |
11    | of the License, or (at your option) any later version.                      |
12    |                                                                             |
13    | This program is distributed in the hope that it will be useful,             |
14    | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
15    | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
16    | GNU General Public License for more details.                                |
17    |                                                                             |
18    | You should have received a copy of the GNU General Public License           |
19    | along with this program; if not, write to the Free Software                 |
20    | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
21    +-----------------------------------------------------------------------------+
22*/
23
24/**
25* Class ilAdvancedSearch
26*
27* Base class for advanced meta search
28*
29* @author Stefan Meyer <meyer@leifos.com>
30* @version $Id
31*
32* @package ilias-search
33*
34*/
35include_once 'Services/Search/classes/class.ilAbstractSearch.php';
36
37class ilMetaDataSearch extends ilAbstractSearch
38{
39    public $mode = '';
40
41    /*
42     * instance of query parser
43     */
44    public $query_parser = null;
45
46    public $db = null;
47
48    /**
49    * Define meta elements to search
50    *
51    * @param array elements to search in. E.G array('keyword','contribute')
52    * @access public
53    */
54    public function setMode($a_mode)
55    {
56        $this->mode = $a_mode;
57    }
58    public function getMode()
59    {
60        return $this->mode;
61    }
62
63
64    public function performSearch()
65    {
66        switch ($this->getMode()) {
67            case 'keyword':
68                return $this->__searchKeywords();
69
70            case 'contribute':
71                return $this->__searchContribute();
72
73            case 'title':
74                return $this->__searchTitles();
75
76            case 'description':
77                return $this->__searchDescriptions();
78
79            default:
80                echo "ilMDSearch::performSearch() no mode given";
81                return false;
82        }
83    }
84
85
86
87    // Private
88    public function __createInStatement()
89    {
90        if (!$this->getFilter()) {
91            return '';
92        } else {
93            $type = "('";
94            $type .= implode("','", $this->getFilter());
95            $type .= "')";
96
97            $in = " AND obj_type IN " . $type;
98
99            return $in;
100        }
101    }
102    public function __searchContribute()
103    {
104        $this->setFields(array('entity'));
105
106        $in = $this->__createInStatement();
107        $where = $this->__createContributeWhereCondition();
108        $locate = $this->__createLocateString();
109
110        $query = "SELECT rbac_id,obj_id,obj_type " .
111            $locate .
112            "FROM il_meta_entity " .
113            $where . " " . $in . ' ';
114
115        $res = $this->db->query($query);
116        while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
117            $this->search_result->addEntry($row->rbac_id, $row->obj_type, $this->__prepareFound($row), $row->obj_id);
118        }
119
120        return $this->search_result;
121    }
122
123
124    public function __searchKeywords()
125    {
126        $this->setFields(array('keyword'));
127
128        $in = $this->__createInStatement();
129        $where = $this->__createKeywordWhereCondition();
130        $locate = $this->__createLocateString();
131
132        $query = "SELECT rbac_id,obj_id,obj_type " .
133            $locate .
134            "FROM il_meta_keyword " .
135            $where . " " . $in . ' ';
136
137        $res = $this->db->query($query);
138        while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
139            $this->search_result->addEntry($row->rbac_id, $row->obj_type, $this->__prepareFound($row), $row->obj_id);
140        }
141
142        return $this->search_result;
143    }
144    public function __searchTitles()
145    {
146        $this->setFields(array('title'));
147
148        $in = $this->__createInStatement();
149        $where = $this->__createTitleWhereCondition();
150        $locate = $this->__createLocateString();
151
152        $query = "SELECT rbac_id,obj_id,obj_type " .
153            $locate .
154            "FROM il_meta_general " .
155            $where . " " . $in . ' ';
156
157        $res = $this->db->query($query);
158        while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
159            $this->search_result->addEntry($row->rbac_id, $row->obj_type, $this->__prepareFound($row), $row->obj_id);
160        }
161
162        return $this->search_result;
163    }
164    public function __searchDescriptions()
165    {
166        $this->setFields(array('description'));
167
168        $in = $this->__createInStatement();
169        $where = $this->__createDescriptionWhereCondition();
170        $locate = $this->__createLocateString();
171
172        $query = "SELECT rbac_id,obj_id,obj_type " .
173            $locate .
174            "FROM il_meta_description " .
175            $where . " " . $in . ' ';
176
177        $res = $this->db->query($query);
178        while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
179            $this->search_result->addEntry($row->rbac_id, $row->obj_type, $this->__prepareFound($row), $row->obj_id);
180        }
181
182        return $this->search_result;
183    }
184}
185