Skip to content

AliHichem/sfDoctrineActAsActivablePlugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

sfDoctrineActAsActivablePlugin
=============================

The `sfDoctrineActAsActivablePlugin` is a symfony plugin that allows use of the doctrine behavior actAsActivable.

This behavior provides methods on your model for setting "is active"/"is not active" state to doctrine records.

This plugin allow  cascade activate/desactivate between doctrine relation

Installation
------------

  * Install the plugin

        $ symfony plugin:install sfDoctrineActAsActivablePlugin

  * Activate the plugin in your project configuration file (in config/ProjectConfiguration.class.php)
and enable the Doctrine callbaks.

        class ProjectConfiguration extends sfProjectConfiguration
        {
            public function setup()
            {
                //...
                $this->enablePlugins('sfDoctrineActAsActivablePlugin');
            }
            public function configureDoctrine(Doctrine_Manager $manager) 
            {
                // Enable callbacks so that Activable behavior can be used
                $manager->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, true);
            }
        }
    }

  * Apply the behavior to your model in your schema file `config/doctrine/schema.yml`, ie:

        # simple
            [yml]
            model:
              actAs: [Activable]

        # advenced
            [yml]
            model:
              actAs: 
                Activable:
                  name: is_active
                  alias: ~
                  options:
                    default: true
                  indexName: activable
                  cascade: 
                    down: true

  * (optional): If you prefer apply a general config for all your activable model, leave activable
    declaration in your schema with "~" and set the default config in your app.yml
        
        # config/doctrine/schema.yml
            Mymodel:
              actAs: 
                Activable: ~
        
        # app/myapp/config/app.yml
            all:
              activable:
                name: is_active
                alias: null
                type: boolean
                length: 1
                options:
                  default: true
                indexName: activable
                cascade:
                  down: false
                  up: false
        
  * Rebuild your models and database
  
        $ symfony doctrine:build-all-reload
    
    alternatively you could build the models, the sql, then run the sql manually
        
  * Clear your cache

        $ symfony cc


  * when working with activale behavior , you will probably want to show all your 
records (active and non-active) to be able to enable the "non-active" 
items. To do that without adding a condition in your DQL, you can force the behavior
with:

        // put this line before building your Doctrine Query
        sfConfig::set('activable_dql_select', FALSE);


(comming soon)

Available schema options:
------------------------

        [yml]
        model:
          actAs: 
            Activable:
              cascade: 
                up: true

Available Record Methods
------------------------

  * activate

        [php]
        $record->activate();
      
  * desactivate
  
        [php]
        $record->deactivate();
      
  * fullActivate
  
        [php]
        $record->fullActivate();
      
  * fullDesactivate
  
        [php]
        $record->fullDeactivate();
      
        

About

symfony 1.4 plugin that allows use of the doctrine behavior actAsActivable.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages