Skip to content

Commit

Permalink
Added plugin admin parameters, replaced is_notifiable by listener for…
Browse files Browse the repository at this point in the history
… user parameters
  • Loading branch information
ptsavdar committed Apr 16, 2015
1 parent b908de4 commit 153f8f5
Show file tree
Hide file tree
Showing 33 changed files with 1,175 additions and 114 deletions.
22 changes: 5 additions & 17 deletions Controller/NotificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;

use Icap\NotificationBundle\Entity\ColorChooser;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

Expand All @@ -32,19 +29,11 @@ class NotificationController extends Controller
*/
public function listAction(Request $request, $user, $page)
{
if ($request->isXMLHttpRequest()) {
$maxResult = $this->container->getParameter('icap_notification.dropdown_items');
$page = 1;
} else {
$maxResult = $this->container->getParameter('icap_notification.max_per_page');
}

$notificationManager = $this->getNotificationManager();
$result = $notificationManager->getUserNotificationsList($user->getId(), $page, $maxResult);
$systemName = $notificationManager->getPlatformName();
$result['systemName'] = $systemName;

if ($request->isXMLHttpRequest()) {
$result = $notificationManager->getDropdownNotifications($user->getId());
$result['systemName'] = $systemName;
$unviewedNotifications = $notificationManager->countUnviewedNotifications(
$user->getId()
);
Expand All @@ -55,8 +44,8 @@ public function listAction(Request $request, $user, $page)
$result
);
} else {
$defaultLayout = $this->container->getParameter('icap_notification.default_layout');
$result['layout'] = $defaultLayout;
$result = $notificationManager->getPaginatedNotifications($user->getId(), $page);
$result['systemName'] = $systemName;

return $result;
}
Expand All @@ -75,9 +64,8 @@ public function listAction(Request $request, $user, $page)
public function rssAction($rssId)
{
$notificationManager = $this->getNotificationManager();
$maxResult = $this->container->getParameter('icap_notification.max_per_page');
try {
$result = $notificationManager->getUserNotificationsListRss($rssId, $maxResult);
$result = $notificationManager->getUserNotificationsListRss($rssId);
$result["systemName"] = $notificationManager->getPlatformName();
} catch (NoResultException $nre) {
$result = array("error" => "no_rss_defined");
Expand Down
74 changes: 74 additions & 0 deletions Controller/NotificationPluginConfigurationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* This file is part of the Claroline Connect package
*
* (c) Claroline Consortium <[email protected]>
*
* Author: Panagiotis TSAVDARIS
*
* Date: 4/14/15
*/

namespace Icap\NotificationBundle\Controller;

use Claroline\CoreBundle\Entity\User;
use Icap\NotificationBundle\Exception\InvalidNotificationFormException;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Request;

class NotificationPluginConfigurationController extends Controller
{
/**
* @Route("/configuration", name="icap_notification_configuration")
* @Template("IcapNotificationBundle:Configuration:config.html.twig")
* @Method({"GET"})
* @ParamConverter("user", options={"authenticatedUser" = true})
* @Security("has_role('ROLE_ADMIN')")
*/
public function getAction(User $user)
{
$configManager = $this->getNotificationPluginConfigurationManager();
$form = $configManager->getForm();

return array('form' => $form->createView());
}

/**
* @Route("/configuration", name="icap_notification_configuration_save")
* @Template("IcapNotificationBundle:Configuration:config.html.twig")
* @Method({"POST"})
* @ParamConverter("user", options={"authenticatedUser" = true})
* @Security("has_role('ROLE_ADMIN')")
*/
public function postAction(Request $request, User $user)
{
$configManager = $this->getNotificationPluginConfigurationManager();
try{
$form = $configManager->processForm($request);
$this->addFlash('success', 'successfully_saved_configuration');
} catch (InvalidNotificationFormException $infe) {
$form = $infe->getForm();
$this->addFlash('error', $infe->getMessage());
}

return array('form' => $form->createView());
}

/**
* @return \Icap\NotificationBundle\Manager\NotificationPluginConfigurationManager
*/
private function getNotificationPluginConfigurationManager()
{
return $this->get('icap.notification.manager.plugin_configuration');
}

private function addFlash($key, $message)
{
$this->get("session")->getFlashBag()->add($key, $message);
}
}
28 changes: 0 additions & 28 deletions DependencyInjection/Configuration.php

This file was deleted.

7 changes: 0 additions & 7 deletions DependencyInjection/IcapNotificationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ class IcapNotificationExtension extends Extension
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

foreach (array('default_layout', 'max_per_page', 'dropdown_items') as $attribute) {
$container->setParameter("icap_notification." . $attribute, $config[$attribute]);
}

$locator = new FileLocator(__DIR__ . '/../Resources/config/services');
$loader = new YamlFileLoader($container, $locator);
$loader->load('services.yml');
Expand Down
153 changes: 153 additions & 0 deletions Entity/NotificationPluginConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?php
/**
* This file is part of the Claroline Connect package
*
* (c) Claroline Consortium <[email protected]>
*
* Author: Panagiotis TSAVDARIS
*
* Date: 4/13/15
*/

namespace Icap\NotificationBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* Class NotificationPluginConfiguration
* @package Icap\NotificationBundle\Entity
*
* @ORM\Entity()
* @ORM\Table(name="icap__notification_plugin_configuration")
*/
class NotificationPluginConfiguration
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;

/**
* @ORM\Column(type="integer", name="dropdown_items")
*/
protected $dropdownItems = 10;

/**
* @ORM\Column(type="integer", name="max_per_page")
*/
protected $maxPerPage = 50;

/**
* @ORM\Column(type="boolean", name="purge_enabled")
*/
protected $purgeEnabled = true;

/**
* @ORM\Column(type="integer", name="purge_after_days")
*/
protected $purgeAfterDays = 60;

/**
* @ORM\Column(type="datetime", name="last_purge_date", nullable=true)
*/
protected $lastPurgeDate;

/**
* @return mixed
*/
public function getId()
{
return $this->id;
}

/**
* @return mixed
*/
public function getDropdownItems()
{
return $this->dropdownItems;
}

/**
* @param $dropdownItems
* @return $this
*/
public function setDropdownItems($dropdownItems)
{
$this->dropdownItems = $dropdownItems;

return $this;
}

/**
* @return mixed
*/
public function getMaxPerPage()
{
return $this->maxPerPage;
}

/**
* @param mixed $maxPerPage
* @return $this
*/
public function setMaxPerPage($maxPerPage)
{
$this->maxPerPage = $maxPerPage;

return $this;
}

/**
* @return mixed
*/
public function getPurgeEnabled()
{
return $this->purgeEnabled;
}

/**
* @param mixed $purgeEnabled
* @return $this
*/
public function setPurgeEnabled($purgeEnabled)
{
$this->purgeEnabled = $purgeEnabled;

return $this;
}

/**
* @return mixed
*/
public function getPurgeAfterDays()
{
return $this->purgeAfterDays;
}

/**
* @param mixed $purgeAfterDays
*/
public function setPurgeAfterDays($purgeAfterDays)
{
$this->purgeAfterDays = $purgeAfterDays;
}

/**
* @return mixed
*/
public function getLastPurgeDate()
{
return $this->lastPurgeDate;
}

/**
* @param mixed $lastPurgeDate
*/
public function setLastPurgeDate($lastPurgeDate)
{
$this->lastPurgeDate = $lastPurgeDate;
}
}
32 changes: 32 additions & 0 deletions Exception/InvalidNotificationFormException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* This file is part of the Claroline Connect package
*
* (c) Claroline Consortium <[email protected]>
*
* Author: Panagiotis TSAVDARIS
*
* Date: 4/14/15
*/

namespace Icap\NotificationBundle\Exception;


class InvalidNotificationFormException extends \RuntimeException
{
protected $form;

public function __construct($message, $form = null)
{
parent::__construct($message);
$this->form = $form;
}

/**
* @return array|null
*/
public function getForm()
{
return $this->form;
}
}
Loading

0 comments on commit 153f8f5

Please sign in to comment.