upPropelLockTableBehaviorPlugin - 1.0.0

The upPropelLockTableBehaviorPlugin add methods on Propel objects to set locks.

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

upPropelLockTableBehaviorPlugin

Features

  • Any Propel object can be locked

Installation

  • Install the plugin :
php symfony plugin:install upPropelLockTableBehaviorPlugin
  • You must have a field into the session to identify an user

  • Enable the plugin for each Propel object you want. For example, at the end of lib/model/User.php, add this line :

sfPropelBehavior::add('User', array('locktable'=>array('session'=>'id')));
  • The session parameter is the name of the session field used to identify the user

Usage

Lock an object with the current user :

$object->lock();

Check if an object is locked :

$object->getLocks();

Remove every lock for an user :

upPropelLockTableBehavior::removeAllLocks($user_id);

You can use this plugin with the form framework, for example, by editing BaseFormPropel :

public function setup()
{
  $class = get_class($this->getObject());

  if ($class) {
    // Since getLocks is a dynamic method, we can't use
    // get_class_methods to check if it does exist.
    // Instead, we can use a try/catch.
    try {
      if ($this->getObject()->getLocks()) {
        foreach ($this->widgetSchema->getFields() as $field) {
          $field->setAttribute('disabled', true);
        }
      } else {
        $this->getObject()->lock();
      }
    } catch (sfException $e) {}
  }
}

Copyright

upPropelLockTableBehaviorPlugin has been developped by Leo Cacheux for Devoteam/Uperto. It has been released under the MIT license.