Skip to content

Commit c93ccdd

Browse files
author
Pe Ell
authored
Merge pull request #9 from cybercog/feature/is-closed
Add Closed Inverse flag
2 parents bfc364a + 386d6e7 commit c93ccdd

18 files changed

+505
-59
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
All notable changes to `laravel-eloquent-flag` will be documented in this file.
44

5+
## 2.1.0 - 2016-01-04
6+
7+
- `is_closed` inverse boolean flag added.
8+
59
## 2.0.0 - 2016-01-04
610

7-
#### Breaking changes
11+
### Breaking changes
812

913
- Namespaces of flag's traits received `Classic` at the end: `Cog\Flag\Traits\Classic`.
1014
- Namespaces of flag's scopes received `Classic` at the end: `Cog\Flag\Scopes\Classic`.
1115

12-
#### Added
16+
### Added
1317

1418
- `Inverse Logic` flags group. Hides entities if flag not set.
1519
- `is_expired` inverse boolean flag added.

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ Due to time constraints, we are not always able to respond as quickly as we woul
2121

2222
This project comes with a configuration file for php-cs-fixer (.php_cs) that you can use to (re)format your sourcecode for compliance with this project's coding guidelines:
2323

24-
```shell
24+
```sh
2525
vendor/bin/php-cs-fixer fix
2626
```
2727

2828
## PHPUnit tests
2929

3030
The phpunit script can be used to invoke the PHPUnit test runner:
3131

32-
```shell
32+
```sh
3333
vendor/bin/phpunit
3434
```
3535

README.md

Lines changed: 98 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ Eloquent flagged attributes behavior. Add commonly used flags to models very qui
1818

1919
## Available flags list
2020

21-
| Trait name | Database columns | Flag type | Logic |
22-
| ---------- | ---------------- | --------- | ----- |
23-
| `HasAcceptedFlag` | `is_accepted` | Boolean | Classic |
24-
| `HasActiveFlag` | `is_active` | Boolean | Classic |
25-
| `HasApprovedFlag` | `is_approved` | Boolean | Classic |
26-
| `HasExpiredInverseFlag` | `is_expired` | Boolean | Inverse |
27-
| `HasKeptFlag` | `is_kept` | Boolean | Classic |
28-
| `HasPublishedFlag` | `is_published` | Boolean | Classic |
29-
| `HasVerifiedFlag` | `is_verified` | Boolean | Classic |
21+
| Trait name | Logic | Database columns | Flag type |
22+
| ---------- | ----- | ---------------- | --------- |
23+
| `HasAcceptedFlag` | Classic | `is_accepted` | Boolean |
24+
| `HasActiveFlag` | Classic | `is_active` | Boolean |
25+
| `HasApprovedFlag` | Classic | `is_approved` | Boolean |
26+
| `HasClosedFlag` | Inverse | `is_closed` | Boolean |
27+
| `HasExpiredFlag` | Inverse | `is_expired` | Boolean |
28+
| `HasKeptFlag` | Classic | `is_kept` | Boolean |
29+
| `HasPublishedFlag` | Classic | `is_published` | Boolean |
30+
| `HasVerifiedFlag` | Classic | `is_verified` | Boolean |
3031

3132
## How it works
3233

@@ -81,32 +82,32 @@ class Post extends Model
8182

8283
#### Get only active models
8384

84-
```shell
85+
```php
8586
Post::all();
8687
Post::withoutInactive();
8788
```
8889

8990
#### Get only inactive models
9091

91-
```shell
92+
```php
9293
Post::onlyInactive();
9394
```
9495

9596
#### Get active + inactive models
9697

97-
```shell
98+
```php
9899
Post::withInactive();
99100
```
100101

101102
#### Activate model
102103

103-
```shell
104+
```php
104105
Post::where('id', 4)->activate();
105106
```
106107

107108
#### Deactivate model
108109

109-
```shell
110+
```php
110111
Post::where('id', 4)->deactivate();
111112
```
112113

@@ -132,32 +133,32 @@ class Post extends Model
132133

133134
#### Get only accepted models
134135

135-
```shell
136+
```php
136137
Post::all();
137138
Post::withoutUnaccepted();
138139
```
139140

140141
#### Get only unaccepted models
141142

142-
```shell
143+
```php
143144
Post::onlyUnaccepted();
144145
```
145146

146147
#### Get accepted + unaccepted models
147148

148-
```shell
149+
```php
149150
Post::withUnaccepted();
150151
```
151152

152153
#### Accept model
153154

154-
```shell
155+
```php
155156
Post::where('id', 4)->accept();
156157
```
157158

158159
#### Deactivate model
159160

160-
```shell
161+
```php
161162
Post::where('id', 4)->unaccept();
162163
```
163164

@@ -183,32 +184,32 @@ class Post extends Model
183184

184185
#### Get only approved models
185186

186-
```shell
187+
```php
187188
Post::all();
188189
Post::withoutUnapproved();
189190
```
190191

191192
#### Get only unapproved models
192193

193-
```shell
194+
```php
194195
Post::onlyUnapproved();
195196
```
196197

197198
#### Get approved + unapproved models
198199

199-
```shell
200+
```php
200201
Post::withUnapproved();
201202
```
202203

203204
#### Approve model
204205

205-
```shell
206+
```php
206207
Post::where('id', 4)->approve();
207208
```
208209

209210
#### Unapprove model
210211

211-
```shell
212+
```php
212213
Post::where('id', 4)->unapprove();
213214
```
214215

@@ -234,32 +235,32 @@ class Post extends Model
234235

235236
#### Get only published models
236237

237-
```shell
238+
```php
238239
Post::all();
239240
Post::withoutUnpublished();
240241
```
241242

242243
#### Get only unpublished models
243244

244-
```shell
245+
```php
245246
Post::onlyUnpublished();
246247
```
247248

248249
#### Get published + unpublished models
249250

250-
```shell
251+
```php
251252
Post::withUnpublished();
252253
```
253254

254255
#### Publish model
255256

256-
```shell
257+
```php
257258
Post::where('id', 4)->publish();
258259
```
259260

260261
#### Unpublish model
261262

262-
```shell
263+
```php
263264
Post::where('id', 4)->unpublish();
264265
```
265266

@@ -285,32 +286,32 @@ class Post extends Model
285286

286287
#### Get only verified models
287288

288-
```shell
289+
```php
289290
Post::all();
290291
Post::withoutUnverified();
291292
```
292293

293294
#### Get only unverified models
294295

295-
```shell
296+
```php
296297
Post::onlyUnverified();
297298
```
298299

299300
#### Get verified + unverified models
300301

301-
```shell
302+
```php
302303
Post::withUnverified();
303304
```
304305

305306
#### Verify model
306307

307-
```shell
308+
```php
308309
Post::where('id', 4)->verify();
309310
```
310311

311312
#### Unverify model
312313

313-
```shell
314+
```php
314315
Post::where('id', 4)->unverify();
315316
```
316317

@@ -361,38 +362,38 @@ By default all records that have a `is_kept` equals to 0 will be excluded from y
361362

362363
#### Get only kept models
363364

364-
```shell
365+
```php
365366
Post::all();
366367
Post::withoutUnkept();
367368
```
368369

369370
#### Get only unkept models
370371

371-
```shell
372+
```php
372373
Post::onlyUnkept();
373374
```
374375

375376
#### Get kept + unkept models
376377

377-
```shell
378+
```php
378379
Post::withUnkept();
379380
```
380381

381382
#### Keep model
382383

383-
```shell
384+
```php
384385
Post::where('id', 4)->keep();
385386
```
386387

387388
#### Unkeep model
388389

389-
```shell
390+
```php
390391
Post::where('id', 4)->unkeep();
391392
```
392393

393394
#### Get unkept models which older than hours
394395

395-
```shell
396+
```php
396397
Post::onlyUnkeptOlderThanHours(4);
397398
```
398399

@@ -420,40 +421,91 @@ class Post extends Model
420421

421422
#### Get only not expired models
422423

423-
```shell
424+
```php
424425
Post::all();
425426
Post::withoutExpired();
426427
```
427428

428429
#### Get only expired models
429430

430-
```shell
431+
```php
431432
Post::onlyExpired();
432433
```
433434

434435
#### Get expired + not expired models
435436

436-
```shell
437+
```php
437438
Post::withExpired();
438439
```
439440

440441
#### Set expire flag to model
441442

442-
```shell
443+
```php
443444
Post::where('id', 4)->expire();
444445
```
445446

446447
#### Remove expire flag from model
447448

448-
```shell
449+
```php
449450
Post::where('id', 4)->unexpire();
450451
```
451452

453+
### Setup a closable model
454+
455+
```php
456+
<?php
457+
458+
namespace App\Models;
459+
460+
use Cog\Flag\Traits\Inverse\HasClosedFlag;
461+
use Illuminate\Database\Eloquent\Model;
462+
463+
class Post extends Model
464+
{
465+
use HasClosedFlag;
466+
}
467+
```
468+
469+
*Model must have boolean `is_closed` column in database table.*
470+
471+
### Available functions
472+
473+
#### Get only not closed models
474+
475+
```php
476+
Post::all();
477+
Post::withoutClosed();
478+
```
479+
480+
#### Get only closed models
481+
482+
```php
483+
Post::onlyClosed();
484+
```
485+
486+
#### Get closed + not closed models
487+
488+
```php
489+
Post::withClosed();
490+
```
491+
492+
#### Set close flag to model
493+
494+
```php
495+
Post::where('id', 4)->close();
496+
```
497+
498+
#### Remove close flag from model
499+
500+
```php
501+
Post::where('id', 4)->unclose();
502+
```
503+
452504
## Testing
453505

454506
Run the tests with:
455507

456-
```shell
508+
```sh
457509
vendor/bin/phpunit
458510
```
459511

0 commit comments

Comments
 (0)