Open Journal Systems  3.0.0
 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  return $filterGroup;
76  }
77 
83  function &getObjectBySymbolic($filterGroupSymbolic) {
84  $result = $this->retrieve(
85  'SELECT * FROM filter_groups'.
86  ' WHERE symbolic = ?', $filterGroupSymbolic);
87 
88  $filterGroup = null;
89  if ($result->RecordCount() != 0) {
90  $filterGroup = $this->_fromRow($result->GetRowAssoc(false));
91  }
92 
93  $result->Close();
94  return $filterGroup;
95  }
96 
101  function updateObject(&$filterGroup) {
102  $this->update(
103  'UPDATE filter_groups
104  SET symbolic = ?,
105  display_name = ?,
106  description = ?,
107  input_type = ?,
108  output_type = ?
109  WHERE filter_group_id = ?',
110  array(
111  $filterGroup->getSymbolic(),
112  $filterGroup->getDisplayName(),
113  $filterGroup->getDescription(),
114  $filterGroup->getInputType(),
115  $filterGroup->getOutputType(),
116  (integer)$filterGroup->getId()
117  )
118  );
119  }
120 
126  function deleteObject(&$filterGroup) {
127  $filterDao = DAORegistry::getDAO('FilterDAO'); /* @var $filterDao FilterDAO */
128 
129  // Check whether there are still templates saved for this filter group.
130  $filterTemplates = $filterDao->getObjectsByGroup($filterGroup->getSymbolic(), null, true, false);
131  if (!empty($filterTemplates)) return false;
132 
133  // Check whether there are still filters saved for this filter group.
134  $filters = $filterDao->getObjectsByGroup($filterGroup->getSymbolic(), null, false, false);
135  if (!empty($filters)) return false;
136 
137  // Delete the group if it's empty.
138  $this->update('DELETE FROM filter_groups WHERE filter_group_id = ?', $filterGroup->getId());
139 
140  return true;
141  }
142 
148  function deleteObjectById($filterGroupId) {
149  $filterGroupId = (int)$filterGroupId;
150  $filterGroup =& $this->getObjectById($filterGroupId);
151  if (!is_a($filterGroup, 'FilterGroup')) return false;
152  return $this->deleteObject($filterGroup);
153  }
154 
160  function deleteObjectBySymbolic($filterGroupSymbolic) {
161  $filterGroup =& $this->getObjectBySymbolic($filterGroupSymbolic);
162  if (!is_a($filterGroup, 'FilterGroup')) return false;
163  return $this->deleteObject($filterGroup);
164  }
165 
166 
167  //
168  // Protected helper methods
169  //
174  function getInsertId() {
175  return parent::_getInsertId('filter_groups', 'filter_group_id');
176  }
177 
182  function newDataObject() {
183  return new FilterGroup();
184  }
185 
186 
187  //
188  // Private helper methods
189  //
197  function _fromRow($row) {
198  // Instantiate the filter group.
199  $filterGroup = $this->newDataObject();
200 
201  // Configure the filter group.
202  $filterGroup->setId((int)$row['filter_group_id']);
203  $filterGroup->setSymbolic($row['symbolic']);
204  $filterGroup->setDisplayName($row['display_name']);
205  $filterGroup->setDescription($row['description']);
206  $filterGroup->setInputType($row['input_type']);
207  $filterGroup->setOutputType($row['output_type']);
208 
209  return $filterGroup;
210  }
211 }
212 
213 ?>
static & getDAO($name, $dbconn=null)
deleteObjectBySymbolic($filterGroupSymbolic)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
& getObjectBySymbolic($filterGroupSymbolic)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
insertObject(&$filterGroup)
Operations for retrieving and modifying FilterGroup objects.
updateObject(&$filterGroup)
deleteObjectById($filterGroupId)
deleteObject(&$filterGroup)
Class that represents filter groups.
& getObject(&$filterGroup)
& getObjectById($filterGroupId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208