-
Notifications
You must be signed in to change notification settings - Fork 359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[VUFIND-1674] Show count of saved items in account menu #3836
base: dev
Are you sure you want to change the base?
Changes from all commits
4a41997
97c6981
26de56a
7b74767
de7aac7
a621607
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
/** | ||
* "Get User Favorites Status" AJAX handler | ||
* | ||
* PHP version 8 | ||
* | ||
* Copyright (C) Villanova University 2024. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
* @category VuFind | ||
* @package AJAX | ||
* @author Demian Katz <demian.katz@villanova.edu> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development Wiki | ||
*/ | ||
|
||
namespace VuFind\AjaxHandler; | ||
|
||
use Laminas\Mvc\Controller\Plugin\Params; | ||
use VuFind\Db\Entity\UserEntityInterface; | ||
use VuFind\Db\Service\ResourceServiceInterface; | ||
use VuFind\Session\Settings as SessionSettings; | ||
|
||
use function count; | ||
|
||
/** | ||
* "Get User Favorites Status" AJAX handler | ||
* | ||
* @category VuFind | ||
* @package AJAX | ||
* @author Demian Katz <demian.katz@villanova.edu> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development Wiki | ||
*/ | ||
class GetUserFavoritesStatus extends AbstractBase | ||
{ | ||
/** | ||
* Constructor | ||
* | ||
* @param SessionSettings $ss Session settings | ||
* @param ?UserEntityInterface $user Logged in user (or null) | ||
* @param ResourceServiceInterface $resourceService Resoruce database service | ||
*/ | ||
public function __construct( | ||
SessionSettings $ss, | ||
protected ?UserEntityInterface $user, | ||
protected ResourceServiceInterface $resourceService | ||
) { | ||
$this->sessionSettings = $ss; | ||
} | ||
|
||
/** | ||
* Handle a request. | ||
* | ||
* @param Params $params Parameter helper from controller | ||
* | ||
* @return array [response data, internal status code, HTTP status code] | ||
*/ | ||
public function handleRequest(Params $params) | ||
{ | ||
$this->disableSessionWrites(); // avoid session write timing bug | ||
$count = $this->user ? count($this->resourceService->getFavorites($this->user)) : 0; | ||
return $this->formatResponse(compact('count')); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
/** | ||
* Factory for GetUserFavoritesStatus AJAX handler. | ||
* | ||
* PHP version 8 | ||
* | ||
* Copyright (C) Villanova University 2024. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
* @category VuFind | ||
* @package AJAX | ||
* @author Demian Katz <demian.katz@villanova.edu> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development Wiki | ||
*/ | ||
|
||
namespace VuFind\AjaxHandler; | ||
|
||
use Laminas\ServiceManager\Exception\ServiceNotCreatedException; | ||
use Laminas\ServiceManager\Exception\ServiceNotFoundException; | ||
use Psr\Container\ContainerExceptionInterface as ContainerException; | ||
use Psr\Container\ContainerInterface; | ||
use VuFind\Db\Service\ResourceServiceInterface; | ||
|
||
/** | ||
* Factory for GetUserFavoritesStatus AJAX handler. | ||
* | ||
* @category VuFind | ||
* @package AJAX | ||
* @author Demian Katz <demian.katz@villanova.edu> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development Wiki | ||
*/ | ||
class GetUserFavoritesStatusFactory implements \Laminas\ServiceManager\Factory\FactoryInterface | ||
{ | ||
/** | ||
* Create an object | ||
* | ||
* @param ContainerInterface $container Service manager | ||
* @param string $requestedName Service being created | ||
* @param null|array $options Extra options (optional) | ||
* | ||
* @return object | ||
* | ||
* @throws ServiceNotFoundException if unable to resolve the service. | ||
* @throws ServiceNotCreatedException if an exception is raised when | ||
* creating a service. | ||
* @throws ContainerException&\Throwable if any other error occurs | ||
* | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function __invoke( | ||
ContainerInterface $container, | ||
$requestedName, | ||
array $options = null | ||
) { | ||
return new $requestedName( | ||
$container->get(\VuFind\Session\Settings::class), | ||
$container->get(\VuFind\Auth\Manager::class)->getUserObject(), | ||
$container->get(\VuFind\Db\Service\PluginManager::class)->get(ResourceServiceInterface::class), | ||
...($options ?: []) | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,3 +107,7 @@ | |
<?=$this->recommend($current)?> | ||
<?php endforeach; ?> | ||
</div> | ||
|
||
<?php if (!isset($list)): ?> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now, the cache only gets invalidated when you go to the favorites page. Maybe it would be better to always invalidate the cache on all list pages, so that list actions cause the favorites total to get recalculated. However, this would make a lot of unnecessary requests or would require the addition of some additional logic to figure out when invalidation is really needed. |
||
<?=$this->render('myresearch/notify-account-status.phtml', ['method' => 'favorites', 'accountStatus' => ['count' => $recordTotal]]); ?> | ||
<?php endif; ?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth creating a new resourceService method that just returns a count to reduce the amount of data pushed around, or is it better to keep this simple and trust the caching?