Special note if you are using a custom buildQuery with JOINs or field aliases:
You will need to override the recordDataToDatabaseData method. Make sure that you _remove_ or rename any fields
which do not exist in the table defined in $this->tableName. Otherwise Joomla! will not know how to insert /
update the data on the table and will throw an Exception denoting a database error. It is generally a BAD idea
using JOINs instead of relations. If unsure, use relations.
public save ( null | array $data = null, string $orderingFilter = '', array $ignore = null, $resetRelations = true ) : |
||
$data | null | array | [Optional] Data to bind |
$orderingFilter | string | A WHERE clause used to apply table item reordering |
$ignore | array | A list of fields to ignore when binding $data |
return | Self, for chaining |
/** * Publish or unpublish a DataModel item based on its publish_up / publish_down fields * * @param DataModel $row The DataModel to publish/unpublish * * @return void */ protected function publishByDate(DataModel $row) { static $uNow = null; \JLoader::import('joomla.utilities.date'); if (is_null($uNow)) { $jNow = new \JDate(); $uNow = $jNow->toUnix(); } $db = $this->container->db; $triggered = false; if ($row->publish_down && $row->publish_down != $db->getNullDate()) { $publish_down = $this->normaliseDate($row->publish_down, '2038-01-18 00:00:00'); $publish_up = $this->normaliseDate($row->publish_up, '2001-01-01 00:00:00'); $jDown = new \JDate($publish_down); $jUp = new \JDate($publish_up); if ($uNow >= $jDown->toUnix() && $row->enabled) { $row->enabled = 0; $triggered = true; } elseif ($uNow >= $jUp->toUnix() && !$row->enabled && $uNow < $jDown->toUnix()) { $row->enabled = 1; $triggered = true; } } if ($triggered) { $row->save(); } }