sfPropelBuildModelOptionsPlugin - 1.0.0

Add the essentials methods for the options

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to the Plugins Home

Signin


Forgot your password?
Create an account

Tools

Stats

advanced search
Information Readme Releases Changelog Contribute
Show source

sfPropelBuildModelOptions plugin

Introduction

The sfPropelBuildModelOptions plugin is an automatic task for add some essentials methods to manage file, sort, label and string in your model.

Installation

  • Install plugin

    $ symfony plugin:install sfPropelBuildModelOptionsPlugin
    
  • Clear your cache

    $ symfony cc
    

Usage

  • In your schema.xml add the attribute description in your columns where you want add the methods. The content of the attributes must be '[label]', '[string|i18n]', '[sort|depend]', '[image]', '[media]' or '[file]'.

  • You must generate your model before use this plugin

    $ symfony propel:build-model
    
  • After this, you can add some essentials methods in your model

    $ symfony propel:build-model-options
    
  • Clear your cache

    $ symfony cc
    

Informations

Roles of the tags

The tags available are :

  • [sort] or [sort|depend] : add the method for sort a position (if |depend is add, the sort will be by the depend) (only one by table). depend is the name of the column (of the same table) which the sort depend
  • [file] : add the method for save a file, check if the file exist and get the path
  • [image] : add the method for save a image, check if the file exist, get the path and the URL
  • [media] : add the method for save a media, check if the file exist, get the path and the URL
  • [string] or [string|i18n] : add the method to overload the method __toString (only one by table) (if |i18n is add the __toString method is add in the orignal class) (if |i18n is add the __toString method is add in the orignal class)
  • [label] : add the method for retrieve by label (or the column name)

Add one or more tag in the description attribute of the column item in the schema (or in comment of the schema in DBDesigner4 and use sfDB4toPropelPlugin)

Methods added

  • [sort] or [sort|depend] : downPosition(), upPosition(), movePosition(), getMaxPosition()
  • [file] : hasColumn(), doDelete(), getColumnPath() (require modified app.yml)
  • [image] : hasColumn(), doDelete(), getColumnPath(), getColumnUrl() (require modified app.yml)
  • [media] : hasColumn(), doDelete(), getColumnPath(), getColumnUrl() (require modified app.yml)
  • [string] or [string|i18n] : __toString()
  • [label] : retrieveByColumn()

Return

Each method adding is log. At the end of the task, a example of app.yml is displayed (for image, media or file tags)

Example

    <table name="license">
      <column name="id" type="INTEGER" primaryKey="true" required="true" autoIncrement="true"/>
      <column name="name" type="VARCHAR" size="255" description="[string]"/>
      <column name="label" type="VARCHAR" size="255" description="[label]"/>
      <column name="url" type="VARCHAR" size="255"/>
      <column name="logo" type="VARCHAR" size="255" description="[image]"/>
      <column name="content" type="LONGVARCHAR"/>
      <column name="position" type="INTEGER" description="[sort]"/>
      <unique name="license_name">
        <unique-column name="name"/>
      </unique>
      <unique name="license_label">
        <unique-column name="label"/>
      </unique>
    </table>

With this xml schema, you can use this methods :

    $license = LicensePeer::retrieveByLabel('mit');
    if ($license === null) {
      return null;
    }

    $license->upPosition(); // if the current position is 3, 
                            // after this the new position is 2
                            // and the license in position 2 is now 3

    $license->downPosition(); // if the current position is 3, 
                              // after this the new position is 4
                              // and the license in position 4 is now 3

    $license->movePosition(4); // if the current position is 9, 
                               // after this the new position is 4
                               // and all licenses higher or equal the position 4
                               // and lower than 9 increase one

    if ($license->hasLogo() === true) {
      // the license has a logo and the file exist
      echo $license->getLogoPath(); // return the absolute path of the logo
      echo $license->getLogoUrl(); // return the URL of the logo
    }

    echo $license; // same as echo $license->getName();

Caution

  • This plugin modified your user model (./lib/model/*.php). You must save your user model before use this plugin.
  • If a method with the same name exist in your user model, the new method will not be add.

TODO

  • Add an option in command-line for exclude some method to the process
  • Parse the data folder for find automatically the function to add