Skip to content

Commit

Permalink
Merge pull request #1 from it-blaster/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
selezenev committed Sep 22, 2015
2 parents f74cd00 + b8850ec commit 69d447f
Show file tree
Hide file tree
Showing 34 changed files with 657 additions and 89 deletions.
82 changes: 82 additions & 0 deletions Admin/GoalAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace ItBlaster\CounterManagementBundle\Admin;

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Show\ShowMapper;

class GoalAdmin extends Admin
{
/**
* @param DatagridMapper $datagridMapper
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('Name')
->add('Code')
->add('Counter')
->add('Page')
->add('ButtonType')
->add('Vendor')
;
}

/**
* @param ListMapper $listMapper
*/
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->add('Id')
->add('Name')
->add('Code')
->add('Counter')
->add('Page')
->add('ButtonType')
->add('Vendor')
->add('_action', 'actions', array(
'actions' => array(
'show' => array(),
'edit' => array(),
'delete' => array(),
)
))
;
}

/**
* @param FormMapper $formMapper
*/
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('Id')
->add('Name')
->add('Code')
->add('Counter')
->add('Page')
->add('ButtonType')
->add('Vendor')
;
}

/**
* @param ShowMapper $showMapper
*/
protected function configureShowFields(ShowMapper $showMapper)
{
$showMapper
->add('Id')
->add('Name')
->add('Code')
->add('Counter')
->add('Page')
->add('ButtonType')
->add('Vendor')
;
}
}
107 changes: 107 additions & 0 deletions Admin/WebCounterAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

namespace ItBlaster\CounterManagementBundle\Admin;

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Show\ShowMapper;
use Symfony\Component\Validator\Constraints\NotBlank;

class WebCounterAdmin extends Admin
{
/**
* @param DatagridMapper $datagridMapper
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('Name', null, array(
'label' => 'Название'
))
->add('Published', null, array(
'label' => 'Публикация'
))
;
}

protected function configureRoutes(RouteCollection $collection)
{
parent::configureRoutes($collection);
$collection->remove('show');
}


/**
* @param ListMapper $listMapper
*/
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->add('Name', null, array(
'label' => 'Название'
))
->add('Number', null, array(
'label' => 'Номер'
))
->add('TypeKey', null, array(
'label' => 'Тип',
))
->add('_action', 'actions', array(
'actions' => array(
'show' => array(),
'edit' => array(),
'delete' => array(),
)
))
;
}

/**
* @param FormMapper $formMapper
*/
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('Name', null, array(
'label' => 'Название',
'required' => true,
'constraints' => array(
new NotBlank()
)
))
->add('Number', null, array(
'label' => 'Номер счетчика',
'required' => true,
'constraints' => array(
new NotBlank()
)
))
->add('Code', null, array(
'label' => 'Код счетчика',
'disabled' => true,
))
->add('TypeKey', 'choice', array(
'label' => 'Тип счетчика',
'choices' => $this->getConfigurationPool()->getContainer()->get('counter_management.manager')->getProvidersChoices(),
'constraints' => array(
new NotBlank()
)
));
}

/**
* @param ShowMapper $showMapper
*/
protected function configureShowFields(ShowMapper $showMapper)
{
$showMapper
->add('Id')
->add('Name')
->add('Published')
->add('Code')
;
}
}
36 changes: 36 additions & 0 deletions Command/CounterAddCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace ItBlaster\CounterManagementBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;


class CounterAddCommand extends ContainerAwareCommand {


protected function configure()
{
$this
->setName('counters:add')
->setDescription('Create counter')
->addArgument(
'type',
InputArgument::OPTIONAL,
'What kind of counter do u want to create?'
)
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{

$counter = $this->getContainer()->get('counter_management.manager')
->getProvider('yandex_metrika')->create(array('code' => '5742498'));

var_dump($counter);
}
}
13 changes: 0 additions & 13 deletions Controller/DefaultController.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php


namespace ItBlaster\CounterManagementBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Reference;


class CounterManagementProviderCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->has('counter_management.manager')) {
return;
}

$definition = $container->findDefinition(
'counter_management.manager'
);

$taggedServices = $container->findTaggedServiceIds(
'counter_management.provider'
);

foreach ($taggedServices as $id => $tags) {
$definition->addMethodCall(
'addProvider',
array(new Reference($id))
);
}
}


}
2 changes: 2 additions & 0 deletions DependencyInjection/ItBlasterCounterManagementExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ public function load(array $configs, ContainerBuilder $container)

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
$loader->load('counter_providers.yml');
$loader->load('sonata_admin.yml');
}
}
7 changes: 7 additions & 0 deletions ItBlasterCounterManagementBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

namespace ItBlaster\CounterManagementBundle;

use ItBlaster\CounterManagementBundle\DependencyInjection\Compiler\CounterManagementProviderCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class ItBlasterCounterManagementBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new CounterManagementProviderCompilerPass());
}
}
51 changes: 51 additions & 0 deletions Listener/WebCounterListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php


namespace ItBlaster\CounterManagementBundle\Listener;


use ItBlaster\CounterManagementBundle\Model\WebCounter;
use ItBlaster\CounterManagementBundle\Model\WebCounterPeer;
use ItBlaster\CounterManagementBundle\Service\Manager;
use Symfony\Component\EventDispatcher\GenericEvent;

class WebCounterListener
{


/**
* @var Manager
*/
protected $counter_management_manager;

/**
* WebCounterListener constructor.
* @param Manager $counter_management_manager
*/
public function __construct(Manager $counter_management_manager)
{
$this->counter_management_manager = $counter_management_manager;
}

public function onPreSave(GenericEvent $event)
{
/** @var WebCounter $web_counter */
$web_counter = $event->getSubject();
if ($web_counter->isColumnModified(WebCounterPeer::NUMBER) || $web_counter->getCode() === null) {
$this->generateCode($web_counter);
}
}

/**
* @param WebCounter $web_counter
*/
protected function generateCode(WebCounter $web_counter)
{
$provider = $this->counter_management_manager->getProvider($web_counter->getTypeKey());
$web_counter->setCode(
$provider->generateCode($web_counter->getNumber())
);
}


}
9 changes: 9 additions & 0 deletions Model/WebCounter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace ItBlaster\CounterManagementBundle\Model;

use ItBlaster\CounterManagementBundle\Model\om\BaseWebCounter;

class WebCounter extends BaseWebCounter
{
}
9 changes: 9 additions & 0 deletions Model/WebCounterGoal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace ItBlaster\CounterManagementBundle\Model;

use ItBlaster\CounterManagementBundle\Model\om\BaseWebCounterGoal;

class WebCounterGoal extends BaseWebCounterGoal
{
}
9 changes: 9 additions & 0 deletions Model/WebCounterGoalPeer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace ItBlaster\CounterManagementBundle\Model;

use ItBlaster\CounterManagementBundle\Model\om\BaseWebCounterGoalPeer;

class WebCounterGoalPeer extends BaseWebCounterGoalPeer
{
}
9 changes: 9 additions & 0 deletions Model/WebCounterGoalQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace ItBlaster\CounterManagementBundle\Model;

use ItBlaster\CounterManagementBundle\Model\om\BaseWebCounterGoalQuery;

class WebCounterGoalQuery extends BaseWebCounterGoalQuery
{
}
Loading

0 comments on commit 69d447f

Please sign in to comment.