Actualización
This commit is contained in:
16
plugin/send_notification_new_lp/README.md
Normal file
16
plugin/send_notification_new_lp/README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
Mailing new LPs to students and their HR Managers
|
||||
======
|
||||
|
||||
This plugin allows you to enable sending of emails to students and their human
|
||||
resources managers when a new learning path (LP) is published.
|
||||
|
||||
When enabling this plugin, it adds a checkbox in the LP's configuration page
|
||||
to define whether the LP publication should be notified to the learners
|
||||
|
||||
For its operation, it is necessary to have an extra field
|
||||
'notify_student_and_hrm_when_available' with 'default_value' equal to 1, which
|
||||
will enable the possibility of executing the main/cron/learning_path_reminder.php
|
||||
cron to send the emails to the users registered in the lp and to their hr.
|
||||
|
||||
It is recommended that it be run once a day since it evaluates all learning paths
|
||||
in the range from 0:00 to 23:59.
|
||||
174
plugin/send_notification_new_lp/SendNotificationToPublishLp.php
Normal file
174
plugin/send_notification_new_lp/SendNotificationToPublishLp.php
Normal file
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Class SendNotificationToPublishLp.
|
||||
*/
|
||||
class SendNotificationToPublishLp extends Plugin
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $notifyStudentField;
|
||||
|
||||
/**
|
||||
* SendNotificationToPublishLp constructor.
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
$this->tblExtraFieldOption = Database::get_main_table(TABLE_EXTRA_FIELD_OPTIONS);
|
||||
parent::__construct(
|
||||
'1.0',
|
||||
'Carlos Alvarado'
|
||||
);
|
||||
$field = new ExtraField('lp');
|
||||
$notifyStudentField = $field->get_handler_field_info_by_field_variable('notify_student_and_hrm_when_available');
|
||||
|
||||
if (empty($notifyStudentField)) {
|
||||
$notifyStudentField = [
|
||||
'field_type' => ExtraField::FIELD_TYPE_RADIO,
|
||||
'variable' => 'notify_student_and_hrm_when_available',
|
||||
'display_text' => 'NotifyStudentAndHrmWhenAvailable',
|
||||
'default_value' => 0,
|
||||
'field_order' => 0,
|
||||
'visible_to_self' => 1,
|
||||
'visible_to_others' => 1,
|
||||
'changeable' => 1,
|
||||
'filter' => 0,
|
||||
];
|
||||
}
|
||||
$this->notifyStudentField = $notifyStudentField;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of SendNotificationToPublishLp.
|
||||
*
|
||||
* @return SendNotificationToPublishLp
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
static $result = null;
|
||||
|
||||
return $result ? $result : $result = new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the plugin installation.
|
||||
*/
|
||||
public function install()
|
||||
{
|
||||
$this->saveNotificationField();
|
||||
$this->setNotifyExtrafieldData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the arrangement for notify_student_and_hrm_when_available, it is adjusted internally so that the values
|
||||
* match the necessary ones.
|
||||
*/
|
||||
public function saveNotificationField()
|
||||
{
|
||||
$schedule = new ExtraField('lp');
|
||||
$data = $this->getDataNotificationField();
|
||||
$data['default_value'] = 0;
|
||||
$data['visible_to_self'] = 1;
|
||||
$data['visible_to_others'] = 1;
|
||||
$data['changeable'] = 1;
|
||||
if (isset($data['id'])) {
|
||||
$schedule->update($data);
|
||||
} else {
|
||||
$schedule->save($data);
|
||||
}
|
||||
$field = new ExtraField('lp');
|
||||
$notifyStudentField = $field->get_handler_field_info_by_field_variable('notify_student_and_hrm_when_available');
|
||||
$this->notifyStudentField = $notifyStudentField;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a array clean of notify_student_and_hrm_when_available.
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
public function getDataNotificationField($install = true)
|
||||
{
|
||||
$data = $this->notifyStudentField;
|
||||
|
||||
$data['field_type'] = ExtraField::FIELD_TYPE_RADIO;
|
||||
$data['field_order'] = isset($data['field_order']) ? $data['field_order'] : $data['field_order']; // at
|
||||
$data['variable'] = isset($data['variable']) ? $data['variable'] : 'notify_student_and_hrm_when_available';
|
||||
$data['display_text'] = isset($data['display_text']) ? $data['display_text'] : 'NotifyStudentAndHrmWhenAvailable';
|
||||
$data['default_value'] = (int) $install;
|
||||
$data['field_order'] = isset($data['field_order']) ? $data['field_order'] : 0;
|
||||
$data['visible_to_self'] = isset($data['visible_to_self']) ? $data['visible_to_self'] : 0;
|
||||
$data['visible_to_others'] = isset($data['visible_to_others']) ? $data['visible_to_others'] : 0;
|
||||
$data['changeable'] = isset($data['changeable']) ? $data['changeable'] : 0;
|
||||
$data['filter'] = isset($data['filter']) ? $data['filter'] : 0;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default_value to 0.
|
||||
*/
|
||||
public function uninstall()
|
||||
{
|
||||
$schedule = new ExtraField('lp');
|
||||
$data = $this->getDataNotificationField(false);
|
||||
$data['default_value'] = 0;
|
||||
$data['visible_to_self'] = 0;
|
||||
$data['visible_to_others'] = 0;
|
||||
$data['changeable'] = 0;
|
||||
if (isset($data['id'])) {
|
||||
$schedule->update($data);
|
||||
} else {
|
||||
$schedule->save($data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the option fields for notify with the generic values yes or not.
|
||||
*/
|
||||
public function setNotifyExtrafieldData()
|
||||
{
|
||||
$options = [
|
||||
0 => get_lang('No'),
|
||||
1 => get_lang('Yes'),
|
||||
];
|
||||
$notifyId = (int) $this->notifyStudentField['id'];
|
||||
if ($notifyId != 0) {
|
||||
for ($i = 0; $i < count($options); $i++) {
|
||||
$order = $i + 1;
|
||||
$extraFieldOptionValue = $options[$i];
|
||||
$query = "SELECT *
|
||||
FROM ".$this->tblExtraFieldOption."
|
||||
WHERE
|
||||
option_value = $i AND
|
||||
field_id = $notifyId";
|
||||
|
||||
$extraFieldOption = Database::fetch_assoc(Database::query($query));
|
||||
$extraFieldId = isset($extraFieldOption['id']) ? (int) ($extraFieldOption['id']) : 0;
|
||||
|
||||
if (
|
||||
$extraFieldId != 0
|
||||
&& $extraFieldOption['field_id'] == $notifyId) {
|
||||
// Update?
|
||||
$query = "UPDATE ".$this->tblExtraFieldOption."
|
||||
SET
|
||||
option_value = $i,
|
||||
option_order = $order,
|
||||
display_text = '$extraFieldOptionValue'
|
||||
WHERE
|
||||
field_id = $notifyId
|
||||
AND id = $extraFieldId";
|
||||
} else {
|
||||
$query = "
|
||||
INSERT INTO ".$this->tblExtraFieldOption."
|
||||
(field_id, option_value, display_text, priority, priority_message, option_order) VALUES
|
||||
( '$notifyId', $i, '$extraFieldOptionValue', NULL, NULL, '$order');
|
||||
";
|
||||
}
|
||||
Database::query($query);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
plugin/send_notification_new_lp/index.php
Normal file
3
plugin/send_notification_new_lp/index.php
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
10
plugin/send_notification_new_lp/install.php
Normal file
10
plugin/send_notification_new_lp/install.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
// Check extra_field remedialcourselist and advancedCourseList
|
||||
|
||||
if (!api_is_platform_admin()) {
|
||||
exit('You must have admin permissions to install plugins');
|
||||
}
|
||||
SendNotificationToPublishLp::create()->install();
|
||||
20
plugin/send_notification_new_lp/plugin.php
Normal file
20
plugin/send_notification_new_lp/plugin.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* This script is a configuration file for the date plugin. You can use it as a master for other platform plugins
|
||||
* (course plugins are slightly different).
|
||||
* These settings will be used in the administration interface for plugins (Chamilo configuration settings->Plugins).
|
||||
*
|
||||
* @package chamilo.plugin
|
||||
*
|
||||
* @author Carlos Alvarado <alvaradocarlo@gmail.com>
|
||||
*/
|
||||
/**
|
||||
* Plugin details (must be present).
|
||||
*/
|
||||
$plugin_info['title'] = 'Mailing new LPs to students and their HR Managers';
|
||||
$plugin_info['comment'] = 'Add the ability to send emails to students and hr when a lp is published. It will be sent in each execution of the respective cron "main/cron/learning_path_reminder.php"';
|
||||
$plugin_info['version'] = '1.0';
|
||||
$plugin_info['author'] = 'Carlos Alvarado';
|
||||
10
plugin/send_notification_new_lp/uninstall.php
Normal file
10
plugin/send_notification_new_lp/uninstall.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
require_once 'SendNotificationToPublishLp.php';
|
||||
|
||||
if (!api_is_platform_admin()) {
|
||||
exit('You must have admin permissions to uninstall plugins');
|
||||
}
|
||||
SendNotificationToPublishLp::create()->uninstall();
|
||||
Reference in New Issue
Block a user