Open Journal Systems  2.4.4
 All Classes Namespaces Functions Variables Groups Pages
ThesisDAO.inc.php
1 <?php
2 
16 import('lib.pkp.classes.db.DAO');
17 
18 /* These constants are used for user-selectable search fields. */
19 define('THESIS_FIELD_FIRSTNAME', 'student_first_name');
20 define('THESIS_FIELD_LASTNAME', 'student_last_name');
21 define('THESIS_FIELD_EMAIL', 'student_email');
22 define('THESIS_FIELD_DEPARTMENT', 'department');
23 define('THESIS_FIELD_UNIVERSITY', 'university');
24 define('THESIS_FIELD_SUBJECT', 'subject');
25 define('THESIS_FIELD_TITLE', 'title');
26 define('THESIS_FIELD_ABSTRACT', 'abstract');
27 define('THESIS_FIELD_NONE', null);
28 
29 /* These constants are used for sorting thesis abstracts. */
30 define('THESIS_ORDER_SUBMISSION_DATE_ASC', 1);
31 define('THESIS_ORDER_SUBMISSION_DATE_DESC', 2);
32 define('THESIS_ORDER_APPROVAL_DATE_ASC', 3);
33 define('THESIS_ORDER_APPROVAL_DATE_DESC', 4);
34 define('THESIS_ORDER_LASTNAME_ASC', 5);
35 define('THESIS_ORDER_LASTNAME_DESC', 6);
36 define('THESIS_ORDER_TITLE_ASC', 7);
37 define('THESIS_ORDER_TITLE_DESC', 8);
38 
39 class ThesisDAO extends DAO {
41  var $parentPluginName;
42 
46  function ThesisDAO($parentPluginName) {
47  $this->parentPluginName = $parentPluginName;
48  parent::DAO();
49  }
50 
56  function &getThesis($thesisId) {
57  $result =& $this->retrieve(
58  'SELECT * FROM theses WHERE thesis_id = ?', $thesisId
59  );
60 
61  $returner = null;
62  if ($result->RecordCount() != 0) {
63  $returner =& $this->_returnThesisFromRow($result->GetRowAssoc(false));
64  }
65  $result->Close();
66  return $returner;
67  }
68 
74  function &getMostRecentActiveThesisByJournalId($journalId) {
75  $result =& $this->retrieve(
76  'SELECT * FROM theses WHERE status = ? AND journal_id = ? ORDER BY date_submitted DESC, thesis_id DESC LIMIT 1', array(THESIS_STATUS_ACTIVE, $journalId)
77  );
78 
79  $returner = null;
80  if ($result->RecordCount() != 0) {
81  $returner =& $this->_returnThesisFromRow($result->GetRowAssoc(false));
82  }
83  $result->Close();
84  return $returner;
85  }
86 
92  function getThesisJournalId($thesisId) {
93  $result =& $this->retrieve(
94  'SELECT journal_id FROM theses WHERE thesis_id = ?', $thesisId
95  );
96 
97  return isset($result->fields[0]) ? $result->fields[0] : 0;
98  }
99 
105  function isThesisActive($thesisId) {
106  $thesisPlugin =& PluginRegistry::getPlugin('generic', $this->parentPluginName);
107  $thesisPlugin->import('Thesis');
108 
109  $result =& $this->retrieve(
110  'SELECT thesis_id FROM theses WHERE status = ? AND thesis_id = ?', array(THESIS_STATUS_ACTIVE, $thesisId)
111  );
112 
113  return isset($result->fields[0]) ? true : false;
114  }
115 
121  function &_returnThesisFromRow(&$row) {
122  $thesisPlugin =& PluginRegistry::getPlugin('generic', $this->parentPluginName);
123  $thesisPlugin->import('Thesis');
124 
125  $thesis = new Thesis();
126  $thesis->setId($row['thesis_id']);
127  $thesis->setJournalId($row['journal_id']);
128  $thesis->setStatus($row['status']);
129  $thesis->setDegree($row['degree']);
130  $thesis->setDegreeName($row['degree_name']);
131  $thesis->setDepartment($row['department']);
132  $thesis->setUniversity($row['university']);
133  $thesis->setDateApproved($this->dateFromDB($row['date_approved']));
134  $thesis->setTitle($row['title']);
135  $thesis->setAbstract($row['abstract']);
136  $thesis->setUrl($row['url']);
137  $thesis->setComment($row['comment']);
138  $thesis->setStudentFirstName($row['student_first_name']);
139  $thesis->setStudentMiddleName($row['student_middle_name']);
140  $thesis->setStudentLastName($row['student_last_name']);
141  $thesis->setStudentEmail($row['student_email']);
142  $thesis->setStudentEmailPublish($row['student_email_publish']);
143  $thesis->setStudentBio($row['student_bio']);
144  $thesis->setSupervisorFirstName($row['supervisor_first_name']);
145  $thesis->setSupervisorMiddleName($row['supervisor_middle_name']);
146  $thesis->setSupervisorLastName($row['supervisor_last_name']);
147  $thesis->setSupervisorEmail($row['supervisor_email']);
148  $thesis->setDiscipline($row['discipline']);
149  $thesis->setSubjectClass($row['subject_class']);
150  $thesis->setSubject($row['subject']);
151  $thesis->setCoverageGeo($row['coverage_geo']);
152  $thesis->setCoverageChron($row['coverage_chron']);
153  $thesis->setCoverageSample($row['coverage_sample']);
154  $thesis->setMethod($row['method']);
155  $thesis->setLanguage($row['language']);
156  $thesis->setDateSubmitted($row['date_submitted']);
157 
158  return $thesis;
159  }
160 
166  function insertThesis(&$thesis) {
167  $ret = $this->update(
168  sprintf('INSERT INTO theses
169  (journal_id, status, degree, degree_name, department, university, date_approved, title, abstract, url, comment, student_first_name, student_middle_name, student_last_name, student_email, student_email_publish, student_bio, supervisor_first_name, supervisor_middle_name, supervisor_last_name, supervisor_email, discipline, subject_class, subject, coverage_geo, coverage_chron, coverage_sample, method, language, date_submitted)
170  VALUES
171  (?, ?, ?, ?, ?, ?, %s, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, %s)',
172  $this->dateToDB($thesis->getDateApproved()), $this->datetimeToDB($thesis->getDateSubmitted())),
173  array(
174  $thesis->getJournalId(),
175  $thesis->getStatus(),
176  $thesis->getDegree(),
177  $thesis->getDegreeName(),
178  $thesis->getDepartment(),
179  $thesis->getUniversity(),
180  $thesis->getTitle(),
181  $thesis->getAbstract(),
182  $thesis->getUrl(),
183  $thesis->getComment(),
184  $thesis->getStudentFirstName(),
185  $thesis->getStudentMiddleName(),
186  $thesis->getStudentLastName(),
187  $thesis->getStudentEmail(),
188  $thesis->getStudentEmailPublish(),
189  $thesis->getStudentBio(),
190  $thesis->getSupervisorFirstName(),
191  $thesis->getSupervisorMiddleName(),
192  $thesis->getSupervisorLastName(),
193  $thesis->getSupervisorEmail(),
194  $thesis->getDiscipline(),
195  $thesis->getSubjectClass(),
196  $thesis->getSubject(),
197  $thesis->getCoverageGeo(),
198  $thesis->getCoverageChron(),
199  $thesis->getCoverageSample(),
200  $thesis->getMethod(),
201  $thesis->getLanguage()
202  )
203  );
204  $thesis->setId($this->getInsertThesisId());
205  return $thesis->getId();
206  }
207 
213  function updateThesis(&$thesis) {
214  return $this->update(
215  sprintf('UPDATE theses
216  SET
217  journal_id = ?,
218  status = ?,
219  degree = ?,
220  degree_name = ?,
221  department = ?,
222  university = ?,
223  date_approved = %s,
224  title = ?,
225  abstract = ?,
226  url = ?,
227  comment = ?,
228  student_first_name = ?,
229  student_middle_name = ?,
230  student_last_name = ?,
231  student_email = ?,
232  student_email_publish = ?,
233  student_bio = ?,
234  supervisor_first_name = ?,
235  supervisor_middle_name = ?,
236  supervisor_last_name = ?,
237  supervisor_email = ?,
238  discipline = ?,
239  subject_class = ?,
240  subject = ?,
241  coverage_geo = ?,
242  coverage_chron = ?,
243  coverage_sample = ?,
244  method = ?,
245  language = ?,
246  date_submitted = %s
247  WHERE thesis_id = ?',
248  $this->dateToDB($thesis->getDateApproved()), $this->datetimeToDB($thesis->getDateSubmitted())),
249  array(
250  $thesis->getJournalId(),
251  $thesis->getStatus(),
252  $thesis->getDegree(),
253  $thesis->getDegreeName(),
254  $thesis->getDepartment(),
255  $thesis->getUniversity(),
256  $thesis->getTitle(),
257  $thesis->getAbstract(),
258  $thesis->getUrl(),
259  $thesis->getComment(),
260  $thesis->getStudentFirstName(),
261  $thesis->getStudentMiddleName(),
262  $thesis->getStudentLastName(),
263  $thesis->getStudentEmail(),
264  $thesis->getStudentEmailPublish(),
265  $thesis->getStudentBio(),
266  $thesis->getSupervisorFirstName(),
267  $thesis->getSupervisorMiddleName(),
268  $thesis->getSupervisorLastName(),
269  $thesis->getSupervisorEmail(),
270  $thesis->getDiscipline(),
271  $thesis->getSubjectClass(),
272  $thesis->getSubject(),
273  $thesis->getCoverageGeo(),
274  $thesis->getCoverageChron(),
275  $thesis->getCoverageSample(),
276  $thesis->getMethod(),
277  $thesis->getLanguage(),
278  $thesis->getId()
279  )
280  );
281  }
282 
288  function deleteThesis($thesis) {
289  return $this->deleteThesisById($thesis->getId());
290  }
291 
297  function deleteThesisById($thesisId) {
298  return $this->update(
299  'DELETE FROM theses WHERE thesis_id = ?', $thesisId
300  );
301  }
302 
307  function deleteThesesByJournal($journalId) {
308  return $this->update(
309  'DELETE FROM theses WHERE journal_id = ?', $journalId
310  );
311  }
312 
325  function &getThesesByJournalId($journalId, $searchType = null, $search = null, $searchMatch = null, $dateFrom = null, $dateTo = null, $resultOrder = null, $rangeInfo = null) {
326  $paramArray = array((int) $journalId);
327  $searchSql = '';
328 
329  if (!empty($search)) switch ($searchType) {
330  case THESIS_FIELD_FIRSTNAME:
331  $searchSql = 'AND LOWER(student_first_name) ' . ($searchMatch=='is'?'=':'LIKE') . ' LOWER(?)';
332  $paramArray[] = ($searchMatch=='is'?$search:'%' . $search . '%');
333  break;
334  case THESIS_FIELD_LASTNAME:
335  $searchSql = 'AND LOWER(student_last_name) ' . ($searchMatch=='is'?'=':'LIKE') . ' LOWER(?)';
336  $paramArray[] = ($searchMatch=='is'?$search:'%' . $search . '%');
337  break;
338  case THESIS_FIELD_EMAIL:
339  $searchSql = 'AND LOWER(student_email) ' . ($searchMatch=='is'?'=':'LIKE') . ' LOWER(?)';
340  $paramArray[] = ($searchMatch=='is'?$search:'%' . $search . '%');
341  break;
342  case THESIS_FIELD_DEPARTMENT:
343  $searchSql = 'AND LOWER(department) ' . ($searchMatch=='is'?'=':'LIKE') . ' LOWER(?)';
344  $paramArray[] = ($searchMatch=='is'?$search:'%' . $search . '%');
345  break;
346  case THESIS_FIELD_UNIVERSITY:
347  $searchSql = 'AND LOWER(university) ' . ($searchMatch=='is'?'=':'LIKE') . ' LOWER(?)';
348  $paramArray[] = ($searchMatch=='is'?$search:'%' . $search . '%');
349  break;
350  case THESIS_FIELD_TITLE:
351  $searchSql = 'AND LOWER(title) ' . ($searchMatch=='is'?'=':'LIKE') . ' LOWER(?)';
352  $paramArray[] = ($searchMatch=='is'?$search:'%' . $search . '%');
353  break;
354  case THESIS_FIELD_SUBJECT:
355  $searchSql = 'AND LOWER(subject) ' . ($searchMatch=='is'?'=':'LIKE') . ' LOWER(?)';
356  $paramArray[] = ($searchMatch=='is'?$search:'%' . $search . '%');
357  break;
358  case THESIS_FIELD_ABSTRACT:
359  $searchSql = 'AND LOWER(abstract) ' . ($searchMatch=='is'?'=':'LIKE') . ' LOWER(?)';
360  $paramArray[] = ($searchMatch=='is'?$search:'%' . $search . '%');
361  break;
362  }
363 
364  if (!empty($dateFrom) || !empty($dateTo)) {
365  if (!empty($dateFrom)) {
366  $searchSql .= ' AND date_approved >= ' . $this->datetimeToDB($dateFrom);
367  }
368  if (!empty($dateTo)) {
369  $searchSql .= ' AND date_approved <= ' . $this->datetimeToDB($dateTo);
370  }
371  }
372 
373  switch ($resultOrder) {
374  case THESIS_ORDER_SUBMISSION_DATE_ASC:
375  $searchSql .= ' ORDER BY date_submitted ASC, thesis_id ASC';
376  break;
377  case THESIS_ORDER_SUBMISSION_DATE_DESC:
378  $searchSql .= ' ORDER BY date_submitted DESC, thesis_id DESC';
379  break;
380  case THESIS_ORDER_APPROVAL_DATE_ASC:
381  $searchSql .= ' ORDER BY date_approved ASC, student_last_name ASC, title ASC';
382  break;
383  case THESIS_ORDER_APPROVAL_DATE_DESC:
384  $searchSql .= ' ORDER BY date_approved DESC, student_last_name ASC, title ASC';
385  break;
386  case THESIS_ORDER_LASTNAME_ASC:
387  $searchSql .= ' ORDER BY student_last_name ASC, title ASC';
388  break;
389  case THESIS_ORDER_LASTNAME_DESC:
390  $searchSql .= ' ORDER BY student_last_name DESC, title ASC';
391  break;
392  case THESIS_ORDER_TITLE_ASC:
393  $searchSql .= ' ORDER BY title ASC, student_last_name ASC';
394  break;
395  case THESIS_ORDER_TITLE_DESC:
396  $searchSql .= ' ORDER BY title DESC, student_last_name ASC';
397  break;
398  default:
399  $searchSql .= ' ORDER BY date_submitted DESC, thesis_id DESC';
400  }
401 
402  $result =& $this->retrieveRange(
403  'SELECT * FROM theses WHERE journal_id = ? ' . $searchSql,
404  $paramArray,
405  $rangeInfo
406  );
407 
408  $returner = new DAOResultFactory($result, $this, '_returnThesisFromRow');
409  return $returner;
410  }
411 
424  function &getActiveThesesByJournalId($journalId, $searchType = null, $search = null, $searchMatch = null, $dateFrom = null, $dateTo = null, $resultOrder = null, $rangeInfo = null) {
425  $thesisPlugin =& PluginRegistry::getPlugin('generic', $this->parentPluginName);
426  $thesisPlugin->import('Thesis');
427 
428  $paramArray = array(THESIS_STATUS_ACTIVE, (int) $journalId);
429  $searchSql = '';
430 
431  if (!empty($search)) switch ($searchType) {
432  case THESIS_FIELD_FIRSTNAME:
433  $searchSql = 'AND LOWER(student_first_name) ' . ($searchMatch=='is'?'=':'LIKE') . ' LOWER(?)';
434  $paramArray[] = ($searchMatch=='is'?$search:'%' . $search . '%');
435  break;
436  case THESIS_FIELD_LASTNAME:
437  $searchSql = 'AND LOWER(student_last_name) ' . ($searchMatch=='is'?'=':'LIKE') . ' LOWER(?)';
438  $paramArray[] = ($searchMatch=='is'?$search:'%' . $search . '%');
439  break;
440  case THESIS_FIELD_EMAIL:
441  $searchSql = 'AND LOWER(student_email) ' . ($searchMatch=='is'?'=':'LIKE') . ' LOWER(?)';
442  $paramArray[] = ($searchMatch=='is'?$search:'%' . $search . '%');
443  break;
444  case THESIS_FIELD_DEPARTMENT:
445  $searchSql = 'AND LOWER(department) ' . ($searchMatch=='is'?'=':'LIKE') . ' LOWER(?)';
446  $paramArray[] = ($searchMatch=='is'?$search:'%' . $search . '%');
447  break;
448  case THESIS_FIELD_UNIVERSITY:
449  $searchSql = 'AND LOWER(university) ' . ($searchMatch=='is'?'=':'LIKE') . ' LOWER(?)';
450  $paramArray[] = ($searchMatch=='is'?$search:'%' . $search . '%');
451  break;
452  case THESIS_FIELD_TITLE:
453  $searchSql = 'AND LOWER(title) ' . ($searchMatch=='is'?'=':'LIKE') . ' LOWER(?)';
454  $paramArray[] = ($searchMatch=='is'?$search:'%' . $search . '%');
455  break;
456  case THESIS_FIELD_SUBJECT:
457  $searchSql = 'AND LOWER(subject) ' . ($searchMatch=='is'?'=':'LIKE') . ' LOWER(?)';
458  $paramArray[] = ($searchMatch=='is'?$search:'%' . $search . '%');
459  break;
460  case THESIS_FIELD_ABSTRACT:
461  $searchSql = 'AND LOWER(abstract) ' . ($searchMatch=='is'?'=':'LIKE') . ' LOWER(?)';
462  $paramArray[] = ($searchMatch=='is'?$search:'%' . $search . '%');
463  break;
464  }
465 
466  if (!empty($dateFrom) || !empty($dateTo)) {
467  if (!empty($dateFrom)) {
468  $searchSql .= ' AND date_approved >= ' . $this->datetimeToDB($dateFrom);
469  }
470  if (!empty($dateTo)) {
471  $searchSql .= ' AND date_approved <= ' . $this->datetimeToDB($dateTo);
472  }
473  }
474 
475  switch ($resultOrder) {
476  case THESIS_ORDER_SUBMISSION_DATE_ASC:
477  $searchSql .= ' ORDER BY date_submitted ASC, thesis_id ASC';
478  break;
479  case THESIS_ORDER_SUBMISSION_DATE_DESC:
480  $searchSql .= ' ORDER BY date_submitted DESC, thesis_id DESC';
481  break;
482  case THESIS_ORDER_APPROVAL_DATE_ASC:
483  $searchSql .= ' ORDER BY date_approved ASC, student_last_name ASC, title ASC';
484  break;
485  case THESIS_ORDER_APPROVAL_DATE_DESC:
486  $searchSql .= ' ORDER BY date_approved DESC, student_last_name ASC, title ASC';
487  break;
488  case THESIS_ORDER_LASTNAME_ASC:
489  $searchSql .= ' ORDER BY student_last_name ASC, title ASC';
490  break;
491  case THESIS_ORDER_LASTNAME_DESC:
492  $searchSql .= ' ORDER BY student_last_name DESC, title ASC';
493  break;
494  case THESIS_ORDER_TITLE_ASC:
495  $searchSql .= ' ORDER BY title ASC, student_last_name ASC';
496  break;
497  case THESIS_ORDER_TITLE_DESC:
498  $searchSql .= ' ORDER BY title DESC, student_last_name ASC';
499  break;
500  default:
501  $searchSql .= ' ORDER BY date_submitted DESC, thesis_id DESC';
502  }
503 
504  $result =& $this->retrieveRange(
505  'SELECT * FROM theses WHERE status = ? AND journal_id = ? ' . $searchSql,
506  $paramArray,
507  $rangeInfo
508  );
509 
510  $returner = new DAOResultFactory($result, $this, '_returnThesisFromRow');
511  return $returner;
512  }
513 
518  function getInsertThesisId() {
519  return $this->getInsertId('theses', 'thesis_id');
520  }
521 }
522 
523 ?>
getThesisJournalId($thesisId)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
& getPlugin($category, $name)
deleteThesesByJournal($journalId)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
getInsertId($table= '', $id= '', $callHooks=true)
Definition: DAO.inc.php:252
deleteThesis($thesis)
dateToDB($d)
Definition: DAO.inc.php:306
ThesisDAO($parentPluginName)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
insertThesis(&$thesis)
& _returnThesisFromRow(&$row)
& getMostRecentActiveThesisByJournalId($journalId)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
& getThesesByJournalId($journalId, $searchType=null, $search=null, $searchMatch=null, $dateFrom=null, $dateTo=null, $resultOrder=null, $rangeInfo=null)
isThesisActive($thesisId)
& getThesis($thesisId)
Operations for retrieving and modifying Thesis objects.
datetimeToDB($dt)
Definition: DAO.inc.php:296
Basic class describing a thesis.
Definition: Thesis.inc.php:24
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
updateThesis(&$thesis)
& getActiveThesesByJournalId($journalId, $searchType=null, $search=null, $searchMatch=null, $dateFrom=null, $dateTo=null, $resultOrder=null, $rangeInfo=null)
deleteThesisById($thesisId)
dateFromDB($d)
Definition: DAO.inc.php:326