parent
df65229c61
commit
2efeb86885
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,192 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CourseBundle\Entity; |
||||
|
||||
use Chamilo\CoreBundle\Entity\Course; |
||||
use Chamilo\CoreBundle\Entity\Session; |
||||
use Doctrine\Common\Collections\ArrayCollection; |
||||
use Doctrine\Common\Collections\Collection; |
||||
use Doctrine\ORM\Mapping as ORM; |
||||
use Gedmo\Mapping\Annotation as Gedmo; |
||||
|
||||
/** |
||||
* @Gedmo\Tree(type="nested") |
||||
* @ORM\Table(name="c_wiki_category") |
||||
* Add @ to the next line if api_get_configuration_value('wiki_categories_enabled') is true |
||||
* ORM\Entity(repositoryClass="Chamilo\CourseBundle\Entity\Repository\CWikiCategoryRepository") |
||||
*/ |
||||
class CWikiCategory |
||||
{ |
||||
/** |
||||
* @var int |
||||
* @ORM\Id() |
||||
* @ORM\GeneratedValue() |
||||
* @ORM\Column(name="id", type="integer") |
||||
*/ |
||||
private $id; |
||||
/** |
||||
* @var string |
||||
* @ORM\Column(name="name", type="string") |
||||
*/ |
||||
private $name; |
||||
/** |
||||
* @var Collection<int, CWiki> |
||||
* @ORM\ManyToMany(targetEntity="Chamilo\CourseBundle\Entity\CWiki", mappedBy="categories") |
||||
*/ |
||||
private $wikiPages; |
||||
/** |
||||
* @var Course |
||||
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course") |
||||
* @ORM\JoinColumn(name="c_id", referencedColumnName="id", nullable=false, onDelete="CASCADE") |
||||
*/ |
||||
private $course; |
||||
/** |
||||
* @var Session|null |
||||
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session") |
||||
* @ORM\JoinColumn(name="session_id", referencedColumnName="id", onDelete="CASCADE") |
||||
*/ |
||||
private $session; |
||||
/** |
||||
* @var int|null |
||||
* @Gedmo\TreeLeft() |
||||
* @ORM\Column(name="lft", type="integer") |
||||
*/ |
||||
private $lft; |
||||
/** |
||||
* @var int|null |
||||
* @Gedmo\TreeLevel() |
||||
* @ORM\Column(name="lvl", type="integer") |
||||
*/ |
||||
private $lvl; |
||||
/** |
||||
* @var int|null |
||||
* @Gedmo\TreeRight() |
||||
* @ORM\Column(name="rgt", type="integer") |
||||
*/ |
||||
private $rgt; |
||||
/** |
||||
* @var CWikiCategory|null |
||||
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CWikiCategory") |
||||
* @ORM\JoinColumn(name="tree_root", referencedColumnName="id", onDelete="CASCADE") |
||||
*/ |
||||
private $root; |
||||
/** |
||||
* @var CWikiCategory|null |
||||
* @Gedmo\TreeParent() |
||||
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CWikiCategory", inversedBy="children") |
||||
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE") |
||||
*/ |
||||
private $parent; |
||||
/** |
||||
* @var Collection<int, CWikiCategory> |
||||
* @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CWikiCategory", mappedBy="parent") |
||||
* @ORM\OrderBy({"lft"="ASC"}) |
||||
*/ |
||||
private $children; |
||||
|
||||
public function __construct() |
||||
{ |
||||
$this->parent = null; |
||||
$this->children = new ArrayCollection(); |
||||
$this->wikiPages = new ArrayCollection(); |
||||
} |
||||
|
||||
public function __toString() |
||||
{ |
||||
return $this->name; |
||||
} |
||||
|
||||
public function getId(): int |
||||
{ |
||||
return $this->id; |
||||
} |
||||
|
||||
public function getName(): string |
||||
{ |
||||
return $this->name; |
||||
} |
||||
|
||||
public function getNodeName(): string |
||||
{ |
||||
return str_repeat(' ', $this->lvl).$this->name; |
||||
} |
||||
|
||||
public function setName(string $name): CWikiCategory |
||||
{ |
||||
$this->name = $name; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
public function getCourse(): Course |
||||
{ |
||||
return $this->course; |
||||
} |
||||
|
||||
public function setCourse(Course $course): CWikiCategory |
||||
{ |
||||
$this->course = $course; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
public function getSession(): ?Session |
||||
{ |
||||
return $this->session; |
||||
} |
||||
|
||||
public function setSession(?Session $session): CWikiCategory |
||||
{ |
||||
$this->session = $session; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
public function getRoot(): ?CWikiCategory |
||||
{ |
||||
return $this->root; |
||||
} |
||||
|
||||
public function getParent(): ?CWikiCategory |
||||
{ |
||||
return $this->parent; |
||||
} |
||||
|
||||
public function setParent(?CWikiCategory $parent): CWikiCategory |
||||
{ |
||||
$this->parent = $parent; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
public function getChildren(): Collection |
||||
{ |
||||
return $this->children; |
||||
} |
||||
|
||||
public function setChildren(Collection $children): CWikiCategory |
||||
{ |
||||
$this->children = $children; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
public function addWikiPage(CWiki $page): CWikiCategory |
||||
{ |
||||
$this->wikiPages->add($page); |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
public function getWikiPages(): Collection |
||||
{ |
||||
return $this->wikiPages; |
||||
} |
||||
|
||||
public function getLvl(): ?int |
||||
{ |
||||
return $this->lvl; |
||||
} |
||||
} |
||||
@ -0,0 +1,44 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CourseBundle\Entity\Repository; |
||||
|
||||
use Chamilo\CoreBundle\Entity\Course; |
||||
use Chamilo\CoreBundle\Entity\Session; |
||||
use Gedmo\Tree\Entity\Repository\NestedTreeRepository; |
||||
|
||||
class CWikiCategoryRepository extends NestedTreeRepository |
||||
{ |
||||
public function findByCourse(Course $course, ?Session $session): array |
||||
{ |
||||
return $this->findBy(['course' => $course, 'session' => $session], ['lft' => 'ASC']); |
||||
} |
||||
|
||||
public function countByCourse(Course $course, ?Session $session): int |
||||
{ |
||||
return $this->count(['couse' => $course, 'session' => $session]); |
||||
} |
||||
|
||||
/** |
||||
* @return array|string |
||||
*/ |
||||
public function buildCourseTree(Course $course, ?Session $session, array $options = []) |
||||
{ |
||||
$whereParams = ['course' => $course]; |
||||
|
||||
if ($session) { |
||||
$whereParams['session'] = $session; |
||||
} |
||||
|
||||
$qb = $this->createQueryBuilder('c') |
||||
->where('c.course = :course') |
||||
->andWhere($session ? 'c.session = :session' : 'c.session IS NULL') |
||||
->orderBy('c.lft', 'ASC') |
||||
->setParameters($whereParams) |
||||
->getQuery() |
||||
; |
||||
|
||||
return $this->buildTree($qb->getArrayResult(), $options); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue