18 import(
'lib.pkp.classes.query.Query');
29 function getById($queryId, $assocType =
null, $assocId =
null) {
30 $params = array((
int) $queryId);
32 $params[] = (int) $assocType;
33 $params[] = (int) $assocId;
39 . ($assocType?
' AND assoc_type = ? AND assoc_id = ?':
''),
44 if ($result->RecordCount() != 0) {
45 $returner = $this->
_fromRow($result->GetRowAssoc(
false));
60 function getByAssoc($assocType, $assocId, $stageId =
null, $userId =
null) {
62 $params[] = (int) ASSOC_TYPE_QUERY;
63 if ($userId) $params[] = (int) $userId;
64 $params[] = (int) $assocType;
65 $params[] = (int) $assocId;
66 if ($stageId) $params[] = (int) $stageId;
67 if ($userId) $params[] = (int) $userId;
73 LEFT JOIN notes n ON n.assoc_type = ? AND n.assoc_id = q.query_id
74 ' . ($userId?
'INNER JOIN query_participants qp ON (q.query_id = qp.query_id AND qp.user_id = ?)':
'') .
'
75 WHERE q.assoc_type = ? AND q.assoc_id = ?
76 ' . ($stageId?
' AND q.stage_id = ?':
'') .
78 AND (n.user_id = ? OR n.title IS NOT NULL
79 OR n.contents IS NOT NULL)':
'') .
'
94 $query->setId($row[
'query_id']);
95 $query->setAssocType($row[
'assoc_type']);
96 $query->setAssocId($row[
'assoc_id']);
97 $query->setStageId($row[
'stage_id']);
98 $query->setIsClosed($row[
'closed']);
99 $query->setSequence($row[
'seq']);
120 'INSERT INTO queries (assoc_type, assoc_id, stage_id, closed, seq)
121 VALUES (?, ?, ?, ?, ?)',
123 (
int) $query->getAssocType(),
124 (
int) $query->getAssocId(),
125 (
int) $query->getStageId(),
126 (
int) $query->getIsClosed(),
127 (
float) $query->getSequence(),
131 return $query->getId();
141 'INSERT INTO query_participants
159 'DELETE FROM query_participants WHERE query_id = ? AND user_id = ?',
160 array((
int) $queryId, (
int) $userId)
170 'DELETE FROM query_participants WHERE query_id = ?',
182 $params = array((
int) $queryId);
183 if ($userId) $params[] = (int) $userId;
186 FROM query_participants
187 WHERE query_id = ?' .
188 ($userId?
' AND user_id = ?':
''),
192 while (!$result->EOF) {
193 $row = $result->getRowAssoc(
false);
194 $userIds[] = (int) $row[
'user_id'];
215 (
int) $query->getAssocType(),
216 (
int) $query->getAssocId(),
217 (
int) $query->getStageId(),
218 (
int) $query->getIsClosed(),
219 (
float) $query->getSequence(),
220 (
int) $query->getId()
239 function deleteById($queryId, $assocType =
null, $assocId =
null) {
240 $params = array((
int) $queryId);
242 $params[] = (int) $assocType;
243 $params[] = (int) $assocId;
246 'DELETE FROM queries WHERE query_id = ?' .
247 ($assocType?
' AND assoc_type = ? AND assoc_id = ?':
''),
251 $this->
update(
'DELETE FROM query_participants WHERE query_id = ?', (
int) $queryId);
255 $noteDao->deleteByAssoc(ASSOC_TYPE_QUERY, $queryId);
259 $notifications = $notificationDao->getByAssoc(ASSOC_TYPE_QUERY, $queryId);
260 while ($notification = $notifications->next()) {
261 $notificationDao->deleteObject($notification);
274 'SELECT query_id FROM queries WHERE assoc_type = ? AND assoc_id = ? ORDER BY seq',
275 array((
int) $assocType, (
int) $assocId)
278 for ($i=1; !$result->EOF; $i++) {
279 list($queryId) = $result->fields;
281 'UPDATE queries SET seq = ? WHERE query_id = ?',
307 $queries = $this->
getByAssoc($assocType, $assocId);
308 while ($query = $queries->next()) {