17 import (
'lib.pkp.classes.context.Category');
27 function getById($categoryId, $contextId =
null, $parentId =
null) {
28 $params = array((
int) $categoryId);
29 if ($contextId) $params[] = (int) $contextId;
30 if ($parentId) $params[] = (int) $parentId;
36 ' . ($contextId?
' AND context_id = ?':
'') .
'
37 ' . ($parentId?
' AND parent_id = ?':
''),
42 if ($result->RecordCount() != 0) {
43 $returner = $this->
_fromRow($result->GetRowAssoc(
false));
58 'SELECT * FROM categories WHERE path = ? AND context_id = ?',
59 array((
string) $path, (
int) $contextId)
62 if ($result->RecordCount() != 0) {
63 $returner = $this->
_fromRow($result->GetRowAssoc(
false));
77 function getByTitle($categoryTitle, $contextId, $locale =
null) {
78 $params = array(
'title', $categoryTitle, (
int) $contextId);
79 if ($locale) $params[] = $locale;
85 WHERE l.category_id = a.category_id AND
86 l.setting_name = ? AND
89 ' . ($locale?
' AND locale = ?':
'') .
'
95 if ($result->RecordCount() != 0) {
96 $returner = $this->
_fromRow($result->GetRowAssoc(
false));
113 INNER JOIN publication_categories pc ON (pc.category_id = c.category_id)
114 WHERE pc.publication_id = ?',
128 'SELECT COUNT(*) FROM categories WHERE path = ?', $path
130 $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true :
false;
152 $category->setId($row[
'category_id']);
153 $category->setContextId($row[
'context_id']);
154 $category->setParentId($row[
'parent_id']);
155 $category->setPath($row[
'path']);
156 $category->setImage(unserialize($row[
'image']));
157 $category->setSequence($row[
'seq']);
171 return array(
'title',
'description');
180 parent::getAdditionalFieldNames(),
193 'category_settings', $category,
195 'category_id' => $category->getId()
207 'INSERT INTO categories
208 (context_id, parent_id, path, image, seq)
212 (
int) $category->getContextId(),
213 (
int) $category->getParentId(),
214 $category->getPath(),
215 serialize($category->getImage() ? $category->getImage() : array()),
216 (
int) $category->getSequence()
222 return $category->getId();
230 $returner = $this->
update(
237 WHERE category_id = ?',
239 (
int) $category->getContextId(),
240 (
int) $category->getParentId(),
241 $category->getPath(),
242 serialize($category->getImage() ? $category->getImage() : array()),
243 (
int) $category->getSequence(),
244 (
int) $category->getId()
257 $params = array((
int) $contextId);
258 if ($parentCategoryId) $params[] = (int) $parentCategoryId;
260 'SELECT category_id FROM categories WHERE context_id = ?' .
261 ($parentCategoryId?
' AND parent_id = ?':
''),
265 for ($i=1; !$result->EOF; $i++) {
266 list($categoryId) = $result->fields;
268 'UPDATE categories SET seq = ? WHERE category_id = ?',
288 $category->getContextId()
298 $params = array((
int) $categoryId);
299 if ($contextId) $params[] = (int) $contextId;
302 'DELETE FROM categories
303 WHERE category_id = ?
304 ' . ($contextId?
' AND context_id = ?':
''),
312 'DELETE FROM category_settings WHERE category_id = ?',
313 array((
int) $categoryId)
318 'DELETE FROM publication_categories WHERE category_id = ?',
319 array((
int) $categoryId)
332 while ($category = $categories->next()) {
345 'INSERT INTO publication_categories (category_id, publication_id)
347 array((
int) $categoryId, (
int) $publicationId)
358 'DELETE FROM publication_categories WHERE publication_id = ?',
359 array((
int) $publicationId)
375 LEFT JOIN categories pc ON (pc.category_id = c.parent_id)
376 WHERE c.context_id = ?
377 ORDER BY (COALESCE((pc.seq * 8192) + pc.category_id, 0) * 8192) + CASE WHEN pc.category_id IS NULL THEN 8192 * ((c.seq * 8192) + c.category_id) ELSE c.seq END',
378 array((
int) $contextId)
393 WHERE context_id = ?',
397 $returner = $result->fields[0];
410 $params = array((
int) $parentId);
411 if ($contextId) $params[] = (int) $contextId;
417 ' . ($contextId?
' AND context_id = ?':
'') .
'
429 return $this->
_getInsertId(
'categories',
'category_id');