diff --git a/app/config/sonata/sonata_admin.yml b/app/config/sonata/sonata_admin.yml index e104d42528..1e3ad3ce04 100644 --- a/app/config/sonata/sonata_admin.yml +++ b/app/config/sonata/sonata_admin.yml @@ -85,6 +85,7 @@ sonata_admin: - sonata.page.admin.site - sonata.notification.admin.message - sonata.admin.settings_current + - sonata.admin.tool sonata.admin.group.user: label: Users icon: '' diff --git a/src/Chamilo/CoreBundle/Admin/AccessUrlAdmin.php b/src/Chamilo/CoreBundle/Admin/AccessUrlAdmin.php index d5dc6521d5..6eb3b971dd 100644 --- a/src/Chamilo/CoreBundle/Admin/AccessUrlAdmin.php +++ b/src/Chamilo/CoreBundle/Admin/AccessUrlAdmin.php @@ -25,7 +25,7 @@ class AccessUrlAdmin extends Admin $formMapper ->add('url', 'url') //->add('code') //if no type is specified, SonataAdminBundle tries to guess it - ->add('description', 'textarea', array('attr' => array('class'=> 'ckeditor'))) + ->add('description', 'ckeditor') ->add('active') ->add('url_type', 'text') ; diff --git a/src/Chamilo/CoreBundle/Admin/AccessUrlRelCourseAdmin.php b/src/Chamilo/CoreBundle/Admin/AccessUrlRelCourseAdmin.php index d0eb3d1ea1..7f04e9bfe8 100644 --- a/src/Chamilo/CoreBundle/Admin/AccessUrlRelCourseAdmin.php +++ b/src/Chamilo/CoreBundle/Admin/AccessUrlRelCourseAdmin.php @@ -1,4 +1,5 @@ add('name') - ->add('description', 'textarea', array('attr' => array('class'=> 'ckeditor'))) + ->add('description', 'ckeditor') ->add('status', 'choice', array('choices' => Career::getStatusList())) ; } diff --git a/src/Chamilo/CoreBundle/Admin/PromotionAdmin.php b/src/Chamilo/CoreBundle/Admin/PromotionAdmin.php index 48b11e1b00..6351647f4d 100644 --- a/src/Chamilo/CoreBundle/Admin/PromotionAdmin.php +++ b/src/Chamilo/CoreBundle/Admin/PromotionAdmin.php @@ -3,18 +3,11 @@ namespace Chamilo\CoreBundle\Admin; -use Chamilo\CoreBundle\Entity\Listener\CourseListener; use Chamilo\CoreBundle\Entity\Promotion; -use Chamilo\CourseBundle\Entity\CTool; -use Chamilo\CoreBundle\Entity\Course; use Sonata\AdminBundle\Admin\Admin; use Sonata\AdminBundle\Form\FormMapper; use Sonata\AdminBundle\Datagrid\DatagridMapper; use Sonata\AdminBundle\Datagrid\ListMapper; -use Sonata\AdminBundle\Show\ShowMapper; -use Chamilo\CourseBundle\ToolChain; - -use Knp\Menu\ItemInterface as MenuItemInterface; /** * Class PromotionAdmin @@ -29,7 +22,7 @@ class PromotionAdmin extends Admin { $formMapper ->add('name') - ->add('description', 'textarea', array('attr' => array('class'=> 'ckeditor'))) + ->add('description', 'ckeditor') ->add('status', 'choice', array('choices' => Promotion::getStatusList())) ->add('career') ; diff --git a/src/Chamilo/CoreBundle/Admin/SessionRelCourseAdmin.php b/src/Chamilo/CoreBundle/Admin/SessionRelCourseAdmin.php index b94f77fd85..5d4633e14d 100644 --- a/src/Chamilo/CoreBundle/Admin/SessionRelCourseAdmin.php +++ b/src/Chamilo/CoreBundle/Admin/SessionRelCourseAdmin.php @@ -18,6 +18,9 @@ use Knp\Menu\ItemInterface as MenuItemInterface; */ class SessionRelCourseAdmin extends Admin { + /** + * @inheritdoc + */ protected function configureShowField(ShowMapper $showMapper) { $showMapper @@ -25,6 +28,9 @@ class SessionRelCourseAdmin extends Admin ; } + /** + * @inheritdoc + */ protected function configureFormFields(FormMapper $formMapper) { $formMapper @@ -34,6 +40,9 @@ class SessionRelCourseAdmin extends Admin ; } + /** + * @inheritdoc + */ protected function configureDatagridFilters(DatagridMapper $datagridMapper) { $datagridMapper @@ -41,6 +50,9 @@ class SessionRelCourseAdmin extends Admin ; } + /** + * @inheritdoc + */ protected function configureListFields(ListMapper $listMapper) { $listMapper diff --git a/src/Chamilo/CoreBundle/Admin/SettingsCurrentAdmin.php b/src/Chamilo/CoreBundle/Admin/SettingsCurrentAdmin.php index 4375b41c9d..94119ac06a 100644 --- a/src/Chamilo/CoreBundle/Admin/SettingsCurrentAdmin.php +++ b/src/Chamilo/CoreBundle/Admin/SettingsCurrentAdmin.php @@ -32,7 +32,7 @@ class SettingsCurrentAdmin extends Admin ->add('type') ->add('category') ->add('selectedValue') - ->add('comment', 'textarea', array('attr' => array('class'=> 'ckeditor'))) + ->add('comment', 'ckeditor') ->add('url') ; } diff --git a/src/Chamilo/CoreBundle/Admin/ToolAdmin.php b/src/Chamilo/CoreBundle/Admin/ToolAdmin.php new file mode 100644 index 0000000000..266b962876 --- /dev/null +++ b/src/Chamilo/CoreBundle/Admin/ToolAdmin.php @@ -0,0 +1,66 @@ +add('name') + ->add('description', 'ckeditor') + ->add('toolResourceRights', 'sonata_type_collection', array( + 'cascade_validation' => true, + ), array( + //'allow_delete' => true, + //'by_reference' => false, + 'edit' => 'inline', + 'inline' => 'table', + //'btn_add' => true, + //'multiple' => true + //'sortable' => 'position', + //'link_parameters' => array('content' => $users), + 'admin_code' => 'sonata.admin.tool_resource_rights' + ) + ) + /*->add('image', 'sonata_media_type', array( + 'provider' => 'sonata.media.provider.image', + 'context' => 'default' + ));*/ + ; + } + + /** + * @inheritdoc + */ + protected function configureDatagridFilters(DatagridMapper $datagridMapper) + { + $datagridMapper + ->add('name') + ; + } + + /** + * @inheritdoc + */ + protected function configureListFields(ListMapper $listMapper) + { + $listMapper + ->addIdentifier('id') + ->addIdentifier('name') + ; + } +} diff --git a/src/Chamilo/CoreBundle/Admin/ToolResourceRightsAdmin.php b/src/Chamilo/CoreBundle/Admin/ToolResourceRightsAdmin.php new file mode 100644 index 0000000000..8549eb958f --- /dev/null +++ b/src/Chamilo/CoreBundle/Admin/ToolResourceRightsAdmin.php @@ -0,0 +1,60 @@ +add('tool') + ->add( + 'role', + 'choice', + array('choices' => ToolResourceRights::getDefaultRoles()) + ) + ->add( + 'mask', + 'choice', + array('choices' => ToolResourceRights::getMaskList()) + ) + ; + } + + /** + * @inheritdoc + */ + protected function configureDatagridFilters(DatagridMapper $datagridMapper) + { + $datagridMapper + ->add('role') + ; + } + + /** + * @inheritdoc + */ + protected function configureListFields(ListMapper $listMapper) + { + $listMapper + ->addIdentifier('id') + ->addIdentifier('role') + ->addIdentifier('mask') + ; + } +} diff --git a/src/Chamilo/CoreBundle/Admin/UserGroupAdmin.php b/src/Chamilo/CoreBundle/Admin/UserGroupAdmin.php index 7bfa8c03e5..3028f9a281 100644 --- a/src/Chamilo/CoreBundle/Admin/UserGroupAdmin.php +++ b/src/Chamilo/CoreBundle/Admin/UserGroupAdmin.php @@ -24,7 +24,7 @@ class UserGroupAdmin extends Admin { $formMapper ->add('name') - ->add('description', 'textarea', array('attr' => array('class'=> 'ckeditor'))) + ->add('description', 'ckeditor') ->add('users', 'sonata_type_collection', array( 'cascade_validation' => true, ), array( diff --git a/src/Chamilo/CoreBundle/Entity/Course.php b/src/Chamilo/CoreBundle/Entity/Course.php index 080d8a55ed..5a79940125 100644 --- a/src/Chamilo/CoreBundle/Entity/Course.php +++ b/src/Chamilo/CoreBundle/Entity/Course.php @@ -225,32 +225,37 @@ class Course /** * @ORM\OneToMany(targetEntity="AccessUrlRelCourse", mappedBy="course", cascade={"persist"}, orphanRemoval=true) **/ - private $urls; + protected $urls; /** * @ORM\OneToMany(targetEntity="SessionRelCourse", mappedBy="course", cascade={"persist"}) **/ - private $sessions; + protected $sessions; /** * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CItemProperty", mappedBy="course") **/ - //private $items; + //protected $items; /** * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CTool", mappedBy="course", cascade={"persist"}) **/ - private $tools; + protected $tools; /** * @ORM\OneToMany(targetEntity="Chamilo\NotebookBundle\Entity\CNotebook", mappedBy="course") **/ - //private $notebooks; + //protected $notebooks; /** * ORM\OneToMany(targetEntity="CurriculumCategory", mappedBy="course") **/ - //private $curriculumCategories; + //protected $curriculumCategories; + + /** + * @var Session + **/ + protected $currentSession; /** * @@ -994,11 +999,32 @@ class Course public static function getStatusList() { return array( - self::CLOSED => 'status_closed', - self::REGISTERED => 'status_registered', + self::CLOSED => 'status_closed', + self::REGISTERED => 'status_registered', self::OPEN_PLATFORM => 'status_open_platform', self::OPEN_WORLD => 'status_open_world', - self::HIDDEN => 'status_hidden', + self::HIDDEN => 'status_hidden', ); } + + /** + * @return Session + */ + public function getCurrentSession() + { + return $this->currentSession; + } + + /** + * @param Session $session + * @return $this + */ + public function setCurrentSession(Session $session) + { + // If the session is registered in the course session list. + if ($this->getSessions()->contains($session->getId())) { + $this->currentSession = $session; + } + return $this; + } } diff --git a/src/Chamilo/CoreBundle/Entity/Resource/AbstractResource.php b/src/Chamilo/CoreBundle/Entity/Resource/AbstractResource.php index 0d970ab047..5574a8e29c 100644 --- a/src/Chamilo/CoreBundle/Entity/Resource/AbstractResource.php +++ b/src/Chamilo/CoreBundle/Entity/Resource/AbstractResource.php @@ -100,11 +100,10 @@ abstract class AbstractResource } /** - * @return mixed + * @return ResourceNode */ public function getResourceNode() { return $this->resourceNode; } - } diff --git a/src/Chamilo/CoreBundle/Entity/Resource/ResourceLink.php b/src/Chamilo/CoreBundle/Entity/Resource/ResourceLink.php index fe825271f1..b007c09b02 100644 --- a/src/Chamilo/CoreBundle/Entity/Resource/ResourceLink.php +++ b/src/Chamilo/CoreBundle/Entity/Resource/ResourceLink.php @@ -4,6 +4,7 @@ namespace Chamilo\CoreBundle\Entity\Resource; use Chamilo\CourseBundle\Entity\CGroupInfo; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; use Gedmo\Mapping\Annotation as Gedmo; use Chamilo\UserBundle\Entity\User; @@ -53,6 +54,35 @@ class ResourceLink */ protected $group; + /** + * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceRights", mappedBy="resourceLink", cascade={"remove"}) + **/ + protected $rights; + + /** + * @return ArrayCollection + */ + public function getRights() + { + return $this->rights; + } + + /** + * @param mixed $rights + */ + public function setRights($rights) + { + $this->rights = $rights; + } + + /** + * @return mixed + */ + public function getGroup() + { + return $this->group; + } + /** * @return int */ @@ -102,49 +132,13 @@ class ResourceLink } /** - * Set cId + * Get user * - * @param integer $cId - * @return AbstractResource + * @return User */ - public function setCId($cId) + public function getUser() { - $this->cId = $cId; - - return $this; - } - - /** - * Get cId - * - * @return integer - */ - public function getCId() - { - return $this->cId; - } - - /** - * Set userId - * - * @param integer $userId - * @return AbstractResource - */ - public function setUserId($userId) - { - $this->userId = $userId; - - return $this; - } - - /** - * Get userId - * - * @return integer - */ - public function getUserId() - { - return $this->userId; + return $this->user; } /** @@ -158,26 +152,13 @@ class ResourceLink } /** - * Set sessionId - * - * @param integer $sessionId - * @return AbstractResource - */ - public function setSessionId($sessionId) - { - $this->sessionId = $sessionId; - - return $this; - } - - /** - * Get sessionId + * Get session * - * @return integer + * @return Session */ - public function getSessionId() + public function getSession() { - return $this->sessionId; + return $this->session; } /** diff --git a/src/Chamilo/CoreBundle/Entity/Resource/ResourceNode.php b/src/Chamilo/CoreBundle/Entity/Resource/ResourceNode.php index 57adf4d08f..e041d137e6 100644 --- a/src/Chamilo/CoreBundle/Entity/Resource/ResourceNode.php +++ b/src/Chamilo/CoreBundle/Entity/Resource/ResourceNode.php @@ -3,6 +3,7 @@ namespace Chamilo\CoreBundle\Entity\Resource; +use Chamilo\CoreBundle\Entity\Tool; use Doctrine\Common\Collections\ArrayCollection; use Symfony\Component\Validator\Constraints as Assert; use Doctrine\ORM\Mapping as ORM; @@ -28,10 +29,9 @@ class ResourceNode protected $id; /** - * @var string - * - * @ORM\Column(name="tool", type="string", length=255, precision=0, scale=0, nullable=false, unique=false) - */ + * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Tool") + * @ORM\JoinColumn(name="tool_id", referencedColumnName="id") + **/ protected $tool; /** @@ -95,7 +95,6 @@ class ResourceNode */ protected $path; - /** * @ORM\Column(name="created_at", type="datetime") * @Gedmo\Timestampable(on="create") @@ -172,9 +171,9 @@ class ResourceNode } /** - * Returns the resource type. + * Returns the tool. * - * @return string + * @return Tool */ public function getTool() { @@ -183,12 +182,11 @@ class ResourceNode /** * Returns the resource type. - * - * @return string + * @param Tool $tool * * @return $this */ - public function setTool($tool) + public function setTool(Tool $tool) { $this->tool = $tool; diff --git a/src/Chamilo/CoreBundle/Entity/Resource/ResourceRights.php b/src/Chamilo/CoreBundle/Entity/Resource/ResourceRights.php new file mode 100644 index 0000000000..06e37fa44d --- /dev/null +++ b/src/Chamilo/CoreBundle/Entity/Resource/ResourceRights.php @@ -0,0 +1,109 @@ +id; + } + + /** + * @return string + */ + public function getMask() + { + return $this->mask; + } + + /** + * @param string $mask + */ + public function setMask($mask) + { + $this->mask = $mask; + } + + /** + * @return mixed + */ + public function getResourceLink() + { + return $this->resourceLink; + } + + /** + * @param mixed $resourceLink + */ + public function setResourceLink($resourceLink) + { + $this->resourceLink = $resourceLink; + } + + /** + * @return string + */ + public function getRole() + { + return $this->role; + } + + /** + * @param string $role + */ + public function setRole($role) + { + $this->role = $role; + } + + /** + * @param int $id + */ + public function setId($id) + { + $this->id = $id; + } +} diff --git a/src/Chamilo/CoreBundle/Entity/Session.php b/src/Chamilo/CoreBundle/Entity/Session.php index 419116248f..2d40260450 100644 --- a/src/Chamilo/CoreBundle/Entity/Session.php +++ b/src/Chamilo/CoreBundle/Entity/Session.php @@ -11,7 +11,14 @@ use Gedmo\Mapping\Annotation as Gedmo; /** * Session * @UniqueEntity("name") - * @ORM\Table(name="session", uniqueConstraints={@ORM\UniqueConstraint(name="name", columns={"name"})}, indexes={@ORM\Index(name="idx_id_coach", columns={"id_coach"}), @ORM\Index(name="idx_id_session_admin_id", columns={"session_admin_id"})}) + * @ORM\Table( + * name="session", + * uniqueConstraints={@ORM\UniqueConstraint(name="name", columns={"name"})}, + * indexes={ + * @ORM\Index(name="idx_id_coach", columns={"id_coach"}), + * @ORM\Index(name="idx_id_session_admin_id", columns={"session_admin_id"}) + * } + * ) * @ORM\Entity */ class Session @@ -149,7 +156,7 @@ class Session protected $users; /** - * + * Constructor */ public function __construct() { @@ -185,6 +192,9 @@ class Session return $this->id; } + /** + * @param int $id + */ public function setId($id) { $this->id = $id; @@ -602,11 +612,18 @@ class Session $this->generalCoach = $coach; } + /** + * @return mixed + */ public function getCategory() { return $this->category; } + /** + * @param $category + * @return $this + */ public function setCategory($category) { $this->category = $category; @@ -626,4 +643,20 @@ class Session self::AVAILABLE => 'status_available', ); } + + /** + * Check if session is visible + * @return bool + */ + public function isActive() + { + $now = new \Datetime('now'); + + if ($now > $this->getAccessStartDate()) { + + return true; + } + + return false; + } } diff --git a/src/Chamilo/CoreBundle/Entity/SessionRelUser.php b/src/Chamilo/CoreBundle/Entity/SessionRelUser.php index 02455eaa69..581f787dc6 100644 --- a/src/Chamilo/CoreBundle/Entity/SessionRelUser.php +++ b/src/Chamilo/CoreBundle/Entity/SessionRelUser.php @@ -65,9 +65,8 @@ class SessionRelUser $this->movedAt = null; } - /** - * Set idSession + * Set Session * * @param Session $session * @@ -76,6 +75,7 @@ class SessionRelUser public function setSession($session) { $this->session = $session; + return $this; } @@ -90,9 +90,9 @@ class SessionRelUser } /** - * Set idUser + * Set User * - * @param integer $user + * @param User $user * @return SessionRelUser */ public function setUser($user) @@ -105,7 +105,7 @@ class SessionRelUser /** * Get idUser * - * @return integer + * @return User */ public function getUser() { diff --git a/src/Chamilo/CoreBundle/Entity/Tool.php b/src/Chamilo/CoreBundle/Entity/Tool.php index 56f700962f..175594bd47 100644 --- a/src/Chamilo/CoreBundle/Entity/Tool.php +++ b/src/Chamilo/CoreBundle/Entity/Tool.php @@ -1,7 +1,9 @@ getName(); + } + + /** + * @return ArrayCollection + */ + public function getToolResourceRights() + { + return $this->toolResourceRights; + } + + /** + * @param ArrayCollection $toolResourceRights + */ + public function setToolResourceRights($toolResourceRights) + { + $this->toolResourceRights = new ArrayCollection(); + + foreach ($toolResourceRights as $toolResourceRight) { + $this->addToolResourceRights($toolResourceRight); + } + } + + /** + * @param ToolResourceRights $toolResourceRight + */ + public function addToolResourceRights(ToolResourceRights $toolResourceRight) + { + $toolResourceRight->setTool($this); + $this->toolResourceRights[] = $toolResourceRight; + } + + /** + * @return mixed + */ + public function getResourceNodes() + { + return $this->resourceNodes; + } + + /** + * @param mixed $resourceNodes + */ + public function setResourceNodes($resourceNodes) + { + $this->resourceNodes = $resourceNodes; + } + /** * Get id * diff --git a/src/Chamilo/CoreBundle/Entity/ToolResourceRights.php b/src/Chamilo/CoreBundle/Entity/ToolResourceRights.php new file mode 100644 index 0000000000..25300cbbf7 --- /dev/null +++ b/src/Chamilo/CoreBundle/Entity/ToolResourceRights.php @@ -0,0 +1,171 @@ +getMask(); + } + + /** + * @return Tool + */ + public function getTool() + { + return $this->tool; + } + + /** + * @param Tool $tool + * + * @return $this + */ + public function setTool($tool) + { + $this->tool = $tool; + + return $this; + } + + /** + * @return string + */ + public function getRole() + { + return $this->role; + } + + /** + * @param string $role + * + * @return $this + */ + public function setRole($role) + { + $this->role = $role; + + return $this; + } + + /** + * @return int + */ + public function getMask() + { + return $this->mask; + } + + /** + * @param mixed $mask + * + * @return $this + */ + public function setMask($mask) + { + $this->mask = $mask; + + return $this; + } + + /** + * Get id + * + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * @return array + */ + public static function getDefaultRoles() + { + return array( + 'ROLE_STUDENT' => 'student', + 'ROLE_TEACHER' => 'teacher' + ); + } + + /** + * @return array + */ + public static function getMaskList() + { + $builder = new MaskBuilder(); + $builder + ->add('view') + ->add('edit') + ; + + $readerMask = $builder->get(); + + $builder = new MaskBuilder(); + $builder + ->add('view') + ->add('edit') + ; + $editorMask = $builder->get(); + + $builder = new MaskBuilder(); + $builder + ->add('view') + ->add('edit') + ->add('delete') + ; + $ownerMask = $builder->get(); + + return array( + $readerMask => 'reader', + $editorMask => 'editor', + $ownerMask => 'owner' + ); + } +} diff --git a/src/Chamilo/CoreBundle/Migrations/Schema/v2/Core.php b/src/Chamilo/CoreBundle/Migrations/Schema/v2/Core.php index 3ea765595f..985db4bd34 100644 --- a/src/Chamilo/CoreBundle/Migrations/Schema/v2/Core.php +++ b/src/Chamilo/CoreBundle/Migrations/Schema/v2/Core.php @@ -131,6 +131,11 @@ class Core implements Migration, OrderedMigrationInterface $queries->addQuery("CREATE TABLE track_e_exercices (exe_id INT AUTO_INCREMENT NOT NULL, exe_user_id INT DEFAULT NULL, exe_date DATETIME NOT NULL, exe_exo_id INT NOT NULL, exe_result DOUBLE PRECISION NOT NULL, exe_weighting DOUBLE PRECISION NOT NULL, c_id INT NOT NULL, status VARCHAR(20) NOT NULL, data_tracking LONGTEXT NOT NULL, start_date DATETIME NOT NULL, steps_counter SMALLINT NOT NULL, session_id INT NOT NULL, orig_lp_id INT NOT NULL, orig_lp_item_id INT NOT NULL, exe_duration INT NOT NULL, expired_time_control DATETIME NOT NULL, orig_lp_item_view_id INT NOT NULL, questions_to_check LONGTEXT NOT NULL, jury_score DOUBLE PRECISION NOT NULL, jury_id INT NOT NULL, INDEX IDX_B62B03F2B9773F9E (exe_exo_id), INDEX IDX_B62B03F2F6A6790 (exe_user_id), PRIMARY KEY(exe_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"); $queries->addQuery("CREATE TABLE track_stored_values (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, sco_id INT NOT NULL, course_id VARCHAR(40) NOT NULL, sv_key VARCHAR(64) NOT NULL, sv_value LONGTEXT NOT NULL, UNIQUE INDEX user_id_2 (user_id, sco_id, course_id, sv_key), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"); $queries->addQuery("CREATE TABLE tool (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) DEFAULT NULL, image VARCHAR(255) DEFAULT NULL, description LONGTEXT DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"); + $queries->addQuery("CREATE TABLE tool_audit (id INT NOT NULL, rev INT NOT NULL, name VARCHAR(255) DEFAULT NULL, image VARCHAR(255) DEFAULT NULL, description LONGTEXT DEFAULT NULL, revtype VARCHAR(4) NOT NULL, PRIMARY KEY(id, rev)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;"); + + $queries->addQuery("CREATE TABLE tool_resource_rights (id INT AUTO_INCREMENT NOT NULL, tool_id INT DEFAULT NULL, role VARCHAR(255) NOT NULL, mask INT NOT NULL, INDEX IDX_95CE3398F7B22CC (tool_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;"); + $queries->addQuery("CREATE TABLE tool_resource_rights_audit (id INT NOT NULL, rev INT NOT NULL, tool_id INT DEFAULT NULL, role VARCHAR(255) DEFAULT NULL, mask INT DEFAULT NULL, revtype VARCHAR(4) NOT NULL, PRIMARY KEY(id, rev)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;"); + $queries->addQuery("CREATE TABLE resource_rights (id INT AUTO_INCREMENT NOT NULL, resource_link_id INT DEFAULT NULL, role VARCHAR(255) NOT NULL, mask INT NOT NULL, UNIQUE INDEX UNIQ_C99C3BF9F004E599 (resource_link_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;"); $queries->addQuery("CREATE TABLE track_e_hotspot (hotspot_id INT AUTO_INCREMENT NOT NULL, hotspot_user_id INT NOT NULL, hotspot_exe_id INT NOT NULL, hotspot_question_id INT NOT NULL, hotspot_answer_id INT NOT NULL, hotspot_correct TINYINT(1) NOT NULL, hotspot_coordinate LONGTEXT NOT NULL, c_id INT NOT NULL, INDEX hotspot_user_id (hotspot_user_id), INDEX hotspot_exe_id (hotspot_exe_id), INDEX hotspot_question_id (hotspot_question_id), PRIMARY KEY(hotspot_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"); $queries->addQuery("CREATE TABLE question_field_values (id INT AUTO_INCREMENT NOT NULL, question_id INT NOT NULL, field_id INT NOT NULL, tms DATETIME NOT NULL, user_id VARCHAR(255) NOT NULL, comment VARCHAR(255) DEFAULT NULL, field_value LONGTEXT DEFAULT NULL, INDEX IDX_83093BA61E27F6BF (question_id), INDEX idx_question_field_values_field_id (field_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"); $queries->addQuery("CREATE TABLE usergroup (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, description LONGTEXT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"); diff --git a/src/Chamilo/CoreBundle/Resources/config/admin.yml b/src/Chamilo/CoreBundle/Resources/config/admin.yml index 4b89b7d8c0..69f6898a69 100644 --- a/src/Chamilo/CoreBundle/Resources/config/admin.yml +++ b/src/Chamilo/CoreBundle/Resources/config/admin.yml @@ -141,3 +141,25 @@ services: - ~ calls: - [ setTranslationDomain, [ChamiloCoreBundle]] + + sonata.admin.tool: + class: Chamilo\CoreBundle\Admin\ToolAdmin + tags: + - { name: sonata.admin, manager_type: orm, group: "LMS", label: "Tool" } + arguments: + - ~ + - Chamilo\CoreBundle\Entity\Tool + - ~ + calls: + - [ setTranslationDomain, [ChamiloCoreBundle]] + + sonata.admin.tool_resource_rights: + class: Chamilo\CoreBundle\Admin\ToolResourceRightsAdmin + tags: + - { name: sonata.admin, manager_type: orm, group: "LMS", label: "ToolResourceRights" } + arguments: + - ~ + - Chamilo\CoreBundle\Entity\ToolResourceRights + - ~ + calls: + - [ setTranslationDomain, [ChamiloCoreBundle]] diff --git a/src/Chamilo/CoreBundle/Resources/config/services.yml b/src/Chamilo/CoreBundle/Resources/config/services.yml index 40089be86b..a6ca613e59 100644 --- a/src/Chamilo/CoreBundle/Resources/config/services.yml +++ b/src/Chamilo/CoreBundle/Resources/config/services.yml @@ -14,6 +14,13 @@ services: tags: - { name: security.voter } + chamilo_core.security.authorization.voter.resource_link: + class: Chamilo\CoreBundle\Security\Authorization\Voter\ResourceLinkVoter + public: false + tags: + - { name: security.voter } + + chamilo_core.directory_namer.user_image: class: Chamilo\CoreBundle\Naming\UserImage diff --git a/src/Chamilo/CoreBundle/Security/Authorization/Voter/CourseVoter.php b/src/Chamilo/CoreBundle/Security/Authorization/Voter/CourseVoter.php index 6512628665..9e3c28db56 100644 --- a/src/Chamilo/CoreBundle/Security/Authorization/Voter/CourseVoter.php +++ b/src/Chamilo/CoreBundle/Security/Authorization/Voter/CourseVoter.php @@ -4,6 +4,7 @@ namespace Chamilo\CoreBundle\Security\Authorization\Voter; use Chamilo\CoreBundle\Entity\Course; +use Chamilo\UserBundle\Entity\User; use Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter; use Symfony\Component\Security\Core\User\UserInterface; @@ -35,7 +36,7 @@ class CourseVoter extends AbstractVoter /** * @param string $attribute * @param Course $course - * @param null $user + * @param User $user * @return bool */ protected function isGranted($attribute, $course, $user = null) @@ -45,14 +46,25 @@ class CourseVoter extends AbstractVoter return false; } - // custom business logic to decide if the given user can view - // and/or edit the given post - if ($attribute == self::VIEW && $course->isActive()) { - return true; - } - - if ($attribute == self::EDIT && $user->getId() === $course->getOwner()->getId()) { - return true; + switch ($attribute) { + case self::VIEW: + $session = $course->getCurrentSession(); + if (empty($session)) { + if ($course->isActive()) { + return true; + } + } else { + if ($session->isActive() && $course->isActive()) { + return true; + } + } + return false; + case self::EDIT: + // Teacher + if ($user->getId() === $course->getOwner()->getId()) { + return true; + } + return false; } return false; diff --git a/src/Chamilo/CoreBundle/Security/Authorization/Voter/ResourceLinkVoter.php b/src/Chamilo/CoreBundle/Security/Authorization/Voter/ResourceLinkVoter.php new file mode 100644 index 0000000000..feaa07cb7f --- /dev/null +++ b/src/Chamilo/CoreBundle/Security/Authorization/Voter/ResourceLinkVoter.php @@ -0,0 +1,98 @@ +getUser(); + + // Owner. + if (isset($userSent) && + $user->getUsername() == $userSent->getUsername()) { + return true; + } + + $rightFromResourceLink = $resourceLink->getRights(); + + if ($rightFromResourceLink->count()) { + /** @var ResourceRights $right */ + $rights = $rightFromResourceLink; + } else { + $rights = $resourceLink->getResourceNode()->getTool()->getToolResourceRights(); + } + + $roles = array(); + foreach ($rights as $right) { + $roles[$right->getRole()] = $right->getMask() ; + } + + $mask = new MaskBuilder(); + $mask->add($attribute); + $code = $mask->get(); + + switch ($attribute) { + case self::VIEW: + + if ($user->getRoles()) + var_dump($code); + exit; + break; + case self::EDIT: + break; + } + + // Course is visible? + if ($attribute == self::VIEW) { + return true; + } + + + return false; + } +} diff --git a/src/Chamilo/CoreBundle/Security/Authorization/Voter/ResourceVoter.php b/src/Chamilo/CoreBundle/Security/Authorization/Voter/ResourceVoter.php new file mode 100644 index 0000000000..8647787651 --- /dev/null +++ b/src/Chamilo/CoreBundle/Security/Authorization/Voter/ResourceVoter.php @@ -0,0 +1,74 @@ +getUsername() == $resourceNode->getCreator()->getUsername()) { + return true; + } + + switch ($attribute) { + case self::VIEW: + + break; + case self::EDIT: + break; + } + + // Course is visible? + if ($attribute == self::VIEW && $resourceNode->isActive()) { + return true; + } + + // Teacher + if ($attribute == self::EDIT && $user->getId() === $course->getOwner()->getId()) { + return true; + } + + return false; + } +} diff --git a/src/Chamilo/CourseBundle/Admin/CourseAdmin.php b/src/Chamilo/CourseBundle/Admin/CourseAdmin.php index 1c343eb6da..3d8b10626e 100644 --- a/src/Chamilo/CourseBundle/Admin/CourseAdmin.php +++ b/src/Chamilo/CourseBundle/Admin/CourseAdmin.php @@ -31,15 +31,7 @@ class CourseAdmin extends Admin ->add('code', 'text', array( //'read_only' => true, )) - /*->add( - 'description', - 'textarea', - array('attr' => array('class' => 'ckeditor')) - )*/ - ->add( - 'description', - 'ckeditor' - ) + ->add('description', 'ckeditor') ->add('courseLanguage', 'language') ->add('departmentName') ->add( @@ -50,7 +42,7 @@ class CourseAdmin extends Admin 'translation_domain' => 'ChamiloCoreBundle' ) ) - ->add('departmentUrl') + ->add('departmentUrl', 'url') ->add('urls', 'sonata_type_collection', array( 'cascade_validation' => true, ), array( diff --git a/src/Chamilo/CourseBundle/EventListener/CourseListener.php b/src/Chamilo/CourseBundle/EventListener/CourseListener.php index 1e9d2315bc..db2c434110 100644 --- a/src/Chamilo/CourseBundle/EventListener/CourseListener.php +++ b/src/Chamilo/CourseBundle/EventListener/CourseListener.php @@ -62,7 +62,6 @@ class CourseListener //$token = $event->getRequest()->query->get('token'); $kernel = $event->getKernel(); $request = $event->getRequest(); - $session = $request->getSession(); /** @var ContainerInterface $container */ $container = $this->container; @@ -80,38 +79,42 @@ class CourseListener /** @var EntityManager $em */ $em = $container->get('doctrine')->getManager(); + $securityChecker = $container->get('security.authorization_checker'); + if (!empty($courseCode)) { /** @var Course $course */ $course = $em->getRepository('ChamiloCoreBundle:Course')->findOneByCode($courseCode); if ($course) { + // Session + $sessionId = $request->get('id_session'); - // Security - if (false === $container->get('security.authorization_checker')->isGranted('view', $course)) { + if (!empty($sessionId)) { + $session = $em->getRepository('ChamiloCoreBundle:Session')->find($sessionId); + if ($session) { + $course->setCurrentSession($session); + $controller[0]->setSession($session); + } + } + + // Check if user is allowed to this course / course-session + if (false === $securityChecker->isGranted('view', $course)) { throw new AccessDeniedException('Unauthorised access!'); } + // Legacy code + $courseInfo = api_get_course_info($course->getCode()); $container->get('twig')->addGlobal('course', $course); $request->getSession()->set('_real_cid', $course->getId()); $request->getSession()->set('_cid', $course->getCode()); $request->getSession()->set('_course', $courseInfo); + /* + Sets the controller course in order to use $this->getCourse() + */ $controller[0]->setCourse($course); - - // Session - $sessionId = $request->get('id_session'); - - $contains = $course->getSessions()->containsKey($sessionId); - //var_dump($contains); - if (!empty($sessionId)) { - $session = $em->getRepository('ChamiloCoreBundle:Session')->find($sessionId); - if (!empty($session)) { - //$controller[0]->setSession($session); - } - } } } - } } } diff --git a/src/Chamilo/NotebookBundle/Controller/NotebookController.php b/src/Chamilo/NotebookBundle/Controller/NotebookController.php index 3b9b4c1599..29bf147e93 100644 --- a/src/Chamilo/NotebookBundle/Controller/NotebookController.php +++ b/src/Chamilo/NotebookBundle/Controller/NotebookController.php @@ -4,9 +4,14 @@ namespace Chamilo\NotebookBundle\Controller; use Chamilo\CoreBundle\Entity\Resource\AbstractResource; +use Chamilo\CoreBundle\Entity\Resource\ResourceLink; +use Chamilo\CoreBundle\Entity\Resource\ResourceNode; +use Chamilo\CoreBundle\Entity\Tool; +use Chamilo\NotebookBundle\Tool\Notebook; use Doctrine\ORM\QueryBuilder; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; +use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException; use Symfony\Component\HttpFoundation\Response; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use APY\DataGridBundle\Grid\Source\Entity; @@ -22,6 +27,8 @@ use Chamilo\NotebookBundle\Entity\NotebookRepository; use Chamilo\NotebookBundle\Entity\NotebookManager; use Chamilo\NotebookBundle\Entity\CNotebook; use Chamilo\CourseBundle\Controller\ToolBaseCrudController; +use Symfony\Component\Security\Acl\Permission\MaskBuilder; +use Symfony\Component\Translation\Exception\NotFoundResourceException; /** * Class NotebookController @@ -52,7 +59,11 @@ class NotebookController extends ToolBaseCrudController } );*/ - $resources = $this->getRepository()->getResourceByCourse($course); + $this->createNew(); + /** @var NotebookRepository $repository */ + $repository = $this->getRepository(); + + $resources = $repository->getResourceByCourse($course); $source->setData($resources); $grid->setSource($source); @@ -131,6 +142,90 @@ class NotebookController extends ToolBaseCrudController ); } + /** + * @param Request $request + * + * @return Response + */ + public function showAction(Request $request) + { + $builder = new MaskBuilder(); + $builder + ->add('view') + ; + $mask = $builder->get(); // int(29)" + /** @var AbstractResource $resource */ + + $resource = $this->findOr404($request); + $resourceNode = $resource->getResourceNode(); + $link = $this->detectLink($resourceNode); + + if (false === $this->get('security.authorization_checker')->isGranted('view', $link)) { + //throw new AccessDeniedException('Unauthorised access!'); + } + + $view = $this + ->view() + ->setTemplate($this->config->getTemplate('show.html')) + ->setTemplateVar($this->config->getResourceName()) + ->setData($resource) + ; + + return $this->handleView($view); + } + + /** + * @param ResourceNode $resourceNode + * @return ResourceLink|null + */ + public function detectLink(ResourceNode $resourceNode) + { + $user = $this->getUser(); + $session = $this->getSession(); + $course = $this->getCourse(); + + $links = $resourceNode->getLinks(); + + $linkFound = null; + + if (!empty($links)) { + /** @var ResourceLink $link */ + foreach ($links as $link) { + $linkCourse = $link->getCourse(); + $linkSession = $link->getSession(); + $linkUser = $link->getUser(); + + if (isset($course) && isset($session)) { + if ($linkCourse->getId() == $course->getId() && + $linkSession->getId() == $session->getId() + ) { + $linkFound = $link; + break; + } + } + + if (isset($course)) { + if ($linkCourse->getId() == $course->getId()) { + $linkFound = $link; + break; + } + } + + if (isset($linkUser)) { + if ($linkUser->getId() == $user->getId()) { + $linkFound = $link; + break; + } + } + } + } + + if (empty($linkFound)) { + throw new NotFoundResourceException('Link not found'); + } + return $linkFound; + } + /** * @param Request $request * @@ -225,4 +320,5 @@ class NotebookController extends ToolBaseCrudController { return $this->get('chamilo_notebook.entity.notebook_manager'); } + } diff --git a/src/Chamilo/NotebookBundle/Entity/NotebookRepository.php b/src/Chamilo/NotebookBundle/Entity/NotebookRepository.php index 68913a1589..c0917e575f 100644 --- a/src/Chamilo/NotebookBundle/Entity/NotebookRepository.php +++ b/src/Chamilo/NotebookBundle/Entity/NotebookRepository.php @@ -6,6 +6,7 @@ namespace Chamilo\NotebookBundle\Entity; use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\Resource\ResourceLink; use Chamilo\CoreBundle\Entity\Session; +use Chamilo\CoreBundle\Entity\Tool; use Chamilo\CourseBundle\Entity\CGroupInfo; use Chamilo\UserBundle\Entity\User; use Chamilo\CoreBundle\Entity\Resource\AbstractResource; @@ -29,7 +30,7 @@ class NotebookRepository extends EntityRepository $resourceNode ->setName($resource->getName()) ->setCreator($creator) - ->setTool($this->getToolName()); + ->setTool($this->getTool()); $this->getEntityManager()->persist($resourceNode); $this->getEntityManager()->flush(); @@ -58,8 +59,6 @@ class NotebookRepository extends EntityRepository } /** - * @param AbstractResource $resource - * @param User $user * @param Course $course * @return ResourceLink */ @@ -71,13 +70,13 @@ class NotebookRepository extends EntityRepository ->innerJoin('node.links', 'links') ->innerJoin($this->getClassName(), 'resource') ->where('node.tool = :tool') - ->andWhere('links.course = :courseId') + ->andWhere('links.course = :course') //->where('link.cId = ?', $course->getId()) //->where('node.cId = 0') //->orderBy('node'); ->setParameters(array( - 'tool'=> $this->getToolName(), - 'courseId' => $course->getId() + 'tool'=> $this->getTool(), + 'course' => $course ) ) ->getQuery() @@ -146,6 +145,17 @@ class NotebookRepository extends EntityRepository $this->getEntityManager()->persist($resourceLink); } + /** + * @return Tool + */ + public function getTool() + { + return $this->getEntityManager() + ->getRepository('ChamiloCoreBundle:Tool') + ->findOneByName($this->getToolName()); + } + + /** * @return string */