<commit_before><?php
/**
 * Description of StudentAdmin
 *
 * @author bartek
 */
namespace Application\Sonata\UserBundle\Admin;

use Sonata\AdminBundle\Admin\Admin as BaseAdmin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Route\RouteCollection;

use FOS\UserBundle\Model\UserManagerInterface;
use FOS\UserBundle\Model\GroupManagerInterface;

class StoreOwnerAdmin extends BaseAdmin {
    
    
    protected $formOptions = array(
        'validation_groups' => 'Create'
    );
    
    public function getNewInstance()
    {
        $class = $this->getClass();

        return new $class('', array());
    }

    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('fullname')
            ->add('email')
        ;
    }

    protected function configureDatagridFilters(DatagridMapper $filterMapper)
    {
        $filterMapper
            ->add('username', 'doctrine_orm_callback', array(
                'callback' => array($this, 'getWithProfileFields'),
                'field_type' => 'text',
                
            ),null, array('attr'=>array('placeholder'=>"lastname, email, phone")))    
            
            
        ;
    }
    
    public function getWithProfileFields($queryBuilder, $alias, $field, $value)
    {
        if (!$value['value']) {
            return;
        }

        $search_str = $value['value'].'%';
        
        $queryBuilder
            ->orWhere(sprintf('%s.lastname', $alias).' like :p1')
                ->setParameter('p1', $search_str)
            ->orWhere(sprintf('%s.email', $alias).' like :p2')
                ->setParameter('p2', $search_str)
            ->orWhere(sprintf('%s.mobile', $alias).' like :p2')
                ->setParameter('p2', $search_str)
        ;

        return true;
    }
    
    
    
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->with('General')
                ->add('firstname')
                ->add('lastname')
                ->add('username')
                ->add('email')
                ->add('plainPassword', 'text', array('required' => false))
            ->end()
            
            ->with('Aditional Informations', array('collapsed' => true))
                ->add('date_of_birth', 'date', array(
                    'input'  => 'timestamp', 
                    'widget' => 'choice', 
                    'pattern' => '{{ year }} {{ month }} {{ day }}', 
                    'data_timezone' => 'Etc/UTC', 
                    'user_timezone' => 'Europe/London',
                    'empty_value' => array('year' => 'Year', 'month' => 'Month', 'day' => 'Day'),
                    'years' => range(date('Y') -80, date('Y') - 10)
                    )
                )
                ->add('place_of_birth')
                ->add('country_of_birth')
                ->add('citizenship')
                ->add('nationality')<commit_msg>Creating Interfaces and Model classes for all bundles Tidying up the whole structure<commit_after><?php
/**
 * Description of StudentAdmin
 *
 * @author bartek
 */
namespace Application\Sonata\UserBundle\Admin;

use Sonata\AdminBundle\Admin\Admin as BaseAdmin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Route\RouteCollection;

use FOS\UserBundle\Model\UserManagerInterface;
use FOS\UserBundle\Model\GroupManagerInterface;

class StoreOwnerAdmin extends BaseAdmin {
    
    
    protected $formOptions = array(
        'validation_groups' => 'Create'
    );
    
    public function getNewInstance()
    {
        $class = $this->getClass();

        return new $class('', array());
    }

    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('fullname')
            ->add('email')
        ;
    }

    protected function configureDatagridFilters(DatagridMapper $filterMapper)
    {
        $filterMapper
            ->add('username', 'doctrine_orm_callback', array(
                'callback' => array($this, 'getWithProfileFields'),
                'field_type' => 'text',
                
            ),null, array('attr'=>array('placeholder'=>"lastname, email, phone")))    
            
            
        ;
    }
    
    public function getWithProfileFields($queryBuilder, $alias, $field, $value)
    {
        if (!$value['value']) {
            return;
        }

        $search_str = $value['value'].'%';
        
        $queryBuilder
            ->orWhere(sprintf('%s.lastname', $alias).' like :p1')
                ->setParameter('p1', $search_str)
            ->orWhere(sprintf('%s.email', $alias).' like :p2')
                ->setParameter('p2', $search_str)
            ->orWhere(sprintf('%s.mobile', $alias).' like :p2')
                ->setParameter('p2', $search_str)
        ;

        return true;
    }
    
    
    
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->with('General')
                ->add('firstname', 'text')
                ->add('lastname', 'text')
                ->add('username')
                ->add('email')
                ->add('plainPassword', 'text', array('required' => false))
            ->end()
            
            ->with('Aditional Informations', array('collapsed' => true))
                ->add('date_of_birth', 'date', array(
                    'input'  => 'timestamp', 
                    'widget' => 'choice', 
                    'pattern' => '{{ year }} {{ month }} {{ day }}', 
                    'data_timezone' => 'Etc/UTC', 
                    'user_timezone' => 'Europe/London',
                    'empty_value' => array('year' => 'Year', 'month' => 'Month', 'day' => 'Day'),
                    'years' => range(date('Y') -80, date('Y') - 10)
                    )
                )
                ->add('place_of_birth')
                ->add('country_of_birth')
                ->add('citizenship')
                ->add('nationality')
{'fraction_non_alphanumeric': 0.14819566960705693, 'fraction_numerical': 0.0032076984763432237, 'mean_word_length': 1.8153498871331828, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6887034', 'n_tokens_mistral': 1780, 'n_tokens_neox': 1703, 'n_words': 309}