ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjectSearch.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 /*
5  +-----------------------------------------------------------------------------+
6  | ILIAS open source |
7  +-----------------------------------------------------------------------------+
8  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
9  | |
10  | This program is free software; you can redistribute it and/or |
11  | modify it under the terms of the GNU General Public License |
12  | as published by the Free Software Foundation; either version 2 |
13  | of the License, or (at your option) any later version. |
14  | |
15  | This program is distributed in the hope that it will be useful, |
16  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18  | GNU General Public License for more details. |
19  | |
20  | You should have received a copy of the GNU General Public License |
21  | along with this program; if not, write to the Free Software |
22  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23  +-----------------------------------------------------------------------------+
24 */
25 
38 {
39  public const CDATE_OPERATOR_BEFORE = 1;
40  public const CDATE_OPERATOR_AFTER = 2;
41  public const CDATE_OPERATOR_ON = 3;
42 
43  private ?int $cdate_operator = null;
44  private ?ilDate $cdate_date = null;
45 
46 
47  public function __construct(ilQueryParser $qp_obj)
48  {
49  parent::__construct($qp_obj);
50  $this->setFields(array('title','description'));
51  }
52 
53 
54  public static function raiseContentChanged(int $obj_id) : void
55  {
56  global $DIC;
57 
58  $DIC->event()->raise(
59  'Services/Search',
60  'contentChanged',
61  [
62  "obj_id" => $obj_id
63  ]
64  );
65  }
66 
67  public function performSearch(): ilSearchResult
68  {
69  $in = $this->__createInStatement();
70  $where = $this->__createWhereCondition();
71 
72 
73 
74  $cdate = '';
75  if ($this->getCreationDateFilterDate() instanceof ilDate) {
76  if ($this->getCreationDateFilterOperator()) {
77  switch ($this->getCreationDateFilterOperator()) {
78  case self::CDATE_OPERATOR_AFTER:
79  $cdate = 'AND create_date >= ' . $this->db->quote($this->getCreationDateFilterDate()->get(IL_CAL_DATE), 'text') . ' ';
80  break;
81 
82  case self::CDATE_OPERATOR_BEFORE:
83  $cdate = 'AND create_date <= ' . $this->db->quote($this->getCreationDateFilterDate()->get(IL_CAL_DATE), 'text') . ' ';
84  break;
85 
86  case self::CDATE_OPERATOR_ON:
87  $cdate = 'AND ' . $this->db->like(
88  'create_date',
89  'text',
90  $this->getCreationDateFilterDate()->get(IL_CAL_DATE) . '%'
91  );
92  break;
93  }
94  }
95  }
96 
97  $locate = $this->__createLocateString();
98 
99  $query = "SELECT obj_id,type " .
100  $locate .
101  "FROM object_data " .
102  $where . " " . $cdate . ' ' . $in . ' ' .
103  "ORDER BY obj_id DESC";
104 
105  ilLoggerFactory::getLogger('src')->debug('Object search query: ' . $query);
106 
107  $res = $this->db->query($query);
108  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
109  $this->search_result->addEntry((int) $row->obj_id, (string) $row->type, $this->__prepareFound($row));
110  }
111  return $this->search_result;
112  }
113 
114 
115 
116  public function __createInStatement(): string
117  {
118  $in = ' AND ' . $this->db->in('type', (array) $this->object_types, false, 'text');
119  if ($this->getIdFilter()) {
120  $in .= ' AND ';
121  $in .= $this->db->in('obj_id', $this->getIdFilter(), false, 'integer');
122  }
123  return $in;
124  }
125 
126 
127  public function setCreationDateFilterDate(ilDate $day): void
128  {
129  $this->cdate_date = $day;
130  }
131 
132  public function setCreationDateFilterOperator(int $a_operator): void
133  {
134  $this->cdate_operator = $a_operator;
135  }
136 
137  public function getCreationDateFilterDate(): ?ilDate
138  {
139  return $this->cdate_date;
140  }
141 
142  public function getCreationDateFilterOperator(): ?int
143  {
144  return $this->cdate_operator;
145  }
146 }
setCreationDateFilterOperator(int $a_operator)
$res
Definition: ltiservices.php:69
static getLogger(string $a_component_id)
Get component logger.
__construct(ilQueryParser $qp_obj)
setFields(array $a_fields)
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
static raiseContentChanged(int $obj_id)
setCreationDateFilterDate(ilDate $day)
const IL_CAL_DATE
ilSearchResult $search_result