private function _getInternally($submissionId = null, $fileStage = null, $fileId = null, $revision = null, $assocType = null, $assocId = null, $stageId = null, $uploaderUserId = null, $uploaderUserGroupId = null, $reviewRoundId = null, $latestOnly = false, $rangeInfo = null)
{
// Retrieve the base query.
$sql = $this->baseQueryForFileSelection();
// Add the revision round file join if a revision round
// filter was requested.
if ($reviewRoundId) {
$sql .= 'INNER JOIN review_round_files rrf
ON sf.submission_id = rrf.submission_id
AND sf.file_id = rrf.file_id
AND sf.revision ' . ($latestOnly ? '>=' : '=') . ' rrf.revision ';
}
// Filter the query.
list($filterClause, $params) = $this->_buildFileSelectionFilter($submissionId, $fileStage, $fileId, $revision, $assocType, $assocId, $stageId, $uploaderUserId, $uploaderUserGroupId, $reviewRoundId);
// Did the user request all or only the latest revision?
if ($latestOnly) {
// Filter the latest revision of each file.
// NB: We have to do this in the SQL for paging to work
// correctly. We use a partial cartesian join here to
// maintain MySQL 3.23 backwards compatibility. This
// should be ok as we usually only have few revisions per
// file.
$sql .= 'LEFT JOIN submission_files sf2 ON sf.file_id = sf2.file_id AND sf.revision < sf2.revision
WHERE sf2.revision IS NULL AND ' . $filterClause;
} else {
$sql .= 'WHERE ' . $filterClause;
}
// Order the query.
$sql .= ' ORDER BY sf.submission_id ASC, sf.file_stage ASC, sf.file_id ASC, sf.revision DESC';
// Execute the query.
if ($rangeInfo) {
$result = $this->retrieveRange($sql, $params, $rangeInfo);
} else {
$result = $this->retrieve($sql, $params);
}
// Build the result array.
$submissionFiles = array();
while (!$result->EOF) {
// Retrieve the next result row.
$row = $result->GetRowAssoc(false);
// Construct a combined id from file id and revision
// that uniquely identifies the file.
$idAndRevision = $row['submission_file_id'] . '-' . $row['submission_revision'];
// Check for duplicates.
assert(!isset($submissionFiles[$idAndRevision]));
// Instantiate the file and add it to the
// result array with a unique key.
// N.B. The subclass implementation of fromRow receives just the $row
// but calls PKPSubmissionFileDAO::fromRow($row, $fileImplementation) as defined here.
$submissionFiles[$idAndRevision] = $this->fromRow($row);
// Move the query cursor to the next record.
$result->MoveNext();
}
$result->Close();
return $submissionFiles;
}