Open Journal Systems  2.4.4
 All Classes Namespaces Functions Variables Groups Pages
ArticleXMLGalleyDAO.inc.php
1 <?php
2 
18 import('classes.article.ArticleGalleyDAO');
19 
20 
23  var $parentPluginName;
24 
28  function ArticleXMLGalleyDAO($parentPluginName) {
29  $this->parentPluginName = $parentPluginName;
30  parent::ArticleGalleyDAO();
31  }
32 
39  function _getXMLGalleyFromId($galleyId, $articleId = null) {
40  $params = array((int) $galleyId);
41  if ($articleId) $params[] = (int) $articleId;
42 
43  // get derived galley from DB
44  $result =& $this->retrieve(
45  'SELECT x.*,
46  x.galley_type AS file_type,
47  g.file_id,
48  g.html_galley,
49  g.style_file_id,
50  g.seq,
51  g.locale,
52  g.remote_url,
53  a.file_name,
54  a.original_file_name,
55  a.file_stage,
56  a.file_type,
57  a.file_size,
58  a.date_uploaded,
59  a.date_modified
60  FROM article_xml_galleys x
61  LEFT JOIN article_galleys g ON (x.galley_id = g.galley_id)
62  LEFT JOIN article_files a ON (g.file_id = a.file_id)
63  WHERE x.galley_id = ?
64  ' . ($articleId?' AND x.article_id = ?':''),
65  $params
66  );
67 
68  // transform row into an ArticleXMLGalley object
69  if ($result->RecordCount() != 0) {
70  $articleGalley =& $this->_returnGalleyFromRow($result->GetRowAssoc(false));
71 
72  $xmlGalleyPlugin =& PluginRegistry::getPlugin('generic', $this->parentPluginName);
73  $xmlGalley = $xmlGalleyPlugin->_returnXMLGalleyFromArticleGalley($articleGalley);
74  return $xmlGalley;
75  }
76  }
77 
81  function appendXMLGalleys($hookName, $args) {
82  $galleys =& $args[0];
83  $articleId =& $args[1];
84 
85  // we have to use this crazy loop because PHP4 can't access objects by reference in foreach()
86  reset($galleys);
87  while (list($key) = each($galleys)) {
88  $galley =& $galleys[$key];
89 
90  // if the galley is an XML galley, append XML-derived galleys
91  if ($galley->getFileType() == "text/xml" || $galley->getFileType() == "application/xml") {
92 
93  // get derived galleys from DB for this article
94  $result =& $this->retrieve(
95  'SELECT galley_id
96  FROM article_xml_galleys x
97  WHERE x.galley_id = ? AND
98  x.article_id = ?
99  ORDER BY galley_id',
100  array($galley->getId(), $articleId)
101  );
102 
103  $xmlGalleyPlugin =& PluginRegistry::getPlugin('generic', $this->parentPluginName);
104  $journal =& Request::getJournal();
105 
106  while (!$result->EOF) {
107  $row = $result->GetRowAssoc(false);
108  $xmlGalley = $this->_getXMLGalleyFromId($row['galley_id'], $articleId);
109 
110 // WARNING: See bug #5152 and note below.
111 /*
112  $xmlGalley->setId($row['xml_galley_id']);
113 
114  // only append PDF galleys if the correct plugin settings are set
115  if ( ($xmlGalleyPlugin->getSetting($journal->getId(), 'nlmPDF') == 1
116  && $xmlGalley->isPdfGalley()) || $xmlGalley->isHTMLGalley()) {
117  array_push($galleys, $xmlGalley);
118  } */
119  $result->moveNext();
120  }
121 
122  // hide source XML galley; this could be made a plugin setting/checkbox
123 // WARNING: See bug #5152 and note below.
124 // if (isset($xmlGalley)) unset($galleys[$key]);
125  }
126  unset($galley);
127  }
128 
129  return true;
130  }
131 
135  function insertXMLGalleys($hookName, $args) {
136  $galley =& $args[0];
137  $galleyId =& $args[1];
138 
139  // If the galley is an XML file, then insert rows in the article_xml_galleys table
140  if ($galley->getLabel() == "XML") {
141 
142  // create an XHTML galley
143  $this->update(
144  'INSERT INTO article_xml_galleys
145  (galley_id, article_id, label, galley_type)
146  VALUES
147  (?, ?, ?, ?)',
148  array(
149  $galleyId,
150  $galley->getArticleId(),
151  'XHTML',
152  'application/xhtml+xml'
153  )
154  );
155 
156 // WARNING: The below code is disabled because of bug #5152. When a galley
157 // exists with the same galley_id as an entry in the article_xml_galleys table,
158 // editing the XML galley will corrupt the entry in the galleys table for the
159 // same galley_id. This has been fixed by retiring the article_xml_galleys
160 // table's xml_galley_id in favour of using the galley_id instead, but this
161 // means that only a single derived galley (=XHTML) is possible for an XML
162 // galley upload.
163 /*
164 
165  // if we have enabled XML-PDF galley generation (plugin setting)
166  // and are using the built-in NLM stylesheet, append a PDF galley as well
167  $journal =& Request::getJournal();
168  $xmlGalleyPlugin =& PluginRegistry::getPlugin('generic', $this->parentPluginName);
169 
170  if ($xmlGalleyPlugin->getSetting($journal->getId(), 'nlmPDF') == 1 &&
171  $xmlGalleyPlugin->getSetting($journal->getId(), 'XSLstylesheet') == 'NLM' ) {
172 
173  // create a PDF galley
174  $this->update(
175  'INSERT INTO article_xml_galleys
176  (galley_id, article_id, label, galley_type)
177  VALUES
178  (?, ?, ?, ?)',
179  array(
180  $galleyId,
181  $galley->getArticleId(),
182  'PDF',
183  'application/pdf'
184  )
185  );
186 
187  }*/
188  return true;
189  }
190  return false;
191  }
192 
197  function deleteXMLGalleys($hookName, $args) {
198  $galleyId =& $args[0];
199  $articleId =& $args[1];
200 
201  if (isset($articleId)) {
202  $this->update(
203  'DELETE FROM article_xml_galleys WHERE galley_id = ? AND article_id = ?',
204  array($galleyId, $articleId)
205  );
206 
207  } else {
208  $this->update(
209  'DELETE FROM article_xml_galleys WHERE galley_id = ?', $galleyId
210  );
211  }
212 
213  }
214 
218  function incrementXMLViews($hookName, $args) {
219  $galleyId =& $args[0];
220 
221  return $this->update(
222  'UPDATE article_xml_galleys SET views = views + 1 WHERE galley_id = ?',
223  $galleyId
224  );
225 
226  }
227 }
228 
229 ?>
insertXMLGalleys($hookName, $args)
& getPlugin($category, $name)
_getXMLGalleyFromId($galleyId, $articleId=null)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
appendXMLGalleys($hookName, $args)
& getJournal()
Definition: Request.inc.php:42
incrementXMLViews($hookName, $args)
Extended DAO methods for XML-derived galleys NB: These require access to a number of hooks in Article...
ArticleXMLGalleyDAO($parentPluginName)
Operations for retrieving and modifying ArticleGalley/ArticleHTMLGalley objects.
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
deleteXMLGalleys($hookName, $args)