parent
49e3bd00c5
commit
fb11547fd2
@ -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(); |
||||
} |
||||
} |
||||
@ -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; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue