Symfony World blog is not maintained anymore. Check new sys.exit() programming blog.

(symfony) multiple select default value

Scene from "Pulp Fiction" by Quentin Tarantino (1994)

Symfony framework provides an easy way of defining default form values (you can find related post here). But you may find problems to define default values of a multiple select (m:n relation) widget.

example

We are given two models:

  • Offer - representing a business offer which is available online
  • Localization - representing geographical region
Two models above share a typical m:n relation, represented by OfferLocalization model, which means that a specific Offer is available in chosen regions.

We want the offer form to display default values for the localizations_list widget (the OfferLocalization m:n relation). Let's say, we want Localizations 3 and 5 (by id) to be the default ones, just like in the picture below (showing regions in Poland):

Unfortunately, the following code will not work:

$this->setDefault('localizations_list', array(3,5));
in the configure() method since the BaseOfferForm class has the public function updateDefaultsFromObject() method implemented (generated by Doctrine):
  public function updateDefaultsFromObject()
  {
    parent::updateDefaultsFromObject();
    if (isset($this->widgetSchema['localizations_list']))
    {
      $this->setDefault('localizations_list', $this->object->Localizations->getPrimaryKeys());
    }
  }

solution

You can simply override this method in the OfferForm class:

  public function updateDefaultsFromObject()
  {
    parent::updateDefaultsFromObject();
    if ($this->isNew())
    {
      $this->setDefault('localizations_list', array(3,5));
    }
  }
and you're done!

excellent modelling tool: cacoo

Scene from the epic "Braveheart" by Mel Gibson (1995)

This time I want to present an excellent visual tool I've started using recently to improve my projects' documentation. It's the Cacoo online diagram editor, which is a professional flash tool.

The basic concept is very easy: you create graphic diagrams. You may structure them in folders and sheets (don't worry, each country should have its own translation already - I'm using Polish version):

There's a history of all changes done on each diagram:
Creating a diagram usually starts with creating your own, custom objects which represent something. You may use standard, predefined objects or import any image from the internet to combine new objects:
You may resize or change the angle of an object:
There are lots of predefined stencils to USE, including entire UML:
The interface is very intuitive - it took me only an hour to learn how to make the most out of cacoo.
There are dozens of easy tools you can use to make really good quality diagrams:
I won't try to list al those tools, I hope the screenshots I made speak for themselves (especially I like the drag n'drop stuff and moving objects across the diagram).
And the most comfortable and user-friendy thing is easy diagram update. If your IT project has changed and your documentatin is not up to date anymore - just log in, make a tiny change in the diagram and dump it again, replace the old diagram in the docs and you're done!

predefined objects to use

Just get a predefined stencil - just like a nice looking professor below:

This stencil is a group of smaller objects. You can choose some objects to be grouped to make moving easier. You can even resize a whole group of objects, including font size changes! And groups can consist of groups...

Anyway, a group member can still be edited separately:

There are really lots and lots of possibilities there. You can do whatever you can think of.
Finally, you can export your work to few file formats (I use ksnapshot - PNG file is enough for me).

try the demo version

The free plan gives you the possibility to hold 25 diagrams and it's enough to create useful diagrams, documenting your projects. I did - and I'm satisfied. Just take a look:

they didn't found me - I found them :)

Just to make it clear - I was not contacted by the Cacoo team and I was not asked if I could write a nice review (things like this happen - some time ago I was asked to review a pro-symfony IDE) ;-). So there was no bribe. One day I was just looking for a free UML-designing software (desktop app or online), because I was finding StarUML less and less satisfying. I found Cacoo and I didn't need to search any longer.

Try it.

svn blame: who made the bug?

Scene from "12 Angry Men" by Sidney Lumet (1957)

In bigger projects it happens quite often that an unknown team member has made a modification that caused a lot of trouble. And no one wants to confess... It is quite uncomfortable to analyse distinct revisions and changes of a file to find who caused the problem, as it is time consuming. This is where svn blame is the perfect tool - you execute it upon a chosen target to display revision number, team member and content line by line. You can easily find who is the author of a bug and when he committed it. It's intereting, that despite being very useful, this tool is not very known.

blame me if you can find me quickly!

The usage is very simple:

tducin@workshop:/var/www/admin/config/doctrine$ svn blame schema.yml
and you have the entire file analysed:
   367     dennis connection: master
   362     tducin
   362     tducin options:
   362     tducin   charset: utf8
   362     tducin   collate: utf8_general_ci
   362     tducin
  3755     george Status:
  3755     george   comment: "Statusy"
   491     dennis   actAs:
  1980     dennis     SoftDelete: ~
  1793     harold     Timestampable: ~
  1793     harold     Signable: ~
   492     tducin   columns:
   492     tducin     name:
  3755     george       type: string(64)
   492     tducin       notnull: true
  2628     tducin       comment: "nazwa"
  3755     george     notify_mail:
  3755     george       type: boolean
  3755     george       notnull: true
  3755     george       default: false
  3755     george       comment: "klient ma być powiadamiany mailowo"
  1541     dennis     stock_mode:
  1541     dennis       type: enum
  1541     dennis       values: [ reserved, sent, cancelled ]
  1541     dennis       default: reserved
  2628     dennis       comment: "tryb magazynowy: reserved, sent, cancelled"
  3755     george     force_reminder:
   892     tducin       type: boolean
   878     tducin       notnull: true
  3755     george       comment: "Wymuszenie dodania wpisu w kalendarzu"
  3755     george     block_update:
  3755     george       type: boolean
  3755     george       notnull: true
  3755     george       comment: "Blokada zmiany statusu"
  4078     harold   indexes:
  4078     harold     softdelete_idx:
  4078     harold       fields: [ deleted_at ]