Skip to content

Commit ae4b098

Browse files
committed
* Collection: + count and populate from selection
1 parent 104c0fb commit ae4b098

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Collection.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Collection extends Component
3434
/**
3535
* @var array of models
3636
*/
37-
public $models;
37+
public $models = [];
3838

3939
/**
4040
* @var string the name of the form. Sets automatically on [[set()]]
@@ -202,6 +202,11 @@ public function load ($data = null) {
202202
if (!$is_bulk) {
203203
$data = [$data];
204204
}
205+
} else if ($data['selection']) {
206+
foreach ($data['selection'] as $id) {
207+
$res[$id] = compact('id');
208+
}
209+
$data = $res;
205210
}
206211
} elseif ($data instanceof \Closure) {
207212
$data = call_user_func($data, $this->model, $this->formName);
@@ -446,6 +451,10 @@ public function getFirstError () {
446451
return false;
447452
}
448453

454+
public function count()
455+
{
456+
return is_array($this->models) ? count($this->models) : 0;
457+
}
449458

450459
public function validate ($attributes = null) {
451460
if (!$this->beforeValidate()) {

0 commit comments

Comments
 (0)