Skip to content

Commit

Permalink
* Collection: + count and populate from selection
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Aug 6, 2015
1 parent 104c0fb commit ae4b098
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Collection extends Component
/**
* @var array of models
*/
public $models;
public $models = [];

/**
* @var string the name of the form. Sets automatically on [[set()]]
Expand Down Expand Up @@ -202,6 +202,11 @@ public function load ($data = null) {
if (!$is_bulk) {
$data = [$data];
}
} else if ($data['selection']) {
foreach ($data['selection'] as $id) {
$res[$id] = compact('id');
}
$data = $res;
}
} elseif ($data instanceof \Closure) {
$data = call_user_func($data, $this->model, $this->formName);
Expand Down Expand Up @@ -446,6 +451,10 @@ public function getFirstError () {
return false;
}

public function count()
{
return is_array($this->models) ? count($this->models) : 0;
}

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

0 comments on commit ae4b098

Please sign in to comment.