├── .gitignore ├── .travis.yml ├── DependencyInjection ├── Compiler │ └── EventProviderCompilerPass.php ├── Configuration.php └── FrequenceWebCalendRExtension.php ├── FrequenceWebCalendRBundle.php ├── README.md ├── Resources ├── config │ └── services.xml └── doc │ └── index.rst ├── Tests ├── DependencyInjection │ ├── Compiler │ │ └── EventProviderCompilerPassTest.php │ └── FrequenceWebCalendRExtensionTest.php ├── FrequenceWebCalendRBundleTest.php └── bootstrap.php ├── composer.json └── phpunit.xml.dist /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | phpunit.xml 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | sudo: false 4 | 5 | branches: 6 | only: 7 | - master 8 | language: php 9 | php: 10 | - 5.6 11 | - 7.0 12 | - 7.1 13 | - 7.2 14 | before_script: 15 | - composer --prefer-source --dev install 16 | -------------------------------------------------------------------------------- /DependencyInjection/Compiler/EventProviderCompilerPass.php: -------------------------------------------------------------------------------- 1 | getDefinition('frequence_web_calendr.event.manager'); 26 | 27 | foreach ($container->findTaggedServiceIds(self::TAG) as $id => $attributes) { 28 | $providerAlias = isset($attributes[0]) && isset($attributes[0]['alias']) ? $attributes[0]['alias'] : $id; 29 | $eventManager->addMethodCall('addProvider', [$providerAlias, new Reference($id)]); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /DependencyInjection/Configuration.php: -------------------------------------------------------------------------------- 1 | root('frequence_web_calend_r'); 23 | 24 | $root 25 | ->children() 26 | ->arrayNode('periods') 27 | ->addDefaultsIfNotSet() 28 | ->children() 29 | ->scalarNode('default_first_weekday') 30 | ->defaultValue(Day::MONDAY) 31 | ->validate() 32 | ->ifNotInArray(range(DAY::SUNDAY, DAY::SATURDAY)) 33 | ->thenInvalid('Day must be be between 0 (Sunday) and 6 (Saturday)') 34 | ->end() 35 | ->end() 36 | ->end() 37 | ->end() 38 | ->end(); 39 | 40 | return $builder; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /DependencyInjection/FrequenceWebCalendRExtension.php: -------------------------------------------------------------------------------- 1 | processConfiguration($configuration, $configs); 26 | 27 | $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); 28 | $loader->load('services.xml'); 29 | 30 | $container 31 | ->getDefinition('frequence_web_calendr.factory') 32 | ->addMethodCall('setFirstWeekday', [$config['periods']['default_first_weekday']]); 33 | 34 | if (\method_exists($container, 'registerForAutoconfiguration')) { 35 | $container->registerForAutoconfiguration(ProviderInterface::class) 36 | ->addTag(EventProviderCompilerPass::TAG); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /FrequenceWebCalendRBundle.php: -------------------------------------------------------------------------------- 1 | addCompilerPass(new EventProviderCompilerPass()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FrequenceWebCalendRBundle [![Build Status](https://secure.travis-ci.org/frequence-web/FrequenceWebCalendRBundle.png?branch=master)](http://travis-ci.org/frequence-web/FrequenceWebCalendRBundle) 2 | 3 | This bundle provides [CalendR](http://github.com/yohang/CalendR.git) integration. 4 | 5 | It allows you to manage calendar and events. 6 | 7 | Calendar generation 8 | -------------------- 9 | 10 | ### Controller: 11 | 12 | ```php 13 | 14 | /** 15 | * @Template() 16 | */ 17 | public function indexAction() 18 | { 19 | return array('month' => $this->get('calendr')->getMonth(2012, 01)); 20 | } 21 | 22 | ``` 23 | 24 | ### Template 25 | 26 | ```html 27 | 28 | 29 | 30 | {% for week in month %} 31 | 32 | {% for day in week %} 33 | 40 | {% endfor %} 41 | 42 | {% endfor %} 43 | 44 |
34 | {% if month.contains(day) %} 35 | {{ day.begin.format('d') }} 36 | {% else %} 37 |   38 | {% endif %} 39 |
45 | 46 | ``` 47 | 48 | Event management 49 | ---------------- 50 | 51 | ### Providers 52 | 53 | To manage your events, you have to create a provider and an event class. See [CalendR doc](http://github.com/yohang/CalendR) 54 | 55 | ### Declare your provider 56 | 57 | This bundle allows you to easily add your providers to the CalendR event manager. Your provider have to be a service. 58 | 59 | 60 | ```yaml 61 | #config.yml 62 | 63 | services: 64 | my_event_provider: 65 | class: Your\Bundle\Event\Provider 66 | tags: 67 | - { name: calendr.event_provider } 68 | 69 | ``` 70 | -------------------------------------------------------------------------------- /Resources/config/services.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | CalendR\Calendar 10 | CalendR\Event\Manager 11 | CalendR\Extension\Twig\CalendRExtension 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Resources/doc/index.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frequence-web/FrequenceWebCalendRBundle/6d9fd44b037a6ba13177b889dea7d01fcf5deaaa/Resources/doc/index.rst -------------------------------------------------------------------------------- /Tests/DependencyInjection/Compiler/EventProviderCompilerPassTest.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | class EventProviderCompilerPassTest extends TestCase 15 | { 16 | /** 17 | * @var EventProviderCompilerPass 18 | */ 19 | protected $object; 20 | 21 | public function setUp() 22 | { 23 | $this->object = new EventProviderCompilerPass; 24 | } 25 | 26 | public function testProcess() 27 | { 28 | $eventManager = $this->getMockBuilder(Definition::class)->setMethods(['addMethodCall'])->getMock(); 29 | $container = $this->getMockBuilder(ContainerBuilder::class) 30 | ->setMethods(['getDefinition', 'findTaggedServiceIds']) 31 | ->getMock(); 32 | 33 | $container 34 | ->expects($this->once()) 35 | ->method('getDefinition') 36 | ->with($this->equalTo('frequence_web_calendr.event.manager')) 37 | ->will($this->returnValue($eventManager)); 38 | 39 | $container 40 | ->expects($this->once()) 41 | ->method('findTaggedServiceIds') 42 | ->with($this->equalTo('calendr.event_provider')) 43 | ->will($this->returnValue(['provider1' => [['alias' => 'foo']], 'provider2' => null])); 44 | 45 | $eventManager 46 | ->expects($this->at(0)) 47 | ->method('addMethodCall') 48 | ->with($this->equalTo('addProvider'), $this->equalTo(['foo', new Reference('provider1')])); 49 | 50 | $eventManager 51 | ->expects($this->at(1)) 52 | ->method('addMethodCall') 53 | ->with($this->equalTo('addProvider'), $this->equalTo(['provider2', new Reference('provider2')])); 54 | 55 | $this->object->process($container); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Tests/DependencyInjection/FrequenceWebCalendRExtensionTest.php: -------------------------------------------------------------------------------- 1 | 12 | */ 13 | class FrequenceWebCalendRExtensionTest extends TestCase 14 | { 15 | /** 16 | * @var FrequenceWebCalendRExtension 17 | */ 18 | protected $object; 19 | 20 | protected function setUp() 21 | { 22 | $this->object = new FrequenceWebCalendRExtension; 23 | } 24 | 25 | public function testLoad() 26 | { 27 | $container = new ContainerBuilder; 28 | $this->object->load([], $container); 29 | 30 | $this->assertTrue($container->hasDefinition('frequence_web_calendr.event.manager')); 31 | $this->assertTrue($container->hasDefinition('frequence_web_calendr.factory')); 32 | $this->assertTrue($container->hasDefinition('frequence_web_calendr.twig_extension')); 33 | $this->assertTrue($container->hasAlias('calendr')); 34 | 35 | $factory = $container->getDefinition('frequence_web_calendr.factory'); 36 | $this->assertTrue($factory->hasMethodCall('setEventManager')); 37 | $this->assertTrue($factory->hasMethodCall('setFirstWeekday')); 38 | 39 | foreach ($factory->getMethodCalls() as $call) { 40 | if ('setFirstWeekday' === $call[0]) { 41 | $this->assertSame(Day::MONDAY, $call[1][0]); 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Tests/FrequenceWebCalendRBundleTest.php: -------------------------------------------------------------------------------- 1 | 12 | */ 13 | class FrequenceWebCalendRBundleTest extends TestCase 14 | { 15 | /** 16 | * @var FrequenceWebCalendRBundle 17 | */ 18 | protected $object; 19 | 20 | protected function setUp() 21 | { 22 | $this->object = new FrequenceWebCalendRBundle; 23 | } 24 | 25 | public function testBuild() 26 | { 27 | $container = $this->getMockBuilder(ContainerBuilder::class)->setMethods(['addCompilerPass'])->getMock(); 28 | 29 | $container 30 | ->expects($this->once()) 31 | ->method('addCompilerPass') 32 | ->with($this->isInstanceOf(EventProviderCompilerPass::class)); 33 | 34 | $this->object->build($container); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | 17 | 18 | Tests/ 19 | 20 | 21 | 22 | 23 | 24 | ./ 25 | 26 | ./Resources 27 | ./Tests 28 | ./vendor 29 | 30 | 31 | 32 | 33 | 34 | --------------------------------------------------------------------------------