17 import(
'lib.pkp.classes.submission.Genre');
18 import(
'lib.pkp.classes.db.DAO');
27 function getById($genreId, $contextId =
null) {
28 $params = array((
int) $genreId);
29 if ($contextId) $params[] = (int) $contextId;
32 'SELECT * FROM genres WHERE genre_id = ?' .
33 ($contextId ?
' AND context_id = ?' :
'') .
38 if ($result->RecordCount() != 0) {
39 $returner = $this->
_fromRow($result->GetRowAssoc(
false));
53 $params = array(1, (
int) $contextId);
57 WHERE enabled = ? AND context_id = ?
75 WHERE enabled = ? AND context_id = ? AND dependent = ?
77 array(1, (
int) $contextId, (
int) $dependentFilesOnly),
94 WHERE enabled = ? AND context_id = ? AND supplementary = ?
96 array(1, (
int) $contextId, (
int) $supplementaryFilesOnly),
111 'SELECT * FROM genres
112 WHERE enabled = ? AND context_id = ? AND dependent = ? AND supplementary = ?
114 array(1, (
int) $contextId, 0, 0),
129 'SELECT * FROM genres WHERE context_id = ? ORDER BY seq',
130 array((
int) $contextId),
144 $params = array($key);
145 if ($contextId) $params[] = (int) $contextId;
147 $sql =
'SELECT * FROM genres WHERE entry_key = ? ' .
148 ($contextId ?
' AND context_id = ?' :
'');
150 $result = $this->
retrieve($sql, $params);
153 if ($result->RecordCount() != 0) {
154 $returner = $this->
_fromRow($result->GetRowAssoc(
false));
165 return array(
'name');
174 'genre_settings', $genre,
175 array(
'genre_id' => $genre->getId())
194 $genre->setId($row[
'genre_id']);
195 $genre->setKey($row[
'entry_key']);
196 $genre->setContextId($row[
'context_id']);
197 $genre->setCategory($row[
'category']);
198 $genre->setDependent($row[
'dependent']);
199 $genre->setSupplementary($row[
'supplementary']);
200 $genre->setSequence($row[
'seq']);
201 $genre->setEnabled($row[
'enabled']);
218 (entry_key, seq, context_id, category, dependent, supplementary)
223 (
float) $genre->getSequence(),
224 (
int) $genre->getContextId(),
225 (
int) $genre->getCategory(),
226 $genre->getDependent() ? 1 : 0,
227 $genre->getSupplementary() ? 1 : 0,
233 return $genre->getId();
252 (
float) $genre->getSequence(),
253 $genre->getDependent() ? 1 : 0,
254 $genre->getSupplementary() ? 1 : 0,
255 $genre->getEnabled() ? 1 : 0,
256 $genre->getCategory(),
257 (
int) $genre->getId(),
277 'UPDATE genres SET enabled = ? WHERE genre_id = ?',
278 array(0, (
int) $genreId)
289 while ($genre = $genres->next()) {
290 $this->
update(
'DELETE FROM genre_settings WHERE genre_id = ?', (
int) $genre->getId());
293 'DELETE FROM genres WHERE context_id = ?', (
int) $contextId
315 $data = $xmlDao->parseStruct(
'registry/genres.xml', array(
'genre'));
316 if (!isset($data[
'genre']))
return false;
319 foreach ($data[
'genre'] as $entry) {
320 $attrs = $entry[
'attributes'];
323 $genre = $this->
getByKey($attrs[
'key'], $contextId);
325 $genre->setContextId($contextId);
326 $genre->setKey($attrs[
'key']);
327 $genre->setCategory($attrs[
'category']);
328 $genre->setDependent($attrs[
'dependent']);
329 $genre->setSupplementary($attrs[
'supplementary']);
330 $genre->setSequence($seq++);
331 foreach ($locales as $locale) {
332 $genre->setName(__($attrs[
'localeKey'], array(), $locale), $locale);
335 if ($genre->getId() > 0) {
336 $genre->setEnabled(1);
349 $defaultKeys = array();
351 $data = $xmlDao->parseStruct(
'registry/genres.xml', array(
'genre'));
352 if (isset($data[
'genre']))
foreach ($data[
'genre'] as $entry) {
353 $attrs = $entry[
'attributes'];
354 $defaultKeys[] = $attrs[
'key'];
367 $params = array($key, (
int) $contextId);
368 if ($genreId) $params[] = (int) $genreId;
370 'SELECT COUNT(*) FROM genres WHERE entry_key = ? AND context_id = ?' . (isset($genreId) ?
' AND genre_id <> ?' :
''),
373 $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true :
false;
383 $this->
update(
'DELETE FROM genre_settings WHERE locale = ?', $locale);