Glossary: Removed c_id and session_id from table

pull/3768/head
Carlos Alvarado 4 years ago
parent b8bd654535
commit ca715b014c
No known key found for this signature in database
GPG Key ID: B612DB1EE6658FBB
  1. 3
      public/main/glossary/index.php
  2. 56
      public/main/inc/lib/glossary.lib.php
  3. 79
      src/CourseBundle/Entity/CGlossary.php
  4. 21
      src/CourseBundle/Repository/CGlossaryRepository.php

@ -57,6 +57,7 @@ $(function() {
// Tracking
Event::event_access_tool(TOOL_GLOSSARY);
/*
function sorter($item1, $item2)
{
if ($item1[2] == $item2[2]) {
@ -65,7 +66,7 @@ function sorter($item1, $item2)
return $item1[2] < $item2[2] ? -1 : 1;
}
*/
// Displaying the header
$action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : '';
$currentUrl = api_get_self().'?'.api_get_cidreq();

@ -27,7 +27,7 @@ class GlossaryManager
*/
public static function get_glossary_terms()
{
$glossary_data = [];
$glossaryData = [];
$repo = Container::getGlossaryRepository();
$courseId = api_get_course_int_id();
@ -39,14 +39,14 @@ class GlossaryManager
$glossaries = $repo->getResourcesByCourse($course, $session);
/** @var CGlossary $item */
foreach ($glossaries as $item) {
$glossary_data[] = [
$glossaryData[] = [
'id' => $item->getIid(),
'name' => $item->getName(),
'description' => $item->getDescription(),
];
}
return $glossary_data;
return $glossaryData;
/*
$table = Database::get_course_table(TABLE_GLOSSARY);
@ -189,8 +189,7 @@ class GlossaryManager
->setName($values['name'])
->setDescription($values['description'])
->setDisplayOrder($max_glossary_item + 1)
->setSessionId($sessionId)
->setCId($courseId);
;
$course = api_get_course_entity($courseId);
$session = api_get_session_entity($sessionId);
@ -329,6 +328,25 @@ class GlossaryManager
$glossary = $repo->findBy($findArray);
*/
// Database table definition
$repo = Container::getGlossaryRepository();
$courseId = api_get_course_int_id();
$sessionId = api_get_session_id();
$course = api_get_course_entity($courseId);
$session = api_get_session_entity($sessionId);
$qb = $repo->getResourcesByCourse($course, $session);
try {
$count = $qb->select('COUNT(resource)')->getQuery()->getSingleScalarResult();
} catch (NoResultException $e) {
$count = 0;
}
return $count;
$table = Database::get_course_table(TABLE_GLOSSARY);
$course_id = api_get_course_int_id();
$get_max = "SELECT MAX(display_order) FROM $table
@ -767,7 +785,7 @@ class GlossaryManager
foreach ($glossaries as $glossary) {
/** @var CGlossary $glossary */
$session_img = api_get_session_image($glossary->getSessionId(), $_user['status']);
$session_img = api_get_session_image($sessionId, $_user['status']);
$array[0] = $glossary->getName().$session_img;
if (!$view || 'table' === $view) {
$array[1] = str_replace(['<p>', '</p>'], ['', '<br />'], $glossary->getDescription());
@ -881,16 +899,18 @@ class GlossaryManager
$return = '<a href="'.api_get_self().'?action=edit_glossary&glossary_id='.$glossary_id.'&'.api_get_cidreq().'&msg=edit">'.
Display::return_icon('edit.png', get_lang('Edit'), '', 22).'</a>';
$repo = Container::getGlossaryRepository();
/** @var CGlossary $glossary_data */
$glossary_data = $repo->find($glossary_id);
$glossary_term = Security::remove_XSS(strip_tags($glossary_data->getName()));
/** @var CGlossary $glossaryData */
$glossaryData = $repo->find($glossary_id);
$glossaryTerm = Security::remove_XSS(strip_tags($glossaryData->getName()));
if (api_is_allowed_to_edit(null, true)) {
if ($glossary_data->getSessionId() == api_get_session_id()) {
$return .= '<a href="'.api_get_self().'?action=delete_glossary&glossary_id='.$glossary_id.'&'.api_get_cidreq().'" onclick="return confirmation(\''.$glossary_term.'\');">'.
Display::return_icon('delete.png', get_lang('Delete'), '', 22).'</a>';
$return .= '<a href="'.api_get_self().'?action=delete_glossary&glossary_id='.$glossary_id.'&'.api_get_cidreq().'" onclick="return confirmation(\''.$glossaryTerm.'\');">'.
Display::return_icon('delete.png', get_lang('Delete'), '', 22).'</a>';
/*
* if ($glossaryData->getSessionId() == api_get_session_id()) {
} else {
$return = get_lang('Edition not available from the session, please edit from the basic course.');
}
*/
}
return $return;
@ -1085,7 +1105,7 @@ class GlossaryManager
0,
'ASC'
);
usort($data, 'sorter');
usort($data, 'self::sorter');
$list = [];
$list[] = ['term', 'definition'];
$allowStrip = api_get_configuration_value('allow_remove_tags_in_glossary_export');
@ -1109,4 +1129,14 @@ class GlossaryManager
break;
}
}
public static function sorter($item1, $item2)
{
if ($item1[2] == $item2[2]) {
return 0;
}
return $item1[2] < $item2[2] ? -1 : 1;
}
}

@ -13,11 +13,7 @@ use Symfony\Component\Validator\Constraints as Assert;
* CGlossary.
*
* @ORM\Table(
* name="c_glossary",
* indexes={
* @ORM\Index(name="course", columns={"c_id"}),
* @ORM\Index(name="session_id", columns={"session_id"})
* }
* name="c_glossary"
* )
* @ORM\Entity
*/
@ -32,13 +28,6 @@ class CGlossary extends AbstractResource implements ResourceInterface
*/
protected $iid;
/**
* @var int
*
* @ORM\Column(name="c_id", type="integer")
*/
protected $cId;
/**
* @Assert\NotBlank()
* @ORM\Column(name="name", type="text", nullable=false)
@ -57,18 +46,6 @@ class CGlossary extends AbstractResource implements ResourceInterface
*/
protected $displayOrder;
/**
* @var int
*
* @ORM\Column(name="session_id", type="integer", nullable=true)
*/
protected $sessionId;
public function __toString(): string
{
return $this->getName();
}
/**
* Set name.
*/
@ -131,30 +108,6 @@ class CGlossary extends AbstractResource implements ResourceInterface
return $this->displayOrder;
}
/**
* Set sessionId.
*
* @param int $sessionId
*
* @return CGlossary
*/
public function setSessionId($sessionId)
{
$this->sessionId = $sessionId;
return $this;
}
/**
* Get sessionId.
*
* @return int
*/
public function getSessionId()
{
return $this->sessionId;
}
/**
* Set glossaryId.
*
@ -169,30 +122,6 @@ class CGlossary extends AbstractResource implements ResourceInterface
return $this;
}
/**
* Set cId.
*
* @param int $cId
*
* @return CGlossary
*/
public function setCId($cId)
{
$this->cId = $cId;
return $this;
}
/**
* Get cId.
*
* @return int
*/
public function getCId()
{
return $this->cId;
}
public function getIid(): int
{
return $this->iid;
@ -212,4 +141,10 @@ class CGlossary extends AbstractResource implements ResourceInterface
{
return $this->setName($name);
}
public function __toString(): string
{
return $this->getName();
}
}

@ -7,19 +7,22 @@ namespace Chamilo\CourseBundle\Repository;
use Chamilo\CoreBundle\Component\Resource\Settings;
use Chamilo\CoreBundle\Component\Resource\Template;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\ResourceInterface;
use Chamilo\CoreBundle\Entity\ResourceNode;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Form\Resource\CGlossaryType;
use Chamilo\CoreBundle\Repository\GridInterface;
use Chamilo\CoreBundle\Repository\ResourceRepository;
use Chamilo\CoreBundle\Repository\ResourceWithLinkInterface;
use Chamilo\CourseBundle\Entity\CGlossary;
use Chamilo\CourseBundle\Entity\CGroup;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Routing\RouterInterface;
final class CGlossaryRepository extends ResourceRepository implements GridInterface
final class CGlossaryRepository extends ResourceRepository implements ResourceWithLinkInterface
{
public function __construct(ManagerRegistry $registry)
{
@ -50,10 +53,10 @@ final class CGlossaryRepository extends ResourceRepository implements GridInterf
{
return $this->getResourcesByCourse($course, $session, $group, $parentNode);
}
/*
public function setResourceProperties(FormInterface $form, $course, $session, $fileType)
{
/** @var CGlossary $newResource */
/** @var CGlossary $newResource * /
$newResource = $form->getData();
$newResource
@ -65,9 +68,19 @@ final class CGlossaryRepository extends ResourceRepository implements GridInterf
return $newResource;
}
*/
public function getResourceFormType(): string
{
return CGlossaryType::class;
}
public function getLink(ResourceInterface $resource, RouterInterface $router): string
{
$params = ['name' => 'glossary/index.php', 'glossary_id' => $resource->getResourceIdentifier()];
if (!empty($extraParams)) {
$params = array_merge($params, $extraParams);
}
return $router->generate('legacy_main', $params);
}
}

Loading…
Cancel
Save