当前位置: 首页>>代码示例>>PHP>>正文


PHP DataSource::processSQLBracket方法代码示例

本文整理汇总了PHP中DataSource::processSQLBracket方法的典型用法代码示例。如果您正苦于以下问题:PHP DataSource::processSQLBracket方法的具体用法?PHP DataSource::processSQLBracket怎么用?PHP DataSource::processSQLBracket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataSource的用法示例。


在下文中一共展示了DataSource::processSQLBracket方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generateTemplate

 public static function generateTemplate($sql, $postedParams = [], $field, $paramDefs = [])
 {
     $returnParams = [];
     ## find all params
     preg_match_all("/\\:[\\w\\d_]+/", $sql, $params);
     $model = $field->model;
     foreach ($params[0] as $idx => $p) {
         if (isset($postedParams[$p])) {
             if (is_string($postedParams[$p])) {
                 $isJs = strpos($postedParams[$p], 'js:') !== false || isset($paramDefs[$p]) && strpos($paramDefs[$p], 'js:') !== false;
                 if ($isJs) {
                     switch (get_class($field)) {
                         case "DataSource":
                             $returnParams[$p] = @$field->queryParams[$p];
                             break;
                         default:
                             $returnParams[$p] = '';
                             break;
                     }
                 } else {
                     $postParam = $postedParams[$p];
                     if (stripos($postParam, 'php:') === 0) {
                         $postParam = substr($postParam, 4);
                     }
                     if (!!$postParam) {
                         $returnParams[$p] = $field->evaluate($postParam, true, ['model' => $model]);
                     }
                 }
             } else {
                 if (is_array($postedParams[$p]) && !empty($postedParams[$p])) {
                     $returnParams[$p] = $postedParams[$p];
                     $params[0][$idx] = ['name' => $p, 'length' => count($postedParams[$p])];
                 }
             }
         }
     }
     ## find all blocks
     preg_match_all("/\\{(.*?)\\}/", $sql, $blocks);
     foreach ($blocks[1] as $block) {
         if (strtolower($block) == "and" || strtolower($block) == "or") {
             continue;
         }
         $bracket = DataSource::processSQLBracket($block, $postedParams, $field);
         $renderBracket = false;
         if (isset($bracket['render'])) {
             $renderBracket = $bracket['render'];
         }
         foreach ($bracket['params'] as $bracketParam => $bracketValue) {
             if (is_array($bracketValue) && count($bracketValue) > 0) {
                 $renderBracket = true;
                 foreach ($bracketValue as $k => $p) {
                     $returnParams[$k] = $p;
                 }
             }
         }
         ## check if there is another params
         preg_match_all("/\\:[\\w\\d_]+/", $bracket['sql'], $attachedParams);
         if (count($attachedParams[0]) > 0) {
             $inParams = 0;
             foreach ($attachedParams[0] as $ap) {
                 if (isset($returnParams[$ap]) && $returnParams[$ap] != "") {
                     $inParams++;
                     ## if current params is an ARRAY then convert to multiple params
                     if (is_array($returnParams[$ap]) && !empty($returnParams[$ap])) {
                         $newParamString = [];
                         foreach ($returnParams[$ap] as $rpIdx => $rp) {
                             $rpKey = $ap . "_" . $rpIdx;
                             $newParamString[] = $rpKey;
                             $returnParams[$rpKey] = $rp;
                         }
                         unset($returnParams[$ap]);
                         $bracket['sql'] = Helper::strReplaceFirst($ap, implode(",", $newParamString), $bracket['sql']);
                     }
                 }
             }
             if ($inParams == count($attachedParams)) {
                 $renderBracket = true;
             }
         }
         if ($renderBracket) {
             $sql = str_replace("{{$block}}", $bracket['sql'], $sql);
         } else {
             $sql = str_replace("{{$block}}", "", $sql);
         }
     }
     ## concat 'WHERE' sql with operators
     if ($sql != "") {
         $sql = DataSource::concatSql($sql, "AND");
         $sql = DataSource::concatSql($sql, "OR");
     }
     ## remove uneeded return params
     preg_match_all("/\\:[\\w\\d_]+/", $sql, $cp);
     foreach ($returnParams as $k => $p) {
         if (!in_array($k, $cp[0]) && !in_array(':' . $k, $cp[0])) {
             unset($returnParams[$k]);
         }
     }
     return ['sql' => trim($sql), 'params' => $returnParams];
 }
开发者ID:alfhan,项目名称:plansys,代码行数:99,代码来源:DataSource.php


注:本文中的DataSource::processSQLBracket方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。