diff --git a/application/views/scripts/admin/terms.phtml b/application/views/scripts/admin/terms.phtml deleted file mode 100755 index e423d1a3..00000000 --- a/application/views/scripts/admin/terms.phtml +++ /dev/null @@ -1,69 +0,0 @@ -

Manage Term Visibility

-
« Back to Administration
- -
- -
- -

Please Note: Any changes made here will take effect during the next synchronization with Banner

- - - - - - - - - - - - - -terms as $term) { - $numSections = intval($term['num_sections']); - $manuallyDisabled = intval($term['manually_disabled']); - $active = ($numSections && !$manuallyDisabled); - print "\n\t"; - print "\n\t\t"; - print "\n\t\t"; - print "\n\t\t"; - - print "\n\t\t"; - - print "\n\t\t"; - - print "\n\t"; -} -?> - -
Term CodeDescriptionSectionsManual OverrideActive?
".$term['STVTERM_CODE']."".$term['STVTERM_DESC']."".$numSections.""; - print "\n\t\t\t
"; - print "\n\t\t\t"; - print "\n\t\t\t"; - print "\n\t\t\t"; - print "\n\t\t\t"; - print "\n\t\t\t"; - print "\n\t\t\t
"; - print "\n\t\t
"; - if ($active) { - print "Yes"; - } else { - print "No: "; - if ($manuallyDisabled) - print "Manually disabled. "; - if (!$numSections) - print "Zero sections. "; - } - print "\n\t\t
diff --git a/src/Controller/Admin.php b/src/Controller/Admin.php index 049d3b9e..1e708525 100755 --- a/src/Controller/Admin.php +++ b/src/Controller/Admin.php @@ -2,11 +2,23 @@ namespace App\Controller; +use App\Service\Osid\IdMap; +use App\Service\Osid\TermHelper; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Security\Core\Exception\AccessDeniedException; class Admin extends AbstractController { + public function __construct( + private EntityManagerInterface $entityManager, + private IdMap $osidIdMap, + private TermHelper $osidTermHelper, + ) { + } + /** * List Admin Screens. */ @@ -19,41 +31,13 @@ public function indexAction() /** * Manage term visibility. */ - #[Route('/admin/terms', name: 'admin_terms')] - public function termsAction() + #[Route('/admin/terms', name: 'admin_terms_list', methods: ['GET'])] + public function termsAction(Request $request) { - $db = Zend_Registry::get('db'); - - if ($this->_getParam('change_visibility')) { - // Verify our CSRF key - if (!$this->_getParam('csrf_key') == $this->_helper->csrfKey()) { - throw new PermissionDeniedException('Invalid CSRF Key. Please log in again.'); - } - - // Verify that this is a valid term. - $catalog = $this->_getParam('catalog'); - $term = $this->_getParam('term'); - $verifyStmt = $db->prepare('SELECT COUNT(*) FROM STVTERM WHERE STVTERM_CODE = ?'); - $verifyStmt->execute([$term]); - $valid = (int) $verifyStmt->fetchColumn(); - $verifyStmt->closeCursor(); - if (!$valid) { - throw new InvalidArgumentException('Invalid term-code: '.$term); - } - - // Disable the term - if ('true' == $this->_getParam('disabled')) { - $visibilityStmt = $db->prepare('INSERT INTO catalog_term_inactive (catalog_id, term_code) VALUES (?, ?);'); - } - // Enable the term - else { - $visibilityStmt = $db->prepare('DELETE FROM catalog_term_inactive WHERE catalog_id = ? AND term_code = ?;'); - } - $visibilityStmt->execute([$catalog, $term]); - } - - $searches = $db->query('SELECT * FROM catalog_term_match')->fetchAll(); + $data = []; + $db = $this->entityManager->getConnection(); + $searches = $db->executeQuery('SELECT * FROM catalog_term_match')->fetchAll(); $catalogs = []; $queries = []; foreach ($searches as $search) { @@ -96,18 +80,66 @@ public function termsAction() catalog ASC, STVTERM_CODE DESC"; $stmt = $db->prepare($query); - $this->view->catalogs = array_unique($catalogs); + $data['catalogs'] = array_unique($catalogs); - // print "
".$query."
"; - if ($this->_getParam('catalog') && in_array($this->_getParam('catalog'), $this->view->catalogs)) { - $catalog = $this->_getParam('catalog'); + if ($request->get('catalog') && in_array($request->get('catalog'), $data['catalogs'])) { + $catalog = $request->get('catalog'); } else { - $catalog = $this->view->catalogs[0]; + $catalog = $data['catalogs'][0]; + } + $stmt->bindValue(1, $catalog); + $stmt->bindValue(2, $catalog); + $stmt->bindValue(3, $catalog); + $result = $stmt->executeQuery(); + $data['selectedCatalog'] = $catalog; + $data['terms'] = $result->fetchAll(); + foreach ($data['terms'] as &$term) { + $term['active'] = intval($term['num_sections']) && !intval($term['manually_disabled']); + } + + return $this->render('admin/terms.html.twig', $data); + } + + /** + * Manage term visibility. + */ + #[Route('/admin/terms', name: 'admin_terms_update', methods: ['POST'])] + public function termUpdateAction(Request $request) + { + $db = $this->entityManager->getConnection(); + + if ($request->get('change_visibility')) { + // Verify our CSRF key + if (!$this->isCsrfTokenValid('admin-terms-update', $request->get('csrf_key'))) { + throw new AccessDeniedException('Invalid CSRF key.'); + } + + // Verify that this is a valid term. + $catalog = $request->get('catalog'); + $term = $request->get('term'); + $verifyStmt = $db->prepare('SELECT COUNT(*) FROM STVTERM WHERE STVTERM_CODE = ?'); + $verifyStmt->bindValue(1, $term); + $result = $verifyStmt->executeQuery(); + $valid = (int) $result->fetchOne(); + $result->free(); + if (!$valid) { + throw new \InvalidArgumentException('Invalid term-code: '.$term); + } + + // Disable the term + if ('true' == $request->get('disabled')) { + $visibilityStmt = $db->prepare('INSERT INTO catalog_term_inactive (catalog_id, term_code) VALUES (?, ?);'); + } + // Enable the term + else { + $visibilityStmt = $db->prepare('DELETE FROM catalog_term_inactive WHERE catalog_id = ? AND term_code = ?;'); + } + $visibilityStmt->bindValue(1, $catalog); + $visibilityStmt->bindValue(2, $term); + $visibilityStmt->executeQuery(); } - $stmt->execute([$catalog, $catalog, $catalog]); - $this->view->catalog = $catalog; - $this->view->terms = $stmt->fetchAll(); + return $this->redirect($this->generateUrl('admin_terms_list', ['catalog' => $catalog])); } #[Route('/admin/markup', name: 'markup')] @@ -142,7 +174,7 @@ public function masqueradeAction() } /** - * Manage archive export configurations + * Manage archive export configurations. */ #[Route('/admin/export', name: 'admin_archive_config')] public function exportAction() diff --git a/templates/admin/terms.html.twig b/templates/admin/terms.html.twig new file mode 100755 index 00000000..d46f119b --- /dev/null +++ b/templates/admin/terms.html.twig @@ -0,0 +1,63 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Manage Term Visibility

+
« Back to Administration
+ +
+ +
+ +

Please Note: Any changes made here will take effect during the next synchronization with Banner

+ + + + + + + + + + + + + +{% for term in terms %} + + + + + + + + + + +{% endfor %} + +
Term CodeDescriptionSectionsManual OverrideActive?
{{ term.STVTERM_CODE }}{{ term.STVTERM_DESC }}{{ term.num_sections }} +
+ + + + + + +
+
+{% if term.active %} + Yes +{% else %} + No: + {{ term.manually_disabled ? 'Manually disabled. ' }} + {{ term.num_sections is empty ? 'Zero sections. ' }} +{% endif %} +
+{% endblock %}