Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TopLinks: Allow position them on top of tools - refs BT#18474
- Loading branch information
Showing
5 changed files
with
210 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
29 changes: 29 additions & 0 deletions
29
plugin/toplinks/src/Entity/Repository/TopLinkRelToolRepository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters