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


PHP Parse::conditions方法代码示例

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


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

示例1: filter

 /**
  * Filters the current users based on the filters given
  * 
  * @param array  $filters  Filters to apply
  * @return void
  */
 public function filter($filters)
 {
     $filters = Helper::ensureArray($filters);
     // nothing to filter, abort
     if (!$this->count()) {
         return;
     }
     $roles = null;
     $conditions = null;
     $where = null;
     // standardize filters
     $given_filters = $filters;
     $filters = array('role' => isset($given_filters['role']) ? $given_filters['role'] : null, 'conditions' => isset($given_filters['conditions']) ? $given_filters['conditions'] : null, 'where' => isset($given_filters['where']) ? $given_filters['where'] : null);
     // determine filters
     if ($filters['role']) {
         $roles = Parse::pipeList($filters['role']);
     }
     if ($filters['conditions']) {
         $conditions = Parse::conditions($filters['conditions']);
     }
     if ($filters['where']) {
         $where = $filters['where'];
     }
     // run filters
     foreach ($this->members as $username => $data) {
         if ($roles) {
             $found = false;
             foreach ($roles as $role) {
                 if (in_array($role, $data['roles'])) {
                     $found = true;
                     break;
                 }
             }
             if (!$found) {
                 unset($this->members[$username]);
                 continue;
             }
         }
         if ($where && !(bool) Parse::template("{{ if " . $where . " }}1{{ else }}0{{ endif }}", $data)) {
             unset($this->members[$username]);
             continue;
         }
         if ($conditions) {
             foreach ($conditions as $field => $instructions) {
                 try {
                     // are we looking for existence?
                     if ($instructions['kind'] === "existence") {
                         if ($instructions['type'] === "has") {
                             if (!isset($data[$field]) || !$data[$field]) {
                                 throw new Exception("Does not fit condition");
                             }
                         } elseif ($instructions['type'] === "lacks") {
                             if (isset($data[$field]) && $data[$field]) {
                                 throw new Exception("Does not fit condition");
                             }
                         } else {
                             throw new Exception("Unknown existence type");
                         }
                         // are we looking for a comparison?
                     } elseif ($instructions['kind'] === "comparison") {
                         if (!isset($data[$field])) {
                             $field = false;
                             $values = null;
                         } else {
                             $field = is_array($data[$field]) ? array_map('strtolower', $data[$field]) : strtolower($data[$field]);
                             $values = is_array($instructions['value']) ? array_map('strtolower', $instructions['value']) : strtolower($instructions['value']);
                         }
                         // convert boolean-like statements to boolean values
                         if (is_array($values)) {
                             foreach ($values as $item => $value) {
                                 if ($value == "true" || $value == "yes") {
                                     $values[$item] = true;
                                 } elseif ($value == "false" || $value == "no") {
                                     $values[$item] = false;
                                 }
                             }
                         } else {
                             if ($values == "true" || $values == "yes") {
                                 $values = true;
                             } elseif ($values == "false" || $values == "no") {
                                 $values = false;
                             }
                         }
                         // equal comparisons
                         if ($instructions['type'] == "equal") {
                             // if this isn't set, it's not equal
                             if (!$field) {
                                 throw new Exception("Does not fit condition");
                             }
                             if (!is_array($field)) {
                                 if ($field != $values) {
                                     throw new Exception("Does not fit condition");
                                 }
                             } elseif (!in_array($values, $field)) {
//.........这里部分代码省略.........
开发者ID:zane-insight,项目名称:WhiteLaceInn,代码行数:101,代码来源:memberset.php

示例2: filter

 /**
  * Filters the current content set down based on the filters given
  *
  * @param array  $filters  Filters to use to narrow down content
  * @return void
  * @throws Exception
  */
 public function filter($filters)
 {
     $hash = Debug::markStart('content', 'filtering');
     $filters = Helper::ensureArray($filters);
     // nothing to filter, abort
     if (!$this->count()) {
         return;
     }
     $since_date = null;
     $until_date = null;
     $remove_hidden = null;
     $remove_drafts = null;
     $keep_type = "all";
     $folders = null;
     $conditions = null;
     $located = false;
     $where = null;
     // standardize filters
     // -------------------
     $given_filters = $filters;
     $filters = array('show_hidden' => isset($given_filters['show_hidden']) ? $given_filters['show_hidden'] : null, 'show_drafts' => isset($given_filters['show_drafts']) ? $given_filters['show_drafts'] : null, 'since' => isset($given_filters['since']) ? $given_filters['since'] : null, 'until' => isset($given_filters['until']) ? $given_filters['until'] : null, 'show_past' => isset($given_filters['show_past']) ? $given_filters['show_past'] : null, 'show_future' => isset($given_filters['show_future']) ? $given_filters['show_future'] : null, 'type' => isset($given_filters['type']) ? strtolower($given_filters['type']) : null, 'folders' => isset($given_filters['folders']) ? $given_filters['folders'] : null, 'conditions' => isset($given_filters['conditions']) ? $given_filters['conditions'] : null, 'located' => isset($given_filters['located']) ? $given_filters['located'] : null, 'where' => isset($given_filters['where']) ? $given_filters['where'] : null);
     // determine filters
     // -----------------
     if (!is_null($filters['show_hidden'])) {
         $remove_hidden = !(bool) $filters['show_hidden'];
     }
     if (!is_null($filters['show_drafts'])) {
         $remove_drafts = !(bool) $filters['show_drafts'];
     }
     if ($filters['since']) {
         $since_date = Date::resolve($filters['since']);
     }
     if ($filters['show_past'] === false && (!$since_date || $since_date < time())) {
         $since_date = Config::getEntryTimestamps() ? time() : Date::resolve("today midnight");
     }
     if ($filters['until']) {
         $until_date = Date::resolve($filters['until']);
     }
     if ($filters['show_future'] === false && (!$until_date || $until_date > time())) {
         $until_date = Config::getEntryTimestamps() ? time() : Date::resolve("tomorrow midnight") - 1;
     }
     if ($filters['type'] === "entries" || $filters['type'] === "pages") {
         $keep_type = $filters['type'];
     }
     if ($filters['folders']) {
         $folders = Parse::pipeList($filters['folders']);
     }
     if ($filters['conditions']) {
         $conditions = Parse::conditions($filters['conditions']);
     }
     if ($filters['located']) {
         $located = true;
     }
     if ($filters['where']) {
         $where = $filters['where'];
     }
     // before we run filters, we need to look through conditions if they
     // were set to see if we're going to need content or content_raw
     // -----------
     if ($conditions) {
         // check for conditions involving content
         $uses_content = false;
         foreach ($conditions as $field => $instructions) {
             if (strtolower($field) === 'content') {
                 $uses_content = true;
                 break;
             }
         }
         // this uses content, which means we need to load it for all content
         if ($uses_content) {
             $this->prepare(true, false);
             $this->content_parsed = false;
         }
     }
     // run filters
     // -----------
     foreach ($this->content as $key => $data) {
         // entry or page removal
         if ($keep_type === "pages" && !$data['_is_page']) {
             unset($this->content[$key]);
             continue;
         } elseif ($keep_type === "entries" && !$data['_is_entry']) {
             unset($this->content[$key]);
             continue;
         }
         // check for non-public content
         if ($remove_drafts && $data['_is_draft']) {
             unset($this->content[$key]);
             continue;
         }
         if ($remove_hidden && $data['_is_hidden']) {
             unset($this->content[$key]);
             continue;
//.........这里部分代码省略.........
开发者ID:zane-insight,项目名称:WhiteLaceInn,代码行数:101,代码来源:contentset.php

示例3: filter

 /**
  * Filters the current content set down based on the filters given
  *
  * @param array  $filters  Filters to use to narrow down content
  * @return void
  * @throws Exception
  */
 public function filter($filters)
 {
     $filters = Helper::ensureArray($filters);
     // nothing to filter, abort
     if (!$this->count()) {
         return;
     }
     $since_date = null;
     $until_date = null;
     $remove_hidden = null;
     $keep_type = "all";
     $folders = null;
     $conditions = null;
     $located = false;
     // standardize filters
     // -------------------
     $given_filters = $filters;
     $filters = array('show_all' => isset($given_filters['show_all']) ? $given_filters['show_all'] : null, 'since' => isset($given_filters['since']) ? $given_filters['since'] : null, 'until' => isset($given_filters['until']) ? $given_filters['until'] : null, 'show_past' => isset($given_filters['show_past']) ? $given_filters['show_past'] : null, 'show_future' => isset($given_filters['show_future']) ? $given_filters['show_future'] : null, 'type' => isset($given_filters['type']) ? strtolower($given_filters['type']) : null, 'folders' => isset($given_filters['folders']) ? $given_filters['folders'] : null, 'conditions' => isset($given_filters['conditions']) ? $given_filters['conditions'] : null, 'located' => isset($given_filters['located']) ? $given_filters['located'] : null);
     // determine filters
     // -----------------
     if ($filters['show_all'] === false) {
         $remove_hidden = true;
     }
     if ($filters['since']) {
         $since_date = Date::resolve($filters['since']);
     }
     if ($filters['show_past'] === false && (!$since_date || $since_date < time())) {
         $since_date = time();
     }
     if ($filters['until']) {
         $until_date = Date::resolve($filters['until']);
     }
     if ($filters['show_future'] === false && (!$until_date || $until_date > time())) {
         $until_date = time();
     }
     if ($filters['type'] === "entries" || $filters['type'] === "pages") {
         $keep_type = $filters['type'];
     }
     if ($filters['folders']) {
         $folders = Helper::parseForFolders($filters['folders']);
     }
     if ($filters['conditions']) {
         $conditions = Parse::conditions($filters['conditions']);
     }
     if ($filters['located']) {
         $located = true;
     }
     // run filters
     // -----------
     foreach ($this->content as $key => $data) {
         // entry or page removal
         if ($keep_type === "pages" && !$data['_is_page']) {
             unset($this->content[$key]);
             continue;
         } elseif ($keep_type === "entries" && !$data['_is_entry']) {
             unset($this->content[$key]);
             continue;
         }
         // check if this is hidden content
         if ($remove_hidden && strpos($data['_local_path'], "/_") !== false) {
             unset($this->content[$key]);
             continue;
         }
         // folder
         if ($folders) {
             $keep = false;
             foreach ($folders as $folder) {
                 if ($folder === "*" || $folder === "/*") {
                     // include all
                     $keep = true;
                     break;
                 } elseif (substr($folder, -1) === "*") {
                     // wildcard check
                     if (strpos($data['_folder'], substr($folder, 0, -1)) === 0) {
                         $keep = true;
                         break;
                     }
                 } else {
                     // plain check
                     if ($folder == $data['_folder']) {
                         $keep = true;
                         break;
                     }
                 }
             }
             if (!$keep) {
                 unset($this->content[$key]);
                 continue;
             }
         }
         // since & show past
         if ($since_date && $data['datestamp'] && $data['datestamp'] < $since_date) {
             unset($this->content[$key]);
//.........这里部分代码省略.........
开发者ID:nob,项目名称:joi,代码行数:101,代码来源:contentset.php


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