/**
  * @param string $fullUrl Full url.
  * @param array $params
  * @return \Phalcon\Mvc\Model\Query
  */
 public static function buildQuery($fullUrl, array $params = array())
 {
     /**
      * @var \Phalcon\Di $di
      */
     global $di;
     /**
      * @var \Phalcon\Mvc\Model $modelName
      */
     $modelName = Text::camelize(Text::uncamelize(Analyzer::getModelName($fullUrl)));
     $builder = new Builder();
     $builder->setDI($di);
     $builder->from($modelName);
     self::setColumns($builder, $params);
     $prepareUrl = self::getPrepareUrlOperators($fullUrl);
     $whereSql = self::buildWhere($prepareUrl);
     $whereSqlReplacement = Macros::replace($whereSql, $params, $modelName);
     $builder->where($whereSqlReplacement);
     $builder = self::limit($builder, $params);
     $builder = self::orderBy($builder, $params);
     $params = new Params($fullUrl, $params);
     $params = $params->getPrepareParams();
     $query = $builder->getQuery();
     $query->setBindParams($params, true);
     return $query;
 }
 public function testGetModelName()
 {
     foreach (self::$variation as $suffix) {
         foreach (self::$crud as $key => $operation) {
             foreach ($operation as $url) {
                 $this->assertEquals(Analyzer::getModelName($url . $suffix), 'TargetGroup', 'getModelName equal targetGroup with ' . $url . $suffix);
             }
         }
     }
 }
 /**
  * Delete record from DB.
  * @return array
  */
 private function delete()
 {
     $params = Params::getMergeParams($this->request);
     if (empty($params['id'])) {
         return array('success' => false, 'msg' => 'param id is require');
     }
     $id = intval($params['id']);
     $modelName = Analyzer::getModelName($this->request->get('_url'));
     /**
      * @var \Phalcon\Mvc\Model $model
      */
     $model = $modelName::findFirst($id);
     if (!$model) {
         return array('success' => false, 'msg' => 'Record with id ' . $id . ' not found');
     }
     $this->securityManager->check(array('model' => $model, 'action' => CrudOperations::DELETE, 'modelName' => $modelName, 'params' => $params));
     $this->logManager->deleteModel($model);
     if ($model->delete()) {
         $this->logManager->deleteModel($model);
         return array('success' => true, 'msg' => 'Record with id ' . $id . ' has removed!');
     }
     return array('success' => false, 'msg' => $this->jsonRecursiveGetMsg($model->getMessages()));
 }