first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-06-08 17:09:23 -04:00
commit df3a033196
17887 changed files with 8637778 additions and 0 deletions
@@ -0,0 +1,108 @@
<?php
/**
* @defgroup controlled_vocab Controlled Vocabulary
*/
/**
* @file classes/controlledVocab/ControlledVocab.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2000-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ControlledVocab
*
* @ingroup controlled_vocab
*
* @see ControlledVocabDAO
*
* @brief Basic class describing an controlled vocab.
*/
namespace PKP\controlledVocab;
use PKP\db\DAORegistry;
class ControlledVocab extends \PKP\core\DataObject
{
//
// Get/set methods
//
/**
* get assoc id
*
* @return int
*/
public function getAssocId()
{
return $this->getData('assocId');
}
/**
* set assoc id
*
* @param int $assocId
*/
public function setAssocId($assocId)
{
$this->setData('assocId', $assocId);
}
/**
* Get associated type.
*
* @return int
*/
public function getAssocType()
{
return $this->getData('assocType');
}
/**
* Set associated type.
*
* @param int $assocType
*/
public function setAssocType($assocType)
{
$this->setData('assocType', $assocType);
}
/**
* Get symbolic name.
*
* @return string
*/
public function getSymbolic()
{
return $this->getData('symbolic');
}
/**
* Set symbolic name.
*
* @param string $symbolic
*/
public function setSymbolic($symbolic)
{
$this->setData('symbolic', $symbolic);
}
/**
* Get a list of controlled vocabulary options.
*
* @param string $settingName optional
*
* @return array $controlledVocabEntryId => name
*/
public function enumerate($settingName = 'name')
{
$controlledVocabDao = DAORegistry::getDAO('ControlledVocabDAO'); /** @var ControlledVocabDAO $controlledVocabDao */
return $controlledVocabDao->enumerate($this->getId(), $settingName);
}
}
if (!PKP_STRICT_MODE) {
class_alias('\PKP\controlledVocab\ControlledVocab', '\ControlledVocab');
}
@@ -0,0 +1,274 @@
<?php
/**
* @file classes/controlledVocab/ControlledVocabDAO.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2000-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ControlledVocabDAO
*
* @ingroup controlled_vocab
*
* @see ControlledVocab
*
* @brief Operations for retrieving and modifying ControlledVocab objects.
*/
namespace PKP\controlledVocab;
use PKP\db\DAORegistry;
use PKP\facades\Locale;
class ControlledVocabDAO extends \PKP\db\DAO
{
/**
* Return the Controlled Vocab Entry DAO for this Controlled Vocab.
* Can be subclassed to provide extended DAOs.
*/
public function getEntryDAO()
{
return DAORegistry::getDAO('ControlledVocabEntryDAO');
}
/**
* Retrieve a controlled vocab by controlled vocab ID.
*
* @param int $controlledVocabId
*
* @return ControlledVocab
*/
public function getById($controlledVocabId)
{
$result = $this->retrieve('SELECT * FROM controlled_vocabs WHERE controlled_vocab_id = ?', [(int) $controlledVocabId]);
$row = $result->current();
return $row ? $this->_fromRow((array) $row) : null;
}
/**
* Fetch a controlled vocab by symbolic info, building it if needed.
*
* @param string $symbolic
* @param int $assocType
* @param int $assocId
*
* @return ControlledVocab
*/
public function _build($symbolic, $assocType = 0, $assocId = 0)
{
// Attempt to fetch an existing controlled vocabulary.
$controlledVocab = $this->getBySymbolic($symbolic, $assocType, $assocId);
if ($controlledVocab) {
return $controlledVocab;
}
// Attempt to build a new controlled vocabulary.
$controlledVocab = $this->newDataObject();
$controlledVocab->setSymbolic($symbolic);
$controlledVocab->setAssocType($assocType);
$controlledVocab->setAssocId($assocId);
$id = $this->insertObject($controlledVocab, false);
if ($id !== null) {
return $controlledVocab;
}
// Presume that an error was a duplicate insert.
// In this case, try to fetch an existing controlled
// vocabulary.
return $this->getBySymbolic($symbolic, $assocType, $assocId);
}
/**
* Construct a new data object corresponding to this DAO.
*
* @return ControlledVocab
*/
public function newDataObject()
{
return new ControlledVocab();
}
/**
* Internal function to return an ControlledVocab object from a row.
*
* @param array $row
*
* @return ControlledVocab
*/
public function _fromRow($row)
{
$controlledVocab = $this->newDataObject();
$controlledVocab->setId($row['controlled_vocab_id']);
$controlledVocab->setAssocType($row['assoc_type']);
$controlledVocab->setAssocId($row['assoc_id']);
$controlledVocab->setSymbolic($row['symbolic']);
return $controlledVocab;
}
/**
* Insert a new ControlledVocab.
*
* @param ControlledVocab $controlledVocab
*
* @return ?int New insert ID on insert, or null on error
*/
public function insertObject($controlledVocab, $dieOnError = true)
{
$success = $this->update(
sprintf('INSERT INTO controlled_vocabs
(symbolic, assoc_type, assoc_id)
VALUES
(?, ?, ?)'),
[
$controlledVocab->getSymbolic(),
(int) $controlledVocab->getAssocType(),
(int) $controlledVocab->getAssocId()
],
true, // callHooks
$dieOnError
);
if ($success) {
$controlledVocab->setId($this->getInsertId());
return $controlledVocab->getId();
} else {
return null;
} // An error occurred on insert
}
/**
* Update an existing controlled vocab.
*
* @param ControlledVocab $controlledVocab
*
* @return bool
*/
public function updateObject($controlledVocab)
{
$returner = $this->update(
sprintf('UPDATE controlled_vocabs
SET symbolic = ?,
assoc_type = ?,
assoc_id = ?
WHERE controlled_vocab_id = ?'),
[
$controlledVocab->getSymbolic(),
(int) $controlledVocab->getAssocType(),
(int) $controlledVocab->getAssocId(),
(int) $controlledVocab->getId()
]
);
return $returner;
}
/**
* Delete a controlled vocab.
*
* @param ControlledVocab $controlledVocab
*
* @return bool
*/
public function deleteObject($controlledVocab)
{
return $this->deleteObjectById($controlledVocab->getId());
}
/**
* Delete a controlled vocab by controlled vocab ID.
*
* @param int $controlledVocabId
*
* @return bool
*/
public function deleteObjectById($controlledVocabId)
{
$controlledVocabEntryDao = DAORegistry::getDAO('ControlledVocabEntryDAO'); /** @var ControlledVocabEntryDAO $controlledVocabEntryDao */
$controlledVocabEntries = $this->enumerate($controlledVocabId);
foreach ($controlledVocabEntries as $controlledVocabEntryId => $controlledVocabEntryName) {
$controlledVocabEntryDao->deleteObjectById($controlledVocabEntryId);
}
return $this->update('DELETE FROM controlled_vocabs WHERE controlled_vocab_id = ?', [(int) $controlledVocabId]);
}
/**
* Retrieve an array of controlled vocabs matching the specified
* symbolic name and assoc info.
*
* @param string $symbolic
* @param int $assocType
* @param int $assocId
*
* @return ?ControlledVocab
*/
public function getBySymbolic($symbolic, $assocType = 0, $assocId = 0)
{
$result = $this->retrieve(
'SELECT * FROM controlled_vocabs WHERE symbolic = ? AND assoc_type = ? AND assoc_id = ?',
[$symbolic, (int) $assocType, (int) $assocId]
);
$row = $result->current();
return $row ? $this->_fromRow((array) $row) : null;
}
/**
* Get a list of controlled vocabulary options.
*
* @param string $symbolic
* @param int $assocType
* @param int $assocId
* @param string $settingName optional
*
* @return array $controlledVocabEntryId => $settingValue
*/
public function enumerateBySymbolic($symbolic, $assocType, $assocId, $settingName = 'name')
{
$controlledVocab = $this->getBySymbolic($symbolic, $assocType, $assocId);
if (!$controlledVocab) {
return [];
}
return $controlledVocab->enumerate($settingName);
}
/**
* Get a list of controlled vocabulary options.
*
* @param int $controlledVocabId
* @param string $settingName optional
*
* @return array $controlledVocabEntryId => name
*/
public function enumerate($controlledVocabId, $settingName = 'name')
{
$result = $this->retrieve(
'SELECT e.controlled_vocab_entry_id,
COALESCE(l.setting_value, p.setting_value, n.setting_value) AS setting_value,
COALESCE(l.setting_type, p.setting_type, n.setting_type) AS setting_type
FROM controlled_vocab_entries e
LEFT JOIN controlled_vocab_entry_settings l ON (l.controlled_vocab_entry_id = e.controlled_vocab_entry_id AND l.setting_name = ? AND l.locale = ?)
LEFT JOIN controlled_vocab_entry_settings p ON (p.controlled_vocab_entry_id = e.controlled_vocab_entry_id AND p.setting_name = ? AND p.locale = ?)
LEFT JOIN controlled_vocab_entry_settings n ON (n.controlled_vocab_entry_id = e.controlled_vocab_entry_id AND n.setting_name = ? AND n.locale = ?)
WHERE e.controlled_vocab_id = ?
ORDER BY e.seq',
[
$settingName, Locale::getLocale(), // Current locale
$settingName, Locale::getPrimaryLocale(), // Primary locale
$settingName, '', // No locale
(int) $controlledVocabId
]
);
$returner = [];
foreach ($result as $row) {
$returner[$row->controlled_vocab_entry_id] = $this->convertFromDB(
$row->setting_value,
$row->setting_type
);
}
return $returner;
}
}
if (!PKP_STRICT_MODE) {
class_alias('\PKP\controlledVocab\ControlledVocabDAO', '\ControlledVocabDAO');
}
@@ -0,0 +1,103 @@
<?php
/**
* @file classes/controlledVocab/ControlledVocabEntry.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2000-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ControlledVocabEntry
*
* @ingroup controlled_vocabs
*
* @see ControlledVocabEntryDAO
*
* @brief Basic class describing a controlled vocab.
*/
namespace PKP\controlledVocab;
class ControlledVocabEntry extends \PKP\core\DataObject
{
//
// Get/set methods
//
/**
* Get the ID of the controlled vocab.
*
* @return int
*/
public function getControlledVocabId()
{
return $this->getData('controlledVocabId');
}
/**
* Set the ID of the controlled vocab.
*
* @param int $controlledVocabId
*/
public function setControlledVocabId($controlledVocabId)
{
$this->setData('controlledVocabId', $controlledVocabId);
}
/**
* Get sequence number.
*
* @return float
*/
public function getSequence()
{
return $this->getData('sequence');
}
/**
* Set sequence number.
*
* @param float $sequence
*/
public function setSequence($sequence)
{
$this->setData('sequence', $sequence);
}
/**
* Get the localized name.
*
* @return string
*/
public function getLocalizedName()
{
return $this->getLocalizedData('name');
}
/**
* Get the name of the controlled vocabulary entry.
*
* @param string $locale
*
* @return string
*/
public function getName($locale)
{
return $this->getData('name', $locale);
}
/**
* Set the name of the controlled vocabulary entry.
*
* @param string $name
* @param string $locale
*/
public function setName($name, $locale)
{
$this->setData('name', $name, $locale);
}
}
if (!PKP_STRICT_MODE) {
class_alias('\PKP\controlledVocab\ControlledVocabEntry', '\ControlledVocabEntry');
}
@@ -0,0 +1,297 @@
<?php
/**
* @file classes/controlledVocab/ControlledVocabEntryDAO.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2000-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ControlledVocabEntryDAO
*
* @ingroup controlled_vocab
*
* @see ControlledVocabEntry
*
* @brief Operations for retrieving and modifying ControlledVocabEntry objects
*/
namespace PKP\controlledVocab;
use PKP\core\PKPApplication;
use PKP\core\PKPString;
use PKP\db\DAOResultFactory;
use PKP\db\DBResultRange;
class ControlledVocabEntryDAO extends \PKP\db\DAO
{
/**
* Retrieve a controlled vocab entry by controlled vocab entry ID.
*
* @param int $controlledVocabEntryId
* @param null|mixed $controlledVocabId
*
* @return ControlledVocabEntry
*/
public function getById($controlledVocabEntryId, $controlledVocabId = null)
{
$params = [(int) $controlledVocabEntryId];
if (!empty($controlledVocabId)) {
$params[] = (int) $controlledVocabId;
}
$result = $this->retrieve(
'SELECT * FROM controlled_vocab_entries WHERE controlled_vocab_entry_id = ?' .
(!empty($controlledVocabId) ? ' AND controlled_vocab_id = ?' : ''),
$params
);
$row = $result->current();
return $row ? $this->_fromRow((array) $row) : null;
}
/**
* Retrieve a controlled vocab entry by resolving one of its settings
* to the corresponding entry id.
*
* @param string $settingValue the setting value to be searched for
* @param string $symbolic the vocabulary to be searched, identified by its symbolic name
* @param int $assocType
* @param int $assocId
* @param string $settingName the setting to be searched
* @param string $locale
*
* @return ControlledVocabEntry
*/
public function getBySetting($settingValue, $symbolic, $assocType = 0, $assocId = 0, $settingName = 'name', $locale = '')
{
$result = $this->retrieve(
'SELECT cve.*
FROM controlled_vocabs cv
INNER JOIN controlled_vocab_entries cve ON cv.controlled_vocab_id = cve.controlled_vocab_id
INNER JOIN controlled_vocab_entry_settings cves ON cve.controlled_vocab_entry_id = cves.controlled_vocab_entry_id
WHERE cves.setting_name = ? AND
cves.locale = ? AND
cves.setting_value = ? AND
cv.symbolic = ? AND
cv.assoc_type = ? AND
cv.assoc_id = ?',
[$settingName, $locale, $settingValue, $symbolic, $assocType, $assocId]
);
$row = $result->current();
return $row ? $this->_fromRow((array) $row) : null;
}
/**
* Construct a new data object corresponding to this DAO.
*
* @return ControlledVocabEntry
*/
public function newDataObject()
{
return new ControlledVocabEntry();
}
/**
* Internal function to return a ControlledVocabEntry object from a
* row.
*
* @param array $row
*
* @return ControlledVocabEntry
*/
public function _fromRow($row)
{
$controlledVocabEntry = $this->newDataObject();
$controlledVocabEntry->setControlledVocabId($row['controlled_vocab_id']);
$controlledVocabEntry->setId($row['controlled_vocab_entry_id']);
$controlledVocabEntry->setSequence($row['seq']);
$this->getDataObjectSettings('controlled_vocab_entry_settings', 'controlled_vocab_entry_id', $row['controlled_vocab_entry_id'], $controlledVocabEntry);
return $controlledVocabEntry;
}
/**
* Get the list of fields for which data can be localized.
*
* @return array
*/
public function getLocaleFieldNames()
{
return ['name'];
}
/**
* Update the localized fields for this table
*
* @param object $controlledVocabEntry
*/
public function updateLocaleFields($controlledVocabEntry)
{
$this->updateDataObjectSettings('controlled_vocab_entry_settings', $controlledVocabEntry, [
'controlled_vocab_entry_id' => $controlledVocabEntry->getId()
]);
}
/**
* Insert a new ControlledVocabEntry.
*
* @param ControlledVocabEntry $controlledVocabEntry
*
* @return int Inserted controlled vocabulary entry ID
*/
public function insertObject($controlledVocabEntry)
{
$this->update(
'INSERT INTO controlled_vocab_entries (controlled_vocab_id, seq)
VALUES (?, ?)',
[
(int) $controlledVocabEntry->getControlledVocabId(),
(float) $controlledVocabEntry->getSequence()
]
);
$controlledVocabEntry->setId($this->getInsertId());
$this->updateLocaleFields($controlledVocabEntry);
return (int)$controlledVocabEntry->getId();
}
/**
* Delete a controlled vocab entry.
*
* @param ControlledVocabEntry $controlledVocabEntry
*/
public function deleteObject($controlledVocabEntry)
{
$this->deleteObjectById($controlledVocabEntry->getId());
}
/**
* Delete a controlled vocab entry by controlled vocab entry ID.
*
* @param int $controlledVocabEntryId
*/
public function deleteObjectById($controlledVocabEntryId)
{
$this->update('DELETE FROM controlled_vocab_entry_settings WHERE controlled_vocab_entry_id = ?', [(int) $controlledVocabEntryId]);
$this->update('DELETE FROM controlled_vocab_entries WHERE controlled_vocab_entry_id = ?', [(int) $controlledVocabEntryId]);
}
/**
* Retrieve an iterator of controlled vocabulary entries matching a
* particular controlled vocabulary ID.
*
* @param int $controlledVocabId
* @param ?DBResultRange $rangeInfo
* @param null|mixed $filter
*
* @return DAOResultFactory<ControlledVocabEntry> Object containing matching CVE objects
*/
public function getByControlledVocabId($controlledVocabId, $rangeInfo = null, $filter = null)
{
$params = [(int) $controlledVocabId];
if (!empty($filter)) {
$params[] = "%{$filter}%";
}
$result = $this->retrieveRange(
'SELECT *
FROM controlled_vocab_entries cve ' .
(!empty($filter) ? 'INNER JOIN controlled_vocab_entry_settings cves ON cve.controlled_vocab_entry_id = cves.controlled_vocab_entry_id ' : '') .
'WHERE controlled_vocab_id = ? ' .
(!empty($filter) ? 'AND cves.setting_value LIKE ? ' : '') .
'ORDER BY seq',
$params,
$rangeInfo
);
return new DAOResultFactory($result, $this, '_fromRow');
}
/**
* Retrieve an array of controlled vocab entries that exist for a given context
* (assigned to at least one submission in that context) and which match the
* requested symbolic (eg - keywords/subjects)
*
* @param string $symbolic One of the CONTROLLED_VOCAB_* constants
* @param int $contextId
* @param string $locale
*
* @return DAOResultFactory<ControlledVocabEntry>
*/
public function getByContextId($symbolic, $contextId, $locale, ?string $term = null)
{
$params = [
$symbolic,
PKPApplication::ASSOC_TYPE_PUBLICATION,
$contextId,
$locale
];
$words = array_map(fn (string $word) => '%' . addcslashes($word, '%_') . '%', PKPString::regexp_split('/\s+/', trim($term)));
$termFilter = '';
if (count($words)) {
array_push($params, ...$words);
$condition = 'cves.setting_value LIKE ?';
$termFilter = " AND ({$condition}" . str_repeat(" OR {$condition}", count($words) - 1) . ')';
}
$result = $this->retrieve(
"SELECT cve.*
FROM controlled_vocab_entries AS cve
INNER JOIN controlled_vocabs AS cv ON cv.controlled_vocab_id = cve.controlled_vocab_id
INNER JOIN controlled_vocab_entry_settings AS cves ON cves.controlled_vocab_entry_id = cve.controlled_vocab_entry_id
INNER JOIN publications as p ON p.publication_id = cv.assoc_id
INNER JOIN submissions AS s ON s.submission_id = p.submission_id
WHERE
cv.symbolic = ?
AND cv.assoc_type = ?
AND s.context_id = ?
AND cves.locale = ?
{$termFilter}
ORDER BY
cves.setting_value",
$params
);
return new DAOResultFactory($result, $this, '_fromRow');
}
/**
* Update an existing review form element.
*
* @param ControlledVocabEntry $controlledVocabEntry
*/
public function updateObject($controlledVocabEntry)
{
$this->update(
'UPDATE controlled_vocab_entries
SET controlled_vocab_id = ?,
seq = ?
WHERE controlled_vocab_entry_id = ?',
[
(int) $controlledVocabEntry->getControlledVocabId(),
(float) $controlledVocabEntry->getSequence(),
(int) $controlledVocabEntry->getId()
]
);
$this->updateLocaleFields($controlledVocabEntry);
}
/**
* Sequentially renumber entries in their sequence order.
*
* @param int $controlledVocabId Controlled vocabulary ID
*/
public function resequence($controlledVocabId)
{
$result = $this->retrieve('SELECT controlled_vocab_entry_id FROM controlled_vocab_entries WHERE controlled_vocab_id = ? ORDER BY seq', [(int) $controlledVocabId]);
for ($i = 1; $row = $result->current(); $i++) {
$this->update('UPDATE controlled_vocab_entries SET seq = ? WHERE controlled_vocab_entry_id = ?', [(int) $i, (int) $row->controlled_vocab_entry_id]);
$result->next();
}
}
}
if (!PKP_STRICT_MODE) {
class_alias('\PKP\controlledVocab\ControlledVocabEntryDAO', '\ControlledVocabEntryDAO');
}