Updating Notebook Resource code.

1.10.x
Julio Montoya 11 years ago
parent faac2a098d
commit 876d1d2919
  1. 1
      app/config/sonata/sonata_admin.yml
  2. 2
      src/Chamilo/CoreBundle/Admin/AccessUrlAdmin.php
  3. 5
      src/Chamilo/CoreBundle/Admin/AccessUrlRelCourseAdmin.php
  4. 5
      src/Chamilo/CoreBundle/Admin/BranchAdmin.php
  5. 9
      src/Chamilo/CoreBundle/Admin/CareerAdmin.php
  6. 9
      src/Chamilo/CoreBundle/Admin/PromotionAdmin.php
  7. 12
      src/Chamilo/CoreBundle/Admin/SessionRelCourseAdmin.php
  8. 2
      src/Chamilo/CoreBundle/Admin/SettingsCurrentAdmin.php
  9. 66
      src/Chamilo/CoreBundle/Admin/ToolAdmin.php
  10. 60
      src/Chamilo/CoreBundle/Admin/ToolResourceRightsAdmin.php
  11. 2
      src/Chamilo/CoreBundle/Admin/UserGroupAdmin.php
  12. 44
      src/Chamilo/CoreBundle/Entity/Course.php
  13. 3
      src/Chamilo/CoreBundle/Entity/Resource/AbstractResource.php
  14. 95
      src/Chamilo/CoreBundle/Entity/Resource/ResourceLink.php
  15. 18
      src/Chamilo/CoreBundle/Entity/Resource/ResourceNode.php
  16. 109
      src/Chamilo/CoreBundle/Entity/Resource/ResourceRights.php
  17. 37
      src/Chamilo/CoreBundle/Entity/Session.php
  18. 10
      src/Chamilo/CoreBundle/Entity/SessionRelUser.php
  19. 69
      src/Chamilo/CoreBundle/Entity/Tool.php
  20. 171
      src/Chamilo/CoreBundle/Entity/ToolResourceRights.php
  21. 5
      src/Chamilo/CoreBundle/Migrations/Schema/v2/Core.php
  22. 22
      src/Chamilo/CoreBundle/Resources/config/admin.yml
  23. 7
      src/Chamilo/CoreBundle/Resources/config/services.yml
  24. 30
      src/Chamilo/CoreBundle/Security/Authorization/Voter/CourseVoter.php
  25. 98
      src/Chamilo/CoreBundle/Security/Authorization/Voter/ResourceLinkVoter.php
  26. 74
      src/Chamilo/CoreBundle/Security/Authorization/Voter/ResourceVoter.php
  27. 12
      src/Chamilo/CourseBundle/Admin/CourseAdmin.php
  28. 35
      src/Chamilo/CourseBundle/EventListener/CourseListener.php
  29. 98
      src/Chamilo/NotebookBundle/Controller/NotebookController.php
  30. 22
      src/Chamilo/NotebookBundle/Entity/NotebookRepository.php

@ -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: '<i class="fa fa-play-circle"></i>'

@ -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')
;

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Admin;
@ -8,10 +9,6 @@ use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Chamilo\CoreBundle\Entity\CourseRelUser;
use Knp\Menu\ItemInterface as MenuItemInterface;
/**
* Class CourseAdmin
* @package Chamilo\CoreBundle\Admin

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Admin;
@ -10,6 +11,10 @@ use Sonata\AdminBundle\Show\ShowMapper;
use Knp\Menu\ItemInterface as MenuItemInterface;
/**
* Class BranchAdmin
* @package Chamilo\CoreBundle\Admin
*/
class BranchAdmin extends Admin
{
// Fields to be shown on create/edit forms

@ -4,17 +4,10 @@
namespace Chamilo\CoreBundle\Admin;
use Chamilo\CoreBundle\Entity\Career;
use Chamilo\CoreBundle\Entity\Listener\CourseListener;
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 CareerAdmin
@ -29,7 +22,7 @@ class CareerAdmin extends Admin
{
$formMapper
->add('name')
->add('description', 'textarea', array('attr' => array('class'=> 'ckeditor')))
->add('description', 'ckeditor')
->add('status', 'choice', array('choices' => Career::getStatusList()))
;
}

@ -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')
;

@ -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

@ -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')
;
}

@ -0,0 +1,66 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
/**
* Class ToolAdmin
* @package Chamilo\CoreBundle\Admin
*/
class ToolAdmin extends Admin
{
/**
* @inheritdoc
*/
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->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')
;
}
}

@ -0,0 +1,60 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Admin;
use Chamilo\CoreBundle\Entity\ToolResourceRights;
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;
/**
* Class ToolResourceRightsAdmin
* @package Chamilo\CoreBundle\Admin
*/
class ToolResourceRightsAdmin extends Admin
{
/**
* @inheritdoc
*/
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->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')
;
}
}

@ -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(

@ -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;
}
}

@ -100,11 +100,10 @@ abstract class AbstractResource
}
/**
* @return mixed
* @return ResourceNode
*/
public function getResourceNode()
{
return $this->resourceNode;
}
}

@ -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;
}
/**

@ -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;

@ -0,0 +1,109 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity\Resource;
use Chamilo\CourseBundle\Entity\CGroupInfo;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Chamilo\UserBundle\Entity\User;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Session;
/**
* @ORM\Entity
* @ORM\Table(name="resource_rights")
*/
class ResourceRights
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\OneToOne(targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceLink")
* @ORM\JoinColumn(name="resource_link_id", referencedColumnName="id")
*/
protected $resourceLink;
/**
* @var string
*
* @ORM\Column(name="role", type="string", length=255, nullable=false)
*/
protected $role;
/**
* @var string
*
* @ORM\Column(name="mask", type="integer", nullable=false)
*/
protected $mask;
/**
* @return int
*/
public function getId()
{
return $this->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;
}
}

@ -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;
}
}

@ -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()
{

@ -1,7 +1,9 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
@ -24,7 +26,7 @@ class Tool
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255, precision=0, scale=0, nullable=true, unique=false)
* @ORM\Column(name="name", type="string", nullable=false, unique=false)
*/
private $name;
@ -38,10 +40,73 @@ class Tool
/**
* @var string
*
* @ORM\Column(name="description", type="text", precision=0, scale=0, nullable=true, unique=false)
* @ORM\Column(name="description", type="text", nullable=true)
*/
private $description;
/**
* @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceNode", mappedBy="tool", cascade={"persist", "remove"})
**/
protected $resourceNodes;
/**
* @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\ToolResourceRights", mappedBy="tool", cascade={"persist", "remove"})
**/
protected $toolResourceRights;
/**
* @return string
*/
public function __toString()
{
return (string)$this->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
*

@ -0,0 +1,171 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Sonata\AdminBundle\Security\Acl\Permission\AdminPermissionMap;
use Symfony\Component\Security\Acl\Permission\BasicPermissionMap;
use Symfony\Component\Security\Acl\Permission\MaskBuilder;
/**
* Tool
*
* @ORM\Table(name="tool_resource_rights")
* @ORM\Entity
*/
class ToolResourceRights
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", precision=0, scale=0, nullable=false, unique=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="role", type="string", length=255, nullable=false)
*/
protected $role;
/**
* @var string
*
* @ORM\Column(name="mask", type="integer", nullable=false)
*/
protected $mask;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Tool", inversedBy="toolResourceRights", cascade={"persist"})
* @ORM\JoinColumn(name="tool_id", referencedColumnName="id")
**/
protected $tool;
/**
* @return string
*/
public function __toString()
{
return (string)$this->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'
);
}
}

@ -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");

@ -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]]

@ -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

@ -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;

@ -0,0 +1,98 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Security\Authorization\Voter;
use Chamilo\CoreBundle\Entity\Resource\ResourceLink;
use Chamilo\CoreBundle\Entity\Resource\ResourceRights;
use Chamilo\CoreBundle\Entity\ToolResourceRights;
use Symfony\Component\Security\Acl\Permission\MaskBuilder;
use Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* Class ResourceVoter
* @package Chamilo\CoreBundle\Security\Authorization\Voter
*/
class ResourceLinkVoter extends AbstractVoter
{
const VIEW = 'view';
const EDIT = 'edit';
const DELETE = 'delete';
/**
* {@inheritdoc}
*/
protected function getSupportedAttributes()
{
return array(self::VIEW, self::EDIT, self::DELETE);
}
/**
* {@inheritdoc}
*/
protected function getSupportedClasses()
{
return array('Chamilo\CoreBundle\Entity\Resource\ResourceLink');
}
/**
* @param string $attribute
* @param ResourceLink $resourceLink
* @param null $user
* .
* @return bool
*/
protected function isGranted($attribute, $resourceLink, $user = null)
{
// make sure there is a user object (i.e. that the user is logged in)
if (!$user instanceof UserInterface) {
return false;
}
$userSent = $resourceLink->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;
}
}

@ -0,0 +1,74 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Security\Authorization\Voter;
use Chamilo\CoreBundle\Entity\Resource\ResourceNode;
use Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* Class ResourceVoter
* @package Chamilo\CoreBundle\Security\Authorization\Voter
*/
class ResourceVoter extends AbstractVoter
{
const VIEW = 'view';
const EDIT = 'edit';
const DELETE = 'delete';
/**
* {@inheritdoc}
*/
protected function getSupportedAttributes()
{
return array(self::VIEW, self::EDIT, self::DELETE);
}
/**
* {@inheritdoc}
*/
protected function getSupportedClasses()
{
return array('Chamilo\CoreBundle\Entity\Resource\ResourceNode');
}
/**
* @param string $attribute
* @param ResourceNode $resourceNode
* @param null $user
* @return bool
*/
protected function isGranted($attribute, $resourceNode, $user = null)
{
// make sure there is a user object (i.e. that the user is logged in)
if (!$user instanceof UserInterface) {
return false;
}
// Owner.
if ($user->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;
}
}

@ -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(

@ -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);
}
}
}
}
}
}
}

@ -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');
}
}

@ -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
*/

Loading…
Cancel
Save