Skip to content

Commit

Permalink
implementation of the cache module and optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
ychadwick committed Feb 20, 2015
1 parent f49a854 commit 6695f45
Show file tree
Hide file tree
Showing 87 changed files with 1,552 additions and 1,066 deletions.
16 changes: 14 additions & 2 deletions Admin/BaseAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ public function setLanguages(array $languages)
$this->languages = $languages;
}

/**
* Set up listner to make sure the correct locale is used
*/
public function setUpTranslatableLocale()
{
/** @var \Gedmo\Translatable\TranslatableListener $translatable */
$translatableListener = $this->getContainer()->get('stof_doctrine_extensions.listener.translatable', ContainerInterface::NULL_ON_INVALID_REFERENCE);
if ($translatableListener) {
$translatableListener->setTranslatableLocale($this->getDefaultLocale());
}
}

/**
* Provide an array of locales where the locale is the key and the label is
* the value for easy display in a dropdown select for example
Expand Down Expand Up @@ -122,10 +134,10 @@ public function getDefaultLocale()
}
}

} else {
return $locale;
}

return $locale;

}

/**
Expand Down
8 changes: 6 additions & 2 deletions Admin/Entity/TranslationAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
*/
class TranslationAdmin extends ORMTranslationAdmin
{
/**
* @var array
*/
protected $managedLocales;

/**
* Whether or not to persist the filters in the session
Expand Down Expand Up @@ -130,8 +134,8 @@ public function getFilterParameters()
}

/**
* @param string $name
* @return multitype|NULL
* @param \Ibrows\SonataTranslationBundle\Admin\unknown $name
* @return \Ibrows\SonataTranslationBundle\Admin\multitype|string
*/
public function getTemplate($name)
{
Expand Down
2 changes: 1 addition & 1 deletion Admin/Model/GalleryAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function getTrackedActions()
*/
public function getIcon()
{
return 'glyph-camera-retro';
return 'glyphicon-camera-retro';
}

/**
Expand Down
32 changes: 15 additions & 17 deletions Admin/Model/LayoutBlockAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,17 @@

namespace Networking\InitCmsBundle\Admin\Model;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityNotFoundException;
use JMS\Serializer\Serializer;
use Networking\InitCmsBundle\Form\DataTransformer\ContentTypeTransformer;
use Networking\InitCmsBundle\Model\LayoutBlock;
use Networking\InitCmsBundle\Model\PageInterface;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\DataTransformer\ArrayToModelTransformer;
use Sonata\AdminBundle\Exception\ModelManagerException;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\AdminBundle\Form\FormMapper;
use Networking\InitCmsBundle\Form\DataTransformer\PageToNumberTransformer;
use Networking\InitCmsBundle\Admin\BaseAdmin;
use Networking\InitCmsBundle\Model\ContentInterface;

/**
* Class LayoutBlockAdmin
Expand Down Expand Up @@ -124,29 +121,30 @@ public function getContentTypes()
return $choices;
}


/**
* @param LayoutBlock $object
* @param mixed $object
* @return mixed|void
* @throws ModelManagerException
*/
public function postPersist($object)
{
public function prePersist($object){
/** @var ContentInterface $contentObject */
if ($contentObject = $object->getContent()) {

$this->getModelManager()->create($contentObject);
$object->setObjectId($contentObject->getId());
$this->getModelManager()->update($object);
try{
$this->getModelManager()->create($contentObject);
$object->setObjectId($contentObject->getId());
$this->autoPageDraft($object->getPage());
}catch (ModelManagerException $e){
throw new ModelManagerException('Cannot create content, object is invalid');
}
}

$this->autoPageDraft($object->getPage());
}


/**
* @param LayoutBlock $object
* @return mixed|void
*/
public function postUpdate($object)
public function preUpdate($object)
{
if ($contentObject = $object->getContent()) {
$this->getModelManager()->update($contentObject);
Expand All @@ -158,7 +156,7 @@ public function postUpdate($object)
* @param LayoutBlock $object
* @return mixed|void
*/
public function postRemove($object)
public function preRemove($object)
{
if ($classType = $object->getClassType()) {

Expand Down
4 changes: 2 additions & 2 deletions Admin/Model/MediaAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ protected function configureFormFields(FormMapper $formMapper)
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->add(
'custom',
->addIdentifier(
'name',
'string',
array(
'template' => 'NetworkingInitCmsBundle:MediaAdmin:list_custom.html.twig',
Expand Down
14 changes: 0 additions & 14 deletions Admin/Model/MenuItemAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,20 +358,6 @@ public function getTemplate($name)
}
}

public function createQuery($context = 'list')
{
/** @var QueryBuilder $query */
$query = parent::createQuery($context);
$aliases = $query->getRootAliases();
if($context === 'list'){
$query->select(sprintf('%s, p', $aliases[0]));
$query->leftJoin(sprintf('%s.page', $aliases[0]), 'p');
}


return $query;
}

/**
* returns all translated link targets
* @return array
Expand Down
25 changes: 21 additions & 4 deletions Admin/Model/PageAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,12 @@ protected function configureDatagridFilters(DatagridMapper $datagridMapper)
public function matchPath(ProxyQuery $ProxyQuery, $alias, $field, $data)
{
if (!$data || !is_array($data) || !array_key_exists('value', $data)) {
return;
return false;
}
$data['value'] = trim($data['value']);

if (strlen($data['value']) == 0) {
return;
return false;
}

$fieldName = 'path';
Expand All @@ -444,6 +444,23 @@ public function matchPath(ProxyQuery $ProxyQuery, $alias, $field, $data)
return true;
}

/**
* @param string $context
* @return \Sonata\AdminBundle\Datagrid\ProxyQueryInterface
*/
public function createQuery($context = 'list')
{
$query = parent::createQuery($context);
if($context == 'list'){
$query->addSelect('c');
$query->leftJoin(sprintf('%s.contentRoute', $query->getRootAlias()), 'c');
$query->orderBy('c.path', 'asc');
}


return $query;
}

/**
* @param ProxyQuery $ProxyQuery
* @param $alias
Expand Down Expand Up @@ -570,7 +587,7 @@ public function getTranslationLanguages()
$translationLanguages = new \Doctrine\Common\Collections\ArrayCollection();

if (!$id = $this->getRequest()->get('id')) {
return;
return false;
}

/** @var $pageManager PageManagerInterface */
Expand Down Expand Up @@ -643,7 +660,7 @@ protected function getDefaultTemplate()
return $this->getSubject()->getTemplateName();
}
$templates = $this->getContainer()->getParameter('networking_init_cms.page.templates');
$firstTemplate = reset($templates);
reset($templates);
$defaultTemplate = key($templates);

return $defaultTemplate;
Expand Down
84 changes: 35 additions & 49 deletions Admin/Model/UserAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected function configureListFields(ListMapper $listMapper)
$listMapper
->addIdentifier('username')
->add('email')
->add('groups')
->add('groups', null, array('template' => 'NetworkingInitCmsBundle:CRUD:list_orm_many_to_many.html.twig'))
->add(
'enabled',
null,
Expand Down Expand Up @@ -139,66 +139,52 @@ protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('General')
->add('username')
->add('email')
->add('plainPassword', 'text', array('required' => false))
->end()
->add('username')
->add('email')
->add('plainPassword', 'text', array('required' => (!$this->getSubject() || is_null($this->getSubject()->getId()))))
->end()
->with('Groups')
->add('groups', 'sonata_type_model', array('required' => false, 'expanded' => true, 'multiple' => true))
->add('groups', 'sonata_type_model', array('required' => false, 'expanded' => true, 'multiple' => true))
->end()
->with('Profile')
// ->add('dateOfBirth', 'birthday', array('required' => false))
->add('firstname', null, array('required' => false))
->add('lastname', null, array('required' => false))
// ->add('website', 'url', array('required' => false))
// ->add('biography', 'text', array('required' => false))
// ->add(
// 'gender',
// 'sonata_user_gender',
// array(
// 'required' => false,
// 'translation_domain' => $this->getTranslationDomain()
// )
// )
->add('locale', 'locale', array('required' => false))
// ->add('timezone', 'timezone', array('required' => false))
// ->add('phone', null, array('required' => false))
->add('firstname', null, array('required' => false))
->add('lastname', null, array('required' => false))
->add('locale', 'locale', array('required' => false))
->end();
// ->with('Social')
// ->add('facebookUid', null, array('required' => false))
// ->add('facebookName', null, array('required' => false))
// ->add('twitterUid', null, array('required' => false))
// ->add('twitterName', null, array('required' => false))
// ->add('gplusUid', null, array('required' => false))
// ->add('gplusName', null, array('required' => false))
// ->end();


if (!$this->getSubject()->hasRole('ROLE_SUPER_ADMIN')) {

$formMapper
->with('Management')
->add(
'realRoles',
'sonata_security_roles',
array(
'expanded' => true,
'multiple' => true,
'required' => false,
'label_render' => false,
'label' => false,
->add(
'realRoles',
'sonata_security_roles',
array(
'expanded' => true,
'multiple' => true,
'required' => false,
'label_render' => false,
'label' => false,
)
)
)
->add('locked', null, array('required' => false), array('inline_block' => true))
->add('expired', null, array('required' => false), array('inline_block' => true))
->add('enabled', null, array('required' => false), array('inline_block' => true))
->add('credentialsExpired', null, array('required' => false), array('inline_block' => true))
->add('locked', null, array('required' => false), array('inline_block' => true))
->add('expired', null, array('required' => false), array('inline_block' => true))
->add('enabled', null, array('required' => false), array('inline_block' => true))
->add('credentialsExpired', null, array('required' => false), array('inline_block' => true))
->end();
}

// $formMapper
// ->with('Security')
// ->add('token', null, array('required' => false))
// ->add('twoStepVerificationCode', null, array('required' => false))
// ->end();
}

/**
* {@inheritdoc}
*/
public function postUpdate($object)
{
$securityContext = $this->getConfigurationPool()->getContainer()->get('security.context');
if($object == $securityContext->getToken()->getUser()){
$this->getRequest()->getSession()->set( 'admin/_locale', $object->getLocale());
}
}
}
Loading

0 comments on commit 6695f45

Please sign in to comment.