Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
[New resource] ClacoForm (#1682)
Browse files Browse the repository at this point in the history
* [WIP] Creates base model

* Adds basic fields management, category management, template management

* Adds keywords management

* Adds basic entries management

* Allows to add keywords to an entry

* Splits entries list in 3 modes

* Allows to add a category to a field choice

* Adds strict unicity for field choice label

* Adds & removes categories depending on fields with choices associated to categories

* Adds rich text field type

* Allow to view an entry and comment it

* Separates button to validate comment from one to activate it. Shows number of comments

* Allows to edit entry from entry view page

* Allows to fetch random entries

* Fuses migration files

* Allows to display the number of entries

* Shows confidential data in entry view

* Allows to choose destination at resource opening

* Removes visible flag from FieldFacet entity

* Sends internal message to category managers

* Removes references to votes

* Makes use of template

* php-cs + eslint

* checkstyle

* checkstyle

* Allows to filter by category and keyword

* Adds resource icon + updates composer.json

* Fixes resource icon
  • Loading branch information
Anh Thao PHAM authored and LaurentGruber committed Dec 16, 2016
1 parent 996a79c commit e82964b
Show file tree
Hide file tree
Showing 112 changed files with 12,698 additions and 80 deletions.
6 changes: 4 additions & 2 deletions composer.json
Expand Up @@ -180,7 +180,8 @@
"Claroline\\FlashCardBundle\\": "plugin/flashcard",
"Innova\\MediaResourceBundle\\": "plugin/media-resource",
"FormaLibre\\OfficeConnectBundle\\": "plugin/o365",
"Claroline\\DashboardBundle\\": "plugin/dashboard"
"Claroline\\DashboardBundle\\": "plugin/dashboard",
"Claroline\\ClacoFormBundle\\": "plugin/claco-form"
}
},
"extra": {
Expand Down Expand Up @@ -235,7 +236,8 @@
"Icap\\LessonBundle\\IcapLessonBundle",
"Claroline\\ChatBundle\\ClarolineChatBundle",
"FormaLibre\\OfficeConnectBundle\\FormaLibreOfficeConnectBundle",
"Claroline\\DashboardBundle\\ClarolineDashboardBundle"
"Claroline\\DashboardBundle\\ClarolineDashboardBundle",
"Claroline\\ClacoFormBundle\\ClarolineClacoFormBundle"
]
}
}
56 changes: 47 additions & 9 deletions main/core/Entity/Facet/FieldFacet.php
Expand Up @@ -11,6 +11,7 @@

namespace Claroline\CoreBundle\Entity\Facet;

use Claroline\CoreBundle\Entity\Resource\ResourceNode;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Accessor;
Expand All @@ -31,8 +32,9 @@ class FieldFacet
const CHECKBOXES_TYPE = 6;
const COUNTRY_TYPE = 7;
const EMAIL_TYPE = 8;
const RICH_TEXT_TYPE = 9;

private static $types = [
protected static $types = [
self::STRING_TYPE,
self::FLOAT_TYPE,
self::DATE_TYPE,
Expand All @@ -41,26 +43,27 @@ class FieldFacet
self::CHECKBOXES_TYPE,
self::COUNTRY_TYPE,
self::EMAIL_TYPE,
self::RICH_TEXT_TYPE,
];

/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @Groups({"api_facet_admin", "api_profile"})
* @Groups({"api_facet_admin", "api_profile", "api_user_min"})
*/
protected $id;

/**
* @ORM\Column
* @Assert\NotBlank()
* @Groups({"api_facet_admin", "api_profile"})
* @Groups({"api_facet_admin", "api_profile", "api_user_min"})
*/
protected $name;

/**
* @ORM\Column(type="integer")
* @Groups({"api_facet_admin", "api_profile"})
* @Groups({"api_facet_admin", "api_profile", "api_user_min"})
*/
protected $type;

Expand All @@ -69,7 +72,7 @@ class FieldFacet
* targetEntity="Claroline\CoreBundle\Entity\Facet\PanelFacet",
* inversedBy="fieldsFacet"
* )
* @ORM\JoinColumn(onDelete="CASCADE", nullable=false)
* @ORM\JoinColumn(onDelete="CASCADE", nullable=true)
*/
protected $panelFacet;

Expand All @@ -83,13 +86,13 @@ class FieldFacet
protected $fieldsFacetValue;

/**
* @ORM\Column(type="integer", name="position")
* @ORM\Column(type="integer", name="position", nullable=true)
* @Groups({"api_facet_admin", "api_profile"})
*/
protected $position;

/**
* @Groups({"api_facet_admin", "api_profile"})
* @Groups({"api_facet_admin", "api_profile", "api_user_min"})
* @Accessor(getter="getInputType")
*/
protected $translationKey;
Expand Down Expand Up @@ -122,6 +125,15 @@ class FieldFacet
*/
protected $isRequired = false;

/**
* @ORM\ManyToOne(
* targetEntity="Claroline\CoreBundle\Entity\Resource\ResourceNode",
* inversedBy="fields"
* )
* @ORM\JoinColumn(name="resource_node", onDelete="CASCADE", nullable=true)
*/
protected $resourceNode;

public function __construct()
{
$this->fieldsFacetValue = new ArrayCollection();
Expand Down Expand Up @@ -188,7 +200,16 @@ public function addFieldFacet(FieldFacetValue $fieldFacetValue)

public function addFieldChoice(FieldFacetChoice $choice)
{
$this->fieldFacetChoices->add($choice);
if (!$this->fieldFacetChoices->contains($choice)) {
$this->fieldFacetChoices->add($choice);
}
}

public function removeFieldChoice(FieldFacetChoice $choice)
{
if ($this->fieldFacetChoices->contains($choice)) {
$this->fieldFacetChoices->removeElement($choice);
}
}

public function setPosition($position)
Expand All @@ -212,6 +233,7 @@ public function getTypeTranslationKey()
case self::CHECKBOXES_TYPE: return 'checkbox';
case self::COUNTRY_TYPE: return 'country';
case self::EMAIL_TYPE: return 'email';
case self::RICH_TEXT_TYPE: return 'rich_text';
default: return 'error';
}
}
Expand All @@ -224,9 +246,10 @@ public function getInputType()
case self::STRING_TYPE: return 'text';
case self::RADIO_TYPE: return 'radio';
case self::SELECT_TYPE: return 'select';
case self::CHECKBOXES_TYPE: return 'checkbox';
case self::CHECKBOXES_TYPE: return 'checkboxes';
case self::COUNTRY_TYPE: return 'country';
case self::EMAIL_TYPE: return 'email';
case self::RICH_TEXT_TYPE: return 'rich_text';
default: return 'error';
}
}
Expand All @@ -236,6 +259,11 @@ public function getFieldFacetChoices()
return $this->fieldFacetChoices;
}

public function getFieldFacetChoicesArray()
{
return $this->fieldFacetChoices->toArray();
}

/**
* For serialization in user profile. It's easier that way.
*/
Expand Down Expand Up @@ -286,4 +314,14 @@ public function getPrettyName()

return strtolower($string);
}

public function getResourceNode()
{
return $this->resourceNode;
}

public function setResourceNode(ResourceNode $resourceNode = null)
{
$this->resourceNode = $resourceNode;
}
}
11 changes: 6 additions & 5 deletions main/core/Entity/Facet/FieldFacetValue.php
Expand Up @@ -26,12 +26,12 @@ class FieldFacetValue
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @Groups({"api_user", "api_profile"})
* @Groups({"api_user", "api_profile", "api_user_min"})
*/
protected $id;

/**
* @ORM\Column(type="string", nullable=true)
* @ORM\Column(type="text", nullable=true)
*/
protected $stringValue;

Expand All @@ -56,7 +56,7 @@ class FieldFacetValue
* inversedBy="fieldsFacetValue",
* cascade={"persist"}
* )
* @ORM\JoinColumn(onDelete="CASCADE", nullable=false)
* @ORM\JoinColumn(onDelete="CASCADE", nullable=true)
*/
protected $user;

Expand All @@ -67,11 +67,12 @@ class FieldFacetValue
* cascade={"persist"}
* )
* @ORM\JoinColumn(onDelete="CASCADE", nullable=false)
* @Groups({"api_user_min"})
*/
protected $fieldFacet;

/**
* @Groups({"api_user", "api_profile"})
* @Groups({"api_user", "api_profile", "api_user_min"})
* @Accessor(getter="getValue")
*/
protected $value;
Expand Down Expand Up @@ -140,7 +141,7 @@ public function getArrayValue()
/**
* @param User $user
*/
public function setUser(User $user)
public function setUser(User $user = null)
{
$this->user = $user;
}
Expand Down
41 changes: 37 additions & 4 deletions main/core/Entity/Resource/ResourceNode.php
Expand Up @@ -11,13 +11,14 @@

namespace Claroline\CoreBundle\Entity\Resource;

use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
use Claroline\CoreBundle\Entity\Facet\FieldFacet;
use Claroline\CoreBundle\Entity\User;
use Claroline\CoreBundle\Entity\Workspace\Workspace;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use JMS\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;

/**
* Base entity for all resources.
Expand Down Expand Up @@ -267,11 +268,20 @@ class ResourceNode
*/
protected $guid;

/**
* @ORM\OneToMany(
* targetEntity="Claroline\CoreBundle\Entity\Facet\FieldFacet",
* mappedBy="resourceNode"
* )
*/
protected $fields;

public function __construct()
{
$this->rights = new ArrayCollection();
$this->children = new ArrayCollection();
$this->logs = new ArrayCollection();
$this->fields = new ArrayCollection();
}

/**
Expand Down Expand Up @@ -507,7 +517,7 @@ public function getPathForDisplay()
*
* @param string $name
*
* @throws \InvalidArgumentException if the name contains the path separator ('/').
* @throws \InvalidArgumentException if the name contains the path separator ('/')
*/
public function setName($name)
{
Expand Down Expand Up @@ -812,4 +822,27 @@ public function getGuid()
{
return $this->guid;
}

public function getFields()
{
return $this->fields->toArray();
}

public function addField(FieldFacet $field)
{
if (!$this->fields->contains($field)) {
$this->fileds->add($field);
}

return $this;
}

public function removeField(FieldFacet $field)
{
if ($this->fields->contains($field)) {
$this->fields->removeElement($field);
}

return $this;
}
}
35 changes: 27 additions & 8 deletions main/core/Form/ResourceNameType.php
Expand Up @@ -11,16 +11,40 @@

namespace Claroline\CoreBundle\Form;

use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Validator\Constraints\NotBlank;

class ResourceNameType extends AbstractType
{
private $withPublication;

public function __construct($withPublication = false)
{
$this->withPublication = $withPublication;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', 'text', array('label' => 'name', 'constraints' => new NotBlank(), 'attr' => array('autofocus' => true)));
$builder->add(
'name',
'text',
['label' => 'name', 'constraints' => new NotBlank(), 'attr' => ['autofocus' => true]]
);

if ($this->withPublication) {
$builder->add(
'published',
'checkbox',
[
'label' => 'publish_resource',
'required' => true,
'mapped' => false,
'attr' => ['checked' => 'checked'],
]
);
}
}

public function getName()
Expand All @@ -30,11 +54,6 @@ public function getName()

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver
->setDefaults(
array(
'translation_domain' => 'platform',
)
);
$resolver->setDefaults(['translation_domain' => 'platform']);
}
}

0 comments on commit e82964b

Please sign in to comment.