Add course_description as a resource node

pull/3124/head
Julio Montoya 5 years ago
parent 34be57a90d
commit e2506faf93
  1. 37
      src/CoreBundle/Form/Resource/CCourseDescriptionType.php
  2. 2
      src/CoreBundle/Resources/config/tools.yml
  3. 36
      src/CourseBundle/Entity/CCourseDescription.php
  4. 67
      src/CourseBundle/Repository/CCourseDescriptionRepository.php
  5. 4
      src/CourseBundle/Resources/config/services.yml

@ -0,0 +1,37 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Form\Resource;
use Chamilo\CourseBundle\Entity\CCourseDescription;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class CCourseDescriptionType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title', TextType::class)
->add('content', TextareaType::class)
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'data_class' => CCourseDescription::class,
]
);
}
public function getName()
{
return 'chamilo_c_course_description';
}
}

@ -119,7 +119,7 @@ services:
arguments:
- 'course_description'
- 'authoring'
- '/main/course_description/index.php'
- '/resources/course_description/course_descriptions'
- '@chamilo_course.settings.course_description'
-
course_descriptions:

@ -4,15 +4,20 @@
namespace Chamilo\CourseBundle\Entity;
use APY\DataGridBundle\Grid\Mapping as GRID;
use Chamilo\CoreBundle\Entity\Resource\AbstractResource;
use Chamilo\CoreBundle\Entity\Resource\ResourceInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* CCourseDescription.
*
* @GRID\Source(columns="iid, title, resourceNode.createdAt", filterable=false, groups={"resource"})
*
* @ORM\Table(name="c_course_description", indexes={@ORM\Index(name="session_id", columns={"session_id"})})
* @ORM\Entity
*/
class CCourseDescription
class CCourseDescription extends AbstractResource implements ResourceInterface
{
public const TYPE_DESCRIPTION = 1;
public const TYPE_OBJECTIVES = 2;
@ -81,6 +86,17 @@ class CCourseDescription
*/
protected $progress;
/**
* CCourseDescription constructor.
*
* @param int $iid
*/
public function __construct()
{
$this->progress = 0;
$this->descriptionType = 1;
}
/**
* Set title.
*
@ -257,15 +273,21 @@ class CCourseDescription
return $this->iid;
}
public function __toString(): string
{
return $this->getTitle();
}
/**
* @param int $iid
*
* @return CCourseDescription
* Resource identifier.
*/
public function setIid($iid)
public function getResourceIdentifier(): int
{
$this->iid = $iid;
return $this->getIid();
}
return $this;
public function getResourceName(): string
{
return $this->getTitle();
}
}

@ -0,0 +1,67 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CourseBundle\Repository;
use APY\DataGridBundle\Grid\Column\Column;
use APY\DataGridBundle\Grid\Grid;
use Chamilo\CoreBundle\Component\Utils\ResourceSettings;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Resource\ResourceNode;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Repository\ResourceRepository;
use Chamilo\CoreBundle\Repository\ResourceRepositoryInterface;
use Chamilo\CourseBundle\Entity\CCourseDescription;
use Chamilo\CourseBundle\Entity\CGroupInfo;
use Chamilo\UserBundle\Entity\User;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
final class CCourseDescriptionRepository extends ResourceRepository implements ResourceRepositoryInterface
{
public function getResourceSettings(): ResourceSettings
{
$settings = parent::getResourceSettings();
$settings
->setAllowNodeCreation(false)
->setAllowResourceCreation(true)
->setAllowResourceUpload(false)
->setAllowDownloadAll(false)
;
return $settings;
}
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null): QueryBuilder
{
return $this->getResourcesByCourse($course, $session, $group, $parentNode);
}
public function getTitleColumn(Grid $grid): Column
{
return $grid->getColumn('title');
}
public function saveUpload(UploadedFile $file) {
}
public function saveResource(FormInterface $form, $course, $session, $fileType)
{
/** @var CCourseDescription $newResource */
$newResource = $form->getData();
$newResource
->setCId($course->getId())
;
if ($session) {
$newResource->setSessionId($session->getId());
}
return $newResource;
}
}

@ -79,6 +79,10 @@ services:
arguments:
$className: 'Chamilo\CourseBundle\Entity\CChatConversation'
Chamilo\CourseBundle\Repository\CCourseDescriptionRepository:
arguments:
$className: 'Chamilo\CourseBundle\Entity\CCourseDescription'
Chamilo\CourseBundle\Repository\CDocumentRepository:
arguments:
$className: 'Chamilo\CourseBundle\Entity\CDocument'

Loading…
Cancel
Save