/** * Редактирует событие * @return void */ function edit() { $user = Core::getInstance()->user; // Определяем массив данных для обработки $request = _Core_Request::getCurrent(); $event_array = array('id' => (int) $request->post['id'], 'chain' => (int) $request->post['chain'], 'type' => (int) $request->post['type'], 'account' => (int) $request->post['account'], 'amount' => (double) str_replace(' ', '', $request->post['amount']), 'category' => (int) $request->post['category'] <= 0 ? null : (int) $request->post['category'], 'date' => Helper_Date::RusDate2Mysql($this->getDateOperation()), 'comment' => (string) $request->post['comment'], 'tags' => isset($request->post['tags']) ? explode(',', $request->post['tags']) : array(), 'convert' => isset($request->post['convert']) ? $request->post['convert'] : 0, 'close' => isset($request->post['close']) ? $request->post['close'] : 0, 'currency' => isset($request->post['currency']) ? $request->post['currency'] : 0, 'toAccount' => isset($request->post['toAccount']) ? $request->post['toAccount'] : null, 'target' => isset($request->post['target']) ? $request->post['target'] : null, 'last' => isset($request->post['last']) ? Helper_Date::RusDate2Mysql($request->post['last']) : '0000-00-00', 'time' => isset($request->post['time']) ? $request->post['time'] : date("H:i:s"), 'every' => isset($request->post['every']) ? (int) $request->post['every'] : 0, 'repeat' => isset($request->post['repeat']) ? (int) $request->post['repeat'] : 1, 'week' => isset($request->post['week']) ? $request->post['week'] : '0000000', 'accepted' => isset($request->post['accepted']) ? (int) $request->post['accepted'] : 0); // Напоминания $notifications = $this->_readNotificationsFromRequest($request); $event_array = array_merge($event_array, $notifications); $event = new Calendar_Event(new Calendar_Model($event_array, $user), $user); if (!$event->checkData()) { $this->tpl->assign('error', array('text' => implode(",\n", $event->getErrors()))); } else { // Если нет цепочки, значит только одна операция if ($event_array['chain'] === 0) { $operation = new Operation_Model(); if ($event_array['type'] <= 1) { if ($event_array['type'] == 0) { $event_array['amount'] = abs($event_array['amount']) * -1; } else { $event_array['amount'] = abs($event_array['amount']); } $operation->edit($event_array['type'], $event_array['id'], $event_array['amount'], $event_array['date'], $event_array['category'], $event_array['comment'], $event_array['account'], $event_array['tags'], $event_array['accepted'], $notifications); } elseif ($event_array['type'] == 2) { $operation->editTransfer($event_array['id'], $event_array['amount'], $event_array['convert'], $event_array['date'], $event_array['account'], $event_array['toAccount'], $event_array['comment'], $event_array['tags'], $event_array['accepted'], $notifications); } $this->tpl->assign('result', array('text' => 'Регулярная операция изменена')); } else { $calendar = new Calendar($user); $calendar->edit($event); $this->tpl->assign('result', array('text' => 'Регулярные операции изменены')); } // @FIXME Перенести этот блок кода в календарь Core::getInstance()->user->initUserEvents(); Core::getInstance()->user->save(); $this->tpl->assign('future', Core::getInstance()->user->getUserEvents('reminder')); $this->tpl->assign('overdue', Core::getInstance()->user->getUserEvents('overdue')); $this->tpl->assign('calendar', Core::getInstance()->user->getUserEvents('calendar')); } }
/** * Подтверждает события * @param array int */ public function acceptEvents($ids) { $overdue = Core::getInstance()->user->getUserEvents('overdue'); $future = Core::getInstance()->user->getUserEvents('future'); $calendar = Core::getInstance()->user->getUserEvents('calendar'); $newIds = array(); foreach ($ids as $id) { if (isset($overdue[$id])) { $operation = $overdue[$id]; } elseif (isset($future[$id])) { $operation = $future[$id]; } elseif (isset($calendar[$id])) { $operation = $calendar[$id]; } else { $this->_errors['error'] = "Не найдена операция для подтверждения"; } $operation['accepted'] = 1; $operation['category'] = $operation['cat_id']; $operation['account'] = $operation['account_id']; $operation['toAccount'] = $operation['transfer']; $operation['amount'] = $operation['money']; $event = new Calendar_Event(new Calendar_Model($operation, Core::getInstance()->user), Core::getInstance()->user); if (!$event->checkData()) { $this->_errors = array_merge($this->_errors, $event->getErrors()); } else { $newIds[] = $id; } } if (count($newIds) > 0) { // Получаем список событий, отмечаем что они выполненные return Calendar_Model::acceptEvents($this->_user, $newIds); } else { return false; } }