static function getExpiryTimeOfSubscription($obj, $addPeriod = 0) { $date = $obj->getStartDate(); for ($i = 0; $i < $obj->getNoOfPeriodPaid() + $addPeriod; $i++) { if ($obj->getPeriod()) { $newTime = strtotime($date . ' + ' . $obj->getPeriod()); if ($newTime) { $date = Helper_Date::formatSqlDatetime($newTime); } } } $expiryTime = strtotime($date); return $expiryTime; }
static function _buildSingleSearchFilter($filterField, $val) { $searchFilter = new SearchFilter(); if (isset($filterField['meta'])) { $searchFilter->setField($filterField['meta']); } else { return NULL; } $searchFilter->setComparison($filterField['operator']); $filterVal = $val; if (isset($filterField['format']) && ($filterField['format'] == 'date' || $filterField['format'] == 'datetime')) { $filterVal = Helper_Date::formatSqlDateTime(strtotime($val)); } $searchFilter->setValue($filterVal); return $searchFilter; }
protected function site_init() { $request = $this->request->current(); $site = Arr::get(ORM_Helper_Site::sites(), $request->site_id); $this->site($site); if (!defined('IS_MASTER_SITE')) { define('IS_MASTER_SITE', $site['type'] == 'master' ? 1 : 0); } if (!defined('SITE_ID')) { define('SITE_ID', $request->site_id); } if (!defined('SITE_ID_MASTER')) { define('SITE_ID_MASTER', $request->site_id_master); } $this->site_time['shift'] = Helper_Date::str_to_sec($site['mmt']); $this->site_time['ts'] = time() + $this->site_time['shift']; }
protected function site_init() { $request = $this->request->current(); if (!Kohana::$is_cli) { $site_id = (int) $request->query('site_id'); if ($site_id and $this->acl->is_allowed($this->user, 'site_switcher', 'show')) { $request->site_id = $site_id; Session::instance()->set('SITE_ID', $site_id); } else { $site_id_sess = (int) Session::instance()->get('SITE_ID'); if (empty($site_id_sess)) { $request->site_id = (int) $this->user->site_id; Session::instance()->set('SITE_ID', $request->site_id); } else { $request->site_id = $site_id_sess; } unset($site_id_sess); } unset($site_id); $master_site = DB::select('id')->from('sites')->where('type', '=', 'master')->and_where('active', '>', 0)->and_where('delete_bit', '=', 0)->execute()->current(); if (empty($master_site)) { throw new HTTP_Exception_404(); } $request->site_id_master = (int) $master_site['id']; } $site = Arr::get(ORM_Helper_Site::sites(), $request->site_id); $this->site($site); if (!defined('IS_MASTER_SITE')) { define('IS_MASTER_SITE', $site['type'] == 'master' ? 1 : 0); } if (!defined('SITE_ID')) { define('SITE_ID', $request->site_id); } if (!defined('SITE_ID_MASTER')) { define('SITE_ID_MASTER', $request->site_id_master); } ORM_Base::$site_id = SITE_ID; ORM_Base::$site_id_master = SITE_ID_MASTER; $this->site_time['shift'] = Helper_Date::str_to_sec($site['mmt']); $this->site_time['ts'] = time() + $this->site_time['shift']; }
static function getLastConfirmedOrdersOfMember($controller, $member, $startTs = NULL, $limit = NULL) { $orders = array(); if ($member) { $memberFilter = new SearchFilter(Order::$FIELD_META_MEMBER, SearchFilter::$EQUAL, $member->getId()); $statusFilter = new SearchFilter(Order::$FIELD_META_ORDER_STATUS, SearchFilter::$NOT_EQUAL, 'Pending'); $filters = array($memberFilter, $statusFilter); if ($startTs) { $timeFilter = new SearchFilter(Order::$FIELD_META_ORDER_DATE, SearchFilter::$GREATER_THAN_EQUAL, Helper_Date::formatSqlDatetime($startTs)); $filters[] = $timeFilter; } $sortField = Order::$FIELD_META_ORDER_DATE; $orders = $controller->getObjects('orders', 'getOrders', array(NULL, $filters, $sortField, TRUE, $limit)); } return $orders; }
/** * Проверяет валидность введённых данных * @param array $params * @return array */ public function checkData(array $operation = array()) { $validated = array(); $this->errorData = array(); // Проверяем ID if (array_key_exists('id', $operation)) { $validated['id'] = (int) $operation['id']; if ($validated['id'] === 0) { $this->errorData['id'] = 'Не указан id события'; } } // Проверяем тип операции if (array_key_exists('type', $operation)) { $validated['type'] = (int) $operation['type']; } // Проверяем счёт if (array_key_exists('account', $operation)) { $validated['account'] = (int) $operation['account']; if ((int) $operation['accepted'] == 1 && $validated['account'] === 0) { $this->errorData['account'] = 'Не выбран счёт'; } $accounts = $this->_user->getUserAccounts(); if (!isset($accounts[$validated['account']])) { $this->errorData['account'] = 'Указанного счёта не существует'; } } // Проверяем сумму if (array_key_exists('amount', $operation)) { if ((int) $operation['accepted'] == 1 && empty($operation['amount'])) { $this->errorData['amount'] = 'Сумма не должна быть равной нулю.'; } $validated['amount'] = $operation['amount']; } // Проверяем категорию if (array_key_exists('category', $operation)) { $validated['category'] = (int) $operation['category']; if (empty($validated['category'])) { $validated['target'] = (int) $operation['target']; $validated['toAccount'] = (int) $operation['toAccount']; if (empty($validated['target']) && empty($validated['toAccount'])) { $this->errorData['category'] = 'Нужно указать '; switch ($operation['type']) { case Operation::TYPE_TRANSFER: $this->errorData['category'] .= 'целевой счёт.'; break; case Operation::TYPE_TARGET: $this->errorData['category'] .= 'цель.'; break; case Operation::TYPE_PROFIT || Operation::TYPE_WASTE: default: $this->errorData['category'] .= 'категорию.'; } } } elseif ((int) $operation['accepted'] == 1 && ($validated['type'] == 0 || $validated['type'] == 1)) { $cat = $this->db->query("SELECT count(*) as co FROM category WHERE cat_id=? AND deleted_at IS NULL", $validated['category']); if ($cat[0]['co'] != 1) { $this->errorData['category'] = 'Выбранной категории не существует!'; } } } // Проверяем дату if (array_key_exists('date', $operation)) { $validated['date'] = Helper_Date::RusDate2Mysql($operation['date']); //$validated['date'] = Helper_Date::getMysqlFromString( $operation['date'] ); if ($validated['date'] == '0000-00-00' || empty($validated['date'])) { $this->errorData['date'] = 'Неверно указана дата.'; } } $validated['comment'] = trim($operation['comment']); // Проверяем теги if (!empty($operation['tags'])) { $validated['tags'] = array(); $tags = explode(',', trim($operation['tags'])); foreach ($tags as $tag) { $tag = trim($tag); if (!empty($tag)) { if (!in_array($tag, $validated['tags'])) { $validated['tags'][] = trim($tag); } } } } else { $validated['tags'] = array(); } // Проверяем тип операцииe // - Перевод со счёта на счёт if ($validated['type'] == 2) { $validated['currency'] = (double) $operation['currency']; if ((double) $operation['currency'] != 0) { $validated['convert'] = round($validated['amount'] * (double) $operation['currency'], 2); } else { $validated['convert'] = 0; } $validated['toAccount'] = (int) $operation['toAccount']; } elseif ($validated['type'] == 4) { $validated['target'] = $operation['target']; if ($operation['close'] == 1) { $validated['close'] = 1; } else { $validated['close'] = 0; } } return $validated; }
public function POST() { $policy = new Policy_LoggedIn($this->app); $policy->ensure(); $userid = $policy->getData(); if (!isset($_FILES['file'])) { $this->error("Nothing to do."); } $file = $_FILES['file']; if (isset($file['error']) && $file['error'] > 0) { $error = $file['error']; if ($error == UPLOAD_ERR_NO_FILE) { $this->error("No file was selected."); } else { if ($error == UPLOAD_ERR_INI_SIZE) { $this->error("The file you're trying to upload is too big."); } else { $this->error("Something went wrong, please try again later."); } } } $tmpName = $file['tmp_name']; ini_set('auto_detect_line_endings', true); $handle = fopen($tmpName, 'r'); $dataLines = array(); while (($data = fgetcsv($handle)) !== false) { $dataLines[] = $data; } ini_set('auto_detect_line_endings', false); if (count($dataLines) < 2) { $this->error("The file uploaded does not contain enough data to import."); } $descripData = $dataLines[0]; $dateOffset = false; $weightOffset = false; $commentOffset = false; for ($i = 0; $i < count($descripData); $i++) { $field = strtolower(trim($descripData[$i])); if ($field == "date") { $dateOffset = $i; } else { if ($field == "weight") { $weightOffset = $i; } else { if ($field == "comment" || $field == "comments" || $field == "note" || $field == "notes") { $commentOffset = $i; } } } } if ($dateOffset === false || $weightOffset === false) { $this->error("The file uploaded is missing the required fields."); } $validRows = 0; for ($i = 1; $i < count($dataLines); $i++) { $tmpData = $dataLines[$i]; $tmpDate = trim($tmpData[$dateOffset]); $tmpWeight = trim($tmpData[$weightOffset]); $tmpComment = ''; if ($commentOffset && isset($tmpData[$commentOffset])) { $tmpComment = trim($tmpData[$commentOffset]); } $tmpWeight = Helper_Weight::validateWeight($tmpWeight); $tmpDate = Helper_Date::validateDate($tmpDate); if ($tmpDate && $tmpWeight) { $mapper = new Mapper_Weight(); $mapper->addWeight($userid, $tmpWeight, $tmpComment, $tmpDate); $validRows++; } } if ($validRows == 0) { $this->error("No valid data found to import."); } $this->success("Import complete. {$validRows} " . ($validRows != 1 ? "rows" : "row") . " were just imported."); }
/** * Срабатывает при перетаскивании события * @return void */ function edit_date() { $id = (int) _Core_Request::getCurrent()->post['id']; $date = Helper_Date::RusDate2Mysql(_Core_Request::getCurrent()->post['date']); $calendar = new Calendar(Core::getInstance()->user); if ($calendar->editDate($id, $date)) { $this->tpl->assign('result', array('text' => 'Операция успешно изменена')); } else { $this->tpl->assign('error', array('text' => implode(",\n", $calendar->getErrors()))); } // @FIXME Перенести этот блок кода в календарь Core::getInstance()->user->initUserEvents(); Core::getInstance()->user->save(); }
function _getDeliveryDateForm($cart) { if (isset($this->withDeliveryDate) && $this->withDeliveryDate) { $inputs = ''; $inputs .= Helper_Xml::xmlInputHidden('cmd', 'delivery_date'); $delDate = ''; if ($cart['delivery_timestamp']) { $delDate = Helper_Date::formatSgpDatetime($cart['delivery_timestamp'], FALSE); if ($this->withDeliveryDate === 'date') { $delDate = Helper_Date::formatSgpDate($cart['delivery_timestamp'], FALSE); } } $inputs .= Helper_Xml::xmlEmptyTag('input', array('type' => 'text', 'name' => 'delivery_date', 'value' => $delDate)); $inputs .= Helper_Xml::xmlEmptyTag('input', array('type' => 'submit', 'value' => 'Update')); $ddLabel = 'Delivery Date'; if (isset($this->deliveryDateLabel) && $this->deliveryDateLabel) { $ddLabel = $this->deliveryDateLabel; } $label = Helper_Xml::xmlTag('span', "{$ddLabel}: "); $shippingForm = Helper_Xml::xmlTag('form', $label . $inputs, array('action' => $cart['link'], 'method' => 'post', 'class' => 'cart-delivery-date')); return $shippingForm; } return ''; }
static function _createBirthdayCoupon($controller, $member, $couponConf) { $coupon = new Coupon(); $coupon->setCouponType('product'); $coupon->setDiscountPercentage($couponConf['discount_percentage']); $coupon->setIsAllProducts(TRUE); $startDate = Helper_Date::formatSqlDatetime(strtotime(date('F Y', $controller->now))); $endDate = Helper_Date::formatSqlDatetime(strtotime(date('F Y', $controller->now) . ' +1 month')); $coupon->setStartDate($startDate); $coupon->setExpiryDate($endDate); $coupon->setNumOfUsage(1); $curYear = date('Y', $controller->now); $couponCode = 'BIRTHDAY-' . $member->getEmail() . "-{$curYear}"; $coupon->setCouponCode($couponCode); $name = $member->getFirstName(); $nyears = $curYear - date('Y', strtotime($member->getDateOfBirth())); $th = Helper_Math::getTh($nyears); $coupon->setTitle("{$name}'s {$nyears}{$th} Birthday"); return $coupon; }
/** * Список операций для счёта (PDA) * * @param array $args */ function account($args = array()) { // Если указан id счёта if (isset($args[0]) && (int) $args[0]) { $accountId = (int) $args[0]; // Получаем последние 10 операций по нему // На самом деле это пока невозможно, получаем все операции $operations = $this->model->getOperationList(Helper_Date::getMysql(3), Helper_Date::getMysql(time()), null, $accountId, -1, null, null, null); } else { //_Core_Router::redirect('/info' , true); } if (!is_array($operations)) { $operations = array(); } $this->_setDrain($operations); $this->tpl->assign('accountId', $accountId); $this->tpl->assign('operations', $operations); $this->tpl->assign('name_page', 'account/operations'); }
public function valid_date($name, $str) { if (empty($str)) { return TRUE; } if (Helper_Date::isDate($str) && !Helper_Date::isEmpty($str)) { return TRUE; } else { return "'{$name}' 不是有效的日期"; } }