示例#1
0
 /**
  * Get a list of data models from the collection.
  */
 function find(array $filter = array())
 {
     if ($filter && !util::isAssoc($filter)) {
         $filter = array($this->_primaryKey => $filter);
     }
     $filter[Node::FIELD_COLLECTION] = self::collectionName();
     $collection = array();
     Node::getAsync($filter, function ($data) use(&$collection) {
         // create a new instance for retrieved data
         $model = get_called_class();
         $model = new $model($data);
         if (isset($this->__request)) {
             $model->__request = $this->__request;
         }
         if (isset($this->__response)) {
             $model->__response = $this->__response;
         }
         // force invoke internal function
         util::forceInvoke(array($model, 'afterLoad'));
         // add if model still has data
         if ($model->data()) {
             $collection[] = $model;
         }
     });
     return $collection;
 }