362ce47e71
Complete the Post CRUD that was previously stub-only: - PostModel (AdminModel) for loading/saving individual posts - Post HtmlView with toolbar (apply, save, cancel, dashboard) - post.xml form with article selector, service selector, message textarea, status dropdown, and scheduled_at calendar picker - Post edit template with results sidebar and re-queue button - Posts list: New button in toolbar, clickable article titles, scheduled_at display with clock icon - 20 new language strings for the post edit UI Authored-by: Moko Consulting Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
84 lines
2.1 KiB
PHP
84 lines
2.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @package MokoJoomCross
|
|
* @subpackage com_mokojoomcross
|
|
* @author Moko Consulting <hello@mokoconsulting.tech>
|
|
* @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\MokoJoomCross\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_mokojoomcross.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();
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|