ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilObjCourseReference.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 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 
34 {
38  private $member_update = false;
39 
40 
47  public function __construct($a_id = 0, $a_call_by_reference = true)
48  {
49  global $ilDB;
50 
51  $this->type = 'crsr';
52  parent::__construct($a_id, $a_call_by_reference);
53  }
54 
58  public function enableMemberUpdate(bool $status)
59  {
60  $this->member_update = $status;
61  }
62 
66  public function isMemberUpdateEnabled(): bool
67  {
68  return $this->member_update;
69  }
70 
75  public static function lookupMemberUpdateEnabled(int $obj_id): bool
76  {
77  global $DIC;
78 
79  $db = $DIC->database();
80 
81  $query = 'select member_update from crs_reference_settings where ' .
82  'obj_id = ' . $db->quote($obj_id, ilDBConstants::T_INTEGER);
83  $res = $db->query($query);
84  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
85  return (bool) $row->member_update;
86  }
87  return false;
88  }
89 
90 
94  public function create(): int
95  {
96  $id = parent::create();
97 
98  $query = 'INSERT INTO crs_reference_settings (obj_id, member_update ) ' .
99  'VALUES ( ' .
100  $this->db->quote($id, ilDBConstants::T_INTEGER) . ', ' .
101  $this->db->quote((int) $this->isMemberUpdateEnabled(), ilDBConstants::T_INTEGER) . ' ' .
102  ')';
103  $this->db->manipulate($query);
104  return $id;
105  }
106 
110  public function read(): void
111  {
112  parent::read();
113 
114  $query = 'SELECT * FROM crs_reference_settings ' .
115  'WHERE obj_id = ' . $this->db->quote($this->getId(), ilDBConstants::T_INTEGER);
116  $res = $this->db->query($query);
117  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
118  $this->enableMemberUpdate($row->member_update);
119  }
120  }
121 
125  public function update(): bool
126  {
127  parent::update();
128  $query = 'UPDATE crs_reference_settings ' .
129  'SET member_update = ' . $this->db->quote((int) $this->isMemberUpdateEnabled(), ilDBConstants::T_INTEGER) . ' ' .
130  'WHERE obj_id = ' . $this->db->quote((int) $this->getId(), ilDBConstants::T_INTEGER);
131  $this->db->manipulate($query);
132 
133  ilLoggerFactory::getLogger('crs')->info($query);
134 
135  return true;
136  }
137 
141  public function delete(): bool
142  {
143  if (!parent::delete()) {
144  return false;
145  }
146  $query = 'DELETE FROM crs_reference_settings ' .
147  'WHERE obj_id = ' . $this->db->quote($this->getId(), ilDBConstants::T_INTEGER);
148  $this->db->manipulate($query);
149  return true;
150  }
151 
152 
156  public function cloneObject(int $a_target_id, int $a_copy_id = 0, bool $a_omit_tree = false): ?ilObject
157  {
158  $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
159  $new_obj->enableMemberUpdate($this->isMemberUpdateEnabled());
160  $new_obj->update();
161  return $new_obj;
162  }
163 }
static lookupMemberUpdateEnabled(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$res
Definition: ltiservices.php:69
static getLogger(string $a_component_id)
Get component logger.
quote($value, string $type)
cloneObject(int $a_target_id, int $a_copy_id=0, bool $a_omit_tree=false)
ilDBInterface $db
global $DIC
Definition: shib_login.php:25
query(string $query)
Run a (read-only) Query on the database.
__construct($a_id=0, $a_call_by_reference=true)
Constructor.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
__construct(Container $dic, ilPlugin $plugin)