Skip to content
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

Migrate Feedback Service #8

Merged
merged 19 commits into from
Mar 7, 2023
Merged
1 change: 1 addition & 0 deletions module/VuFind/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@
'result_cache' => 'filesystem',
'metadata_cache' => 'filesystem',
'hydration_cache' => 'filesystem',
'proxy_dir' => LOCAL_CACHE_DIR . '/doctrine-proxies',
],
],
'driver' => [
Expand Down
100 changes: 100 additions & 0 deletions module/VuFind/src/VuFind/Db/Entity/Feedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ class Feedback implements EntityInterface
*/
protected $updatedBy;

/**
* Id getter
*
* @return int
*/
public function getId()
{
return $this->id;
}

/**
* Message setter
*
Expand All @@ -194,6 +204,16 @@ public function setMessage(string $message): Feedback
return $this;
}

/**
* Message getter
*
* @return string
*/
public function getMessage()
{
return $this->message;
}

/**
* Form data setter.
*
Expand All @@ -207,6 +227,16 @@ public function setFormData(string $data): Feedback
return $this;
}

/**
* Form data getter
*
* @return string
*/
public function getFormData()
{
return $this->formData;
}

/**
* Form name setter.
*
Expand All @@ -220,6 +250,16 @@ public function setFormName(string $name): Feedback
return $this;
}

/**
* Form name getter
*
* @return string
*/
public function getFormName()
{
return $this->formName;
}

/**
* Created setter.
*
Expand All @@ -233,6 +273,16 @@ public function setCreated(DateTime $dateTime): Feedback
return $this;
}

/**
* Created getter
*
* @return Datetime
*/
public function getCreated()
{
return $this->created;
}

/**
* Updated setter.
*
Expand All @@ -246,6 +296,16 @@ public function setUpdated(DateTime $dateTime): Feedback
return $this;
}

/**
* Updated getter
*
* @return Datetime
*/
public function getUpdated()
{
return $this->updated;
}

/**
* Status setter.
*
Expand All @@ -259,6 +319,16 @@ public function setStatus(string $status): Feedback
return $this;
}

/**
* Status getter
*
* @return string
*/
public function getStatus()
{
return $this->status;
}

/**
* Site URL setter.
*
Expand All @@ -272,6 +342,16 @@ public function setSiteUrl(string $url): Feedback
return $this;
}

/**
* Site URL getter
*
* @return string
*/
public function getSiteUrl()
{
return $this->siteUrl;
}

/**
* User setter.
*
Expand All @@ -285,6 +365,16 @@ public function setUser(?User $user): Feedback
return $this;
}

/**
* User getter
*
* @return User
*/
public function getUser()
{
return $this->user;
}

/**
* Updatedby setter.
*
Expand All @@ -297,4 +387,14 @@ public function setUpdatedBy(?User $user): Feedback
$this->updatedBy = $user;
return $this;
}

/**
* Updatedby getter
*
* @return User
*/
public function getUpdatedBy()
{
return $this->updatedBy;
}
}
10 changes: 10 additions & 0 deletions module/VuFind/src/VuFind/Db/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,14 @@ class User implements EntityInterface
* @ORM\Column(name="last_language", type="string", length=30, nullable=false)
*/
protected $lastLanguage = '';

/**
* Id getter
*
* @return int
*/
public function getId()
{
return $this->id;
}
}
1 change: 0 additions & 1 deletion module/VuFind/src/VuFind/Db/Row/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
ChangeTracker::class => RowGatewayFactory::class,
Comments::class => RowGatewayFactory::class,
ExternalSession::class => RowGatewayFactory::class,
Feedback::class => RowGatewayFactory::class,
skellamp marked this conversation as resolved.
Show resolved Hide resolved
OaiResumption::class => RowGatewayFactory::class,
Ratings::class => RowGatewayFactory::class,
Record::class => RowGatewayFactory::class,
Expand Down
157 changes: 155 additions & 2 deletions module/VuFind/src/VuFind/Db/Service/FeedbackService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* PHP version 7
*
* Copyright (C) Villanova University 2022.
* Copyright (C) Villanova University 2023.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
Expand All @@ -21,13 +21,16 @@
*
* @category VuFind
* @package Database
* @author Demian Katz <demian.katz@villanova.edu>
* @author Sudharma Kellampalli <skellamp@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:plugins:database_gateways Wiki
*/
namespace VuFind\Db\Service;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Pagination\Paginator;
use VuFind\Db\Entity\Feedback;
use VuFind\Db\Entity\PluginManager as EntityPluginManager;

/**
* Database service for feedback.
Expand All @@ -40,6 +43,32 @@
*/
class FeedbackService extends AbstractService
{
/**
* Db column name to Doctrine entity field mapper
*
* @var array
*/
protected $fieldMap = [
'form_data' => 'formData',
'form_name' => 'formName',
'site_url' => 'siteUrl',
'user_id' => 'user',
'updated_by' => 'updatedBy',
];

/**
skellamp marked this conversation as resolved.
Show resolved Hide resolved
* Constructor
*
* @param EntityManager $entityManager Doctrine ORM entity manager
* @param EntityPluginManager $entityPluginManager VuFind entity plugin manager
*/
public function __construct(
EntityManager $entityManager,
EntityPluginManager $entityPluginManager
) {
parent::__construct($entityManager, $entityPluginManager);
}

/**
* Create a feedback entity object.
*
Expand All @@ -50,4 +79,128 @@ public function createEntity(): Feedback
$class = $this->getEntityClass(Feedback::class);
return new $class;
}

/**
* Get feedback by filter
*
* @param string|null $formName Form name
* @param string|null $siteUrl Site URL
* @param string|null $status Current status
* @param int|null $page Current page
* @param int $limit Limit per page
*
* @return Paginator
*/
public function getFeedbackByFilter(
$formName = null,
$siteUrl = null,
$status = null,
$page = null,
$limit = 20
): Paginator {
$dql = "SELECT f, CONCAT(u.firstname, ' ', u.lastname) AS user_name, "
. "CONCAT(m.firstname, ' ', m.lastname) AS manager_name "
. "FROM " . $this->getEntityClass(Feedback::class) . " f "
. "LEFT JOIN f.user u "
. "LEFT JOIN f.updatedBy m";
$parameters = $dqlWhere = [];

if (null !== $formName) {
$dqlWhere[] = "f.formName = :formName";
$parameters['formName'] = $formName;
}
if (null !== $siteUrl) {
$dqlWhere[] = "f.siteUrl = :siteUrl";
$parameters['siteUrl'] = $siteUrl;
}
if (null !== $status) {
$dqlWhere[] = "f.status = :status";
$parameters['status'] = $status;
}
if (!empty($dqlWhere)) {
$dql .= ' WHERE ' . implode(' AND ', $dqlWhere);
}
$dql .= " ORDER BY f.created DESC";
$query = $this->entityManager->createQuery($dql);
$query->setParameters($parameters);

if (null !== $page) {
$query->setMaxResults($limit);
skellamp marked this conversation as resolved.
Show resolved Hide resolved
$query->setFirstResult($limit * ($page - 1));
}
$paginator = new Paginator($query);
$paginator->setUseOutputWalkers(false);
return $paginator;
}

/**
* Delete feedback by ids
*
* @param array $ids IDs
*
* @return int Count of deleted rows
*/
public function deleteByIdArray(array $ids): int
{
// Do nothing if we have no IDs to delete!
if (empty($ids)) {
return 0;
}
$dql = 'DELETE FROM ' . $this->getEntityClass(Feedback::class) . ' fb '
. 'WHERE fb.id IN (:ids)';
$query = $this->entityManager->createQuery($dql);
$query->setParameters(compact('ids'));
$query->execute();
return count($ids);
}

/**
* Get values for a column
*
* @param string $column Column name
*
* @return array
*/
public function getColumn(string $column): array
{
$dql = "SELECT f.id, f." . $this->mapField($column)
. " FROM " . $this->getEntityClass(Feedback::class) . " f "
. "ORDER BY f." . $this->mapField($column);
$query = $this->entityManager->createQuery($dql);
return $query->getResult();
}

/**
* Update a column
*
* @param string $column Column name
* @param mixed $value Column value
* @param int $id id value
*
* @return bool
*/
public function updateColumn($column, $value, $id)
{
$parameters = [];
$dql = "UPDATE " . $this->getEntityClass(Feedback::class) . " f "
. "SET f." . $this->mapField($column) . " = :value "
. "WHERE f.id = :id";
$parameters['value'] = $value;
$parameters['id'] = $id;
$query = $this->entityManager->createQuery($dql);
$query->setParameters($parameters);
return $query->execute();
}

/**
* Column mapper
*
* @param string $column Column name
*
* @return string
*/
protected function mapField($column)
{
return $this->fieldMap[$column] ?? $column;
}
}
Loading