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


PHP Helper::refactorDateRange方法代码示例

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


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

示例1: saveBudget

 /**
  * @param $data
  * @param $budgetId
  * @return int
  */
 public function saveBudget($data, $budgetId)
 {
     /** @var \DDD\Dao\Finance\Budget\Budget $budgetDao */
     $budgetDao = $this->getServiceLocator()->get('dao_finance_budget_budget');
     $dateRange = Helper::refactorDateRange($data['period']);
     if ($budgetId) {
         // Apply amount changes to balance
         $oldData = $budgetDao->getBudgetData($budgetId);
         $balance = $oldData['balance'] + $data['amount'] - $oldData['amount'];
     } else {
         // Starting balance is the same as amount
         $balance = $data['amount'];
     }
     $params = ['name' => $data['name'], 'status' => $data['status'], 'from' => $dateRange['date_from'], 'to' => $dateRange['date_to'], 'amount' => $data['amount'], 'balance' => $balance, 'description' => $data['description'], 'department_id' => $data['is_global'] ? null : $data['department_id'], 'is_global' => $data['is_global']];
     if ($data['country_id'] > 0) {
         $params['country_id'] = $data['country_id'];
     } else {
         $params['country_id'] = null;
     }
     if ($budgetId) {
         $budgetDao->save($params, ['id' => $budgetId]);
     } else {
         $auth = $this->getServiceLocator()->get('library_backoffice_auth');
         $userId = $auth->getIdentity()->id;
         $params['user_id'] = $userId;
         $budgetId = $budgetDao->save($params);
     }
     return $budgetId;
 }
开发者ID:arbi,项目名称:MyCode,代码行数:34,代码来源:Budget.php

示例2: getAllBudgets

 /**
  * @param $params
  * @param $userId
  * @return array
  */
 public function getAllBudgets($params, $userId)
 {
     $this->resultSetPrototype->setArrayObjectPrototype(new \ArrayObject());
     $where = new Where();
     if (isset($params['name']) && $params['name']) {
         $where->like($this->getTable() . '.name', $params['name'] . '%');
     }
     if (isset($params['status']) && $params['status']) {
         $where->equalTo($this->getTable() . '.status', $params['status']);
     }
     if (isset($params['user']) && $params['user']) {
         $where->equalTo($this->getTable() . '.user_id', $params['user']);
     }
     if (isset($params['period']) && $params['period']) {
         $dateRange = Helper::refactorDateRange($params['period']);
         $where->greaterThanOrEqualTo($this->getTable() . '.to', $dateRange['date_from']);
         $where->lessThanOrEqualTo($this->getTable() . '.from', $dateRange['date_to']);
     }
     if (isset($params['frozen']) && $params['frozen'] >= 0) {
         $where->equalTo($this->getTable() . '.frozen', $params['frozen']);
     }
     if (isset($params['archived']) && $params['archived'] >= 0) {
         $where->equalTo($this->getTable() . '.archived', $params['archived']);
     }
     if ($userId) {
         $where->equalTo($this->getTable() . '.user_id', $userId);
     }
     if (isset($params['department']) && $params['department'] >= 0) {
         $where->equalTo($this->getTable() . '.department_id', $params['department']);
     }
     if (isset($params['country']) && $params['country'] >= 0) {
         $where->equalTo($this->getTable() . '.country_id', $params['country']);
     }
     if (isset($params['global']) && $params['global'] >= 0) {
         $where->equalTo($this->getTable() . '.is_global', $params['global']);
     }
     $offset = $params['iDisplayStart'];
     $limit = $params['iDisplayLength'];
     $sortCol = $params['iSortCol_0'];
     $sortDir = $params['sSortDir_0'];
     $result = $this->fetchAll(function (Select $select) use($offset, $limit, $sortCol, $sortDir, $where) {
         $sortColumns = ['status', 'name', 'department_name', 'from', 'amount', 'balance', 'user_name'];
         $select->columns(['id', 'name', 'from', 'to', 'amount', 'description', 'status', 'user_id', 'department_id', 'country_id', 'is_global', 'balance']);
         $select->join(['users' => DbTables::TBL_BACKOFFICE_USERS], $this->getTable() . '.user_id = users.id', ['user_name' => new Expression('CONCAT(firstname, " ", lastname)')], Select::JOIN_LEFT);
         $select->join(['teams' => DbTables::TBL_TEAMS], $this->getTable() . '.department_id = teams.id', ['department_name' => 'name'], Select::JOIN_LEFT);
         $select->where($where);
         $select->group($this->getTable() . '.id')->order($sortColumns[$sortCol] . ' ' . $sortDir)->offset((int) $offset)->limit((int) $limit);
         $select->quantifier(new Expression('SQL_CALC_FOUND_ROWS'));
     });
     $statement = $this->adapter->query('SELECT FOUND_ROWS() as total');
     $resultCount = $statement->execute();
     $row = $resultCount->current();
     $total = $row['total'];
     return ['result' => $result, 'total' => $total];
 }
开发者ID:arbi,项目名称:MyCode,代码行数:60,代码来源:Budget.php

示例3: updateInventoryRangeByPrice

 /**
  * @param $apartmentId
  * @param $dateRange
  * @param $weekDays
  * @param $price
  * @param $priceType
  * @param int $setLockPrice
  * @param int $forceLockPrice
  * @param int $forceUpdatePrice
  * @return $this|array|bool|Inventory
  */
 public function updateInventoryRangeByPrice($apartmentId, $dateRange, $weekDays, $price, $priceType, $setLockPrice = 0, $forceLockPrice = 0, $forceUpdatePrice = 0)
 {
     /**
      * @var \DDD\Dao\Apartment\Inventory $inventoryDao
      */
     $inventoryDao = $this->getServiceLocator()->get('dao_apartment_inventory');
     // Define Variables
     $dateRange = Helper::refactorDateRange($dateRange);
     $weekDays = Helper::reformatWeekdays($weekDays);
     // check price changes
     if (!$forceUpdatePrice) {
         $priceAVGOld = $inventoryDao->getPriceAVGRange($apartmentId, $dateRange['date_from'], $dateRange['date_to'], $weekDays);
         $priceAVGNew = $inventoryDao->getPriceAVGRangeByPriceType($apartmentId, $dateRange['date_from'], $dateRange['date_to'], $weekDays, $price, $priceType);
         if ($priceAVGNew < $priceAVGOld - $priceAVGOld * self::PRICE_CHANGE_LIMIT / 100) {
             return ['status' => 'limit_exceed', 'msg' => TextConstants::PRICE_EXCEED_LIMIT];
         }
     }
     return $this->updatePriceByRange($apartmentId, $price, $dateRange['date_from'], $dateRange['date_to'], $weekDays, $priceType, $setLockPrice, $forceLockPrice);
 }
开发者ID:arbi,项目名称:MyCode,代码行数:30,代码来源:Inventory.php

示例4: updateAction

 public function updateAction()
 {
     $output = ['bo' => ['status' => 'error']];
     try {
         /**
          * @var Request $request
          * @var \DDD\Service\Apartment\Inventory $inventoryService
          * @var Rate $apartmentRateService
          * @var \DDD\Service\Apartment\General $apartmentService
          */
         $request = $this->getRequest();
         /**
          * Definitions
          */
         if ($request->isPost() && $request->isXmlHttpRequest()) {
             $inventoryService = $this->getServiceLocator()->get('service_apartment_inventory');
             // Required as Route params
             $apartmentId = $this->params()->fromRoute('apartment_id');
             // Required
             $type = $this->params()->fromPost('type', null);
             // availability|price|price-extra
             $dateRange = $this->params()->fromPost('date_range', null);
             $weekDays = $this->params()->fromPost('days', null);
             // Optional (depends on type of choice)
             $availability = $this->params()->fromPost('avail', null);
             $amount = $this->params()->fromPost('amount', null);
             $priceType = $this->params()->fromPost('price_type', null);
             $lockPrice = $this->params()->fromPost('lock_price', null);
             $comment = $this->params()->fromPost('comment', null);
             $forceUpdatePrice = $this->params()->fromPost('force_update_price', null);
             // Check Imposable Situation
             if (is_null($apartmentId)) {
                 throw new \Exception('Some parameters from route are missing.');
             }
             // Check Required Parameters
             if (is_null($type) || is_null($dateRange) || is_null($weekDays) || empty($dateRange) || empty($weekDays)) {
                 throw new \Exception('Some required parameters are missing.');
             }
             if (!empty($dateRange)) {
                 $dates = explode(' - ', $dateRange);
                 $start = strtotime($dates[0]);
                 $end = strtotime($dates[1]);
                 if (count($dates) != 2 || $start < strtotime("-2 day") || $end > strtotime("+1 year")) {
                     throw new \Exception('Incorrect date range.');
                 }
             }
             // Check Action Type
             if (!in_array($type, ['availability', 'price', 'price-extra'])) {
                 throw new \Exception('Type is wrong.');
             }
             if ($type == 'availability' && !is_null($availability)) {
                 if (!$availability && !$comment) {
                     throw new \Exception(TextConstants::AVAILABILITY_CLOSE_MSG);
                 }
                 $responseUpdate = $inventoryService->updateInventoryRangeByAvailability($apartmentId, $dateRange, $weekDays, $availability);
                 if ($responseUpdate['status'] == 'success') {
                     $output['bo']['status'] = 'success';
                     $output['bo']['msg'] = $responseUpdate['msg'];
                     $accommodationsDao = $this->getServiceLocator()->get('dao_accommodation_accommodations');
                     $accInfo = $accommodationsDao->fetchOne(["id" => $apartmentId]);
                     $sellingStatus = [ApartmentService::APARTMENT_STATUS_LIVE_AND_SELLING, ApartmentService::APARTMENT_STATUS_SELLING_NOT_SEARCHABLE];
                     if (in_array($accInfo->getStatus(), $sellingStatus) && !is_null($availability) && $availability == 0) {
                         $auth = $this->getServiceLocator()->get('library_backoffice_auth');
                         $userId = $auth->getIdentity()->id;
                         $accName = $accInfo->getName();
                         $notifService = $this->getServiceLocator()->get('service_notifications');
                         $userManagerDao = $this->getServiceLocator()->get('dao_user_user_manager');
                         $userGroupDao = $this->getServiceLocator()->get('dao_user_user_groups');
                         $userInfo = $userManagerDao->getUserById($userId);
                         $roledUsers = $userGroupDao->getUsersByGroupId(Roles::ROLE_APARTMENT_AVAILABILITY_MONITOR);
                         $recipient = [];
                         foreach ($roledUsers as $roledUser) {
                             $recipient[] = $roledUser->getUserId();
                         }
                         $dateRangeArray = Helper::refactorDateRange($dateRange);
                         $now = date('Y-m-d');
                         $sender = NotificationService::$availabilityMonitoring;
                         $calendarDate = date('Y/m', strtotime($dateRangeArray['date_from']));
                         $days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
                         $exceptDays = [];
                         foreach ($weekDays as $key => $value) {
                             if ($value == 0) {
                                 $exceptDays[] = $days[$key];
                             }
                         }
                         if ($exceptDays) {
                             $exceptDays = implode(', ', $exceptDays);
                             $exceptDays = 'except: <b>' . $exceptDays . '</b>';
                         } else {
                             $exceptDays = '';
                         }
                         if ($availability) {
                             $notifMsg = TextConstants::OPEN_APARTMENT_INVENTORY;
                         } else {
                             $notifMsg = TextConstants::CLOSE_APARTMENT_INVENTORY;
                         }
                         if ($comment) {
                             $reasonMessage = !empty($comment) ? '<br><i>Reason:</i> "' . $comment . '"' : '';
                             /* @var $actionLogger \Library\ActionLogger\Logger */
                             $actionLogger = $this->getServiceLocator()->get('ActionLogger');
//.........这里部分代码省略.........
开发者ID:arbi,项目名称:MyCode,代码行数:101,代码来源:InventoryRange.php


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