PHPackages                             fduch2k/yii-flagged-activerecord - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. fduch2k/yii-flagged-activerecord

ActiveLibrary[Database &amp; ORM](/categories/database)

fduch2k/yii-flagged-activerecord
================================

Extends CActiveRecord class to add bitflag fields operations

0.2.2(10y ago)28091MITPHPPHP &gt;=5.1.0

Since Sep 18Pushed 10y ago3 watchersCompare

[ Source](https://github.com/fduch2k/yii-flagged-activerecord)[ Packagist](https://packagist.org/packages/fduch2k/yii-flagged-activerecord)[ RSS](/packages/fduch2k-yii-flagged-activerecord/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (5)Used By (0)

TSFlaggedActiveRecord for Yii 1.1.x
===================================

[](#tsflaggedactiverecord-for-yii-11x)

Extends CActiveRecord class to add bitflag fields operations. [Changelog](#changelog)

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

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

```

or add

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

to the require section of your composer.json.

Usage
-----

[](#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:

### Scopes

[](#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

[](#flag-getterssetters)

```
$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

[](#getting-flag-value)

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

### Apply flag conditions to criteria

[](#apply-flag-conditions-to-criteria)

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

Changelog
---------

[](#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

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 89.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~99 days

Total

4

Last Release

3956d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6d9d5a14fba428b983f9dd4fd33a97146b68ffe51739784a5632ceea887c75e2?d=identicon)[fduch2k](/maintainers/fduch2k)

---

Top Contributors

[![fduch2k](https://avatars.githubusercontent.com/u/367574?v=4)](https://github.com/fduch2k "fduch2k (17 commits)")[![R0dgerV](https://avatars.githubusercontent.com/u/8501695?v=4)](https://github.com/R0dgerV "R0dgerV (2 commits)")

---

Tags

yiibitmaskCActiveRecord

### Embed Badge

![Health badge](/badges/fduch2k-yii-flagged-activerecord/health.svg)

```
[![Health](https://phpackages.com/badges/fduch2k-yii-flagged-activerecord/health.svg)](https://phpackages.com/packages/fduch2k-yii-flagged-activerecord)
```

###  Alternatives

[yiiext/activerecord-relation-behavior

Inspired by and put together the awesomeness of many yii extensions that aim to improve saving of related records. Comes with 100% test coverage and well structured and clean code so it can savely be used in enterprise production enviroment.

9336.5k](/packages/yiiext-activerecord-relation-behavior)[yiiext/migrate-command

This is an enhanced version of the Yii Database Migration Tool that adds module support and many more usefull features.

34173.8k4](/packages/yiiext-migrate-command)[sammaye/mongoyii

A Yii MongoDB ORM

13681.3k](/packages/sammaye-mongoyii)[henzeb/enumhancer

Your framework-agnostic Swiss Army knife for PHP 8.1+ native enums

69287.4k2](/packages/henzeb-enumhancer)[sjaakp/yii2-sortable-behavior

Sort ActiveRecords and related records in Yii2.

36144.7k](/packages/sjaakp-yii2-sortable-behavior)[sjaakp/yii2-spatial

Yii2 ActiveRecord supporting MySQL spatial data

1873.8k1](/packages/sjaakp-yii2-spatial)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
