2017 © Pedro Peláez
 

library yii-flagged-activerecord

Extends CActiveRecord class to add bitflag fields operations

image

fduch2k/yii-flagged-activerecord

Extends CActiveRecord class to add bitflag fields operations

  • Tuesday, July 14, 2015
  • by fduch2k
  • Repository
  • 3 Watchers
  • 2 Stars
  • 731 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

TSFlaggedActiveRecord for Yii 1.1.x

Extends CActiveRecord class to add bitflag fields operations. Changelog, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist fduch2k/yii-flagged-activerecord "*"

or add, (*4)

"fduch2k/yii-flagged-activerecord": "*"

to the require section of your composer.json., (*5)

Usage

class Article extends TSFlaggedActiveRecord 
{
    //...
    // By default flag field has name 'flags', you can override it 
    // if your prefer other name

    // public $flagsField = 'flags';

    // By default flags values without specified bit computed automatically 
    // (draft => 1, published => 2, deleted => 128)
    public function flags() 
    {
        return array(
            'draft',
            'published',
            'deleted' => 128
        );
    }

    // Flag labels uses in interface messages
    // By default an flag label is generated using
    // CModel::generateAttributeLabel
    public function flagLabels()
    {
        return array(
            'deleted'=>'Removed'
        );
    }

}

Now you can use it in you code:, (*6)

Scopes


// Find all published articles $articles = Article::model()->published()->findAll(); // or all drafts $articles = Article::model()->withFlag('draft')->findAll(); // or deleted drafts $articles = Article::model()->withFlag('draft, deleted')->findAll(); // or not deleted $articles = Article::model()->withoutFlag('deleted')->findAll();

Flag getters/setters

$article = Article::model()->findByPk(10);
// Check if article is not deleted...
if ($article->isDeleted === false) {
    //...then publish it
    $article->isPublished = true;
}
$article->save();

Getting flag value

echo Article::model()->getFlag('deleted'); // outputs 128

Apply flag conditions to criteria

// get criteria to find not deleted article drafts
$criteria = Article::model()->applyFlags(new CDbCriteria(), array('draft', '!deleted'));

Changelog

0.2.2 / 2015-07-14

  • Fix generating text representation of flags

0.2.1 / 2014-12-04

  • Add getting flag name for its value

0.2.0 / 2014-11-21

  • Overrides getAttributes and setAttributes methods to cover flag functionality
  • Added getFlagNames method
  • Method setFlag now can correctly work with boolean string 'true' 'false' (string that eqaul to 'true' is true othewise is false)
  • Added osx specific files to ignore

The Versions

14/07 2015

dev-master

9999999-dev

Extends CActiveRecord class to add bitflag fields operations

  Sources   Download

MIT

The Requires

 

by Alexander Hramov

yii bitmask cactiverecord

14/07 2015

0.2.2

0.2.2.0

Extends CActiveRecord class to add bitflag fields operations

  Sources   Download

MIT

The Requires

 

by Alexander Hramov

yii bitmask cactiverecord

04/12 2014

0.2.1

0.2.1.0

Extends CActiveRecord class to add bitflag fields operations

  Sources   Download

MIT

The Requires

 

by Alexander Hramov

yii bitmask cactiverecord

21/11 2014

0.2.0

0.2.0.0

Extends CActiveRecord class to add bitflag fields operations

  Sources   Download

MIT

The Requires

 

by Alexander Hramov

yii bitmask cactiverecord

18/09 2014

0.1.0

0.1.0.0

Extends CActiveRecord class to add bitflag fields operations

  Sources   Download

MIT

The Requires

 

by Alexander Hramov

yii bitmask cactiverecord