コード例 #1
0
 /**
  * @param string $string
  * @param array $params
  * @param $modelName Model name.
  * @return string
  */
 private static function replaceColumnsLikes($string, array $params, $modelName)
 {
     $columns = isset($params['columns']) ? $params['columns'] : self::getModelColumns($modelName);
     $columns = array_map(function ($column) {
         return Text::uncamelize($column) . ' LIKE :search:';
     }, $columns);
     $columns = implode(' OR ', $columns);
     return preg_replace('/{columns likes}/', $columns, $string);
 }
コード例 #2
0
 /**
  * @param array $params
  * @param $portionString
  * @return bool|int|string
  */
 private function findKeyParamByPortionString(array $params, $portionString)
 {
     foreach ($params as $key => $param) {
         $key = Text::getColumnLowerCase($key);
         $portionString = Text::getColumnLowerCase($portionString);
         if (preg_match('/^' . $key . '/', $portionString)) {
             return $key;
         }
     }
     return false;
 }
コード例 #3
0
 public function testGetColumnLowerCase()
 {
     $expectedKey = 'lowerCase';
     foreach (self::$strings as $key => $expectedArray) {
         if ($key !== $expectedKey) {
             continue;
         }
         foreach ($expectedArray as $expectedValue => $string) {
             $result = Text::getColumnLowerCase($string);
             $this->assertEquals($result, $expectedValue, 'getColumnLowerCase returns expected value');
         }
     }
 }
コード例 #4
0
 public function testGetTextSqlOperationContaining()
 {
     $operatorExpected = 'containing';
     foreach (self::$crud as $key => $operation) {
         if ($operatorExpected !== $key) {
             continue;
         }
         foreach ($operation as $param => $conditionPortion) {
             $sql = Operations::getTextSqlOperation(new Portion($conditionPortion));
             $this->assertEquals($sql, Text::uncamelize($param) . ' LIKE :' . $param . ':', 'getTextSqlOperation create expected sql text');
         }
     }
 }
コード例 #5
0
 /**
  * @param \Phalcon\Mvc\Model\Query\Builder $builder
  * @param array $excludeColumns
  */
 private static function setExcludeColumns($builder, $excludeColumns)
 {
     $modelName = $builder->getFrom();
     /**
      * @var \Phalcon\Mvc\Model $model
      */
     $model = new $modelName();
     $columns = $model->getModelsMetaData()->getAttributes($model);
     $columns = array_diff($columns, $excludeColumns);
     foreach ($columns as $key => $column) {
         foreach ($excludeColumns as $excludeColumn) {
             $excludeColumn = Text::lower($excludeColumn);
             if (!Text::endsWith($excludeColumn, '*')) {
                 break;
             }
             $excludeColumn = str_replace('*', '', $excludeColumn);
             $column = Text::lower($column);
             $isStartWith = Text::startsWith($column, $excludeColumn);
             if ($isStartWith) {
                 unset($columns[$key]);
                 break;
             }
         }
     }
     $builder->columns($columns);
 }
コード例 #6
0
 private static function getColumnName(Portion $portion)
 {
     $columnName = $portion->getColumnName();
     return Text::uncamelize($columnName);
 }