Open Journal Systems  2.4.4
 All Classes Namespaces Functions Variables Groups Pages
FilterGroupDAO.inc.php
1 <?php
2 
17 import('lib.pkp.classes.filter.FilterGroup');
18 
19 class FilterGroupDAO extends DAO {
23  function FilterGroupDAO() {
24  parent::DAO();
25  }
26 
33  function insertObject(&$filterGroup) {
34  $this->update(
35  sprintf('INSERT INTO filter_groups
36  (symbolic, display_name, description, input_type, output_type)
37  VALUES (?, ?, ?, ?, ?)'),
38  array(
39  $filterGroup->getSymbolic(),
40  $filterGroup->getDisplayName(),
41  $filterGroup->getDescription(),
42  $filterGroup->getInputType(),
43  $filterGroup->getOutputType()
44  )
45  );
46  $filterGroup->setId((int)$this->getInsertId());
47  return $filterGroup->getId();
48  }
49 
55  function &getObject(&$filterGroup) {
56  return $this->getObjectById($filterGroup->getId());
57  }
58 
64  function &getObjectById($filterGroupId) {
65  $result =& $this->retrieve(
66  'SELECT * FROM filter_groups'.
67  ' WHERE filter_group_id = ?', $filterGroupId);
68 
69  $filterGroup = null;
70  if ($result->RecordCount() != 0) {
71  $filterGroup =& $this->_fromRow($result->GetRowAssoc(false));
72  }
73 
74  $result->Close();
75  unset($result);
76 
77  return $filterGroup;
78  }
79 
85  function &getObjectBySymbolic($filterGroupSymbolic) {
86  $result =& $this->retrieve(
87  'SELECT * FROM filter_groups'.
88  ' WHERE symbolic = ?', $filterGroupSymbolic);
89 
90  $filterGroup = null;
91  if ($result->RecordCount() != 0) {
92  $filterGroup =& $this->_fromRow($result->GetRowAssoc(false));
93  }
94 
95  $result->Close();
96  unset($result);
97 
98  return $filterGroup;
99  }
100 
105  function updateObject(&$filterGroup) {
106  $returner = $this->update(
107  'UPDATE filter_groups
108  SET symbolic = ?,
109  display_name = ?,
110  description = ?,
111  input_type = ?,
112  output_type = ?
113  WHERE filter_group_id = ?',
114  array(
115  $filterGroup->getSymbolic(),
116  $filterGroup->getDisplayName(),
117  $filterGroup->getDescription(),
118  $filterGroup->getInputType(),
119  $filterGroup->getOutputType(),
120  (integer)$filterGroup->getId()
121  )
122  );
123  }
124 
130  function deleteObject(&$filterGroup) {
131  $filterDao =& DAORegistry::getDAO('FilterDAO'); /* @var $filterDao FilterDAO */
132 
133  // Check whether there are still templates saved for this filter group.
134  $filterTemplates = $filterDao->getObjectsByGroup($filterGroup->getSymbolic(), null, true, false);
135  if (!empty($filterTemplates)) return false;
136 
137  // Check whether there are still filters saved for this filter group.
138  $filters = $filterDao->getObjectsByGroup($filterGroup->getSymbolic(), null, false, false);
139  if (!empty($filters)) return false;
140 
141  // Delete the group if it's empty.
142  $this->update('DELETE FROM filter_groups WHERE filter_group_id = ?', $filterGroup->getId());
143 
144  return true;
145  }
146 
152  function deleteObjectById($filterGroupId) {
153  $filterGroupId = (int)$filterGroupId;
154  $filterGroup =& $this->getObjectById($filterGroupId);
155  if (!is_a($filterGroup, 'FilterGroup')) return false;
156  return $this->deleteObject($filterGroup);
157  }
158 
164  function deleteObjectBySymbolic($filterGroupSymbolic) {
165  $filterGroup =& $this->getObjectBySymbolic($filterGroupSymbolic);
166  if (!is_a($filterGroup, 'FilterGroup')) return false;
167  return $this->deleteObject($filterGroup);
168  }
169 
170 
171  //
172  // Protected helper methods
173  //
178  function getInsertId() {
179  return parent::getInsertId('filter_groups', 'filter_group_id');
180  }
181 
186  function newDataObject() {
187  return new FilterGroup();
188  }
189 
190 
191  //
192  // Private helper methods
193  //
201  function &_fromRow(&$row) {
202  // Instantiate the filter group.
203  $filterGroup = $this->newDataObject();
204 
205  // Configure the filter group.
206  $filterGroup->setId((int)$row['filter_group_id']);
207  $filterGroup->setSymbolic($row['symbolic']);
208  $filterGroup->setDisplayName($row['display_name']);
209  $filterGroup->setDescription($row['description']);
210  $filterGroup->setInputType($row['input_type']);
211  $filterGroup->setOutputType($row['output_type']);
212 
213  return $filterGroup;
214  }
215 }
216 
217 ?>
deleteObjectBySymbolic($filterGroupSymbolic)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
& getObjectBySymbolic($filterGroupSymbolic)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
insertObject(&$filterGroup)
Operations for retrieving and modifying FilterGroup objects.
updateObject(&$filterGroup)
deleteObjectById($filterGroupId)
deleteObject(&$filterGroup)
& getDAO($name, $dbconn=null)
Class that represents filter groups.
& getObject(&$filterGroup)
& getObjectById($filterGroupId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211