![]() |
|
Snippets |
|
My First snippet ever AND, my first contribution to the programming world... hope you like it ;)
This snippet is for those of you who, just like me, have 30 fields in one class and doesnt want to write them all down in the admin generator and erase the ones you don't want.
if you want to display all field except one, here's how:
generator: class: sfPropelAdminGenerator param: model_class: users theme: default list: sort: [updated_at, desc] hide: [the_fields_i_dont_want]
Notice the "HIDE" option.
If you want to display all fields AND you want to add a partial, it gets a little tricky (and ugly, but it does the trick until something better is created)
generator: class: sfPropelAdminGenerator param: model_class: users theme: default list: sort: [updated_at, desc] display: [_my_partial, <?php echo implode(', ',JobPeer::getFieldNames(BasePeer::TYPE_FIELDNAME)) ?>] max_per_page: 20
Notice the "DISPLAY" option ... I know, it's ugly to have php in a yml file ...
You can also combien the two and get all columns and hide the ones you don't want .
P.S. I should have wrote this earlier but this snippet wouldn't exists if it weren't for pookey from #symfony (irc). THanks again man ;)
This is a simple helper to create a tag cloud from an array of tags.
Creating a tag cloud is as easy as calling the helper:
<?php use_helper('Tagcloud'); TagcloudHelper::showCloud($tags);
Where tags is an array that is defined in the following syntax:
array('tag1' => 10, 'tag2' => 15, 'tag3' => 4);
The values in this array are deciding the weight of your tag. It's usually the amount of posts that have this tag, but could also be determined in your own way. As long as the passed array has this syntax, your tag cloud will be built.
This tagcloud will use a piece of css that must be present in your css file:
.cloud_xsmall { font-size: 80%; } .cloud_small { font-size: 100%; } .cloud_medium { font-size: 120%; } .cloud_large { font-size: 140%; } .cloud_xlarge { font-size: 160%; }
Obviously, this piece of css can easily be adapted to suit your needs.
Be sure that there is a route in your routing.yml that can handle the url /tag/:tag
The actual Helper:
<?php class TagcloudHelper { /** * Generate the tag array and echo the cloud * * @return array * */ public function showCloud($tags) { asort($tags); reset($tags); $this->smallest = current($tags); end($tags); $this->largest = current($tags); $diff = $this->largest - $this->smallest; $this->interval = round($diff/3); reset($this->tags); $this->cloud_tags = array(); foreach($this->tags as $tag => $amount) { echo link_to($tag, 'tag/' . urlencode($tag), array('class' => $this->getSize($amount))) . ' '; } } /** * Get the size (css class) based on the amount * * @param integer $amount * @return array */ private function getSize($amount) { if ($amount == $this->smallest) { return 'cloud_xsmall'; } if ($amount == $this->largest) { return 'cloud_xlarge'; } if ($amount > $this->smallest + (2*$this->interval)) { return 'cloud_large'; } if ($amount > $this->smallest + $this->interval) { return 'cloud_medium'; } return 'cloud_small'; } }