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


PHP Where::andPredicate方法代码示例

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


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

示例1: constructWhereForItemSearchForDatatable

 /**
  * @param $params
  * @return Where
  * @throws \Exception
  */
 private function constructWhereForItemSearchForDatatable($params)
 {
     $where = new Where();
     $itemTable = DbTables::TBL_EXPENSE_ITEM;
     if (!empty($params['item-search-supplier'])) {
         $where->equalTo("{$itemTable}.account_id", $params['item-search-supplier']);
     }
     if (!empty($params['creator_id'])) {
         $where->equalTo("{$itemTable}.creator_id", $params['creator_id']);
     }
     if (!empty($params['item-search-creation-date'])) {
         list($creationFrom, $creationTo) = explode(' - ', $params['item-search-creation-date']);
         $creationFrom = date(Constants::DATABASE_DATE_FORMAT, strtotime($creationFrom));
         $creationTo = date(Constants::DATABASE_DATE_FORMAT, strtotime($creationTo));
         $where->expression("date({$itemTable}.date_created) BETWEEN ? AND ?", [$creationFrom, $creationTo]);
     }
     if (!empty($params['item-search-reference'])) {
         $where->like("{$itemTable}.account_reference", "%{$params['item-search-reference']}%");
     }
     if ($params['item-search-amount'] !== '') {
         $where->equalTo("{$itemTable}.amount", $params['item-search-amount']);
     }
     if (!empty($params['item-search-period'])) {
         list($periodFrom, $periodTo) = explode(' - ', $params['item-search-period']);
         $periodFrom = date(Constants::DATABASE_DATE_FORMAT, strtotime($periodFrom));
         $periodTo = date(Constants::DATABASE_DATE_FORMAT, strtotime($periodTo));
         $whereP = new Where();
         $whereP->between("{$itemTable}.period_from", $periodFrom, $periodTo);
         $whereP->or;
         $whereP->between("{$itemTable}.period_to", $periodFrom, $periodTo);
         $where->andPredicate($whereP);
     }
     if (!empty($params['item-search-category'])) {
         list($categoryId, $categoryType) = explode('_', $params['item-search-category']);
         // Conventional: 1 - category, 2 - sub category
         if ($categoryType == 1) {
             $where->equalTo("sub_category.category_id", $categoryId);
             $where->equalTo("sub_category.category_id", $categoryId);
         } elseif ($categoryType == 2) {
             $where->equalTo("{$itemTable}.sub_category_id", $categoryId);
         } else {
             throw new \Exception('Invalid category type.');
         }
     }
     if (!empty($params['item-search-cost-center'])) {
         list($costCenterType, $costCenterId) = explode('_', $params['item-search-cost-center']);
         // Conventional: 1 - apartment, 2 - office section
         if (in_array($costCenterType, [1, 2])) {
             $where->equalTo("cost.cost_center_id", $costCenterId);
             $where->equalTo("cost.cost_center_type", $costCenterType);
         } else {
             throw new \Exception('Invalid cost center type.');
         }
     }
     return $where;
 }
开发者ID:arbi,项目名称:MyCode,代码行数:61,代码来源:ExpenseTicket.php


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