Skip to content

Commit

Permalink
Added notification configuration for core and resources
Browse files Browse the repository at this point in the history
  • Loading branch information
ptsavdar committed Apr 10, 2015
1 parent 498d88f commit 967518a
Show file tree
Hide file tree
Showing 55 changed files with 2,662 additions and 1,059 deletions.
12 changes: 8 additions & 4 deletions Controller/FollowerResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ class FollowerResourceController extends Controller
*/
public function renderFormAction($resourceId, $resourceClass, $user)
{
$followerResource = $this->get('icap.notification.manager')->getFollowerResource($user->getId(), $resourceId, $resourceClass);
$followerResource = $this->get('icap.notification.manager')->getFollowerResource(
$user->getId(),
$resourceId,
$resourceClass
);

$hasActiveNotifications = false;
if (!empty($followerResource)) {
Expand All @@ -31,9 +35,9 @@ public function renderFormAction($resourceId, $resourceClass, $user)

return array(
'hasActiveNotifications' => $hasActiveNotifications,
'resourceId' => $resourceId,
'resourceClass' => base64_encode($resourceClass),
'userId' => $user->getId()
'resourceId' => $resourceId,
'resourceClass' => base64_encode($resourceClass),
'userId' => $user->getId()
);
}

Expand Down
47 changes: 42 additions & 5 deletions Controller/NotificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Icap\NotificationBundle\Controller;

use Doctrine\ORM\NoResultException;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
Expand All @@ -11,6 +12,7 @@
use Icap\NotificationBundle\Entity\ColorChooser;

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

class NotificationController extends Controller
{
Expand All @@ -37,13 +39,15 @@ public function listAction(Request $request, $user, $page)
$maxResult = $this->container->getParameter('icap_notification.max_per_page');
}

$result = $this->get("icap.notification.manager")
->getUserNotificationsList($user->getId(), $page, $maxResult);
$systemName = $this->container->getParameter('icap_notification.system_name');
$notificationManager = $this->getNotificationManager();
$result = $notificationManager->getUserNotificationsList($user->getId(), $page, $maxResult);
$systemName = $notificationManager->getPlatformName();
$result['systemName'] = $systemName;

if ($request->isXMLHttpRequest()) {
$unviewedNotifications = $this->get('icap.notification.manager')->countUnviewedNotifications($user->getId());
$unviewedNotifications = $notificationManager->countUnviewedNotifications(
$user->getId()
);
$result['unviewedNotifications'] = $unviewedNotifications;

return $this->render(
Expand All @@ -52,10 +56,43 @@ public function listAction(Request $request, $user, $page)
);
} else {
$defaultLayout = $this->container->getParameter('icap_notification.default_layout');
$systemName = $this->container->getParameter('icap_notification.system_name');
$result['layout'] = $defaultLayout;

return $result;
}
}

/**
* @Route(
* "/rss/{rssId}",
* defaults={"_format":"xml"},
* name="icap_notification_rss"
* )
* @Template()
* @param $rssId
* @return mixed
*/
public function rssAction($rssId)
{
$notificationManager = $this->getNotificationManager();
$maxResult = $this->container->getParameter('icap_notification.max_per_page');
try {
$result = $notificationManager->getUserNotificationsListRss($rssId, $maxResult);
$result["systemName"] = $notificationManager->getPlatformName();
} catch (NoResultException $nre) {
$result = array("error" => "no_rss_defined");
} catch (NotFoundHttpException $nfe) {
$result = array("error" => "zero_notifications");
}

return $result;
}

/**
* @return \Icap\NotificationBundle\Manager\NotificationManager
*/
private function getNotificationManager()
{
return $this->get("icap.notification.manager");
}
}
75 changes: 75 additions & 0 deletions Controller/NotificationUserParametersController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* This file is part of the Claroline Connect package
*
* (c) Claroline Consortium <[email protected]>
*
* Author: Panagiotis TSAVDARIS
*
* Date: 4/8/15
*/

namespace Icap\NotificationBundle\Controller;

use Claroline\CoreBundle\Entity\User;
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 Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;


class NotificationUserParametersController extends Controller
{
/**
* @Route("/parameters", name="icap_notification_user_parameters")
* @Method({"GET"})
* @Template("IcapNotificationBundle:Parameters:config.html.twig")
* @ParamConverter("user", options={"authenticatedUser" = true})
*/
public function getAction(User $user)
{
$parametersManager = $this->getParametersManager();
$parameters = $parametersManager->getParametersByUserId($user->getId());
$types = $parametersManager->allTypesList($parameters);

return array('types' => $types, 'rssId' => $parameters->getRssId());
}

/**
* @Route("/parameters", name="icap_notification_save_user_parameters")
* @Method({"POST"})
* @Template("IcapNotificationBundle:Parameters:config.html.twig")
* @ParamConverter("user", options={"authenticatedUser" = true})
*/
public function postAction(Request $request, User $user)
{
$this->getParametersManager()->processUpdate($request->request->all(), $user->getId());

return new RedirectResponse($this->generateUrl("claro_desktop_parameters_menu"));
}

/**
* @Route("/regenerate_rss", name="icap_notification_regenerate_rss_url")
* @Template("IcapNotificationBundle:Parameters:config.html.twig")
* @ParamConverter("user", options={"authenticatedUser" = true})
*/
public function regenerateRssUrlAction(User $user)
{
$parametersManager = $this->getParametersManager();
$parameters = $parametersManager->regenerateRssId($user->getId());
$types = $parametersManager->allTypesList($parameters);

return array('types' => $types, 'rssId' => $parameters->getRssId());
}

/**
* @return \Icap\NotificationBundle\Manager\NotificationUserParametersManager
*/
private function getParametersManager()
{
return $this->get("icap.notification.manager.notification_user_parameters");
}
}
10 changes: 4 additions & 6 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ public function getConfigTreeBuilder()

$rootNode
->children()
->scalarNode('default_layout')->isRequired()->end()
->integerNode('max_per_page')->defaultValue(50)->end()
->integerNode('dropdown_items')->defaultValue(10)->end()
->scalarNode('system_name')->isRequired()->end()
->end()
;
->scalarNode('default_layout')->isRequired()->end()
->integerNode('max_per_page')->defaultValue(50)->end()
->integerNode('dropdown_items')->defaultValue(10)->end()
->end();

return $treeBuilder;
}
Expand Down
4 changes: 2 additions & 2 deletions DependencyInjection/IcapNotificationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public function load(array $configs, ContainerBuilder $container)
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

foreach (array('default_layout', 'max_per_page', 'dropdown_items', 'system_name') as $attribute) {
$container->setParameter("icap_notification.".$attribute, $config[$attribute]);
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');
Expand Down
105 changes: 88 additions & 17 deletions Entity/ColorChooser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,89 @@

namespace Icap\NotificationBundle\Entity;

class ColorChooser {
class ColorChooser
{
protected $colorArray = array(
'#1ABC9C', '#16A085', '#2ECC71', '#27AE60', '#3498DB', '#2980B9', '#9B59B6', '#8E44AD', '#34495E', '#2C3E50',
'#22313F', '#F1C40F', '#F39C12', '#E67E22', '#D35400', '#E74C3C', '#C0392B', '#BDC3C7', '#95A5A6', '#7F8C8D',
'#F17288', '#1DD2AF', '#19B698', '#40D47E', '#2CC36B', '#4AA3DF', '#2E8ECE', '#A66BBE', '#9B50BA', '#3D566E',
'#354B60', '#F2CA27', '#F4A62A', '#E98B39', '#EC5E00', '#EA6153', '#D14233', '#CBD0D3', '#A3B1B2', '#8C9899',
'#CB5A5E', '#0E7AC3', '#731046', '#C2237F', '#56BE8E', '#E0D90E', '#0095A6', '#E33938', '#FF3E00', '#C9112F',
'#FF65B3', '#5BC4BE'
'#1ABC9C',
'#16A085',
'#2ECC71',
'#27AE60',
'#3498DB',
'#2980B9',
'#9B59B6',
'#8E44AD',
'#34495E',
'#2C3E50',
'#22313F',
'#F1C40F',
'#F39C12',
'#E67E22',
'#D35400',
'#E74C3C',
'#C0392B',
'#BDC3C7',
'#95A5A6',
'#7F8C8D',
'#F17288',
'#1DD2AF',
'#19B698',
'#40D47E',
'#2CC36B',
'#4AA3DF',
'#2E8ECE',
'#A66BBE',
'#9B50BA',
'#3D566E',
'#354B60',
'#F2CA27',
'#F4A62A',
'#E98B39',
'#EC5E00',
'#EA6153',
'#D14233',
'#CBD0D3',
'#A3B1B2',
'#8C9899',
'#CB5A5E',
'#0E7AC3',
'#731046',
'#C2237F',
'#56BE8E',
'#E0D90E',
'#0095A6',
'#E33938',
'#FF3E00',
'#C9112F',
'#FF65B3',
'#5BC4BE'
);
protected $alphabet = array(
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z'
);
protected $nameArray = array();
protected $needleArray = array();
Expand All @@ -30,7 +101,7 @@ public function getColorForName($name)
$needle = $name[0];

//We test if the needle already exists, if so we add one more letter
while (strlen($needle)<strlen($name) && in_array($needle, $this->needleArray)) {
while (strlen($needle) < strlen($name) && in_array($needle, $this->needleArray)) {
$needle .= $name[strlen($needle)];
}

Expand All @@ -44,7 +115,7 @@ public function getColorForName($name)
}
}

public function setNameArray ($nameArray)
public function setNameArray($nameArray)
{
foreach ($nameArray as $name) {
$this->getColorForName($name);
Expand All @@ -53,21 +124,21 @@ public function setNameArray ($nameArray)
return $this;
}

public function setAlphabet ($alphabet)
public function setAlphabet($alphabet)
{
$this->alphabet = $alphabet;

return $this;
}

public function setColorArray ($colorArray)
public function setColorArray($colorArray)
{
$this->colorArray = $colorArray;

return $this;
}

public function addColor ($color)
public function addColor($color)
{
if (!in_array($color, $this->colorArray)) {
array_push($this->colorArray, $color);
Expand All @@ -76,7 +147,7 @@ public function addColor ($color)
return $this;
}

public function addColors ($colorArray)
public function addColors($colorArray)
{
foreach ($colorArray as $color) {
$this->addColor($color);
Expand All @@ -85,10 +156,10 @@ public function addColors ($colorArray)
return $this;
}

private function getColorForNeedle ($needle)
private function getColorForNeedle($needle)
{
$score = 0;
for ($i=0; $i<strlen($needle); $i++) {
for ($i = 0; $i < strlen($needle); $i++) {
$score += array_search($needle[$i], $this->alphabet);
}
$colorIndex = $score % count($this->colorArray);
Expand Down
Loading

0 comments on commit 967518a

Please sign in to comment.