Skip to content

Commit

Permalink
pkp/pkp-lib#513 Various clean-up and standardization
Browse files Browse the repository at this point in the history
  • Loading branch information
asmecher committed May 7, 2015
1 parent ed93478 commit a001ca6
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 122 deletions.
2 changes: 1 addition & 1 deletion classes/article/ArticleDAO.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ function deleteById($submissionId) {
$publishedArticleDao->deletePublishedArticleByArticleId($submissionId);

$articleGalleyDao = DAORegistry::getDAO('ArticleGalleyDAO');
$articleGalleyDao->deleteGalleysByArticle($submissionId);
$articleGalleyDao->deleteByArticleId($submissionId);

$articleSearchDao = DAORegistry::getDAO('ArticleSearchDAO');
$articleSearchDao->deleteSubmissionKeywords($submissionId);
Expand Down
12 changes: 3 additions & 9 deletions classes/article/ArticleGalley.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,15 @@ function ArticleGalley() {
* @return boolean
*/
function isHTMLGalley() {
if ($this->getGalleyType() == 'htmlarticlegalleyplugin')
return true;
else
return false;
return $this->getGalleyType() == 'htmlarticlegalleyplugin';
}

/**
* Check if galley is a PDF galley.
* @return boolean
*/
function isPdfGalley() {
if ($this->getGalleyType() == 'pdfarticlegalleyplugin')
return true;
else
return false;
return $this->getGalleyType() == 'pdfarticlegalleyplugin';
}

/**
Expand Down Expand Up @@ -163,7 +157,7 @@ function getRemoteURL() {
* @return boolean
*/
function getIsAvailable() {
return $this->getData('isAvailable') ? true : false;
return (boolean) $this->getData('isAvailable');
}

/**
Expand Down
81 changes: 26 additions & 55 deletions classes/article/ArticleGalleyDAO.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,12 @@ function pubIdExists($pubIdType, $pubId, $galleyId, $journalId) {
* @param $articleId int
* @return ArticleGalley
*/
function &getGalleyByPubId($pubIdType, $pubId, $articleId = null) {
$galleyFactory =& $this->getGalleysBySetting('pub-id::'.$pubIdType, $pubId, $articleId);
if ($galleyFactory->wasEmpty()) {
$galley = null;
} else {
assert($galleyFactory->getCount() == 1);
$galley =& $galleyFactory->next();
}
function getGalleyByPubId($pubIdType, $pubId, $articleId = null) {
$galleyFactory = $this->getGalleysBySetting('pub-id::'.$pubIdType, $pubId, $articleId);
if ($galleyFactory->wasEmpty()) return null;

return $galley;
assert($galleyFactory->getCount() == 1);
return $galleyFactory->next();
}

/**
Expand Down Expand Up @@ -186,7 +182,7 @@ function getByJournalId($journalId) {
* @param $articleId int
* @return ArticleGalley object
*/
function getGalleyByBestGalleyId($galleyId, $articleId) {
function getByBestGalleyId($galleyId, $articleId) {
$galley = null;
if ($galleyId != '') $galley = $this->getGalleyByPubId('publisher-id', $galleyId, $articleId);
if (!isset($galley) && ctype_digit("$galleyId")) $galley = $this->getById((int) $galleyId, $articleId);
Expand Down Expand Up @@ -217,7 +213,7 @@ function getAdditionalFieldNames() {
* Update the localized fields for this galley.
* @param $galley
*/
function updateLocaleFields(&$galley) {
function updateLocaleFields($galley) {
$this->updateDataObjectSettings('submission_galley_settings', $galley, array(
'galley_id' => $galley->getId()
));
Expand Down Expand Up @@ -254,12 +250,11 @@ function _fromRow($row) {
function insertObject($galley) {
$this->update(
'INSERT INTO submission_galleys
(submission_id, file_id, label, locale, seq, remote_url, is_available, galley_type)
(submission_id, label, locale, seq, remote_url, is_available, galley_type)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?)',
(?, ?, ?, ?, ?, ?, ?)',
array(
(int) $galley->getSubmissionId(),
0,
$galley->getLabel(),
$galley->getLocale(),
$galley->getSeq() == null ? $this->getNextGalleySequence($galley->getSubmissionId()) : $galley->getSeq(),
Expand All @@ -284,7 +279,6 @@ function updateObject($galley) {
$this->update(
'UPDATE submission_galleys
SET
file_id = ?,
label = ?,
locale = ?,
seq = ?,
Expand All @@ -293,7 +287,6 @@ function updateObject($galley) {
galley_type = ?
WHERE galley_id = ?',
array(
0,
$galley->getLabel(),
$galley->getLocale(),
$galley->getSeq(),
Expand All @@ -310,34 +303,31 @@ function updateObject($galley) {
* Delete an ArticleGalley.
* @param $galley ArticleGalley
*/
function deleteGalley(&$galley) {
return $this->deleteGalleyById($galley->getId());
function deleteObject($galley) {
return $this->deleteById($galley->getId());
}

/**
* Delete a galley by ID.
* @param $galleyId int
* @param $articleId int optional
* @param $galleyId int Galley ID.
* @param $articleId int Optional article ID.
*/
function deleteGalleyById($galleyId, $articleId = null) {
function deleteById($galleyId, $articleId = null) {

HookRegistry::call('ArticleGalleyDAO::deleteGalleyById', array(&$galleyId, &$articleId));
HookRegistry::call('ArticleGalleyDAO::deleteById', array(&$galleyId, &$articleId));

if (isset($articleId)) {
$this->update(
'DELETE FROM submission_galleys WHERE galley_id = ? AND submission_id = ?',
array((int) $galleyId, (int) $articleId)
);
} else {
$this->update(
'DELETE FROM submission_galleys WHERE galley_id = ?', (int) $galleyId
);
}
$params = array((int) $galleyId);
if ($articleId) $params[] = (int) $articleId;
$this->update(
'DELETE FROM submission_galleys
WHERE galley_id = ?'
. ($articleId?' AND submission_id = ?':''),
$params
);
if ($this->getAffectedRows()) {
$this->update('DELETE FROM submission_galley_settings WHERE galley_id = ?', array((int) $galleyId));
$submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
// Import constants
import('lib.pkp.classes.submission.SubmissionFile');
import('lib.pkp.classes.submission.SubmissionFile'); // Import constants

$galleyFiles = $submissionFileDao->getLatestRevisionsByAssocId(ASSOC_TYPE_GALLEY, $galleyId, $articleId, SUBMISSION_FILE_PROOF);
foreach ($galleyFiles as $file) {
Expand All @@ -354,32 +344,13 @@ function deleteGalleyById($galleyId, $articleId = null) {
* NOTE that this will not delete article_file entities or the respective files.
* @param $articleId int
*/
function deleteGalleysByArticle($articleId) {
function deleteByArticleId($articleId) {
$galleys = $this->getBySubmissionId($articleId);
while ($galley = $galleys->next()) {
$this->deleteGalleyById($galley->getId(), $articleId);
$this->deleteById($galley->getId(), $articleId);
}
}

/**
* Check if a galley exists with the associated file ID.
* @param $articleId int
* @param $fileId int
* @return boolean
*/
function galleyExistsByFileId($articleId, $fileId) {
$result = $this->retrieve(
'SELECT COUNT(*) FROM submission_galleys
WHERE submission_id = ? AND file_id = ?',
array((int) $articleId, (int) $fileId)
);

$returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;

$result->Close();
return $returner;
}

/**
* Sequentially renumber galleys for an article in their sequence order.
* @param $articleId int
Expand Down
11 changes: 0 additions & 11 deletions classes/article/PublishedArticleDAO.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -710,17 +710,6 @@ function resequencePublishedArticles($sectionId, $issueId) {
$this->flushCache();
}

/**
* Increment the views count for a galley.
* @param $articleId int
*/
function incrementViewsByArticleId($articleId) {
return $this->update(
'UPDATE published_submissions SET views = views + 1 WHERE submission_id = ?',
(int) $articleId
);
}

/**
* Return years of oldest/youngest published article on site or within a journal
* @param $journalId int Optional
Expand Down
33 changes: 1 addition & 32 deletions classes/issue/IssueGalleyDAO.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function deleteObject($galley) {
* @param $issueId int optional
*/
function deleteById($galleyId, $issueId = null) {
HookRegistry::call('IssueGalleyDAO::deleteGalleyById', array(&$galleyId, &$issueId));
HookRegistry::call('IssueGalleyDAO::deleteById', array(&$galleyId, &$issueId));

if (isset($issueId)) {
$this->update(
Expand Down Expand Up @@ -344,37 +344,6 @@ function deleteByIssueId($issueId) {
}
}

/**
* Check if a galley exists with the associated file ID.
* @param $issueId int
* @param $fileId int
* @return boolean
*/
function galleyExistsByFileId($issueId, $fileId) {
$result = $this->retrieve(
'SELECT COUNT(*) FROM issue_galleys
WHERE issue_id = ? AND file_id = ?',
array((int) $issueId, (int) $fileId)
);

$returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
$result->Close();
return $returner;
}

/**
* Increment the views count for a galley.
* @param $galleyId int
*/
function incrementViews($galleyId) {
if ( !HookRegistry::call('IssueGalleyDAO::incrementViews', array(&$galleyId)) ) {
return $this->update(
'UPDATE issue_galleys SET views = views + 1 WHERE galley_id = ?',
(int) $galleyId
);
} else return false;
}

/**
* Sequentially renumber galleys for an issue in their sequence order.
* @param $issueId int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ function update($args, $request) {
function delete($args, $request) {
$articleGalleyDao = DAORegistry::getDAO('ArticleGalleyDAO');
$articleGalley = $this->getAuthorizedContextObject(ASSOC_TYPE_GALLEY);
$articleGalleyDao->deleteGalley($articleGalley);
$articleGalleyDao->deleteObject($articleGalley);
return DAO::getDataChangedEvent();
}

Expand All @@ -256,7 +256,7 @@ function delete($args, $request) {
function setAvailable($args, $request) {
$submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
$articleGalleyDao = DAORegistry::getDAO('ArticleGalleyDAO');
$articleGalley = $articleGalleyDao->getGalleyByBestGalleyId(
$articleGalley = $articleGalleyDao->getByBestGalleyId(
$request->getUserVar('articleGalleyId'),
$submission->getId() // Make sure to validate the context.
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function saveApproveProof($args, $request) {
$user = $request->getUser();

$articleGalleyDao = DAORegistry::getDAO('ArticleGalleyDAO');
$galley = $articleGalleyDao->getGalleyByBestGalleyId($submissionFile->getAssocId(), $submission->getId());
$galley = $articleGalleyDao->getByBestGalleyId($submissionFile->getAssocId(), $submission->getId());

SubmissionLog::logEvent($request, $submission, SUBMISSION_LOG_PROOFS_APPROVED, 'submission.event.proofsApproved', array('formatName' => $galley->getLabel(),'name' => $user->getFullName(), 'username' => $user->getUsername()));
}
Expand Down
3 changes: 0 additions & 3 deletions dbscripts/xml/ojs_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,6 @@
<field name="submission_id" type="I8">
<NOTNULL/>
</field>
<field name="file_id" type="I8">
<NOTNULL/>
</field>
<field name="label" type="C2" size="32"/>
<field name="seq" type="F">
<NOTNULL/>
Expand Down
4 changes: 2 additions & 2 deletions pages/article/ArticleHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function initialize($request, $args) {

$galleyDao = DAORegistry::getDAO('ArticleGalleyDAO');
if ($this->journal->getSetting('enablePublicGalleyId')) {
$this->galley = $galleyDao->getGalleyByBestGalleyId($galleyId, $this->article->getId());
$this->galley = $galleyDao->getByBestGalleyId($galleyId, $this->article->getId());
}

if (!$this->galley) {
Expand Down Expand Up @@ -126,7 +126,7 @@ function view($args, $request) {

$galleyDao = DAORegistry::getDAO('ArticleGalleyDAO');
if ($journal->getSetting('enablePublicGalleyId')) {
$galley = $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getId());
$galley = $galleyDao->getByBestGalleyId($galleyId, $article->getId());
}

if (!isset($galley)) {
Expand Down
2 changes: 1 addition & 1 deletion pages/rt/RTHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function printerFriendly($args, $request) {

$articleGalleyDao = DAORegistry::getDAO('ArticleGalleyDAO');
if ($journal->getSetting('enablePublicGalleyId')) {
$galley = $articleGalleyDao->getGalleyByBestGalleyId($galleyId, $article->getId());
$galley = $articleGalleyDao->getByBestGalleyId($galleyId, $article->getId());
} else {
$galley = $articleGalleyDao->getById($galleyId, $article->getId());
}
Expand Down
10 changes: 5 additions & 5 deletions plugins/importexport/datacite/classes/DOIExportPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ function _displayGalleyList(&$templateMgr, &$journal) {
* @param $journal Journal
* @return array
*/
function &_getUnregisteredIssues(&$journal) {
function _getUnregisteredIssues($journal) {
// Retrieve all issues that have not yet been registered.
$issueDao = DAORegistry::getDAO('IssueDAO'); /* @var $issueDao IssueDAO */
$issues = $issueDao->getBySetting($this->getPluginId(). '::' . DOI_EXPORT_REGDOI, null, $journal->getId());
Expand All @@ -1112,7 +1112,7 @@ function &_getUnregisteredIssues(&$journal) {
* @param $journal Journal
* @return array
*/
function &_getUnregisteredArticles(&$journal) {
function _getUnregisteredArticles($journal) {
// Retrieve all published articles that have not yet been registered.
$publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO'); /* @var $publishedArticleDao PublishedArticleDAO */
$articles = $publishedArticleDao->getBySetting($this->getPluginId(). '::' . DOI_EXPORT_REGDOI, null, $journal->getId());
Expand All @@ -1134,17 +1134,17 @@ function &_getUnregisteredArticles(&$journal) {
* @param $journal Journal
* @return array
*/
function &_getUnregisteredGalleys(&$journal) {
function _getUnregisteredGalleys($journal) {
// Retrieve all galleys that have not yet been registered.
$galleyDao = DAORegistry::getDAO('ArticleGalleyDAO'); /* @var $galleyDao ArticleGalleyDAO */
$galleyFactory = $galleyDao->getGalleysBySetting($this->getPluginId(). '::' . DOI_EXPORT_REGDOI, null, null, $journal->getId());

// Retrieve issues, articles and language for galleys.
$galleyData = array();
while ($galley = $galleyFactory->next()) {
$preparedGalley =& $this->_prepareGalleyData($galley, $journal);
$preparedGalley = $this->_prepareGalleyData($galley, $journal);
if (is_array($preparedGalley)) {
$galleyData[] =& $preparedGalley;
$galleyData[] = $preparedGalley;
}
unset($galley, $preparedGalley);
}
Expand Down

0 comments on commit a001ca6

Please sign in to comment.