TopLinks: Allow position them on top of tools - refs BT#18474

pull/3831/head
Angel Fernando Quiroz Campos 5 years ago
parent 49e3bd00c5
commit fb11547fd2
  1. 34
      plugin/toplinks/index.php
  2. 29
      plugin/toplinks/src/Entity/Repository/TopLinkRelToolRepository.php
  3. 29
      plugin/toplinks/src/Entity/TopLink.php
  4. 102
      plugin/toplinks/src/Entity/TopLinkRelTool.php
  5. 17
      plugin/toplinks/src/TopLinksPlugin.php

@ -1,2 +1,36 @@
<?php
/* For license terms, see /license.txt */
use Chamilo\PluginBundle\Entity\TopLinks\TopLinkRelTool;
$httpRequest = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
if ('/main/course_home/course_home.php' === $httpRequest->getScriptName() && !api_is_allowed_to_edit()) {
$course = api_get_course_entity();
$em = Database::getManager();
$linkToolRepo = $em->getRepository(TopLinkRelTool::class);
$linkTools = $linkToolRepo->findInCourse($course);
$toolIds = [];
/** @var TopLinkRelTool $linkTool */
foreach ($linkTools as $linkTool) {
$toolIds[] = $linkTool->getTool()->getIid();
}
?>
<script>
$(function () {
var ids = JSON.parse('<?php echo json_encode($toolIds) ?>');
$(ids).each(function (index, id) {
var $toolA = $('#istooldesc_' + id).parents('.course-tool').parent();
$toolA.prependTo($toolA.parent());
});
});
</script>
<?php
}

@ -0,0 +1,29 @@
<?php
/* For license terms, see /license.txt */
namespace Chamilo\PluginBundle\Entity\TopLinks\Repository;
use Chamilo\CoreBundle\Entity\Course;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\Expr\Join;
/**
* Class TopLinkRelToolRepository.
*
* @package Chamilo\PluginBundle\Entity\TopLinks\Repository
*/
class TopLinkRelToolRepository extends EntityRepository
{
public function findInCourse(Course $course)
{
$qb = $this->createQueryBuilder('tlrt');
return $qb
->innerJoin('tlrt.tool', 'tool', Join::WITH)
->where($qb->expr()->eq('tool.cId', ':course'))
->setParameter('course', $course)
->getQuery()
->getResult();
}
}

@ -4,6 +4,10 @@
namespace Chamilo\PluginBundle\Entity\TopLinks;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CourseBundle\Entity\CTool;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
/**
@ -48,11 +52,18 @@ class TopLink
* @ORM\Column(name="icon", type="string", nullable=true)
*/
private $icon;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\OneToMany(targetEntity="Chamilo\PluginBundle\Entity\TopLinks\TopLinkRelTool", mappedBy="link", orphanRemoval=true, cascade={"persist", "remove"})
*/
private $tools;
public function __construct()
{
$this->target = '_blank';
$this->icon = null;
$this->tools = new ArrayCollection();
}
/**
@ -142,4 +153,22 @@ class TopLink
return $this;
}
/**
* @return \Doctrine\Common\Collections\Collection
*/
public function getTools()
{
return $this->tools;
}
public function addTool(CTool $tool)
{
$linkTool = new TopLinkRelTool();
$linkTool
->setTool($tool)
->setLink($this);
$this->tools->add($linkTool);
}
}

@ -0,0 +1,102 @@
<?php
/* For license terms, see /license.txt */
namespace Chamilo\PluginBundle\Entity\TopLinks;
use Chamilo\CourseBundle\Entity\CTool;
use Doctrine\ORM\Mapping as ORM;
/**
* Class TopLinkRelTool.
*
* @package Chamilo\PluginBundle\Entity\TopLinks
*
* @ORM\Table(name="toplinks_link_rel_tool")
* @ORM\Entity(repositoryClass="Chamilo\PluginBundle\Entity\TopLinks\Repository\TopLinkRelToolRepository")
*/
class TopLinkRelTool
{
/**
* @var int
*
* @ORM\Column(type="integer", name="id")
* @ORM\Id()
* @ORM\GeneratedValue()
*/
private $id;
/**
* @var \Chamilo\PluginBundle\Entity\TopLinks\TopLink
*
* @ORM\ManyToOne(targetEntity="Chamilo\PluginBundle\Entity\TopLinks\TopLink", inversedBy="tools")
* @ORM\JoinColumn(name="link_id", referencedColumnName="id")
*/
private $link;
/**
* @var \Chamilo\CourseBundle\Entity\CTool
*
* @ORM\OneToOne(targetEntity="Chamilo\CourseBundle\Entity\CTool")
* @ORM\JoinColumn(name="tool_id", referencedColumnName="iid")
*/
private $tool;
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @param int $id
*
* @return TopLinkRelTool
*/
public function setId(int $id): TopLinkRelTool
{
$this->id = $id;
return $this;
}
/**
* @return \Chamilo\PluginBundle\Entity\TopLinks\TopLink
*/
public function getLink(): TopLink
{
return $this->link;
}
/**
* @param \Chamilo\PluginBundle\Entity\TopLinks\TopLink $link
*
* @return TopLinkRelTool
*/
public function setLink(TopLink $link): TopLinkRelTool
{
$this->link = $link;
return $this;
}
/**
* @return \Chamilo\CourseBundle\Entity\CTool
*/
public function getTool(): CTool
{
return $this->tool;
}
/**
* @param \Chamilo\CourseBundle\Entity\CTool $tool
*
* @return TopLinkRelTool
*/
public function setTool(CTool $tool): TopLinkRelTool
{
$this->tool = $tool;
return $this;
}
}

@ -3,6 +3,7 @@
/* For license terms, see /license.txt */
use Chamilo\PluginBundle\Entity\TopLinks\TopLink;
use Chamilo\PluginBundle\Entity\TopLinks\TopLinkRelTool;
use Doctrine\ORM\Tools\SchemaTool;
/**
@ -48,12 +49,24 @@ class TopLinksPlugin extends Plugin implements HookPluginInterface
public function addToolInCourse(int $courseId, TopLink $link)
{
$this->createLinkToCourseTool(
$tool = $this->createLinkToCourseTool(
$link->getTitle(),
$courseId,
null,
'toplinks/start.php?'.http_build_query(['link' => $link->getId()])
);
if (null === $tool) {
return;
}
$tool->setTarget($link->getTarget());
$link->addTool($tool);
$em = Database::getManager();
$em->persist($link);
$em->flush();
}
public function install()
@ -63,6 +76,7 @@ class TopLinksPlugin extends Plugin implements HookPluginInterface
$tableReferences = [
'toplinks_link' => $em->getClassMetadata(TopLink::class),
'toplinks_link_rel_tool' => $em->getClassMetadata(TopLinkRelTool::class),
];
$tablesExists = $schemaManager->tablesExist(array_keys($tableReferences));
@ -91,6 +105,7 @@ class TopLinksPlugin extends Plugin implements HookPluginInterface
$tableReferences = [
'toplinks_link' => $em->getClassMetadata(TopLink::class),
'toplinks_link_rel_tool' => $em->getClassMetadata(TopLinkRelTool::class),
];
$schemaTool = new SchemaTool($em);

Loading…
Cancel
Save