/** * Function send response with list of record attributes or empty array if no record found. * * @param boolean $sendToEndUser Whether the response should be sent to the end user or should be returned as an array. * @return array result. Null if the result sended to end user. */ public function getList($sendToEndUser = null) { if (is_bool($sendToEndUser)) { $this->sendToEndUser = $sendToEndUser; } $this->checkModel(); $this->criteria = new CDbCriteria($this->getFinalCriteriaParams()); try { $relationData = new ApiRelationProvider(array('config' => $this->getRelations(), 'model' => $this->model)); } catch (CException $e) { $result = array('error' => array($e->getMessage())); $this->statusCode = 400; return $this->returnResult($result); } $this->criteria->with = $relationData->getRelationsList(); if (is_array($this->criteria->with) && !empty($this->criteria->with)) { $this->criteria->together = true; } $this->criteria->mergeWith($this->getFilterCriteria(), 'OR'); $this->criteria->mergeWith($this->getSearchCriteria(), 'OR'); $this->criteria->mergeWith($this->baseCriteria, 'AND'); try { $records = $this->model->findAll($this->criteria); $result = array(); foreach ($records as $record) { $result[] = array_merge($record->attributes, $relationData->getData($record)); } } catch (Exception $ex) { $message = property_exists($ex, 'errorInfo') ? $ex->errorInfo : $ex->getMessage(); $result = array("error" => $message); $this->statusCode = 400; } return $this->returnResult($result, $this->statusCode == 200 ? array($this->getContentRangeHeader()) : array()); }