Skip to content

Instantly share code, notes, and snippets.

View sglessard's full-sized avatar
🏠
Working from home

Simon Guillem-Lessard sglessard

🏠
Working from home
View GitHub Profile
// tested on http://sandbox.onlinephpfunctions.com/
class Section {
public $id;
}
$a = new Section();
$a->id = 10;
$aa = new Section();
$aa->id = 20;
@sglessard
sglessard / FieldFunction.php
Created April 9, 2015 16:00
DQL FieldFunction (did not work on my WC)
<?php
/**
* Usage: FIELD(str,str1,str2,str3,...)
*
* FIELD returns the index (position) of str in the str1, str2, str3, ... list.
* Returns 0 if str is not found. If all arguments to FIELD() are strings, all
* arguments are compared as strings. If all arguments are numbers, they are
* compared as numbers. Otherwise, the arguments are compared as double.
* If str is NULL, the return value is 0 because NULL fails equality comparison
* with any value. FIELD() is the complement of ELT(). (Taken from MySQL
@sglessard
sglessard / sf2-entities-recommandations
Last active August 29, 2015 14:18
Recommandations Symfony 2 : Entities
Create method "publicCriteria" that returns active criteria
Create method "findAllActive" for listing
Create method "findOneBySlugForDetail" for detail
@sglessard
sglessard / transChoice.example.php
Created January 24, 2015 01:59
transChoice in controller
// Let Symfony guess (translation must be defined in messages.[locale].yml
$duree = $this->get('translator')->transChoice('There is one apple|There are %count% apples',$circuit->getDuree(),array('%count%'=>$circuit->getDuree()));
// Specify intervals (']' '[' : include/exclude)
$duree = $this->get('translator')->transChoice('{1} 1 jour|]1,Inf] %count% jours',$circuit->getDuree(),array('%count%'=>$circuit->getDuree()));
@sglessard
sglessard / gist:781994f6567867988716
Created January 21, 2015 03:23
UI Tooltip on CKEditor
// UI Tooltips
// Article.translation.introduction title attribute set inside FormType.
// Parameters same as UnifikSystemBundle
$('#cke_article_translation_introduction iframe').attr('title',$('#article_translation_introduction').attr('title')).tooltip({
position: { 'my': 'left+8 center', 'at': 'right center' },
show: { duration: 200 }
});
@sglessard
sglessard / gist:e0ef407c5ea46727a01c
Created January 21, 2015 01:57
APY Grid manipulateRow count
$source->manipulateRow(function ($row) {
// ArticlesTranslation's Comments count
$row->setField('comments_count', $row->getEntity()->getComments()->count());
return $row;
});
$grid->addColumn(new NumberColumn(['id' => 'comments_count', 'field' => 'comments_count', 'title' => 'Comments', 'source' => false, 'filterable'=>false, 'sortable'=>false]), 3);
public function addQueryTranslationSupport(QueryBuilder $query, $source, $locale, $resetJoin = false)
{
if ($resetJoin) {
$query->resetDQLPart('join');
}
$query->andWhere('_translations.locale is null or _translations.locale = :locale');
$query->setParameter('locale', $locale);
}
@sglessard
sglessard / main-functions.js
Created December 5, 2014 15:04
Auto adjust sfWidgetFormDate 'to date' when 'from date' is modified
// Bind sfWidgetFormDate year change
// A partir de la valeur year de date_debut, changer la valeur year de date_fin
// @author SGL
function bindSfWidgetFormDateDebutYearChange(input_id) {
$(input_id).change(function() {
// Avec sfWidgetFormDate, la meme classe est applique au tous les widgets (year/month/day)
// Si widget est year
if (input_id.match(/_year$/)) {
var output_id = input_id.replace('_date_debut_','_date_fin_');
// Ne pas changer la date si elle a deja ete selectionee
@sglessard
sglessard / someForm.class.php
Created December 5, 2014 02:05
sf1 - setPostValidator with sfValidatorSchemaCompare
// Verifier si date_fin est superieur a date_debut
// date_fin est optionnel
$this->validatorSchema->setPostValidator(new sfValidatorOr(array(
new sfValidatorAnd( array (
new sfValidatorSchemaCompare ('date_debut', sfValidatorSchemaCompare::NOT_EQUAL, null),
new sfValidatorSchemaCompare ('date_fin', sfValidatorSchemaCompare::EQUAL, null)
)),
new sfValidatorSchemaCompare('date_fin', sfValidatorSchemaCompare::GREATER_THAN_EQUAL, 'date_debut',array('throw_global_error' => false), array('invalid' => 'La date de fin "%left_field%" doit être supérieure à la date de début "%right_field%".' ))
)));
@sglessard
sglessard / someForm.class.php
Last active August 29, 2015 14:10
sf1 : using sfValidatorAnd and sfValidatorOr
$this->setValidators(array(
'no_candidate' => new sfValidatorAnd(array(
new sfValidatorString(array('required' => true, 'trim'=>true),array('required'=>"Veuillez entrer votre numéro de candidat ou votre code permanent.")),
new sfValidatorOr(array(
new sfValidatorRegex(array('pattern' => '/^[0-9]+$/', 'trim'=>true),array()),
new sfValidatorRegex(array('pattern' => '/^[a-zA-Z]{4}[0-9]{8}+$/', 'trim'=>true),array())
),array(),array('invalid'=>'Numéro de candidat ou code permanent invalide.'))
),array('halt_on_error'=>true),array('required'=>"Veuillez entrer votre numéro de candidat ou votre code permanent.")),
// ...