/** * Проверяет валидность введённых данных * @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; }
/** * Срабатывает при перетаскивании события * @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(); }