Skip to content

Commit 967518a

Browse files
committed
Added notification configuration for core and resources
1 parent 498d88f commit 967518a

File tree

55 files changed

+2662
-1059
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2662
-1059
lines changed

Controller/FollowerResourceController.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ class FollowerResourceController extends Controller
2222
*/
2323
public function renderFormAction($resourceId, $resourceClass, $user)
2424
{
25-
$followerResource = $this->get('icap.notification.manager')->getFollowerResource($user->getId(), $resourceId, $resourceClass);
25+
$followerResource = $this->get('icap.notification.manager')->getFollowerResource(
26+
$user->getId(),
27+
$resourceId,
28+
$resourceClass
29+
);
2630

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

3236
return array(
3337
'hasActiveNotifications' => $hasActiveNotifications,
34-
'resourceId' => $resourceId,
35-
'resourceClass' => base64_encode($resourceClass),
36-
'userId' => $user->getId()
38+
'resourceId' => $resourceId,
39+
'resourceClass' => base64_encode($resourceClass),
40+
'userId' => $user->getId()
3741
);
3842
}
3943

Controller/NotificationController.php

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Icap\NotificationBundle\Controller;
44

5+
use Doctrine\ORM\NoResultException;
56
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
67
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
78
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
@@ -11,6 +12,7 @@
1112
use Icap\NotificationBundle\Entity\ColorChooser;
1213

1314
use Symfony\Component\HttpFoundation\Request;
15+
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1416

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

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

4547
if ($request->isXMLHttpRequest()) {
46-
$unviewedNotifications = $this->get('icap.notification.manager')->countUnviewedNotifications($user->getId());
48+
$unviewedNotifications = $notificationManager->countUnviewedNotifications(
49+
$user->getId()
50+
);
4751
$result['unviewedNotifications'] = $unviewedNotifications;
4852

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

5861
return $result;
5962
}
6063
}
64+
65+
/**
66+
* @Route(
67+
* "/rss/{rssId}",
68+
* defaults={"_format":"xml"},
69+
* name="icap_notification_rss"
70+
* )
71+
* @Template()
72+
* @param $rssId
73+
* @return mixed
74+
*/
75+
public function rssAction($rssId)
76+
{
77+
$notificationManager = $this->getNotificationManager();
78+
$maxResult = $this->container->getParameter('icap_notification.max_per_page');
79+
try {
80+
$result = $notificationManager->getUserNotificationsListRss($rssId, $maxResult);
81+
$result["systemName"] = $notificationManager->getPlatformName();
82+
} catch (NoResultException $nre) {
83+
$result = array("error" => "no_rss_defined");
84+
} catch (NotFoundHttpException $nfe) {
85+
$result = array("error" => "zero_notifications");
86+
}
87+
88+
return $result;
89+
}
90+
91+
/**
92+
* @return \Icap\NotificationBundle\Manager\NotificationManager
93+
*/
94+
private function getNotificationManager()
95+
{
96+
return $this->get("icap.notification.manager");
97+
}
6198
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* This file is part of the Claroline Connect package
4+
*
5+
* (c) Claroline Consortium <[email protected]>
6+
*
7+
* Author: Panagiotis TSAVDARIS
8+
*
9+
* Date: 4/8/15
10+
*/
11+
12+
namespace Icap\NotificationBundle\Controller;
13+
14+
use Claroline\CoreBundle\Entity\User;
15+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
16+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
17+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
18+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
19+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
20+
use Symfony\Component\HttpFoundation\RedirectResponse;
21+
use Symfony\Component\HttpFoundation\Request;
22+
23+
24+
class NotificationUserParametersController extends Controller
25+
{
26+
/**
27+
* @Route("/parameters", name="icap_notification_user_parameters")
28+
* @Method({"GET"})
29+
* @Template("IcapNotificationBundle:Parameters:config.html.twig")
30+
* @ParamConverter("user", options={"authenticatedUser" = true})
31+
*/
32+
public function getAction(User $user)
33+
{
34+
$parametersManager = $this->getParametersManager();
35+
$parameters = $parametersManager->getParametersByUserId($user->getId());
36+
$types = $parametersManager->allTypesList($parameters);
37+
38+
return array('types' => $types, 'rssId' => $parameters->getRssId());
39+
}
40+
41+
/**
42+
* @Route("/parameters", name="icap_notification_save_user_parameters")
43+
* @Method({"POST"})
44+
* @Template("IcapNotificationBundle:Parameters:config.html.twig")
45+
* @ParamConverter("user", options={"authenticatedUser" = true})
46+
*/
47+
public function postAction(Request $request, User $user)
48+
{
49+
$this->getParametersManager()->processUpdate($request->request->all(), $user->getId());
50+
51+
return new RedirectResponse($this->generateUrl("claro_desktop_parameters_menu"));
52+
}
53+
54+
/**
55+
* @Route("/regenerate_rss", name="icap_notification_regenerate_rss_url")
56+
* @Template("IcapNotificationBundle:Parameters:config.html.twig")
57+
* @ParamConverter("user", options={"authenticatedUser" = true})
58+
*/
59+
public function regenerateRssUrlAction(User $user)
60+
{
61+
$parametersManager = $this->getParametersManager();
62+
$parameters = $parametersManager->regenerateRssId($user->getId());
63+
$types = $parametersManager->allTypesList($parameters);
64+
65+
return array('types' => $types, 'rssId' => $parameters->getRssId());
66+
}
67+
68+
/**
69+
* @return \Icap\NotificationBundle\Manager\NotificationUserParametersManager
70+
*/
71+
private function getParametersManager()
72+
{
73+
return $this->get("icap.notification.manager.notification_user_parameters");
74+
}
75+
}

DependencyInjection/Configuration.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ public function getConfigTreeBuilder()
1818

1919
$rootNode
2020
->children()
21-
->scalarNode('default_layout')->isRequired()->end()
22-
->integerNode('max_per_page')->defaultValue(50)->end()
23-
->integerNode('dropdown_items')->defaultValue(10)->end()
24-
->scalarNode('system_name')->isRequired()->end()
25-
->end()
26-
;
21+
->scalarNode('default_layout')->isRequired()->end()
22+
->integerNode('max_per_page')->defaultValue(50)->end()
23+
->integerNode('dropdown_items')->defaultValue(10)->end()
24+
->end();
2725

2826
return $treeBuilder;
2927
}

DependencyInjection/IcapNotificationExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public function load(array $configs, ContainerBuilder $container)
2626
$configuration = new Configuration();
2727
$config = $this->processConfiguration($configuration, $configs);
2828

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

3333
$locator = new FileLocator(__DIR__ . '/../Resources/config/services');

Entity/ColorChooser.php

Lines changed: 88 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,89 @@
22

33
namespace Icap\NotificationBundle\Entity;
44

5-
class ColorChooser {
5+
class ColorChooser
6+
{
67
protected $colorArray = array(
7-
'#1ABC9C', '#16A085', '#2ECC71', '#27AE60', '#3498DB', '#2980B9', '#9B59B6', '#8E44AD', '#34495E', '#2C3E50',
8-
'#22313F', '#F1C40F', '#F39C12', '#E67E22', '#D35400', '#E74C3C', '#C0392B', '#BDC3C7', '#95A5A6', '#7F8C8D',
9-
'#F17288', '#1DD2AF', '#19B698', '#40D47E', '#2CC36B', '#4AA3DF', '#2E8ECE', '#A66BBE', '#9B50BA', '#3D566E',
10-
'#354B60', '#F2CA27', '#F4A62A', '#E98B39', '#EC5E00', '#EA6153', '#D14233', '#CBD0D3', '#A3B1B2', '#8C9899',
11-
'#CB5A5E', '#0E7AC3', '#731046', '#C2237F', '#56BE8E', '#E0D90E', '#0095A6', '#E33938', '#FF3E00', '#C9112F',
12-
'#FF65B3', '#5BC4BE'
8+
'#1ABC9C',
9+
'#16A085',
10+
'#2ECC71',
11+
'#27AE60',
12+
'#3498DB',
13+
'#2980B9',
14+
'#9B59B6',
15+
'#8E44AD',
16+
'#34495E',
17+
'#2C3E50',
18+
'#22313F',
19+
'#F1C40F',
20+
'#F39C12',
21+
'#E67E22',
22+
'#D35400',
23+
'#E74C3C',
24+
'#C0392B',
25+
'#BDC3C7',
26+
'#95A5A6',
27+
'#7F8C8D',
28+
'#F17288',
29+
'#1DD2AF',
30+
'#19B698',
31+
'#40D47E',
32+
'#2CC36B',
33+
'#4AA3DF',
34+
'#2E8ECE',
35+
'#A66BBE',
36+
'#9B50BA',
37+
'#3D566E',
38+
'#354B60',
39+
'#F2CA27',
40+
'#F4A62A',
41+
'#E98B39',
42+
'#EC5E00',
43+
'#EA6153',
44+
'#D14233',
45+
'#CBD0D3',
46+
'#A3B1B2',
47+
'#8C9899',
48+
'#CB5A5E',
49+
'#0E7AC3',
50+
'#731046',
51+
'#C2237F',
52+
'#56BE8E',
53+
'#E0D90E',
54+
'#0095A6',
55+
'#E33938',
56+
'#FF3E00',
57+
'#C9112F',
58+
'#FF65B3',
59+
'#5BC4BE'
1360
);
1461
protected $alphabet = array(
15-
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
16-
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
62+
'a',
63+
'b',
64+
'c',
65+
'd',
66+
'e',
67+
'f',
68+
'g',
69+
'h',
70+
'i',
71+
'j',
72+
'k',
73+
'l',
74+
'm',
75+
'n',
76+
'o',
77+
'p',
78+
'q',
79+
'r',
80+
's',
81+
't',
82+
'u',
83+
'v',
84+
'w',
85+
'x',
86+
'y',
87+
'z'
1788
);
1889
protected $nameArray = array();
1990
protected $needleArray = array();
@@ -30,7 +101,7 @@ public function getColorForName($name)
30101
$needle = $name[0];
31102

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

@@ -44,7 +115,7 @@ public function getColorForName($name)
44115
}
45116
}
46117

47-
public function setNameArray ($nameArray)
118+
public function setNameArray($nameArray)
48119
{
49120
foreach ($nameArray as $name) {
50121
$this->getColorForName($name);
@@ -53,21 +124,21 @@ public function setNameArray ($nameArray)
53124
return $this;
54125
}
55126

56-
public function setAlphabet ($alphabet)
127+
public function setAlphabet($alphabet)
57128
{
58129
$this->alphabet = $alphabet;
59130

60131
return $this;
61132
}
62133

63-
public function setColorArray ($colorArray)
134+
public function setColorArray($colorArray)
64135
{
65136
$this->colorArray = $colorArray;
66137

67138
return $this;
68139
}
69140

70-
public function addColor ($color)
141+
public function addColor($color)
71142
{
72143
if (!in_array($color, $this->colorArray)) {
73144
array_push($this->colorArray, $color);
@@ -76,7 +147,7 @@ public function addColor ($color)
76147
return $this;
77148
}
78149

79-
public function addColors ($colorArray)
150+
public function addColors($colorArray)
80151
{
81152
foreach ($colorArray as $color) {
82153
$this->addColor($color);
@@ -85,10 +156,10 @@ public function addColors ($colorArray)
85156
return $this;
86157
}
87158

88-
private function getColorForNeedle ($needle)
159+
private function getColorForNeedle($needle)
89160
{
90161
$score = 0;
91-
for ($i=0; $i<strlen($needle); $i++) {
162+
for ($i = 0; $i < strlen($needle); $i++) {
92163
$score += array_search($needle[$i], $this->alphabet);
93164
}
94165
$colorIndex = $score % count($this->colorArray);

0 commit comments

Comments
 (0)