Tuesday, 21 May 2013

Symfony internationalization

The problem was a Unix server which is shipped with an old intl drivers.
The error in the log file is 'request.CRITICAL: Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("The language resource bundle could not be loaded for locale "fr"") '
Download the icu file https://github.com/kbsali/sf2-icu/tree/master/4.2

The solution was to copy the icu files into symfony.
Copy the 4.2 icu to vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/data
Edit the file Locale.php in folder vendor/symfony/symfony/src/Symfony/Component/Locale

    const ICU_DATA_VERSION = '4.2';
Originally it's
    const ICU_DATA_VERSION = '49';

Tuesday, 30 October 2012

Globals why should we avoid them in PHP

I don't remember when was the last time I used the keyword global in php to allow a function to use a global variable. Why did I do it today? Because I built a prototype and wanted a quick solution, but the function is evoked by an event, hence the value of the content can change unexpectedly.

I think it taught me not to take shortcuts, as the consequences can be bad.
I took it from the example of XML Element Structure on the official php website.

Monday, 27 February 2012

Maintaining accessibility when creating dynamic element driven by JavaScript

Clients these days require to have dynamic flashy style pages, but a lot of organisations need to maintain their website accessible to a wide audience, whether they don't want to lose potential customers, but also discrimination laws force them to do so.
jQuery and others frameworks offer to create sliders and other rich GUIs rapidly, but try to disable Javascript (easiest when using FireFox to install web developer tool and the disable menu will do the trick) and you found out things stop working.
One of the tricks to achieve both nice looking accessible slider is to use list element and style it with CSS. Generaly you want to create a scroll down list that people can navigate even with a mouse and in the onLoad or onReady event of the JavaScript you hide the vertical scroll bar and style the element.
Javascript enabled
Javascript disabled
In the second image on the right side of the image you can spot the scroll bar and the white line just above the white helmet the person wears is the seperation between seperate items in the list.

The HTML sample is where class is the CSS style, I used in this example the default one, but you can modify and create new ones based on the default one.
<div class="jcarousel-skin-tango" id="mydiv">
    <li><img src="" /></li>
    <li><img src="" /></li>
The mechanism is based on JavaScript and I used jCarousel.js
that is a plugin for jQuery.

Monday, 28 February 2011

catching click event for download files for stats

We use the Urchin ver 6 to have the stats of our CMS system. We wanted to have the data in house rather than let google keeps it for us.
Our CMS system has a security layer that before allowing someone download a file (PDF, DOC etc..) perform verfication and then redirects to download the file that operation isn't recoreded in the web server log that used by Urchin and therefore we couldn't record the files been downloaded.
I found the following post http://www.goodwebpractices.com/roi/track-downloads-in-google-analytics-automatically.html providing with a solution. What they suggest is simple when the page is loaded we run a javascript code that add a click event to perform the urchinTracker javasript, which in return will write to the web server log the filename been downloaded.
This javascript code also allow to record clicks on mailto link, but I haven't tested this option.

Wednesday, 10 November 2010

importing external data to mySQL

For a project i was working on I had to import a csv file provided by booking.com
The constraint of this file is that i wanted to be able to allow to reimport that file as booking.com publishes updates with a list of new hotels quite often. That means that if another table in the database relies on the data of the imported file we can't create a normal foreign key as when we reimport the file, we can't guarantee the primary key will remain identical.

I decided to create the foreign key to a hash of the combination of town name and country name, why not only the town name? as for example London exists in England and in Canada, which would cause a problem as we want the foreign key to have only one option in the imported table.

Symfony doesn't know how to handle none numerical values of foreign key, hence we need to do the task of the association between the tables ourself.

in my schema.yml i configured the table PromoteTown that has a relation to BookingComHotels

      type: BINARY(16)
      notnull: true
      unique: true
      type: integer(4)
    BookingComHotels: { local: town_hotel_id, foreign: id_hash, onDelete: cascade, foreignAlias: PromoteTowns }

and in the model i have a method to insert to PromoteTown, the $this is related to BookingComHotels as this function is in BookingComHotels class.

        $hash = $this->getIdHash();
        $pt = new PromoteTown();
        $pt->type = '2';
        $pt->town_hotel_id = $hash;
        $pt->link('BookingComHotels', $hash);

Monday, 1 November 2010

installing PHPUnit

to install the latest version of PHPUnit, 3.5 in my case. you need to upgrade the PEAR that come by default with snow Leopard.
sudo pear upgrade pear
will upgrade the snow Leopard Pear.
then I just followed the instructions PHPUnit website

Saturday, 4 September 2010

unique on multiple columns

In Doctrine documentation I couldn't come across on how to mark in YML file to have unique on 2 columns.
The idea is as this example demonstrates of setting the category_id and user_id fields as unique:
type: string(255)
type: integer
notnull: true      
type: integer(4)
notnull: true
user_id: []
category_id: []
type: unique