first commit
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/navigationMenu/NavigationMenu.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 NavigationMenu
|
||||
*
|
||||
* @ingroup navigationMenu
|
||||
*
|
||||
* @see NavigationMenuDAO
|
||||
*
|
||||
* @brief Class describing a NavigationMenu.
|
||||
*/
|
||||
|
||||
namespace PKP\navigationMenu;
|
||||
|
||||
class NavigationMenu extends \PKP\core\DataObject
|
||||
{
|
||||
/** @var array $menuTree Hierarchical array of NavigationMenuItems */
|
||||
public $menuTree = null;
|
||||
|
||||
//
|
||||
// Get/set methods
|
||||
//
|
||||
|
||||
/**
|
||||
* Get contextId of this NavigationMenu
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getContextId()
|
||||
{
|
||||
return $this->getData('contextId');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set contextId of this NavigationMenu
|
||||
*
|
||||
* @param int $contextId
|
||||
*/
|
||||
public function setContextId($contextId)
|
||||
{
|
||||
$this->setData('contextId', $contextId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title of this NavigationMenu. Not localized.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->getData('title');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title of this NavigationMenu. Not localized.
|
||||
*
|
||||
* @param string $title
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->setData('title', $title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get areaName of this NavigationMenu. Not localized.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAreaName()
|
||||
{
|
||||
return $this->getData('areaName');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set navigationArea name of this NavigationMenu. Not localized.
|
||||
*
|
||||
* @param string $areaName
|
||||
*/
|
||||
public function setAreaName($areaName)
|
||||
{
|
||||
$this->setData('areaName', $areaName);
|
||||
}
|
||||
}
|
||||
|
||||
if (!PKP_STRICT_MODE) {
|
||||
class_alias('\PKP\navigationMenu\NavigationMenu', '\NavigationMenu');
|
||||
}
|
||||
@@ -0,0 +1,352 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/navigationMenu/NavigationMenuDAO.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 NavigationMenuDAO
|
||||
*
|
||||
* @ingroup navigationMenu
|
||||
*
|
||||
* @see NavigationMenu
|
||||
*
|
||||
* @brief Operations for retrieving and modifying NavigationMenu objects.
|
||||
*/
|
||||
|
||||
namespace PKP\navigationMenu;
|
||||
|
||||
use APP\core\Services;
|
||||
use PKP\cache\CacheManager;
|
||||
use PKP\cache\GenericCache;
|
||||
use PKP\db\DAORegistry;
|
||||
use PKP\db\DAOResultFactory;
|
||||
use PKP\site\SiteDAO;
|
||||
use PKP\xml\PKPXMLParser;
|
||||
|
||||
class NavigationMenuDAO extends \PKP\db\DAO
|
||||
{
|
||||
/**
|
||||
* Generate a new data object.
|
||||
*
|
||||
* @return NavigationMenu
|
||||
*/
|
||||
public function newDataObject()
|
||||
{
|
||||
return new NavigationMenu();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a navigation menu by navigation menu ID.
|
||||
*
|
||||
* @param int $navigationMenuId navigation menu ID
|
||||
* @param int $contextId Context Id
|
||||
*
|
||||
* @return ?NavigationMenu
|
||||
*/
|
||||
public function getById($navigationMenuId, $contextId = null)
|
||||
{
|
||||
$params = [(int) $navigationMenuId];
|
||||
if ($contextId !== null) {
|
||||
$params[] = (int) $contextId;
|
||||
}
|
||||
$result = $this->retrieve(
|
||||
'SELECT * FROM navigation_menus WHERE navigation_menu_id = ?' .
|
||||
($contextId !== null ? ' AND context_id = ?' : ''),
|
||||
$params
|
||||
);
|
||||
|
||||
$row = (array) $result->current();
|
||||
return $row ? $this->_fromRow($row) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a navigation menu by context Id.
|
||||
*
|
||||
* @param int $contextId Context Id
|
||||
*
|
||||
* @return DAOResultFactory<NavigationMenu>
|
||||
*/
|
||||
public function getByContextId($contextId)
|
||||
{
|
||||
$result = $this->retrieve('SELECT * FROM navigation_menus WHERE context_id = ?', [(int) $contextId]);
|
||||
return new DAOResultFactory($result, $this, '_fromRow');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a navigation menu by navigation menu area.
|
||||
*
|
||||
* @param int $contextId Context Id
|
||||
* @param string $areaName Template Area name
|
||||
*
|
||||
* @return DAOResultFactory<NavigationMenu>
|
||||
*/
|
||||
public function getByArea($contextId, $areaName)
|
||||
{
|
||||
$result = $this->retrieve('SELECT * FROM navigation_menus WHERE area_name = ? and context_id = ?', [$areaName, (int) $contextId]);
|
||||
return new DAOResultFactory($result, $this, '_fromRow');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a navigation menu by title
|
||||
*
|
||||
* @param int $contextId Context Id
|
||||
* @param string $title
|
||||
*
|
||||
* @return ?NavigationMenu
|
||||
*/
|
||||
public function getByTitle($contextId, $title)
|
||||
{
|
||||
$result = $this->retrieve('SELECT * FROM navigation_menus WHERE context_id = ? and title = ?', [(int) $contextId, $title]);
|
||||
$row = (array) $result->current();
|
||||
return $row ? $this->_fromRow($row) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a navigationMenu exists with the given title.
|
||||
*
|
||||
* @param int $contextId
|
||||
* @param int $title
|
||||
*
|
||||
* @return bool True if a NM exists by that title
|
||||
*/
|
||||
public function navigationMenuExistsByTitle($contextId, $title)
|
||||
{
|
||||
$result = $this->retrieve('SELECT COUNT(*) AS row_count FROM navigation_menus WHERE title = ? AND context_id = ?', [$title, (int) $contextId]);
|
||||
$row = (array) $result->current();
|
||||
return $row && $row['row_count'] != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the locale field names.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLocaleFieldNames()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal function to return an NavigationMenu object from a row.
|
||||
*
|
||||
* @param array $row
|
||||
*
|
||||
* @return NavigationMenu
|
||||
*/
|
||||
public function _fromRow($row)
|
||||
{
|
||||
$navigationMenu = $this->newDataObject();
|
||||
$navigationMenu->setId($row['navigation_menu_id']);
|
||||
$navigationMenu->setTitle($row['title']);
|
||||
$navigationMenu->setAreaName($row['area_name']);
|
||||
$navigationMenu->setContextId($row['context_id']);
|
||||
|
||||
return $navigationMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a new NavigationMenu.
|
||||
*
|
||||
* @param NavigationMenu $navigationMenu
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function insertObject($navigationMenu)
|
||||
{
|
||||
$this->update(
|
||||
'INSERT INTO navigation_menus (title, area_name, context_id) VALUES (?, ?, ?)',
|
||||
[$navigationMenu->getTitle(), $navigationMenu->getAreaName(), (int) $navigationMenu->getContextId()]
|
||||
);
|
||||
$navigationMenu->setId($this->getInsertId());
|
||||
return $navigationMenu->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing NavigationMenu
|
||||
*
|
||||
* @param NavigationMenu $navigationMenu
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function updateObject($navigationMenu)
|
||||
{
|
||||
$returner = $this->update(
|
||||
'UPDATE navigation_menus
|
||||
SET title = ?,
|
||||
area_name = ?,
|
||||
context_id = ?
|
||||
WHERE navigation_menu_id = ?',
|
||||
[
|
||||
$navigationMenu->getTitle(),
|
||||
$navigationMenu->getAreaName(),
|
||||
(int) $navigationMenu->getContextId(),
|
||||
(int) $navigationMenu->getId(),
|
||||
]
|
||||
);
|
||||
$this->unCache($navigationMenu->getId());
|
||||
return (bool) $returner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a NavigationMenu.
|
||||
*
|
||||
* @param NavigationMenu $navigationMenu
|
||||
*/
|
||||
public function deleteObject($navigationMenu)
|
||||
{
|
||||
return $this->deleteById($navigationMenu->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a NavigationMenu.
|
||||
*
|
||||
* @param int $navigationMenuId
|
||||
*/
|
||||
public function deleteById($navigationMenuId)
|
||||
{
|
||||
$this->unCache($navigationMenuId);
|
||||
$this->update('DELETE FROM navigation_menus WHERE navigation_menu_id = ?', [(int) $navigationMenuId]);
|
||||
$navigationMenuItemAssignmentDao = DAORegistry::getDAO('NavigationMenuItemAssignmentDAO'); /** @var NavigationMenuItemAssignmentDAO $navigationMenuItemAssignmentDao */
|
||||
$navigationMenuItemAssignmentDao->deleteByMenuId($navigationMenuId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete NavigationMenus by contextId.
|
||||
*
|
||||
* @param int $contextId
|
||||
*/
|
||||
public function deleteByContextId($contextId)
|
||||
{
|
||||
$navigationMenus = $this->getByContextId($contextId);
|
||||
while ($navigationMenu = $navigationMenus->next()) {
|
||||
$this->deleteObject($navigationMenu);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the XML file and move the settings to the DB
|
||||
*
|
||||
* @param int $contextId
|
||||
* @param string $filename
|
||||
*
|
||||
* @return bool true === success
|
||||
*/
|
||||
public function installSettings($contextId, $filename)
|
||||
{
|
||||
$xmlParser = new PKPXMLParser();
|
||||
$tree = $xmlParser->parse($filename);
|
||||
|
||||
if ($contextId == \PKP\core\PKPApplication::CONTEXT_ID_NONE) {
|
||||
$siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */
|
||||
$site = $siteDao->getSite();
|
||||
}
|
||||
if (!$tree) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($tree->getChildren() as $navigationMenuNode) {
|
||||
$site = $navigationMenuNode->getAttribute('site');
|
||||
if ($contextId == \PKP\core\PKPApplication::CONTEXT_ID_NONE && !$site) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($navigationMenuNode->name == 'navigationMenu') {
|
||||
$title = $navigationMenuNode->getAttribute('title');
|
||||
$area = $navigationMenuNode->getAttribute('area');
|
||||
|
||||
$navigationMenu = null;
|
||||
|
||||
// Check if the given area has a NM attached.
|
||||
// If it does the NM is not being processed and a warning is being thrown
|
||||
$navigationMenusWithArea = $this->getByArea($contextId, $area)->toArray();
|
||||
if (count($navigationMenusWithArea) != 0) {
|
||||
error_log("WARNING: The NavigationMenu (ContextId: {$contextId}, Title: {$title}, Area: {$area}) will be skipped because the specified area has already a NavigationMenu attached.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->navigationMenuExistsByTitle($contextId, $title)) {
|
||||
$navigationMenu = $this->getByTitle($contextId, $title);
|
||||
$navigationMenu->setAreaName($area);
|
||||
|
||||
// update the navigationMenu into the DB
|
||||
$navigationMenuId = $this->updateObject($navigationMenu);
|
||||
} else {
|
||||
$navigationMenu = $this->newDataObject();
|
||||
$navigationMenu->setTitle($title);
|
||||
$navigationMenu->setContextId($contextId);
|
||||
$navigationMenu->setAreaName($area);
|
||||
|
||||
// insert the navigationMenu into the DB
|
||||
$navigationMenuId = $this->insertObject($navigationMenu);
|
||||
$navigationMenu->setId($navigationMenuId);
|
||||
}
|
||||
|
||||
$seq = 0;
|
||||
foreach ($navigationMenuNode->getChildren() as $navigationMenuItemFirstLevelNode) {
|
||||
$navigationMenuItemDao = DAORegistry::getDAO('NavigationMenuItemDAO'); /** @var NavigationMenuItemDAO $navigationMenuItemDao */
|
||||
$navigationMenuItemDao->installNodeSettings($contextId, $navigationMenuItemFirstLevelNode, $navigationMenu->getId(), null, $seq, true);
|
||||
|
||||
$seq++;
|
||||
}
|
||||
} elseif ($navigationMenuNode->name == 'navigationMenuItem') {
|
||||
$navigationMenuItemDao = DAORegistry::getDAO('NavigationMenuItemDAO'); /** @var NavigationMenuItemDAO $navigationMenuItemDao */
|
||||
$navigationMenuItemDao->installNodeSettings($contextId, $navigationMenuNode, null, null, 0, true);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* unCache the NM with id
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function unCache($id)
|
||||
{
|
||||
$cache = $this->getCache($id);
|
||||
if ($cache) {
|
||||
$cache->flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the settings cache for a given ID
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return GenericCache
|
||||
*/
|
||||
public function getCache($id)
|
||||
{
|
||||
static $navigationMenuCache = [];
|
||||
return $navigationMenuCache[$id] ??= CacheManager::getManager()->getCache(
|
||||
'navigationMenu',
|
||||
$id,
|
||||
[$this, '_cacheMiss']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for a cache miss.
|
||||
*
|
||||
* @param GenericCache $cache
|
||||
* @param string $id
|
||||
*/
|
||||
public function _cacheMiss($cache, $id)
|
||||
{
|
||||
/** @var NavigationMenuDAO */
|
||||
$navigationMenuDao = DAORegistry::getDAO('NavigationMenuDAO');
|
||||
$navigationMenu = $navigationMenuDao->getById($cache->getCacheId());
|
||||
Services::get('navigationMenu')->getMenuTree($navigationMenu);
|
||||
|
||||
return $navigationMenu;
|
||||
}
|
||||
}
|
||||
|
||||
if (!PKP_STRICT_MODE) {
|
||||
class_alias('\PKP\navigationMenu\NavigationMenuDAO', '\NavigationMenuDAO');
|
||||
}
|
||||
@@ -0,0 +1,332 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/navigationMenu/NavigationMenuItem.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 NavigationMenuItem
|
||||
*
|
||||
* @ingroup navigationMenu
|
||||
*
|
||||
* @see NavigationMenuItemDAO
|
||||
*
|
||||
* @brief Basic class describing a NavigationMenuItem.
|
||||
*/
|
||||
|
||||
namespace PKP\navigationMenu;
|
||||
|
||||
class NavigationMenuItem extends \PKP\core\DataObject
|
||||
{
|
||||
// Types for all default navigationMenuItems
|
||||
public const NMI_TYPE_ABOUT = 'NMI_TYPE_ABOUT';
|
||||
public const NMI_TYPE_SUBMISSIONS = 'NMI_TYPE_SUBMISSIONS';
|
||||
public const NMI_TYPE_EDITORIAL_TEAM = 'NMI_TYPE_EDITORIAL_TEAM';
|
||||
public const NMI_TYPE_CONTACT = 'NMI_TYPE_CONTACT';
|
||||
public const NMI_TYPE_ANNOUNCEMENTS = 'NMI_TYPE_ANNOUNCEMENTS';
|
||||
public const NMI_TYPE_CUSTOM = 'NMI_TYPE_CUSTOM';
|
||||
public const NMI_TYPE_REMOTE_URL = 'NMI_TYPE_REMOTE_URL';
|
||||
|
||||
public const NMI_TYPE_USER_LOGOUT = 'NMI_TYPE_USER_LOGOUT';
|
||||
public const NMI_TYPE_USER_LOGOUT_AS = 'NMI_TYPE_USER_LOGOUT_AS';
|
||||
public const NMI_TYPE_USER_PROFILE = 'NMI_TYPE_USER_PROFILE';
|
||||
public const NMI_TYPE_ADMINISTRATION = 'NMI_TYPE_ADMINISTRATION';
|
||||
public const NMI_TYPE_USER_DASHBOARD = 'NMI_TYPE_USER_DASHBOARD';
|
||||
public const NMI_TYPE_USER_REGISTER = 'NMI_TYPE_USER_REGISTER';
|
||||
public const NMI_TYPE_USER_LOGIN = 'NMI_TYPE_USER_LOGIN';
|
||||
public const NMI_TYPE_SEARCH = 'NMI_TYPE_SEARCH';
|
||||
public const NMI_TYPE_PRIVACY = 'NMI_TYPE_PRIVACY';
|
||||
|
||||
/** @var array $navigationMenuItems The navigationMenuItems underneath this navigationMenuItem */
|
||||
public $navigationMenuItems = [];
|
||||
|
||||
public $_isDisplayed = true;
|
||||
public $_isChildVisible = false;
|
||||
|
||||
//
|
||||
// Get/set methods
|
||||
//
|
||||
|
||||
/**
|
||||
* Set path for this navigation menu item.
|
||||
*
|
||||
* @param string $path
|
||||
*/
|
||||
public function setPath($path)
|
||||
{
|
||||
$this->setData('path', $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get path for this navigation menu item.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPath()
|
||||
{
|
||||
return $this->getData('path');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set url for this navigation menu item.
|
||||
*
|
||||
* @param string $url
|
||||
*/
|
||||
public function setUrl($url)
|
||||
{
|
||||
$this->setData('url', $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get url for this navigation menu item.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl()
|
||||
{
|
||||
return $this->getData('url');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set type for this navigation menu item.
|
||||
*
|
||||
* @param string $type
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
$this->setData('type', $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type for this navigation menu item.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->getData('type');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get contextId for this navigation menu item.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getContextId()
|
||||
{
|
||||
return $this->getData('contextId');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set context_id for this navigation menu item.
|
||||
*
|
||||
* @param int $contextId
|
||||
*/
|
||||
public function setContextId($contextId)
|
||||
{
|
||||
$this->setData('contextId', $contextId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title of the navigation Menu.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocalizedTitle()
|
||||
{
|
||||
return $this->getLocalizedData('title');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title of the navigation menu item.
|
||||
*
|
||||
* @param string $locale
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTitle($locale)
|
||||
{
|
||||
return $this->getData('title', $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the title of the navigation menu item.
|
||||
*
|
||||
* @param string $title
|
||||
* @param string $locale
|
||||
*/
|
||||
public function setTitle($title, $locale)
|
||||
{
|
||||
$this->setData('title', $title, $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content of the navigation Menu.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocalizedContent()
|
||||
{
|
||||
return $this->getLocalizedData('content');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content of the navigation menu item.
|
||||
*
|
||||
* @param string $locale
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent($locale)
|
||||
{
|
||||
return $this->getData('content', $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the content of the navigation menu item.
|
||||
*
|
||||
* @param string $content
|
||||
* @param string $locale
|
||||
*/
|
||||
public function setContent($content, $locale)
|
||||
{
|
||||
$this->setData('content', $content, $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get seq for this navigation menu item.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getSequence()
|
||||
{
|
||||
return $this->getData('seq');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set seq for this navigation menu item.
|
||||
*
|
||||
* @param int $seq
|
||||
*/
|
||||
public function setSequence($seq)
|
||||
{
|
||||
$this->setData('seq', $seq);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $isDisplayed for this navigation menu item.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsDisplayed()
|
||||
{
|
||||
return $this->_isDisplayed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $isDisplayed for this navigation menu item.
|
||||
*
|
||||
* @param bool $isDisplayed
|
||||
*/
|
||||
public function setIsDisplayed($isDisplayed)
|
||||
{
|
||||
$this->_isDisplayed = $isDisplayed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $isChildVisible for this navigation menu item.
|
||||
*
|
||||
* @return bool true if at least one NMI child is visible. It is defined at the Service functionality level
|
||||
*/
|
||||
public function getIsChildVisible()
|
||||
{
|
||||
return $this->_isChildVisible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $isChildVisible for this navigation menu item.
|
||||
*
|
||||
* @param bool $isChildVisible true if at least one NMI child is visible. It is defined at the Service functionality level
|
||||
*/
|
||||
public function setIsChildVisible($isChildVisible)
|
||||
{
|
||||
$this->_isChildVisible = $isChildVisible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the titleLocaleKey of the navigation Menu.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitleLocaleKey()
|
||||
{
|
||||
return $this->getData('titleLocaleKey');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set titleLocaleKey for this navigation menu item.
|
||||
*
|
||||
* @param string $titleLocaleKey
|
||||
*/
|
||||
public function setTitleLocaleKey($titleLocaleKey)
|
||||
{
|
||||
return $this->setData('titleLocaleKey', $titleLocaleKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the remoteUrl of the navigation Menu.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocalizedRemoteUrl()
|
||||
{
|
||||
return $this->getLocalizedData('remoteUrl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the remoteUrl of the navigation menu item.
|
||||
*
|
||||
* @param string $locale
|
||||
*/
|
||||
public function getRemoteUrl($locale)
|
||||
{
|
||||
return $this->getData('remoteUrl', $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the remoteUrl of the navigation menu item.
|
||||
*
|
||||
* @param string $url
|
||||
* @param string $locale
|
||||
*/
|
||||
public function setRemoteUrl($url, $locale)
|
||||
{
|
||||
$this->setData('remoteUrl', $url, $locale);
|
||||
}
|
||||
}
|
||||
|
||||
if (!PKP_STRICT_MODE) {
|
||||
class_alias('\PKP\navigationMenu\NavigationMenuItem', '\NavigationMenuItem');
|
||||
foreach ([
|
||||
'NMI_TYPE_ABOUT',
|
||||
'NMI_TYPE_SUBMISSIONS',
|
||||
'NMI_TYPE_EDITORIAL_TEAM',
|
||||
'NMI_TYPE_CONTACT',
|
||||
'NMI_TYPE_ANNOUNCEMENTS',
|
||||
'NMI_TYPE_CUSTOM',
|
||||
'NMI_TYPE_REMOTE_URL',
|
||||
'NMI_TYPE_USER_LOGOUT',
|
||||
'NMI_TYPE_USER_LOGOUT_AS',
|
||||
'NMI_TYPE_USER_PROFILE',
|
||||
'NMI_TYPE_ADMINISTRATION',
|
||||
'NMI_TYPE_USER_DASHBOARD',
|
||||
'NMI_TYPE_USER_REGISTER',
|
||||
'NMI_TYPE_USER_LOGIN',
|
||||
'NMI_TYPE_SEARCH',
|
||||
'NMI_TYPE_PRIVACY',
|
||||
] as $constantName) {
|
||||
define($constantName, constant('\NavigationMenuItem::' . $constantName));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/navigationMenu/NavigationMenuItemAssignment.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 NavigationMenuItemAssignment
|
||||
*
|
||||
* @ingroup navigationMenu
|
||||
*
|
||||
* @see NavigationMenuItemAssignmentDAO
|
||||
*
|
||||
* @brief Basic class describing a NavigationMenuItemAssignment. Each
|
||||
* assignment describes a NavigationMenuItem assigned to a NavigationMenu,
|
||||
* including it's position and if it's nested within another NavigationMenuItem
|
||||
*/
|
||||
|
||||
namespace PKP\navigationMenu;
|
||||
|
||||
class NavigationMenuItemAssignment extends \PKP\core\DataObject
|
||||
{
|
||||
/** @var NavigationMenuItem $navigationMenuItem The object this assignment refers to */
|
||||
public $navigationMenuItem = null;
|
||||
|
||||
/** @var array $children List of NavigationMenuItem objects nested under this one. */
|
||||
public $children = [];
|
||||
|
||||
//
|
||||
// Get/set methods
|
||||
//
|
||||
/**
|
||||
* Get menuId for this navigation menu item assignment.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getMenuId()
|
||||
{
|
||||
return $this->getData('menuId');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set menuId for this navigation menu item assignment.
|
||||
*
|
||||
* @param int $menuId
|
||||
*/
|
||||
public function setMenuId($menuId)
|
||||
{
|
||||
$this->setData('menuId', $menuId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get menuItemId for this navigation menu item assignment.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getMenuItemId()
|
||||
{
|
||||
return $this->getData('menuItemId');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set menuItemId for this navigation menu item assignment.
|
||||
*
|
||||
* @param int $menuItemId
|
||||
*/
|
||||
public function setMenuItemId($menuItemId)
|
||||
{
|
||||
$this->setData('menuItemId', $menuItemId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get parent menu item ID
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getParentId()
|
||||
{
|
||||
return $this->getData('parentId');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set parent menu item ID
|
||||
*
|
||||
* @param int $parentId
|
||||
*/
|
||||
public function setParentId($parentId)
|
||||
{
|
||||
$this->setData('parentId', $parentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get seq for this navigation menu item.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getSequence()
|
||||
{
|
||||
return $this->getData('seq');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set seq for this navigation menu item.
|
||||
*
|
||||
* @param int $seq
|
||||
*/
|
||||
public function setSequence($seq)
|
||||
{
|
||||
$this->setData('seq', $seq);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the NavigationMenuItem this assignment represents.
|
||||
*
|
||||
* This object is only available in some cases, when the NavigationMenuItem
|
||||
* has been stored for re-use.
|
||||
*
|
||||
* @return NavigationMenuItem
|
||||
*/
|
||||
public function getMenuItem()
|
||||
{
|
||||
return $this->navigationMenuItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the NavigationMenuItem this assignment represents
|
||||
*/
|
||||
public function setMenuItem($obj)
|
||||
{
|
||||
$this->navigationMenuItem = $obj instanceof \PKP\navigationMenu\NavigationMenuItem ? $obj : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title of the object.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocalizedTitle()
|
||||
{
|
||||
return $this->getLocalizedData('title');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title of the object.
|
||||
*
|
||||
* @param string $locale
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle($locale)
|
||||
{
|
||||
return $this->getData('title', $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the title of the object.
|
||||
*
|
||||
* @param string $title
|
||||
* @param string $locale
|
||||
*/
|
||||
public function setTitle($title, $locale)
|
||||
{
|
||||
$this->setData('title', $title, $locale);
|
||||
}
|
||||
}
|
||||
|
||||
if (!PKP_STRICT_MODE) {
|
||||
class_alias('\PKP\navigationMenu\NavigationMenuItemAssignment', '\NavigationMenuItemAssignment');
|
||||
}
|
||||
@@ -0,0 +1,326 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/navigationMenu/NavigationMenuItemAssignmentDAO.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 NavigationMenuItemAssignment
|
||||
*
|
||||
* @ingroup navigationMenuItem
|
||||
*
|
||||
* @see NavigationMenuItem
|
||||
*
|
||||
* @brief Operations for retrieving and modifying NavigationMenuItemAssignment
|
||||
* objects
|
||||
*/
|
||||
|
||||
namespace PKP\navigationMenu;
|
||||
|
||||
use PKP\db\DAORegistry;
|
||||
use PKP\db\DAOResultFactory;
|
||||
|
||||
class NavigationMenuItemAssignmentDAO extends \PKP\db\DAO
|
||||
{
|
||||
/**
|
||||
* Retrieve a navigation menu item assignment by ID.
|
||||
*
|
||||
* @param int $navigationMenuItemAssignmentId
|
||||
*
|
||||
* @return ?NavigationMenuItemAssignment
|
||||
*/
|
||||
public function getById($navigationMenuItemAssignmentId)
|
||||
{
|
||||
$result = $this->retrieve(
|
||||
'SELECT * FROM navigation_menu_item_assignments WHERE navigation_menu_item_assignment_id = ?',
|
||||
[(int) $navigationMenuItemAssignmentId]
|
||||
);
|
||||
$row = (array) $result->current();
|
||||
return $row ? $this->_fromRow($row) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new data object.
|
||||
*
|
||||
* @return NavigationMenuItemAssignment
|
||||
*/
|
||||
public function newDataObject()
|
||||
{
|
||||
return new NavigationMenuItemAssignment();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve items by menu id
|
||||
*
|
||||
* @param int $menuId
|
||||
*
|
||||
* @return DAOResultFactory<NavigationMenuItemAssignment>
|
||||
*/
|
||||
public function getByMenuId($menuId)
|
||||
{
|
||||
$result = $this->retrieve(
|
||||
'SELECT nmi.*,nmh.navigation_menu_id,nmh.parent_id,nmh.seq, nmh.navigation_menu_item_assignment_id
|
||||
FROM navigation_menu_item_assignments as nmh
|
||||
LEFT JOIN navigation_menu_items as nmi ON (nmh.navigation_menu_item_id = nmi.navigation_menu_item_id)
|
||||
WHERE nmh.navigation_menu_id = ?
|
||||
ORDER BY nmh.seq',
|
||||
[(int) $menuId]
|
||||
);
|
||||
return new DAOResultFactory($result, $this, '_fromRow');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve items by menu item id
|
||||
*
|
||||
* @param int $menuItemId
|
||||
*
|
||||
* @return DAOResultFactory<NavigationMenuItemAssignment>
|
||||
*/
|
||||
public function getByMenuItemId($menuItemId)
|
||||
{
|
||||
$result = $this->retrieve(
|
||||
'SELECT nmi.*, nmh.navigation_menu_id, nmh.parent_id, nmh.seq, nmh.navigation_menu_item_assignment_id
|
||||
FROM navigation_menu_item_assignments as nmh
|
||||
LEFT JOIN navigation_menu_items as nmi ON (nmh.navigation_menu_item_id = nmi.navigation_menu_item_id)
|
||||
WHERE nmh.navigation_menu_item_id = ?
|
||||
ORDER BY nmh.seq',
|
||||
[(int) $menuItemId]
|
||||
);
|
||||
return new DAOResultFactory($result, $this, '_fromRow');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve items by navigationMenuItemId menu item id and ParentId
|
||||
*
|
||||
* @param int $navigationMenuItemId
|
||||
* @param int $menuId
|
||||
* @param int $parentId
|
||||
*
|
||||
* @return NavigationMenuItemAssignment
|
||||
*/
|
||||
public function getByNMIIdAndMenuIdAndParentId($navigationMenuItemId, $menuId, $parentId = null)
|
||||
{
|
||||
$params = [(int) $menuId, (int) $navigationMenuItemId];
|
||||
if ($parentId) {
|
||||
$params[] = (int) $parentId;
|
||||
}
|
||||
$result = $this->retrieve(
|
||||
'SELECT nmh.*
|
||||
FROM navigation_menu_item_assignments as nmh
|
||||
WHERE nmh.navigation_menu_id = ?
|
||||
AND nmh.navigation_menu_item_id = ?' .
|
||||
($parentId ? ' AND nmh.parent_id = ?' : ''),
|
||||
$params
|
||||
);
|
||||
$row = (array) $result->current();
|
||||
return $row ? $this->_fromRow($row) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve items by navigationMenu id and ParentId
|
||||
*
|
||||
* @param int $menuId
|
||||
* @param int $parentId 0 if we want to return NMIAssignments with no parents
|
||||
*
|
||||
* @return DAOResultFactory<NavigationMenuItemAssignment>
|
||||
*/
|
||||
public function getByMenuIdAndParentId($menuId, $parentId)
|
||||
{
|
||||
$result = $this->retrieve(
|
||||
'SELECT nmh.*
|
||||
FROM navigation_menu_item_assignments as nmh
|
||||
WHERE nmh.navigation_menu_id = ?
|
||||
AND nmh.parent_id = ?',
|
||||
[(int) $menuId, (int) $parentId]
|
||||
);
|
||||
return new DAOResultFactory($result, $this, '_fromRow');
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal function to return a NavigationMenuItemAssignment object from a
|
||||
* row.
|
||||
*
|
||||
* @param array $row
|
||||
*
|
||||
* @return NavigationMenuItemAssignment
|
||||
*/
|
||||
public function _fromRow($row)
|
||||
{
|
||||
$assignment = $this->newDataObject();
|
||||
$assignment->setId($row['navigation_menu_item_assignment_id']);
|
||||
$assignment->setMenuId($row['navigation_menu_id']);
|
||||
$assignment->setMenuItemId($row['navigation_menu_item_id']);
|
||||
$assignment->setParentId($row['parent_id']);
|
||||
$assignment->setSequence($row['seq']);
|
||||
|
||||
$this->getDataObjectSettings('navigation_menu_item_assignment_settings', 'navigation_menu_item_assignment_id', $row['navigation_menu_item_assignment_id'], $assignment);
|
||||
|
||||
return $assignment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing NavigationMenuItemAssignment.
|
||||
*
|
||||
* @param NavigationMenuItemAssignment $navigationMenuItemAssignment
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function updateObject($navigationMenuItemAssignment)
|
||||
{
|
||||
$returner = $this->update(
|
||||
'UPDATE navigation_menu_item_assignments
|
||||
SET
|
||||
navigation_menu_id = ?,
|
||||
navigation_menu_item_id = ?,
|
||||
parent_id = ?,
|
||||
seq = ?,
|
||||
WHERE navigation_menu_item_assignment_id = ?',
|
||||
[
|
||||
(int) $navigationMenuItemAssignment->getMenuId(),
|
||||
(int) $navigationMenuItemAssignment->getMenuItemId(),
|
||||
(int) $navigationMenuItemAssignment->getParentId(),
|
||||
(int) $navigationMenuItemAssignment->getSequence(),
|
||||
(int) $navigationMenuItemAssignment->getId(),
|
||||
]
|
||||
);
|
||||
$this->updateLocaleFields($navigationMenuItemAssignment);
|
||||
$this->unCacheRelatedNavigationMenus($navigationMenuItemAssignment->getId());
|
||||
return (bool) $returner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a new NavigationMenuItemAssignment.
|
||||
*
|
||||
* @param NavigationMenuItemAssignment $assignment
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function insertObject($assignment)
|
||||
{
|
||||
$this->update(
|
||||
'INSERT INTO navigation_menu_item_assignments
|
||||
(navigation_menu_id, navigation_menu_item_id, parent_id, seq)
|
||||
VALUES
|
||||
(?, ?, ?, ?)',
|
||||
[
|
||||
(int) $assignment->getMenuId(),
|
||||
(int) $assignment->getMenuItemId(),
|
||||
(int) $assignment->getParentId(),
|
||||
(int) $assignment->getSequence(),
|
||||
]
|
||||
);
|
||||
$assignment->setId($this->getInsertId());
|
||||
|
||||
// Add default title (of the navigationMenuItem)
|
||||
$navigationMenuItemDao = DAORegistry::getDAO('NavigationMenuItemDAO'); /** @var NavigationMenuItemDAO $navigationMenuItemDao */
|
||||
$navigationMenuItem = $navigationMenuItemDao->getById($assignment->getMenuItemId());
|
||||
|
||||
$assignment->setTitle($navigationMenuItem->getTitle(null), null);
|
||||
|
||||
$this->updateLocaleFields($assignment);
|
||||
|
||||
$this->unCacheRelatedNavigationMenus($assignment->getId());
|
||||
|
||||
return $assignment->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all assignments by NavigationMenu ID
|
||||
*
|
||||
* @param int $menuId id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteByMenuId($menuId)
|
||||
{
|
||||
$navigationMenuItemAssignments = $this->getByMenuId($menuId);
|
||||
while ($navigationMenuItemAssignment = $navigationMenuItemAssignments->next()) {
|
||||
$this->deleteObject($navigationMenuItemAssignment);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all assignments by NavigationMenuItem ID
|
||||
*
|
||||
* @param int $menuItemId id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteByMenuItemId($menuItemId)
|
||||
{
|
||||
$navigationMenuItemAssignments = $this->getByMenuItemId($menuItemId);
|
||||
while ($navigationMenuItemAssignment = $navigationMenuItemAssignments->next()) {
|
||||
$this->deleteObject($navigationMenuItemAssignment);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a NavigationMenuItemAssignment.
|
||||
*
|
||||
* @param NavigationMenuItemAssignment $navigationMenuItemAssignment
|
||||
*/
|
||||
public function deleteObject($navigationMenuItemAssignment)
|
||||
{
|
||||
return $this->deleteById($navigationMenuItemAssignment->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a NavigationMenuItemAssignment by NavigationMenuItemAssignment ID.
|
||||
*
|
||||
* @param int $navigationMenuItemAssignmentId
|
||||
*/
|
||||
public function deleteById($navigationMenuItemAssignmentId)
|
||||
{
|
||||
$this->unCacheRelatedNavigationMenus($navigationMenuItemAssignmentId);
|
||||
|
||||
$this->update('DELETE FROM navigation_menu_item_assignment_settings WHERE navigation_menu_item_assignment_id = ?', [(int) $navigationMenuItemAssignmentId]);
|
||||
$this->update('DELETE FROM navigation_menu_item_assignments WHERE navigation_menu_item_assignment_id = ?', [(int) $navigationMenuItemAssignmentId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of localized field names for this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLocaleFieldNames()
|
||||
{
|
||||
return ['title'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the settings for this object
|
||||
*
|
||||
* @param object $navigationMenuItemAssignment
|
||||
*/
|
||||
public function updateLocaleFields($navigationMenuItemAssignment)
|
||||
{
|
||||
$this->updateDataObjectSettings('navigation_menu_item_assignment_settings', $navigationMenuItemAssignment, [
|
||||
'navigation_menu_item_assignment_id' => $navigationMenuItemAssignment->getId()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uncache the related NMs to the NMIA with $id
|
||||
*/
|
||||
public function unCacheRelatedNavigationMenus($id)
|
||||
{
|
||||
if ($navigationMenuItemAssignment = $this->getById($id)) {
|
||||
/** @var NavigationMenuDAO */
|
||||
$navigationMenuDao = DAORegistry::getDAO('NavigationMenuDAO');
|
||||
$cache = $navigationMenuDao->getCache($navigationMenuItemAssignment->getMenuId());
|
||||
if ($cache) {
|
||||
$cache->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!PKP_STRICT_MODE) {
|
||||
class_alias('\PKP\navigationMenu\NavigationMenuItemAssignmentDAO', '\NavigationMenuItemAssignmentDAO');
|
||||
}
|
||||
@@ -0,0 +1,549 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/navigationMenu/NavigationMenuItemDAO.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 NavigationMenuItemDAO
|
||||
*
|
||||
* @ingroup navigationMenuItem
|
||||
*
|
||||
* @see NavigationMenuItem
|
||||
*
|
||||
* @brief Operations for retrieving and modifying NavigationMenuItem objects. NMI = NavigationMenuItem
|
||||
*/
|
||||
|
||||
namespace PKP\navigationMenu;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use PKP\db\DAORegistry;
|
||||
use PKP\db\DAOResultFactory;
|
||||
use PKP\xml\PKPXMLParser;
|
||||
use PKP\xml\XMLNode;
|
||||
|
||||
class NavigationMenuItemDAO extends \PKP\db\DAO
|
||||
{
|
||||
/**
|
||||
* Retrieve a navigation menu item by ID.
|
||||
*
|
||||
* @param int $navigationMenuItemId
|
||||
*
|
||||
* @return ?NavigationMenuItem
|
||||
*/
|
||||
public function getById($navigationMenuItemId)
|
||||
{
|
||||
$params = [(int) $navigationMenuItemId];
|
||||
$result = $this->retrieve(
|
||||
'SELECT * FROM navigation_menu_items WHERE navigation_menu_item_id = ?',
|
||||
$params
|
||||
);
|
||||
|
||||
$row = (array) $result->current();
|
||||
return $row ? $this->_fromRow($row) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a navigation menu item by path.
|
||||
*
|
||||
* @param int $contextId Context Id
|
||||
* @param string $path
|
||||
*
|
||||
* @return ?NavigationMenuItem
|
||||
*/
|
||||
public function getByPath($contextId, $path)
|
||||
{
|
||||
$result = $this->retrieve(
|
||||
'SELECT * FROM navigation_menu_items WHERE path = ? and context_id = ? and type= ?',
|
||||
[$path, (int) $contextId, 'NMI_TYPE_CUSTOM']
|
||||
);
|
||||
|
||||
$row = (array) $result->current();
|
||||
return $row ? $this->_fromRow($row) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a navigation menu items by context Id.
|
||||
*
|
||||
* @param int $contextId Context Id
|
||||
*
|
||||
* @return DAOResultFactory<NavigationMenuItem>
|
||||
*/
|
||||
public function getByContextId($contextId)
|
||||
{
|
||||
$result = $this->retrieve(
|
||||
'SELECT * FROM navigation_menu_items WHERE context_id = ?',
|
||||
[(int) $contextId]
|
||||
);
|
||||
|
||||
return new DAOResultFactory($result, $this, '_fromRow');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve items by menu id
|
||||
*
|
||||
* @param int $menuId
|
||||
*
|
||||
* @return DAOResultFactory<NavigationMenuItem>
|
||||
*/
|
||||
public function getByMenuId($menuId)
|
||||
{
|
||||
$result = $this->retrieve(
|
||||
'SELECT nmi.*
|
||||
FROM navigation_menu_item_assignments as nmh
|
||||
LEFT JOIN navigation_menu_items as nmi ON (nmh.navigation_menu_item_id = nmi.navigation_menu_item_id)
|
||||
WHERE nmh.navigation_menu_id = ?
|
||||
ORDER BY nmh.seq',
|
||||
[(int) $menuId]
|
||||
);
|
||||
return new DAOResultFactory($result, $this, '_fromRow');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve items by menuItemType and setting_name = titleLocaleKey
|
||||
*
|
||||
* @param int $contextId
|
||||
* @param string $menuItemType
|
||||
* @param string $menuItemTitleLocaleKey
|
||||
*
|
||||
* @return ?NavigationMenuItem
|
||||
*/
|
||||
public function getByTypeAndTitleLocaleKey($contextId, $menuItemType, $menuItemTitleLocaleKey)
|
||||
{
|
||||
$result = $this->retrieve(
|
||||
'SELECT *
|
||||
FROM navigation_menu_items
|
||||
LEFT JOIN navigation_menu_item_settings ON (navigation_menu_items.navigation_menu_item_id = navigation_menu_item_settings.navigation_menu_item_id)
|
||||
WHERE navigation_menu_items.type = ?
|
||||
AND (navigation_menu_item_settings.setting_name = \'titleLocaleKey\' and navigation_menu_item_settings.setting_value = ?)
|
||||
AND navigation_menu_items.context_id = ?',
|
||||
[$menuItemType, $menuItemTitleLocaleKey, (int) $contextId]
|
||||
);
|
||||
$row = (array) $result->current();
|
||||
return $row ? $this->_fromRow($row) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the menu items with the specified type.
|
||||
*
|
||||
* @param int $type NMI_TYPE_...
|
||||
* @param int $contextId
|
||||
*
|
||||
* @return DAOResultFactory<NavigationMenuItem> containing matching NavigationMenuItems
|
||||
*/
|
||||
public function getByType($type, $contextId = null)
|
||||
{
|
||||
$params = [$type];
|
||||
if ($contextId !== null) {
|
||||
$params[] = $contextId;
|
||||
}
|
||||
$result = $this->retrieve(
|
||||
'SELECT * FROM navigation_menu_items WHERE type = ?' .
|
||||
($contextId !== null ? ' AND context_id = ?' : ''),
|
||||
$params
|
||||
);
|
||||
return new DAOResultFactory($result, $this, '_fromRow');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of localized field names for this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLocaleFieldNames()
|
||||
{
|
||||
return ['title', 'content', 'remoteUrl'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc DAO::getAdditionalFieldNames()
|
||||
*/
|
||||
public function getAdditionalFieldNames()
|
||||
{
|
||||
return ['titleLocaleKey'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new data object.
|
||||
*
|
||||
* @return NavigationMenuItem
|
||||
*/
|
||||
public function newDataObject()
|
||||
{
|
||||
return new NavigationMenuItem();
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal function to return a NavigationMenuItem object from a row.
|
||||
*
|
||||
* @param array $row
|
||||
*
|
||||
* @return NavigationMenuItem
|
||||
*/
|
||||
public function _fromRow($row, $dataObject = false)
|
||||
{
|
||||
$navigationMenuItem = $this->newDataObject();
|
||||
$navigationMenuItem->setId($row['navigation_menu_item_id']);
|
||||
$navigationMenuItem->setContextId($row['context_id']);
|
||||
$navigationMenuItem->setType($row['type']);
|
||||
$navigationMenuItem->setPath($row['path']);
|
||||
|
||||
$this->getDataObjectSettings('navigation_menu_item_settings', 'navigation_menu_item_id', $row['navigation_menu_item_id'], $navigationMenuItem);
|
||||
|
||||
return $navigationMenuItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the settings for this object
|
||||
*
|
||||
* @param object $navigationMenuItem
|
||||
*/
|
||||
public function updateLocaleFields($navigationMenuItem)
|
||||
{
|
||||
$this->updateDataObjectSettings('navigation_menu_item_settings', $navigationMenuItem, [
|
||||
'navigation_menu_item_id' => $navigationMenuItem->getId()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a new NavigationMenuItem.
|
||||
*
|
||||
* @param NavigationMenuItem $navigationMenuItem
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function insertObject($navigationMenuItem)
|
||||
{
|
||||
$this->update(
|
||||
'INSERT INTO navigation_menu_items
|
||||
(path, context_id, type)
|
||||
VALUES
|
||||
(?, ?, ?)',
|
||||
[
|
||||
$navigationMenuItem->getPath(),
|
||||
(int) $navigationMenuItem->getContextId(),
|
||||
$navigationMenuItem->getType(),
|
||||
]
|
||||
);
|
||||
$navigationMenuItem->setId($this->getInsertId());
|
||||
$this->updateLocaleFields($navigationMenuItem);
|
||||
|
||||
$this->unCacheRelatedNavigationMenus($navigationMenuItem->getId());
|
||||
|
||||
return $navigationMenuItem->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing NavigationMenuItem.
|
||||
*
|
||||
* @param NavigationMenuItem $navigationMenuItem
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function updateObject($navigationMenuItem)
|
||||
{
|
||||
$returner = $this->update(
|
||||
'UPDATE navigation_menu_items
|
||||
SET
|
||||
path = ?,
|
||||
context_id = ?,
|
||||
type = ?
|
||||
WHERE navigation_menu_item_id = ?',
|
||||
[
|
||||
$navigationMenuItem->getPath(),
|
||||
(int) $navigationMenuItem->getContextId(),
|
||||
$navigationMenuItem->getType(),
|
||||
(int) $navigationMenuItem->getId(),
|
||||
]
|
||||
);
|
||||
$this->updateLocaleFields($navigationMenuItem);
|
||||
|
||||
$this->unCacheRelatedNavigationMenus($navigationMenuItem->getId());
|
||||
|
||||
return $returner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a NavigationMenuItem.
|
||||
*
|
||||
* @param NavigationMenuItem $navigationMenuItem
|
||||
*/
|
||||
public function deleteObject($navigationMenuItem)
|
||||
{
|
||||
return $this->deleteById($navigationMenuItem->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a NavigationMenuItem by navigationMenuItem ID.
|
||||
*
|
||||
* @param int $navigationMenuItemId
|
||||
*/
|
||||
public function deleteById($navigationMenuItemId)
|
||||
{
|
||||
$this->unCacheRelatedNavigationMenus($navigationMenuItemId);
|
||||
|
||||
$this->update('DELETE FROM navigation_menu_item_settings WHERE navigation_menu_item_id = ?', [(int) $navigationMenuItemId]);
|
||||
$this->update('DELETE FROM navigation_menu_items WHERE navigation_menu_item_id = ?', [(int) $navigationMenuItemId]);
|
||||
|
||||
$navigationMenuItemAssignmentDao = DAORegistry::getDAO('NavigationMenuItemAssignmentDAO'); /** @var NavigationMenuItemAssignmentDAO $navigationMenuItemAssignmentDao */
|
||||
$navigationMenuItemAssignmentDao->deleteByMenuItemId($navigationMenuItemId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete NavigationMenuItems by contextId.
|
||||
*
|
||||
* @param int $contextId
|
||||
*/
|
||||
public function deleteByContextId($contextId)
|
||||
{
|
||||
$navigationMenuItems = $this->getByContextId($contextId);
|
||||
|
||||
while ($navigationMenuItem = $navigationMenuItems->next()) {
|
||||
$this->deleteObject($navigationMenuItem);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the XML file and move the settings to the DB
|
||||
*
|
||||
* @param int $contextId
|
||||
* @param string $filename
|
||||
*
|
||||
* @return bool true === success
|
||||
*/
|
||||
public function installSettings($contextId, $filename)
|
||||
{
|
||||
$xmlParser = new PKPXMLParser();
|
||||
$tree = $xmlParser->parse($filename);
|
||||
|
||||
if ($contextId == \PKP\core\PKPApplication::CONTEXT_ID_NONE) {
|
||||
$siteDao = DAORegistry::getDAO('SiteDAO'); /** @var \PKP\site\SiteDAO $siteDao */
|
||||
$site = $siteDao->getSite();
|
||||
}
|
||||
|
||||
if (!$tree) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($tree->getChildren() as $setting) {
|
||||
$site = $setting->getAttribute('site');
|
||||
if ($contextId == \PKP\core\PKPApplication::CONTEXT_ID_NONE && !$site) {
|
||||
continue;
|
||||
}
|
||||
$this->installNodeSettings($contextId, $setting, null, null, 0, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a XML node to DB
|
||||
*
|
||||
* @param int $contextId
|
||||
* @param XMLNode $node
|
||||
* @param int $navigationMenuId
|
||||
* @param int $navigationMenuItemParentId
|
||||
* @param int $seq
|
||||
* @param bool $checkChildren Optional
|
||||
*
|
||||
* @return bool true === success
|
||||
*/
|
||||
public function installNodeSettings($contextId, $node, $navigationMenuId = null, $navigationMenuItemParentId = null, $seq = 0, $checkChildren = false)
|
||||
{
|
||||
$titleKey = $node->getAttribute('title');
|
||||
$path = $node->getAttribute('path');
|
||||
$type = $node->getAttribute('type');
|
||||
|
||||
$navigationMenuItemExisting = $this->getByTypeAndTitleLocaleKey($contextId, $type, $titleKey);
|
||||
|
||||
if (!isset($navigationMenuItemExisting)) {
|
||||
$navigationMenuItem = $this->newDataObject();
|
||||
$navigationMenuItem->setPath($path);
|
||||
$navigationMenuItem->setContextId($contextId);
|
||||
|
||||
$navigationMenuItem->setType($type);
|
||||
|
||||
$navigationMenuItemId = $this->insertObject($navigationMenuItem);
|
||||
|
||||
// add the i18n keys to the settings table so that they
|
||||
// can be used when a new locale is added/reloaded
|
||||
$this->updateSetting($navigationMenuItemId, 'titleLocaleKey', $titleKey);
|
||||
} else {
|
||||
$navigationMenuItemId = $navigationMenuItemExisting->getId();
|
||||
|
||||
$this->updateSetting($navigationMenuItemId, 'titleLocaleKey', $titleKey);
|
||||
}
|
||||
|
||||
// insert into Assignments
|
||||
if ($navigationMenuId) {
|
||||
$navigationMenuItemAssignmentDao = DAORegistry::getDAO('NavigationMenuItemAssignmentDAO'); /** @var NavigationMenuItemAssignmentDAO $navigationMenuItemAssignmentDao */
|
||||
$assignmentExists = $navigationMenuItemAssignmentDao->getByNMIIdAndMenuIdAndParentId($navigationMenuItemId, $navigationMenuId, $navigationMenuItemParentId);
|
||||
|
||||
if (!isset($assignmentExists)) {
|
||||
$navigationMenuItemAssignment = $navigationMenuItemAssignmentDao->newDataObject();
|
||||
|
||||
$navigationMenuItemAssignment->setMenuItemId($navigationMenuItemId);
|
||||
$navigationMenuItemAssignment->setMenuId($navigationMenuId);
|
||||
|
||||
if ($navigationMenuItemParentId) {
|
||||
$navigationMenuItemAssignment->setParentId($navigationMenuItemParentId);
|
||||
}
|
||||
|
||||
$navigationMenuItemAssignment->setSequence($seq);
|
||||
|
||||
// Insert Assignment
|
||||
$navigationMenuItemAssignmentDao->insertObject($navigationMenuItemAssignment);
|
||||
}
|
||||
}
|
||||
|
||||
if ($checkChildren) {
|
||||
$seqSec = 0;
|
||||
|
||||
foreach ($node->getChildren() as $navigationMenuItemSecondLevelNode) {
|
||||
$this->installNodeSettings($contextId, $navigationMenuItemSecondLevelNode, $navigationMenuId, $navigationMenuItemId, $seqSec, false);
|
||||
$seqSec++;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for update navigationMenuItem setting
|
||||
*
|
||||
* @param int $navigationMenuItemId
|
||||
* @param string $name
|
||||
* @param string $type data type of the setting. If omitted, type will be guessed
|
||||
* @param bool $isLocalized
|
||||
*/
|
||||
public function updateSetting($navigationMenuItemId, $name, $value, $type = null, $isLocalized = false)
|
||||
{
|
||||
$keyFields = ['setting_name', 'locale', 'navigation_menu_item_id'];
|
||||
|
||||
if (!$isLocalized) {
|
||||
$value = $this->convertToDB($value, $type);
|
||||
DB::table('navigation_menu_item_settings')->updateOrInsert(
|
||||
['navigation_menu_item_id' => (int) $navigationMenuItemId, 'setting_name' => $name, 'locale' => ''],
|
||||
['setting_value' => trim($value, '##'), 'setting_type' => $type]
|
||||
);
|
||||
} else {
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $locale => $localeValue) {
|
||||
$this->update('DELETE FROM navigation_menu_item_settings WHERE navigation_menu_item_id = ? AND setting_name = ? AND locale = ?', [(int) $navigationMenuItemId, $name, $locale]);
|
||||
if (empty($localeValue)) {
|
||||
continue;
|
||||
}
|
||||
$type = null;
|
||||
$this->update(
|
||||
'INSERT INTO navigation_menu_item_settings
|
||||
(navigation_menu_item_id, setting_name, setting_value, setting_type, locale)
|
||||
VALUES (?, ?, ?, ?, ?)',
|
||||
[$navigationMenuItemId, $name, trim($this->convertToDB($localeValue, $type), '##'), $type, $locale]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a context setting value.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $locale optional
|
||||
*/
|
||||
public function getSetting($navigationMenuItemId, $name, $locale = null)
|
||||
{
|
||||
$params = [(int) $navigationMenuItemId, $name];
|
||||
if ($locale) {
|
||||
$params[] = $locale;
|
||||
}
|
||||
$result = $this->retrieve(
|
||||
'SELECT setting_name, setting_value, setting_type, locale
|
||||
FROM navigation_menu_item_settings
|
||||
WHERE navigation_menu_item_id = ? AND
|
||||
setting_name = ?' .
|
||||
($locale ? ' AND locale = ?' : ''),
|
||||
$params
|
||||
);
|
||||
|
||||
foreach ($result as $row) {
|
||||
$returner[$row->locale] = $this->convertFromDB($row->setting_value, $row->setting_type);
|
||||
}
|
||||
if (count($returner) == 1) {
|
||||
return array_shift($returner);
|
||||
}
|
||||
if (count($returner) == 0) {
|
||||
return false;
|
||||
}
|
||||
return $returner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all settings associated with a locale
|
||||
*
|
||||
* @param string $locale
|
||||
*/
|
||||
public function deleteSettingsByLocale($locale)
|
||||
{
|
||||
return $this->update('DELETE FROM navigation_menu_item_settings WHERE locale = ?', [$locale]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uncache the related NMs to the NMI with $id
|
||||
*/
|
||||
public function unCacheRelatedNavigationMenus($id)
|
||||
{
|
||||
/** @var NavigationMenuDAO */
|
||||
$navigationMenuDao = DAORegistry::getDAO('NavigationMenuDAO');
|
||||
/** @var NavigationMenuItemAssignmentDAO */
|
||||
$navigationMenuItemAssignmentDao = DAORegistry::getDAO('NavigationMenuItemAssignmentDAO');
|
||||
$assignments = $navigationMenuItemAssignmentDao->getByMenuItemId($id);
|
||||
if ($assignments) {
|
||||
$assignmentsArray = $assignments->toArray();
|
||||
foreach ($assignmentsArray as $assignment) {
|
||||
$cache = $navigationMenuDao->getCache($assignment->getMenuId());
|
||||
if ($cache) {
|
||||
$cache->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Port static page as a Custom NMI
|
||||
*
|
||||
* @param \APP\plugins\generic\staticPages\classes\StaticPage $staticPage
|
||||
*
|
||||
* @return int The id of the inserted NMI. Null if non is inserted
|
||||
*/
|
||||
public function portStaticPage($staticPage)
|
||||
{
|
||||
$path = $staticPage->getPath();
|
||||
$contextId = $staticPage->getContextId();
|
||||
|
||||
$existingNMIWithPath = $this->getByPath($contextId, $path);
|
||||
|
||||
$retNavigationMenuItemId = null;
|
||||
|
||||
if (!isset($existingNMIWithPath)) {
|
||||
$navigationMenuItem = $this->newDataObject();
|
||||
|
||||
$navigationMenuItem->setPath($path);
|
||||
$navigationMenuItem->setContextId($contextId);
|
||||
$navigationMenuItem->setType(NavigationMenuItem::NMI_TYPE_CUSTOM);
|
||||
|
||||
$navigationMenuItem->setTitle($staticPage->getTitle(null), null);
|
||||
$navigationMenuItem->setContent($staticPage->getContent(null), null);
|
||||
|
||||
$retNavigationMenuItemId = $this->insertObject($navigationMenuItem);
|
||||
}
|
||||
|
||||
return $retNavigationMenuItemId;
|
||||
}
|
||||
}
|
||||
|
||||
if (!PKP_STRICT_MODE) {
|
||||
class_alias('\PKP\navigationMenu\NavigationMenuItemDAO', '\NavigationMenuItemDAO');
|
||||
}
|
||||
Reference in New Issue
Block a user