/** * Save history that associated with form data * * @param JSession $session * @param mixed $post * @param string $pageKey * @param string $title * * @return int ID of saved history */ private function saveByPost($session, $post, $pageKey, $title) { if (!$session->has($post['postSessionKey'])) { return; } $formData = $session->get($post['postSessionKey']); $formHash = md5($formData); $form = json_decode($formData); $id = $form->cid; if (is_array($id)) { $id = array_shift($id); } $userId = JFactory::getUser()->id; $history = JTable::getInstance('History', 'PowerAdminTable'); $history->load(array('user_id' => $userId, 'object_key' => $pageKey, 'object_id' => $id)); if ($history->id == null) { $history->bind(array('user_id' => $userId, 'object_key' => $pageKey, 'object_id' => $id)); } $history->bind(array('title' => $title, 'visited' => time(), 'form' => $formData, 'form_hash' => $formHash, 'component' => empty($history->component) && !empty($post['parent']) ? $post['parent'] : $history->component, 'list_page' => empty($history->list_page) && !empty($post['name']) ? $post['name'] : $history->list_page, 'list_page_params' => empty($history->list_page_params) && !empty($post['params']) ? $post['params'] : $history->list_page_params, 'icon' => empty($history->icon) && !empty($post['iconPath']) ? $post['iconPath'] : $history->icon, 'css' => empty($history->css) && !empty($post['iconCss']) ? $post['iconCss'] : $history->css)); $history->description = $post['description']; $history->store(); return $history->id; }