dereuromark 8 年 前
コミット
1658a634ba
2 ファイル変更28 行追加0 行削除
  1. 27 0
      docs/Behavior/Toggle.md
  2. 1 0
      docs/README.md

+ 27 - 0
docs/Behavior/Toggle.md

@@ -0,0 +1,27 @@
+# Toggle Behavior
+
+A CakePHP behavior to handle unique toggles.
+
+An implementation of a unique field toggle per table or scope.
+This will ensure that on a set of records only one can be a "toggled" one, setting the others to false then.
+On delete it will give the toggle status to another record if applicable.
+
+### Usage
+
+#### Basic usage
+Include behavior in your Table class as
+```php
+$this->addBehavior('Tools.Toggle', [
+	'field' => 'primary', 
+	'scopeFields' => ['user_id'],
+	'scope' => [],
+]);
+```
+
+Set the `field` to your table field. Optionally, you can also set scope fields and a manual scope. 
+Those will always be taken into consideration as scope conditions.
+
+### Configuration
+
+The `'findOrder'` can be used to further customize the find result when looking for a new toggle record.
+By default it will try to use the `modified` field as `DESC`. But maybe you would want it to sort by another field.

+ 1 - 0
docs/README.md

@@ -36,6 +36,7 @@ Behaviors:
 * [Bitmasked](Behavior/Bitmasked.md)
 * [Reset](Behavior/Reset.md)
 * [String](Behavior/String.md)
+* [Toogle](Behavior/Toggle.md)
 
 ## Basic enhancements of the core