Commit c9da08a2 authored by Hermann Mayer's avatar Hermann Mayer

Added Icon Selector for Page Controller (new/edit). Implemented Service for…

Added Icon Selector for Page Controller (new/edit). Implemented Service for dynamic role hierarchies. Refreshed Entities. SidebarSections can now require a user-group (special sections).
parent d16df291
......@@ -9,10 +9,10 @@ security:
encode_as_base64: false
iterations: 1
role_hierarchy:
ROLE_AUTHOR: ROLE_USER
ROLE_ADMIN: ROLE_AUTHOR
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
# role_hierarchy:
# ROLE_AUTHOR: ROLE_USER
# ROLE_ADMIN: ROLE_AUTHOR
# ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
database:
......
......@@ -9,6 +9,7 @@
"symfony/symfony": "2.1.*",
"doctrine/orm": ">=2.2.3,<2.4-dev",
"doctrine/doctrine-bundle": "1.0.*",
"twig/twig": "1.9.*",
"twig/extensions": "1.0.*",
"symfony/assetic-bundle": "2.1.*",
"symfony/swiftmailer-bundle": "2.1.*",
......
{
"hash": "2adf4fa0b3ab06281128aac13e1bba88",
"hash": "6b42c9865fd2e49929ff03f0da736c5f",
"packages": [
{
"name": "doctrine/common",
......@@ -1304,7 +1304,7 @@
"require": {
"php": ">=5.2.4"
},
"time": "2012-08-25 15:32:57",
"time": "2012-08-25 17:32:57",
"type": "library",
"extra": {
"branch-alias": {
......
deploy @ 94901e44
Subproject commit ef76f3399ae64ad57c29be9fe65ec2e8a5d8531d
Subproject commit 94901e44d9fa5cdce44ed52666ec49c89be3bb60
......@@ -42,6 +42,20 @@ class EditorController extends Controller
));
}
/**
* iconsAction
*
* @param mixed $syncElement
* @access public
* @return void
*/
public function iconsAction($syncElement)
{
return $this->render('JityHomepageBundle:Editor:icons.html.twig', array(
'syncElement' => $syncElement
));
}
/**
* buildAction
*
......
......@@ -108,6 +108,7 @@ werden Favoriten für Sie in der Applikation gespeichert.
$section = new SidebarSection();
$section
->setGroup($this->getReference('author-group'))
->setTitle('Quick Operations')
->setContent('<p>
Als Administrator oder Autor bietet Ihnen diese Sektion
......
......@@ -11,41 +11,61 @@ class LoadGroupData extends AbstractFixture implements OrderedFixtureInterface
{
public function load(ObjectManager $manager)
{
// Build Admin Group
$adminGroup = new Group();
$adminGroup
->setName('Administratoren')
->setRole('ROLE_ADMIN')
// Build User Group
$userGroup = new Group();
$userGroup
->setName('Benutzer')
->setRole('ROLE_USER')
;
$manager->persist($adminGroup);
// Build Auhtor Group
$authorGroup = new Group();
$authorGroup
->addParent($userGroup)
->setName('Autoren')
->setRole('ROLE_AUTHOR')
;
$manager->persist($authorGroup);
// Build Admin Group
$adminGroup = new Group();
$adminGroup
->addParent($authorGroup)
->setName('Administratoren')
->setRole('ROLE_ADMIN')
;
// Build Switchables Group
$switchablesGroup = new Group();
$switchablesGroup
->addParent($authorGroup)
->setName('Switchables')
->setRole('ROLE_ALLOWED_TO_SWITCH')
;
// Build User Group
$userGroup = new Group();
$userGroup
->setName('Benutzer')
->setRole('ROLE_USER')
// Build Super Admin Group
$superAdminGroup = new Group();
$superAdminGroup
->addParent($adminGroup)
->addParent($switchablesGroup)
->setName('Super Administratoren')
->setRole('ROLE_SUPER_ADMIN')
;
// Save all Groups
$manager->persist($userGroup);
$manager->persist($authorGroup);
$manager->persist($adminGroup);
$manager->persist($switchablesGroup);
$manager->persist($superAdminGroup);
// Flush to Database
$manager->flush();
// Build Fixture References
$this->addReference('switchables-group', $switchablesGroup);
$this->addReference('superadmin-group', $superAdminGroup);
$this->addReference('admin-group', $adminGroup);
$this->addReference('author-group', $userGroup);
$this->addReference('author-group', $authorGroup);
$this->addReference('user-group', $userGroup);
}
......
......@@ -30,3 +30,4 @@ class JityHomepageExtension extends Extension
$loader->load('services.yml');
}
}
<?php
namespace Jity\HomepageBundle\DependencyInjection;
use Doctrine\ORM\EntityManager;
/**
* RoleHierarchy
*
* @uses Symfony
* @version $id$
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
class RoleHierarchy extends \Symfony\Component\Security\Core\Role\RoleHierarchy
{
private $em;
/**
* __construct
*
* @param array $hierarchy
* @param EntityManager $em
* @access public
* @return void
*/
public function __construct(array $hierarchy, EntityManager $em)
{
$this->em = $em;
parent::__construct($this->buildRoleMap());
}
/**
* buildRoleMap
*
* @access private
* @return void
*/
private function buildRoleMap()
{
$hierarchy = array();
// Get all defined roles
// $roles = $this->em->getRepository('JityHomepageBundle:Group')->findAll();
// Use DQL because its more powerfull and only one query is needed
$q = $this->em->createQueryBuilder('u')
->select('g, p')
->from('JityHomepageBundle:Group', 'g')
->leftJoin('g.parents', 'p')
->getQuery()
;
$roles = $q->getResult();
// Build new hierarchy map as array
foreach ($roles as $role) {
if ($parents = $role->getParents()) {
$roleParents = array();
foreach ($parents as $parent) {
$roleParents[] = $parent->getRole();
}
$hierarchy[$role->getRole()] = $roleParents;
}
}
return $hierarchy;
}
}
......@@ -28,6 +28,12 @@ class Category
protected $pages;
/**
* __construct
*
* @access public
* @return void
*/
public function __construct()
{
$this->pages = new \Doctrine\Common\Collections\ArrayCollection();
......@@ -96,4 +102,14 @@ class Category
$page->setCategory($category);
}
}
}
/**
* Remove pages
*
* @param Jity\HomepageBundle\Entity\Page $pages
*/
public function removePage(\Jity\HomepageBundle\Entity\Page $pages)
{
$this->pages->removeElement($pages);
}
}
\ No newline at end of file
......@@ -108,4 +108,4 @@ class Contact
{
return $this->message;
}
}
}
\ No newline at end of file
......@@ -18,13 +18,23 @@ class Group implements RoleInterface, \Serializable
*/
protected $id;
/**
* @ORM\ManyToMany(targetEntity="Group")
* @ORM\JoinTable(name="group_hierarchy",
*
* joinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="parent_group_id", referencedColumnName="id")}
* )
*/
protected $parents;
/**
* @ORM\Column(name="name", type="string", length=30)
*/
protected $name;
/**
* @ORM\Column(name="role", type="string", length=20, unique=true)
* @ORM\Column(name="role", type="string", length=100, unique=true)
*/
protected $role;
......@@ -33,10 +43,23 @@ class Group implements RoleInterface, \Serializable
*/
protected $users;
/**
* @ORM\OneToMany(targetEntity="SidebarSection", mappedBy="group")
**/
protected $sections;
/**
* __construct
*
* @access public
* @return void
*/
public function __construct()
{
$this->users = new \Doctrine\Common\Collections\ArrayCollection();
$this->parents = new \Doctrine\Common\Collections\ArrayCollection();
$this->users = new \Doctrine\Common\Collections\ArrayCollection();
$this->sections = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
......@@ -143,4 +166,81 @@ class Group implements RoleInterface, \Serializable
$this->users
) = \json_decode($serialized);
}
/**
* Remove users
*
* @param Jity\HomepageBundle\Entity\User $users
*/
public function removeUser(\Jity\HomepageBundle\Entity\User $users)
{
$this->users->removeElement($users);
}
/**
* Add sections
*
* @param Jity\HomepageBundle\Entity\SidebarSection $sections
* @return Group
*/
public function addSection(\Jity\HomepageBundle\Entity\SidebarSection $sections)
{
$this->sections[] = $sections;
return $this;
}
/**
* Remove sections
*
* @param Jity\HomepageBundle\Entity\SidebarSection $sections
*/
public function removeSection(\Jity\HomepageBundle\Entity\SidebarSection $sections)
{
$this->sections->removeElement($sections);
}
/**
* Get sections
*
* @return Doctrine\Common\Collections\Collection
*/
public function getSections()
{
return $this->sections;
}
/**
* Add parents
*
* @param Jity\HomepageBundle\Entity\Group $parents
* @return Group
*/
public function addParent(\Jity\HomepageBundle\Entity\Group $parents)
{
$this->parents[] = $parents;
return $this;
}
/**
* Remove parents
*
* @param Jity\HomepageBundle\Entity\Group $parents
*/
public function removeParent(\Jity\HomepageBundle\Entity\Group $parents)
{
$this->parents->removeElement($parents);
}
/**
* Get parents
*
* @return Doctrine\Common\Collections\Collection
*/
public function getParents()
{
return $this->parents;
}
}
......@@ -42,6 +42,12 @@ class Media
protected $pages;
/**
* __construct
*
* @access public
* @return void
*/
public function __construct()
{
$this->pages = new \Doctrine\Common\Collections\ArrayCollection();
......@@ -140,4 +146,14 @@ class Media
{
return $this->resource;
}
}
/**
* Remove pages
*
* @param Jity\HomepageBundle\Entity\Page $pages
*/
public function removePage(\Jity\HomepageBundle\Entity\Page $pages)
{
$this->pages->removeElement($pages);
}
}
\ No newline at end of file
......@@ -91,7 +91,7 @@ class Navigation
*
* @return void
*/
public function replaceCategoryOnPages(\Jity\HomepageBundle\Entity\Navigation $navigation)
public function replaceNavigationOnPages(\Jity\HomepageBundle\Entity\Navigation $navigation)
{
foreach ($this->pages as $page) {
......@@ -101,4 +101,14 @@ class Navigation
// onDelete Cascade?
}
}
}
/**
* Remove pages
*
* @param Jity\HomepageBundle\Entity\Page $pages
*/
public function removePage(\Jity\HomepageBundle\Entity\Page $pages)
{
$this->pages->removeElement($pages);
}
}
\ No newline at end of file
......@@ -45,7 +45,7 @@ class Page
/**
* @ORM\ManyToMany(targetEntity="Media", inversedBy="pages")
* @ORM\JoinTable(name="hp_pages_medias")
* @ORM\JoinTable(name="pages_medias")
**/
protected $medias;
......@@ -63,7 +63,7 @@ class Page
/**
* @ORM\ManyToMany(targetEntity="Navigation", inversedBy="pages")
* @ORM\JoinTable(name="hp_pages_navigations")
* @ORM\JoinTable(name="pages_navigations")
**/
protected $navigations;
......@@ -74,9 +74,15 @@ class Page
protected $author;
/**
* __construct
*
* @access public
* @return void
*/
public function __construct()
{
$this->medias = new \Doctrine\Common\Collections\ArrayCollection();
$this->medias = new \Doctrine\Common\Collections\ArrayCollection();
$this->navigations = new \Doctrine\Common\Collections\ArrayCollection();
}
......@@ -321,4 +327,4 @@ class Page
{
$this->navigations->removeElement($navigations);
}
}
}
\ No newline at end of file
......@@ -33,10 +33,16 @@ class Sidebar
protected $pages;
/**
* __construct
*
* @access public
* @return void
*/
public function __construct()
{
$this->sections = new \Doctrine\Common\Collections\ArrayCollection();
$this->pages = new \Doctrine\Common\Collections\ArrayCollection();
$this->pages = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
......@@ -70,17 +76,6 @@ class Sidebar
return $this->name;
}
/**
* Add sections
*
* @param Jity\HomepageBundle\Entity\SidebarSection $sections
*/
public function addSidebarSection(\Jity\HomepageBundle\Entity\SidebarSection $sections)
{
$this->sections[] = $sections;
return $this;
}
/**
* Get sections
*
......@@ -123,4 +118,37 @@ class Sidebar
$page->setSidebar($sidebar);
}
}
}
/**
* Add sections
*
* @param Jity\HomepageBundle\Entity\SidebarSection $sections
* @return Sidebar
*/
public function addSection(\Jity\HomepageBundle\Entity\SidebarSection $sections)
{
$this->sections[] = $sections;
return $this;
}
/**
* Remove sections
*
* @param Jity\HomepageBundle\Entity\SidebarSection $sections
*/
public function removeSection(\Jity\HomepageBundle\Entity\SidebarSection $sections)
{
$this->sections->removeElement($sections);
}
/**
* Remove pages
*
* @param Jity\HomepageBundle\Entity\Page $pages
*/
public function removePage(\Jity\HomepageBundle\Entity\Page $pages)
{
$this->pages->removeElement($pages);
}
}
\ No newline at end of file
......@@ -17,6 +17,12 @@ class SidebarSection
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Group", inversedBy="sidebarSections")
* @ORM\JoinColumn(name="group_id", referencedColumnName="id")
**/
protected $group;
/**
* @ORM\Column(type="string", length=100)
*/
......@@ -106,4 +112,27 @@ class SidebarSection
{
return $this->sidebar;
}
}
/**
* Set group
*
* @param Jity\HomepageBundle\Entity\Group $group
* @return SidebarSection
*/
public function setGroup(\Jity\HomepageBundle\Entity\Group $group = null)
{
$this->group = $group;
return $this;
}
/**
* Get group
*
* @return Jity\HomepageBundle\Entity\Group
*/
public function getGroup()
{
return $this->group;
}
}
\ No newline at end of file
......@@ -71,19 +71,25 @@ class User implements AdvancedUserInterface, EquatableInterface, \Serializable
/**
* @ORM\ManyToMany(targetEntity="Group", inversedBy="users")
* @ORM\JoinTable(name="hp_users_groups")
* @ORM\JoinTable(name="users_groups")
*/
protected $groups;
/**
* __construct
*
* @access public
* @return void
*/
public function __construct()
{
$this->pages = new \Doctrine\Common\Collections\ArrayCollection();
$this->status = 0;
$this->salt = md5(uniqid(null, true));
$this->salt = md5(uniqid(null, true));
$this->lastLogin = new \DateTime('@0');
$this->lastLogin = new \DateTime('@0');
$this->registeredAt = new \DateTime();
}
......@@ -189,7 +195,6 @@ class User implements AdvancedUserInterface, EquatableInterface, \Serializable
public function setStatus($status)
{
if (in_array($status, array(self::STATUS_ACTIVE, self::STATUS_LOCKED))) {
$this->status = $status;
}
......@@ -437,5 +442,24 @@ class User implements AdvancedUserInterface, EquatableInterface, \Serializable
$this->groups,
) = \json_decode($serialized);
}
}
/**
* Remove pages
*
* @param Jity\HomepageBundle\Entity\Page $pages
*/
public function removePage(\Jity\HomepageBundle\Entity\Page $pages)
{
$this->pages->removeElement($pages);
}
/**
* Remove groups
*
* @param Jity\HomepageBundle\Entity\Group $groups
*/
public function removeGroup(\Jity\HomepageBundle\Entity\Group $groups)
{
$this->groups->removeElement($groups);
}
}
\ No newline at end of file
......@@ -9,8 +9,23 @@ use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\NoResultException;
/**
* UserRepository
*
* @uses EntityRepository
* @uses UserProviderInterface
* @version $id$
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
class UserRepository extends EntityRepository implements UserProviderInterface
{
/**
* loadUserByUsername
*
* @param mixed $username
* @access public
* @return void
*/
public function loadUserByUsername($username)
{
$q = $this
......@@ -27,7 +42,7 @@ class UserRepository extends EntityRepository implements UserProviderInterface
// if there is no record matching the criteria.
$user = $q->getSingleResult();
} catch (NoResultException $e) {
throw new UsernameNotFoundException(sprintf('Unable to find an active admin AcmeUserBundle:User object identified by "%s".', $username), null, 0, $e);
throw new UsernameNotFoundException(sprintf('Unable to find an active User object identified by "%s".', $username), null, 0, $e);
}
// We found a valid user, update the Account Informations
......@@ -37,6 +52,13 @@ class UserRepository extends EntityRepository implements UserProviderInterface
return $user;
}
/**
* refreshUser
*
* @param UserInterface $user
* @access public
* @return void
*/
public function refreshUser(UserInterface $user)
{
$class = get_class($user);
......@@ -47,8 +69,16 @@ class UserRepository extends EntityRepository implements UserProviderInterface
return $this->loadUserByUsername($user->getUsername());
}