Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
SubmissionSearchDAO.inc.php
1 <?php
2 
17 class SubmissionSearchDAO extends DAO {
21  function SubmissionSearchDAO() {
22  parent::DAO();
23  }
24 
30  function insertKeyword($keyword) {
31  static $submissionSearchKeywordIds = array();
32  if (isset($submissionSearchKeywordIds[$keyword])) return $submissionSearchKeywordIds[$keyword];
33  $result = $this->retrieve(
34  'SELECT keyword_id FROM submission_search_keyword_list WHERE keyword_text = ?',
35  $keyword
36  );
37  if($result->RecordCount() == 0) {
38  $result->Close();
39  if ($this->update(
40  'INSERT INTO submission_search_keyword_list (keyword_text) VALUES (?)',
41  $keyword,
42  true,
43  false
44  )) {
45  $keywordId = $this->_getInsertId('submission_search_keyword_list', 'keyword_id');
46  } else {
47  $keywordId = null; // Bug #2324
48  }
49  } else {
50  $keywordId = $result->fields[0];
51  $result->Close();
52  }
53 
54  $submissionSearchKeywordIds[$keyword] = $keywordId;
55 
56  return $keywordId;
57  }
58 
65  function deleteSubmissionKeywords($submissionId, $type = null, $assocId = null) {
66  $sql = 'SELECT object_id FROM submission_search_objects WHERE submission_id = ?';
67  $params = array((int) $submissionId);
68 
69  if (isset($type)) {
70  $sql .= ' AND type = ?';
71  $params[] = (int) $type;
72  }
73 
74  if (isset($assocId)) {
75  $sql .= ' AND assoc_id = ?';
76  $params[] = (int) $assocId;
77  }
78 
79  $result = $this->retrieve($sql, $params);
80  while (!$result->EOF) {
81  $objectId = $result->fields[0];
82  $this->update('DELETE FROM submission_search_object_keywords WHERE object_id = ?', $objectId);
83  $this->update('DELETE FROM submission_search_objects WHERE object_id = ?', $objectId);
84  $result->MoveNext();
85  }
86  $result->Close();
87  }
88 
96  function insertObject($submissionId, $type, $assocId, $keepExisting = false) {
97  $result = $this->retrieve(
98  'SELECT object_id FROM submission_search_objects WHERE submission_id = ? AND type = ? AND assoc_id = ?',
99  array((int) $submissionId, (int) $type, (int) $assocId)
100  );
101  if ($result->RecordCount() == 0) {
102  $this->update(
103  'INSERT INTO submission_search_objects (submission_id, type, assoc_id) VALUES (?, ?, ?)',
104  array((int) $submissionId, (int) $type, (int) $assocId)
105  );
106  $objectId = $this->_getInsertId('submission_search_objects', 'object_id');
107 
108  } else {
109  $objectId = $result->fields[0];
110  $this->update(
111  'DELETE FROM submission_search_object_keywords WHERE object_id = ?',
112  (int) $objectId
113  );
114  }
115  $result->Close();
116  return $objectId;
117  }
118 
126  function insertObjectKeyword($objectId, $keyword, $position) {
127  $keywordId = $this->insertKeyword($keyword);
128  if ($keywordId === null) return null; // Bug #2324
129  $this->update(
130  'INSERT INTO submission_search_object_keywords (object_id, keyword_id, pos) VALUES (?, ?, ?)',
131  array((int) $objectId, (int) $keywordId, (int) $position)
132  );
133  return $keywordId;
134  }
135 
139  function clearIndex() {
140  $this->update('DELETE FROM submission_search_object_keywords');
141  $this->update('DELETE FROM submission_search_objects');
142  $this->update('DELETE FROM submission_search_keyword_list');
143  $this->setCacheDir(Config::getVar('files', 'files_dir') . '/_db');
144  $dataSource = $this->getDataSource();
145  $dataSource->CacheFlush();
146  }
147 }
148 
149 ?>
DAO class for submission search index.
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
insertObjectKeyword($objectId, $keyword, $position)
deleteSubmissionKeywords($submissionId, $type=null, $assocId=null)
static getVar($section, $key, $default=null)
Definition: Config.inc.php:35
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
& getDataSource()
Definition: DAO.inc.php:38
setCacheDir()
Definition: DAO.inc.php:268
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
insertObject($submissionId, $type, $assocId, $keepExisting=false)