Invio Email
This commit is contained in:
@ -1,6 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<config>
|
||||
<fieldset label="COM_CIRCOLARI" name="circolari">
|
||||
<field
|
||||
name="email_oggetto"
|
||||
type="text"
|
||||
label="Oggetto email"
|
||||
description="Testo email diretta ai docenti per la firma"
|
||||
rows="8"
|
||||
cols="60"
|
||||
filter="raw" />
|
||||
<field
|
||||
name="email_testo"
|
||||
type="textarea"
|
||||
|
||||
@ -9,10 +9,7 @@
|
||||
<option value="-2">JTRASHED</option>
|
||||
</field>
|
||||
<field name="ordering" type="number" default="0" />
|
||||
<field name="checked_out" type="hidden" filter="unset" />
|
||||
<field name="checked_out_time" type="hidden" filter="unset" />
|
||||
<field name="created_by" type="createdby" hidden="true" />
|
||||
<field name="modified_by" type="modifiedby" hidden="true" />
|
||||
|
||||
|
||||
<field name="title" type="text" label="JGLOBAL_TITLE" required="true" filter="safehtml" />
|
||||
<field name="alias" type="text" label="JFIELD_ALIAS_LABEL" description="JFIELD_ALIAS_DESC" />
|
||||
@ -51,7 +48,57 @@
|
||||
showon="firma_obbligatoria:1" />
|
||||
<field name="scadenza" type="CalSafe" label="Data Scadenza Firma"
|
||||
showon="firma_obbligatoria:1" />
|
||||
|
||||
<field name="hits" type="number" readonly="true" label="JGLOBAL_HITS" default="0" />
|
||||
<field name="notify" type="radio"
|
||||
label="Invia email"
|
||||
description="Se Sì, invia subito una email ai gruppi selezionati"
|
||||
default="0"
|
||||
filter="unset"
|
||||
showon="firma_obbligatoria:1"
|
||||
layout="joomla.form.field.radio.switcher">
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
</fieldset>
|
||||
|
||||
<fieldset name="publishing" label="PUBBLICAZIONE">
|
||||
<field name="hits" type="number" readonly="true" label="JGLOBAL_HITS" default="0" />
|
||||
<field name="created"
|
||||
type="CalSafe"
|
||||
label="JGLOBAL_FIELD_CREATED_LABEL"
|
||||
readonly="true" />
|
||||
|
||||
<field name="created_by"
|
||||
type="createdby"
|
||||
label="JGLOBAL_FIELD_CREATED_BY_LABEL"
|
||||
readonly="true" />
|
||||
|
||||
<field name="modified"
|
||||
type="CalSafe"
|
||||
label="JGLOBAL_FIELD_MODIFIED_LABEL"
|
||||
readonly="true" />
|
||||
|
||||
<field name="modified_by"
|
||||
type="modifiedby"
|
||||
label="JGLOBAL_FIELD_MODIFIED_BY_LABEL"
|
||||
readonly="true" />
|
||||
|
||||
<field name="publish_up"
|
||||
type="CalSafe"
|
||||
label="JGLOBAL_FIELD_PUBLISH_UP_LABEL"
|
||||
description="Data/ora di pubblicazione"
|
||||
showtime="true"
|
||||
format="Y-m-d H:i:s"
|
||||
translateformat="0"
|
||||
filter="raw" />
|
||||
|
||||
<field name="publish_down"
|
||||
type="CalSafe"
|
||||
label="JGLOBAL_FIELD_PUBLISH_DOWN_LABEL"
|
||||
description="Data/ora di dispubblicazione"
|
||||
showtime="true"
|
||||
format="Y-m-d H:i:s"
|
||||
translateformat="0"
|
||||
filter="raw" />
|
||||
</fieldset>
|
||||
|
||||
</form>
|
||||
5
administrator/sql/updates/1.1.9.sql
Normal file
5
administrator/sql/updates/1.1.9.sql
Normal file
@ -0,0 +1,5 @@
|
||||
ALTER TABLE `#__circolari`
|
||||
ADD COLUMN `created` DATETIME NULL DEFAULT NULL AFTER `checked_out_time`,
|
||||
ADD COLUMN `modified` DATETIME NULL DEFAULT NULL AFTER `created_by`,
|
||||
ADD COLUMN `publish_up` DATETIME NULL DEFAULT NULL AFTER `modified_by`,
|
||||
ADD COLUMN `publish_down` DATETIME NULL DEFAULT NULL AFTER `publish_up`;
|
||||
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Circolari
|
||||
@ -13,6 +14,7 @@ namespace Pcrt\Component\Circolari\Administrator\Controller;
|
||||
|
||||
use Joomla\CMS\MVC\Controller\FormController;
|
||||
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
|
||||
use Pcrt\Component\Circolari\Administrator\Service\Notifier;
|
||||
|
||||
/**
|
||||
* Circolare controller class.
|
||||
@ -24,11 +26,36 @@ class CircolareController extends FormController
|
||||
protected $view_list = 'circolares';
|
||||
protected $view_item = 'circolare';
|
||||
|
||||
|
||||
|
||||
public function __construct($config = array(), MVCFactoryInterface $factory = null, $app = null, $input = null)
|
||||
{
|
||||
parent::__construct($config, $factory, $app, $input);
|
||||
$this->registerTask('apply', 'save');
|
||||
$this->registerTask('save2new', 'save');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function save($key = null, $urlVar = null)
|
||||
{
|
||||
$app = \Joomla\CMS\Factory::getApplication();
|
||||
$input = $app->input;
|
||||
$post = $input->get('jform', [], 'array');
|
||||
$notify= (int)($post['notify'] ?? 0);
|
||||
|
||||
$result = parent::save($key, $urlVar);
|
||||
|
||||
if ($result && $notify) {
|
||||
$model = $this->getModel('Circolare');
|
||||
$id = (int) $model->getState($model->getName().'.id') ?: (int)($post['id'] ?? 0);
|
||||
if ($id <= 0) {
|
||||
$db = \Joomla\CMS\Factory::getContainer()->get('DatabaseDriver');
|
||||
$id = (int) $db->insertid();
|
||||
}
|
||||
if ($id > 0) {
|
||||
(new Notifier())->sendForCircolare($id, ['onlyIfFirmaObbligatoria' => true]);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
61
administrator/src/Service/Notifier.php
Normal file
61
administrator/src/Service/Notifier.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Circolari
|
||||
* @author Tommaso Cippitelli <tommaso.cippitelli@protocollicreativi.it>
|
||||
* @copyright 2025 Tommaso Cippitelli
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Pcrt\Component\Circolari\Administrator\Controller;
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\MVC\Controller\FormController;
|
||||
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
|
||||
use Pcrt\Component\Circolari\Administrator\Service\Notifier;
|
||||
|
||||
/**
|
||||
* Circolare controller class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class CircolareController extends FormController
|
||||
{
|
||||
protected $view_list = 'circolares';
|
||||
protected $view_item = 'circolare';
|
||||
|
||||
|
||||
public function __construct($config = array(), MVCFactoryInterface $factory = null, $app = null, $input = null)
|
||||
{
|
||||
parent::__construct($config, $factory, $app, $input);
|
||||
$this->registerTask('apply', 'save');
|
||||
$this->registerTask('save2new', 'save');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function save($key = null, $urlVar = null)
|
||||
{
|
||||
$app = \Joomla\CMS\Factory::getApplication();
|
||||
$input = $app->input;
|
||||
$post = $input->get('jform', [], 'array');
|
||||
$notify= (int)($post['notify'] ?? 0);
|
||||
|
||||
$result = parent::save($key, $urlVar);
|
||||
|
||||
if ($result && $notify) {
|
||||
$model = $this->getModel('Circolare');
|
||||
$id = (int) $model->getState($model->getName().'.id') ?: (int)($post['id'] ?? 0);
|
||||
if ($id <= 0) {
|
||||
$db = \Joomla\CMS\Factory::getContainer()->get('DatabaseDriver');
|
||||
$id = (int) $db->insertid();
|
||||
}
|
||||
if ($id > 0) {
|
||||
(new Notifier())->sendForCircolare($id, ['onlyIfFirmaObbligatoria' => true]);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@ -153,12 +153,64 @@ class CircolareTable extends Table implements VersionableTableInterface, Taggabl
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function store($updateNulls = true)
|
||||
{
|
||||
public function store($updateNulls = true)
|
||||
{
|
||||
$now = Factory::getDate()->toSql();
|
||||
$user = Factory::getUser();
|
||||
|
||||
$isNew = empty($this->id);
|
||||
|
||||
return parent::store($updateNulls);
|
||||
}
|
||||
if ($isNew) {
|
||||
// created/created_by
|
||||
if (empty($this->created)) { $this->created = $now; }
|
||||
if (empty($this->created_by)) { $this->created_by = (int) $user->id; }
|
||||
|
||||
// Se nasce già pubblicata, imposta publish_up
|
||||
if ((int) ($this->state ?? 0) === 1 && empty($this->publish_up)) {
|
||||
$this->publish_up = $now;
|
||||
}
|
||||
} else {
|
||||
// modified/modified_by
|
||||
$this->modified = $now;
|
||||
if (property_exists($this, 'modified_by')) {
|
||||
$this->modified_by = (int) $user->id;
|
||||
}
|
||||
|
||||
// Rileva cambio di stato per publish_up / publish_down
|
||||
$db = $this->getDbo();
|
||||
$q = $db->getQuery(true)
|
||||
->select($db->quoteName(['state','publish_up']))
|
||||
->from($db->quoteName('#__circolari'))
|
||||
->where($db->quoteName('id') . ' = ' . (int) $this->id);
|
||||
$db->setQuery($q);
|
||||
$old = (array) $db->loadAssoc();
|
||||
|
||||
if ($old) {
|
||||
$oldState = (int) ($old['state'] ?? 0);
|
||||
$newState = (int) ($this->state ?? 0);
|
||||
|
||||
if ($oldState !== $newState) {
|
||||
// Passaggio a PUBBLICATA → publish_up (se non già impostata)
|
||||
if ($newState === 1 && empty($this->publish_up)) {
|
||||
$this->publish_up = $now;
|
||||
}
|
||||
// Passaggio da PUBBLICATA a NON pubblicata → publish_down ora
|
||||
if ($oldState === 1 && $newState !== 1) {
|
||||
$this->publish_down = $now;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Normalizza ancora (nel caso abbiamo appena impostato date)
|
||||
foreach (['scadenza','created','modified','publish_up','publish_down'] as $f) {
|
||||
if (isset($this->$f)) {
|
||||
$this->$f = self::normalizeDate($this->$f);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::store($updateNulls);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function convert an array of Access objects into an rules array.
|
||||
@ -281,6 +333,12 @@ class CircolareTable extends Table implements VersionableTableInterface, Taggabl
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (['scadenza','created','modified','publish_up','publish_down'] as $f) {
|
||||
if (isset($this->$f)) {
|
||||
$this->$f = self::normalizeDate($this->$f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return parent::check();
|
||||
}
|
||||
@ -360,4 +418,29 @@ class CircolareTable extends Table implements VersionableTableInterface, Taggabl
|
||||
$this->_db->setQuery($q);
|
||||
return ((int) $this->_db->loadResult()) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizza varie date in formato SQL
|
||||
*/
|
||||
protected static function normalizeDate(?string $raw): ?string
|
||||
{
|
||||
if ($raw === null) return null;
|
||||
$raw = trim((string) $raw);
|
||||
if ($raw === '' || $raw === '0000-00-00 00:00:00') return null;
|
||||
|
||||
$raw = str_replace('T', ' ', substr($raw, 0, 19));
|
||||
foreach (['Y-m-d H:i:s','Y-m-d H:i','d-m-Y H:i:s','d-m-Y H:i','Y-m-d'] as $fmt) {
|
||||
$dt = \DateTime::createFromFormat($fmt, $raw);
|
||||
if ($dt instanceof \DateTime) {
|
||||
return $dt->format('Y-m-d H:i:s');
|
||||
}
|
||||
}
|
||||
try {
|
||||
$dt = new \DateTime($raw);
|
||||
return $dt->format('Y-m-d H:i:s');
|
||||
} catch (\Throwable $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -37,21 +37,38 @@ HTMLHelper::_('bootstrap.tooltip');
|
||||
<?php echo $this->form->renderField('title'); ?>
|
||||
<?php echo $this->form->renderField('alias'); ?>
|
||||
<?php echo $this->form->renderField('categoria_id'); ?>
|
||||
<?php echo $this->form->renderField('hits'); ?>
|
||||
<?php echo $this->form->renderField('description'); ?>
|
||||
<?php echo $this->form->renderField('attachment'); ?>
|
||||
<?php echo $this->form->renderField('image'); ?>
|
||||
<?php echo $this->form->renderField('firma_obbligatoria'); ?>
|
||||
<?php echo $this->form->renderField('usergroup_ids'); ?>
|
||||
<?php echo $this->form->renderField('scadenza'); ?>
|
||||
<?php echo $this->form->renderField('notify'); ?>
|
||||
</fieldset>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<?php echo HTMLHelper::_('uitab.endTab'); ?>
|
||||
<?php echo \Joomla\CMS\HTML\HTMLHelper::_('uitab.addTab', 'myTab', 'publishing', Text::_('Pubblicazione', true)); ?>
|
||||
<div class="row-fluid">
|
||||
<div class="col-md-12 form-horizontal">
|
||||
<fieldset class="adminform">
|
||||
<legend><?php echo Text::_('Pubblicazione'); ?></legend>
|
||||
<?php echo $this->form->renderField('hits'); ?>
|
||||
<?php echo $this->form->renderField('created'); ?>
|
||||
<?php echo $this->form->renderField('created_by'); ?>
|
||||
<?php echo $this->form->renderField('modified'); ?>
|
||||
<?php echo $this->form->renderField('modified_by'); ?>
|
||||
<?php echo $this->form->renderField('publish_up'); ?>
|
||||
<?php echo $this->form->renderField('publish_down'); ?>
|
||||
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
<?php echo \Joomla\CMS\HTML\HTMLHelper::_('uitab.endTab'); ?>
|
||||
|
||||
<input type="hidden" name="jform[id]" value="<?php echo isset($this->item->id) ? $this->item->id : ''; ?>" />
|
||||
<input type="hidden" name="jform[state]" value="<?php echo isset($this->item->state) ? $this->item->state : ''; ?>" />
|
||||
<?php echo $this->form->renderField('created_by'); ?>
|
||||
<?php echo $this->form->renderField('modified_by'); ?>
|
||||
<?php echo HTMLHelper::_('uitab.endTabSet'); ?>
|
||||
<input type="hidden" name="task" value="" />
|
||||
<?php echo HTMLHelper::_('form.token'); ?>
|
||||
|
||||
Reference in New Issue
Block a user