public function actionModelcollection() { $requestedData = $this->validateModel(); $paramModel = $_REQUEST['model']; $className = $requestedData['class']; $method = $requestedData['method']; $model = new $className(); $where = ''; $divader = ''; if ($method !== null) { $model->{$method}(); } else { $model->addQuery('select', array('table' => $model->getTableName())); } if (isset($paramModel[$className]['filter'])) { $where = $this->parseFilter($paramModel[$className]['filter'], $model, $paramModel[$className]['filterGroupOperators']); } if ($where != '') { $model->addQuery('where', array('where_condition' => $where)); } $sortBy = 'DESC'; if (isset($paramModel[$className]['sortBy'])) { if ($paramModel[$className]['sortBy'] == 'ASC') { $sortBy = 'ASC'; } } $model->addQuery('order', array('order' => implode($model->getPrimaryKeys(), ",") . ' ' . $sortBy)); if (isset($paramModel[$className]['limitStart'])) { $start = (int) $paramModel[$className]['limitStart']; $end = (int) $paramModel[$className]['limitEnd']; if ($start != 0 || $end != 0) { $limit = $start; if ($end != 0) { $limit = $start . ',' . $end; } $model->addQuery('limit', array('limit' => $limit)); } } $modelCollection = new Core_Model_Adapter_ModelCollection(); $result = $modelCollection->getModelCollection($model, false); $countResult = null; if (isset($paramModel['count'])) { $countResult = $model->count(); } if (!$model->isValid()) { echo json_encode(array('status' => 'error', 'errors' => $modelCollection->modelValidationErrors())); } else { $dataForJson = array('status' => 'ok', 'data' => $modelCollection->toServiceArray()); if (isset($countResult)) { $dataForJson['count'] = $countResult; } echo json_encode($dataForJson); } }