dolibarr/htdocs/comm/action/class/actioncommreminder.class.php

275 lines
9.4 KiB
PHP
Raw Permalink Normal View History

2017-10-31 23:10:29 +01:00
<?php
/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
2017-10-31 23:10:29 +01:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2017-10-31 23:10:29 +01:00
*/
/**
* \file htdocs/comm/action/class/actioncommreminder.class.php
2017-10-31 23:10:29 +01:00
* \ingroup agenda
* \brief This file is a CRUD class file for ActionCommReminder (Create/Read/Update/Delete)
*/
// Put here all includes required by your class file
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
2017-10-31 23:10:29 +01:00
/**
* Class for ActionCommReminder
*/
class ActionCommReminder extends CommonObject
{
/**
* @var string ID to identify managed object
*/
public $element = 'actioncomm_reminder';
2018-09-02 09:27:59 +02:00
2017-10-31 23:10:29 +01:00
/**
* @var string Name of table without prefix where object is stored
*/
public $table_element = 'actioncomm_reminder';
2018-09-02 09:27:59 +02:00
2017-10-31 23:10:29 +01:00
/**
* @var string String with name of icon for actioncommreminder. Must be the part after the 'object_' into object_actioncommreminder.png
*/
public $picto = 'generic';
const STATUS_TODO = 0;
const STATUS_DONE = 1;
2020-11-21 17:42:07 +01:00
const STATUS_ERROR = -1;
2017-10-31 23:10:29 +01:00
/**
* 'type' if the field format.
* 'label' the translation key.
* 'enabled' is a condition when the field must be managed.
* 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only. Using a negative value means field is not shown by default on list but can be selected for viewing)
* 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
* 'index' if we want an index in database.
2019-02-10 12:59:09 +01:00
* 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommended to name the field fk_...).
2017-10-31 23:10:29 +01:00
* 'position' is the sort order of field.
* 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
* 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
* 'help' is a string visible as a tooltip on field
* 'comment' is not used. You can store here any text of your choice. It is not used by application.
* 'default' is a default value for creation (can still be replaced by the global setup of default values)
* 'showoncombobox' if field must be shown into the label of combobox
*/
2023-03-02 14:13:17 +01:00
// BEGIN MODULEBUILDER PROPERTIES
2017-10-31 23:10:29 +01:00
/**
* @var array<string,array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int<-6,6>|string,alwayseditable?:int<0,1>,noteditable?:int<0,1>,default?:string,index?:int,foreignkey?:string,searchall?:int<0,1>,isameasure?:int<0,1>,css?:string,csslist?:string,help?:string,showoncombobox?:int<0,4>,disabled?:int<0,1>,arrayofkeyval?:array<int|string,string>,autofocusoncreate?:int<0,1>,comment?:string,copytoclipboard?:int<1,2>,validate?:int<0,1>,showonheader?:int<0,1>}> Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
2017-10-31 23:10:29 +01:00
*/
public $fields = array(
'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'visible' => -1, 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'index' => 1, 'comment' => "Id",),
'entity' => array('type' => 'integer', 'label' => 'Entity', 'visible' => 0, 'enabled' => 1, 'position' => 20, 'notnull' => 1, 'index' => 1,),
'dateremind' => array('type' => 'datetime', 'label' => 'DateRemind', 'visible' => 1, 'enabled' => 1, 'position' => 60, 'notnull' => 1, 'index' => 1,),
'typeremind' => array('type' => 'varchar(32)', 'label' => 'TypeRemind', 'visible' => -1, 'enabled' => 1, 'position' => 55, 'notnull' => 1, 'comment' => "email, browser, sms",),
'fk_user' => array('type' => 'integer', 'label' => 'User', 'visible' => -1, 'enabled' => 1, 'position' => 65, 'notnull' => 1, 'index' => 1,),
'offsetvalue' => array('type' => 'integer', 'label' => 'OffsetValue', 'visible' => 1, 'enabled' => 1, 'position' => 56, 'notnull' => 1,),
'offsetunit' => array('type' => 'varchar(1)', 'label' => 'OffsetUnit', 'visible' => 1, 'enabled' => 1, 'position' => 57, 'notnull' => 1, 'comment' => "y, m, d, w, h, i",),
2024-03-15 00:10:44 +01:00
'status' => array('type' => 'integer', 'label' => 'Status', 'visible' => 1, 'enabled' => 1, 'position' => 58, 'notnull' => 1, 'default' => '0', 'index' => 0, 'arrayofkeyval' => array('0' => 'ToDo', '1' => 'Done')),
'lasterror' => array('type' => 'varchar(128)', 'label' => 'LastError', 'visible' => -1, 'enabled' => 1, 'position' => 59, 'index' => 0),
'fk_actioncomm' => array('type' => 'integer', 'label' => 'Project', 'visible' => 1, 'enabled' => 1, 'position' => 70, 'notnull' => 1, 'index' => 1,),
'fk_email_template' => array('type' => 'integer', 'label' => 'EmailTemplate', 'visible' => 1, 'enabled' => 1, 'position' => 80, 'notnull' => 0),
2017-10-31 23:10:29 +01:00
);
2018-10-09 08:53:08 +02:00
/**
* @var int ID
*/
2017-10-31 23:10:29 +01:00
public $rowid;
2018-10-09 08:53:08 +02:00
/**
* @var int Entity
*/
public $entity;
/**
* @var int date remind
*/
2017-10-31 23:10:29 +01:00
public $dateremind;
2023-02-28 08:56:38 +01:00
/**
* @var string reminder type email, browser, sms
*/
2017-10-31 23:10:29 +01:00
public $typeremind;
2018-08-31 17:55:31 +02:00
/**
* @var int User ID
*/
2017-10-31 23:10:29 +01:00
public $fk_user;
2018-08-31 17:55:31 +02:00
2023-02-28 08:56:38 +01:00
/**
* @var int offset value
*/
2017-10-31 23:10:29 +01:00
public $offsetvalue;
2023-02-28 08:56:38 +01:00
/**
* @var string y, m, d, w, h, i
*/
2017-10-31 23:10:29 +01:00
public $offsetunit;
2018-10-05 15:48:38 +02:00
/**
* @var int Status
*/
2017-10-31 23:10:29 +01:00
public $status;
2018-10-05 15:48:38 +02:00
2020-11-21 17:42:07 +01:00
/**
* @var string Last error message
*/
public $lasterror;
/**
* @var int Project
*/
public $fk_actioncomm;
2020-08-26 16:06:20 +02:00
/**
* @var int Template Mail
*/
public $fk_email_template;
2023-03-02 14:13:17 +01:00
// END MODULEBUILDER PROPERTIES
2020-08-26 16:06:20 +02:00
2024-09-13 15:58:26 +02:00
2017-10-31 23:10:29 +01:00
/**
* Constructor
*
* @param DoliDB $db Database handler
2017-10-31 23:10:29 +01:00
*/
public function __construct(DoliDB $db)
{
$this->db = $db;
$this->ismultientitymanaged = 0;
2023-11-27 11:39:32 +01:00
if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
2021-02-23 18:59:19 +01:00
$this->fields['rowid']['visible'] = 0;
}
2022-08-28 13:43:50 +02:00
if (!isModEnabled('multicompany')) {
2021-02-23 18:59:19 +01:00
$this->fields['entity']['enabled'] = 0;
}
2017-10-31 23:10:29 +01:00
}
/**
* Create object into database
*
* @param User $user User that creates
* @param int $notrigger 0=launch triggers after, 1=disable triggers
2023-12-01 19:51:32 +01:00
* @return int Return integer <0 if KO, Id of created object if OK
2017-10-31 23:10:29 +01:00
*/
public function create(User $user, $notrigger = 0)
2017-10-31 23:10:29 +01:00
{
return $this->createCommon($user, $notrigger);
}
/**
* Load object in memory from the database
*
* @param int $id Id object
* @param string $ref Ref
2023-12-01 19:51:32 +01:00
* @return int Return integer <0 if KO, 0 if not found, >0 if OK
2017-10-31 23:10:29 +01:00
*/
public function fetch($id, $ref = null)
{
$result = $this->fetchCommon($id, $ref);
return $result;
}
/**
* Update object into database
*
* @param User $user User that modifies
* @param int $notrigger 0=launch triggers after, 1=disable triggers
2023-12-01 19:51:32 +01:00
* @return int Return integer <0 if KO, >0 if OK
2017-10-31 23:10:29 +01:00
*/
public function update(User $user, $notrigger = 0)
2017-10-31 23:10:29 +01:00
{
return $this->updateCommon($user, $notrigger);
}
/**
* Delete object in database
*
* @param User $user User that deletes
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int Return integer <0 if KO, >0 if OK
2017-10-31 23:10:29 +01:00
*/
public function delete(User $user, $notrigger = 0)
2017-10-31 23:10:29 +01:00
{
return $this->deleteCommon($user, $notrigger);
}
/**
2022-01-18 13:44:52 +01:00
* Return label of the status of a reminder
2017-10-31 23:10:29 +01:00
*
2022-01-18 13:44:52 +01:00
* @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
2017-10-31 23:10:29 +01:00
* @return string Label of status
*/
2019-02-27 20:45:07 +01:00
public function getLibStatut($mode = 0)
2017-10-31 23:10:29 +01:00
{
return $this->LibStatut($this->status, $mode);
2017-10-31 23:10:29 +01:00
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-31 23:10:29 +01:00
/**
* Return the status
*
2019-02-27 20:45:07 +01:00
* @param int $status Id status
* @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
* @return string Label of status
2017-10-31 23:10:29 +01:00
*/
2019-02-27 20:45:07 +01:00
public static function LibStatut($status, $mode = 0)
2017-10-31 23:10:29 +01:00
{
// phpcs:enable
2017-10-31 23:10:29 +01:00
global $langs;
2021-10-16 19:37:57 +02:00
$labelStatus = $langs->transnoentitiesnoconv('ToDo');
2021-02-23 18:59:19 +01:00
if ($status == 1) {
2021-10-16 19:37:57 +02:00
$labelStatus = $langs->transnoentitiesnoconv('Done');
2021-02-23 18:59:19 +01:00
} elseif ($status == -1) {
2021-10-16 19:37:57 +02:00
$labelStatus = $langs->transnoentitiesnoconv('Error');
2021-02-23 18:59:19 +01:00
}
2020-11-21 17:42:07 +01:00
2021-10-16 19:37:57 +02:00
$labelStatusShort = $langs->transnoentitiesnoconv('ToDo');
2021-02-23 18:59:19 +01:00
if ($status == 1) {
2021-10-16 19:37:57 +02:00
$labelStatus = $langs->transnoentitiesnoconv('Done');
2021-02-23 18:59:19 +01:00
} elseif ($status == -1) {
2021-10-16 19:37:57 +02:00
$labelStatus = $langs->transnoentitiesnoconv('Error');
2021-02-23 18:59:19 +01:00
}
2020-11-21 17:42:07 +01:00
$statusType = 'status5';
2021-02-23 18:59:19 +01:00
if ($status == 1) {
$statusType = 'status4';
} elseif ($status == -1) {
$statusType = 'status8';
}
2020-11-21 17:42:07 +01:00
return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
2017-10-31 23:10:29 +01:00
}
/**
* Initialise object with example values
* Id must be 0 if object instance is a specimen
*
* @return int
2017-10-31 23:10:29 +01:00
*/
public function initAsSpecimen()
{
return $this->initAsSpecimenCommon();
2017-10-31 23:10:29 +01:00
}
}