Wiki: Add support for page categories - refs BT#20357

Author: @AngelFQC
pull/4529/head
Angel Fernando Quiroz Campos 3 years ago committed by GitHub
parent df65229c61
commit 2efeb86885
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      main/install/configuration.dist.php
  2. 6
      main/wiki/index.php
  3. 2214
      main/wiki/wiki.inc.php
  4. 37
      src/Chamilo/CourseBundle/Entity/CWiki.php
  5. 192
      src/Chamilo/CourseBundle/Entity/CWikiCategory.php
  6. 44
      src/Chamilo/CourseBundle/Entity/Repository/CWikiCategoryRepository.php

@ -2347,6 +2347,22 @@ INSERT INTO `extra_field` (`extra_field_type`, `field_type`, `variable`, `displa
//CREATE INDEX c_attendance_sheet_user ON track_e_access_complete (attendance_sheet_id, user_id);
//$_configuration['attendance_allow_comments'] = false;
// Enable categories in Wiki tool.
// 1. Run the following DB changes:
/*
CREATE TABLE c_wiki_rel_category (wiki_id INT NOT NULL, category_id INT NOT NULL, INDEX IDX_AC88945BAA948DBE (wiki_id), INDEX IDX_AC88945B12469DE2 (category_id), PRIMARY KEY(wiki_id, category_id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB;
CREATE TABLE c_wiki_category (id INT AUTO_INCREMENT NOT NULL, c_id INT NOT NULL, session_id INT DEFAULT NULL, tree_root INT DEFAULT NULL, parent_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, lft INT NOT NULL, lvl INT NOT NULL, rgt INT NOT NULL, INDEX IDX_17F1099A91D79BD3 (c_id), INDEX IDX_17F1099A613FECDF (session_id), INDEX IDX_17F1099AA977936C (tree_root), INDEX IDX_17F1099A727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB;
ALTER TABLE c_wiki_rel_category ADD CONSTRAINT FK_AC88945BAA948DBE FOREIGN KEY (wiki_id) REFERENCES c_wiki (iid) ON DELETE CASCADE;
ALTER TABLE c_wiki_rel_category ADD CONSTRAINT FK_AC88945B12469DE2 FOREIGN KEY (category_id) REFERENCES c_wiki_category (id) ON DELETE CASCADE;
ALTER TABLE c_wiki_category ADD CONSTRAINT FK_17F1099A91D79BD3 FOREIGN KEY (c_id) REFERENCES course (id) ON DELETE CASCADE;
ALTER TABLE c_wiki_category ADD CONSTRAINT FK_17F1099A613FECDF FOREIGN KEY (session_id) REFERENCES session (id) ON DELETE CASCADE;
ALTER TABLE c_wiki_category ADD CONSTRAINT FK_17F1099AA977936C FOREIGN KEY (tree_root) REFERENCES c_wiki_category (id) ON DELETE CASCADE;
ALTER TABLE c_wiki_category ADD CONSTRAINT FK_17F1099A727ACA70 FOREIGN KEY (parent_id) REFERENCES c_wiki_category (id) ON DELETE CASCADE;
*/
// 2. Add an "@" before "ORM\ManyToMany" and "@ORM\JoinTable" in the "CWiki::$categories" property definition (in src/Chamilo/CourseBundle/Entity/CWiki.php)
// 3. Add an "@" before "ORM\Entity" in the "CWikiCategory" class definition (in src/Chamilo/CourseBundle/Entity/CWikiCategory.php)
//$_configuration['wiki_categories_enabled'] = false;
// KEEP THIS AT THE END
// -------- Custom DB changes
// Add user activation by confirmation email

@ -71,7 +71,7 @@ if ($groupId) {
$is_allowed_to_edit = api_is_allowed_to_edit(false, true);
// The page we are dealing with
$page = isset($_GET['title']) ? $_GET['title'] : 'index';
$page = $_GET['title'] ?? 'index';
$action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : 'showpage';
$view = isset($_GET['view']) ? Security::remove_XSS($_GET['view']) : null;
@ -88,8 +88,8 @@ $wiki->blockConcurrentEditions(api_get_user_id(), $action);
/* MAIN WIKI AREA */
ob_start();
$handleAction = $wiki->handleAction($action);
if (!$handleAction && $action == 'export_to_pdf') {
$wiki->handleAction($action);
if ($action == 'export_to_pdf') {
$wiki->handleAction('showpage');
}
$content = ob_get_contents();

File diff suppressed because it is too large Load Diff

@ -3,6 +3,8 @@
namespace Chamilo\CourseBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
@ -219,6 +221,23 @@ class CWiki
* @ORM\Column(name="session_id", type="integer", nullable=true)
*/
protected $sessionId;
/**
* @var Collection<int, CWikiCategory>
*
* Add @ to the next lines if api_get_configuration_value('wiki_categories_enabled') is true
* ORM\ManyToMany(targetEntity="Chamilo\CourseBundle\Entity\CWikiCategory", inversedBy="wikiPages")
* ORM\JoinTable(
* name="c_wiki_rel_category",
* joinColumns={@ORM\JoinColumn(name="wiki_id", referencedColumnName="iid", onDelete="CASCADE")},
* inverseJoinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id", onDelete="CASCADE")}
* )
*/
private $categories;
public function __construct()
{
$this->categories = new ArrayCollection();
}
/**
* Set pageId.
@ -844,6 +863,11 @@ class CWiki
return $this->id;
}
public function getIid(): int
{
return $this->iid;
}
/**
* Set cId.
*
@ -867,4 +891,17 @@ class CWiki
{
return $this->cId;
}
public function getCategories()
{
return $this->categories;
}
public function addCategory(CWikiCategory $category): CWiki
{
$category->addWikiPage($this);
$this->categories->add($category);
return $this;
}
}

@ -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('&nbsp;&nbsp;&nbsp;&nbsp;', $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…
Cancel
Save