* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved. * @license GNU General Public License version 3 or later; see LICENSE * SPDX-License-Identifier: GPL-3.0-or-later */ namespace Joomla\Component\MokoSuiteCross\Administrator\Model; defined('_JEXEC') or die; use Joomla\CMS\Factory; use Joomla\CMS\MVC\Model\AdminModel; class PostModel extends AdminModel { public function getForm($data = [], $loadData = true) { $form = $this->loadForm( 'com_mokosuitecross.post', 'post', ['control' => 'jform', 'load_data' => $loadData] ); if (empty($form)) { return false; } // Lock article_id and service_id on existing records $id = $this->getState('post.id', 0); if ($id > 0) { $form->setFieldAttribute('article_id', 'readonly', 'true'); $form->setFieldAttribute('service_id', 'readonly', 'true'); } return $form; } protected function loadFormData() { return $this->getItem(); } /** * Prepare and sanitise the table prior to saving. */ protected function prepareTable($table) { $now = Factory::getDate()->toSql(); // Validate scheduled_at datetime format if (!empty($table->scheduled_at)) { try { $date = Factory::getDate($table->scheduled_at); $table->scheduled_at = $date->toSql(); } catch (\Throwable $e) { $table->scheduled_at = null; } } if (empty($table->id)) { $table->created = $now; $table->modified = $now; if (empty($table->status)) { $table->status = empty($table->scheduled_at) ? 'queued' : 'scheduled'; } if (empty($table->retry_count)) { $table->retry_count = 0; } if (empty($table->platform_post_id)) { $table->platform_post_id = ''; } if (empty($table->platform_response)) { $table->platform_response = ''; } if (empty($table->error_message)) { $table->error_message = ''; } } else { $table->modified = $now; } } }