Пример #1
0
 /**
  * get functions that used in sql if $return_func is false then return
  *  clean sql
  *
  * @param bool|true $return_func
  * @param null $sql string sql query
  *
  * @return mixed
  */
 public function functions($return_func = true, $sql = NULL)
 {
     if (!$sql) {
         $sql = $this->sql;
     }
     $this->lexer->lex($sql);
     $sql = $this->lexer->clean();
     $functions = explode('|', $this->functions);
     // we calc position of each function that exist in sql
     $exists_functions = array();
     foreach ($functions as $func) {
         if (($pos = strpos($sql, $func . ' (')) !== false || ($pos = strpos($sql, $func . '(')) !== false) {
             $exists_functions[] = array('func' => $func, 'position' => $pos);
         }
     }
     if ($return_func) {
         return $exists_functions;
     } elseif (count($exists_functions)) {
         // we have to remove function from last position to remove ) and inside code in theme.
         $exists_functions = Tools::sort($exists_functions, 'position', SORT_DESC);
         foreach ($exists_functions as $func) {
             $sql = String::removeSubStr($sql, $func['func'], ')', true);
         }
         return $sql;
     } else {
         return $sql;
     }
 }