dolibarr 21.0.0-alpha
webportalpartnership.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2023-2024 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2023-2024 Lionel Vessiller <lvessiller@easya.solutions>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Put here all includes required by your class file
28require_once DOL_DOCUMENT_ROOT . '/partnership/class/partnership.class.php';
29
34{
38 public $module = 'webportal';
39
43 const ARRAY_STATUS_LABEL = array(
44 Partnership::STATUS_DRAFT => 'Draft',
45 Partnership::STATUS_VALIDATED => 'Accepted',
46 Partnership::STATUS_APPROVED => 'Refused',
47 Partnership::STATUS_REFUSED => 'Suspended',
48 Partnership::STATUS_CANCELED => 'Terminated',
49 );
50
54 protected $partnership_static = null;
55
94 // BEGIN MODULEBUILDER PROPERTIES
98 public $fields = array(
99 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => "Id",),
100 'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'notnull' => 1, 'visible' => 5, 'noteditable' => 1, 'default' => '(PROV)', 'index' => 1, 'searchall' => 1, 'showoncombobox' => 1, 'comment' => "Reference of object", 'showonheader' => 1,),
101 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'position' => 15, 'notnull' => 1, 'visible' => -2, 'default' => '1', 'index' => 1,),
102
103 'fk_type' => array('type' => 'integer:PartnershipType:partnership/class/partnership_type.class.php:0:(active:=:1)', 'label' => 'Type', 'enabled' => 1, 'position' => 20, 'notnull' => 1, 'visible' => 5, 'csslist' => '',),
104 'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))', 'label' => 'ThirdParty', 'picto' => 'company', 'enabled' => 1, 'position' => 50, 'notnull' => -1, 'visible' => 5, 'index' => 1, 'css' => '', 'csslist' => '',),
105 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'position' => 61, 'notnull' => 0, 'visible' => 0,),
106 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'position' => 62, 'notnull' => 0, 'visible' => 0,),
107 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -2,),
108 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2,),
109 'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'position' => 510, 'notnull' => 1, 'visible' => -2, 'foreignkey' => 'user.rowid',),
110 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => -2,),
111 'last_main_doc' => array('type' => 'varchar(255)', 'label' => 'LastMainDoc', 'enabled' => 1, 'position' => 600, 'notnull' => 0, 'visible' => 0,),
112 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'visible' => -2,),
113 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'position' => 1010, 'notnull' => -1, 'visible' => 0,),
114 'date_partnership_start' => array('type' => 'date', 'label' => 'DatePartnershipStart', 'enabled' => 1, 'position' => 52, 'notnull' => 1, 'visible' => 5,),
115 'date_partnership_end' => array('type' => 'date', 'label' => 'DatePartnershipEnd', 'enabled' => 1, 'position' => 53, 'notnull' => 0, 'visible' => 5,),
116 'url_to_check' => array('type' => 'varchar(255)', 'label' => 'UrlToCheck', 'enabled' => 1, 'position' => 70, 'notnull' => 0, 'visible' => -5,),
117 'count_last_url_check_error' => array('type' => 'integer', 'label' => 'CountLastUrlCheckError', 'enabled' => 1, 'position' => 71, 'notnull' => 0, 'visible' => -2, 'default' => '0',),
118 'last_check_backlink' => array('type' => 'datetime', 'label' => 'LastCheckBacklink', 'enabled' => 1, 'position' => 72, 'notnull' => 0, 'visible' => -2,),
119 'reason_decline_or_cancel' => array('type' => 'text', 'label' => 'ReasonDeclineOrCancel', 'enabled' => 1, 'position' => 73, 'notnull' => 0, 'visible' => -2,),
120 'ip' => array('type' => 'varchar(250)', 'label' => 'Ip', 'enabled' => 1, 'position' => 74, 'notnull' => 0, 'visible' => -2,),
121
122 'status' => array('type' => 'smallint', 'label' => 'Status', 'enabled' => 1, 'position' => 2000, 'notnull' => 1, 'visible' => 5, 'default' => '0', 'index' => 1, 'arrayofkeyval' => self::ARRAY_STATUS_LABEL, 'showonheader' => 1,),
123 );
124 //public $rowid;
125 //public $ref;
126 //public $entity;
127 //public $fk_type;
128 //public $fk_user_creat;
129 //public $fk_user_modif;
130 //public $last_main_doc;
131 //public $import_key;
132 //public $model_pdf;
133 //public $date_partnership_start;
134 //public $date_partnership_end;
135 //public $url_to_check;
136 //public $count_last_url_check_error;
137 //public $last_check_backlink;
138 //public $reason_decline_or_cancel;
139 //public $fk_soc;
140 //public $fk_member;
141 //public $ip;
142 //public $status;
143 // END MODULEBUILDER PROPERTIES
144
150 protected function getPartnershipStatic()
151 {
152 if (!$this->partnership_static) {
153 $this->partnership_static = new Partnership($this->db);
154 }
155
156 return $this->partnership_static;
157 }
158
164 public function __construct(DoliDB $db)
165 {
166 global $langs;
167
168 $this->db = $db;
169
170 $this->isextrafieldmanaged = 0;
171
172 $this->getPartnershipStatic();
173
174 // Translate some data of arrayofkeyval
175 if (is_object($langs)) {
176 foreach ($this->fields as $key => $val) {
177 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
178 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
179 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
180 }
181 }
182 }
183 }
184 }
185
192 public function getTooltipContentArray($params)
193 {
194 global $conf, $langs;
195
196 $datas = [];
197
198 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
199 return ['optimize' => $langs->trans("WebPortalPartnership")];
200 }
201 $datas['picto'] = img_picto('', $this->picto) . ' <u>' . $langs->trans("WebPortalPartnership") . '</u>';
202 if (isset($this->status)) {
203 $datas['picto'] .= ' ' . $this->getLibStatut(5);
204 }
205 $datas['ref'] .= '<br><b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
206
207 return $datas;
208 }
209
220 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
221 {
222 global $conf, $langs, $hookmanager;
223
224 if (!empty($conf->dol_no_mouse_hover)) {
225 $notooltip = 1; // Force disable tooltips
226 }
227
228 $option = 'nolink';
229
230 $result = '';
231 $params = [
232 'id' => $this->id,
233 'objecttype' => $this->element,
234 'option' => $option,
235 ];
236 $classfortooltip = 'classfortooltip';
237 $dataparams = '';
238 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
239 $classfortooltip = 'classforajaxtooltip';
240 $dataparams = ' data-params="' . dol_escape_htmltag(json_encode($params)) . '"';
241 $label = '';
242 } else {
243 $label = implode($this->getTooltipContentArray($params));
244 }
245
246 $url = '';
247 //$url = DOL_URL_ROOT.'/partnership/partnership_card.php?id='.$this->id;
248
249 if ($option != 'nolink') {
250 // Add param to save lastsearch_values or not
251 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
252 if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
253 $add_save_lastsearch_values = 1;
254 }
255 if ($add_save_lastsearch_values) {
256 $url .= '&save_lastsearch_values=1';
257 }
258 }
259
260 $linkclose = '';
261 if (empty($notooltip)) {
262 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
263 $label = $langs->trans("ShowPartnership");
264 $linkclose .= ' alt="' . dol_escape_htmltag($label, 1) . '"';
265 }
266 $linkclose .= ($label ? ' title="' . dol_escape_htmltag($label, 1) . '"' : ' title="tocomplete"');
267 $linkclose .= $dataparams . ' class="' . $classfortooltip . ($morecss ? ' ' . $morecss : '') . '"';
268 } else {
269 $linkclose = ($morecss ? ' class="' . $morecss . '"' : '');
270 }
271
272 if ($option == 'nolink') {
273 $linkstart = '<span';
274 } else {
275 $linkstart = '<a href="' . $url . '"';
276 }
277 $linkstart .= $linkclose . '>';
278 if ($option == 'nolink') {
279 $linkend = '</span>';
280 } else {
281 $linkend = '</a>';
282 }
283
284 $result .= $linkstart;
285
286 if (empty($this->showphoto_on_popup)) {
287 if ($withpicto) {
288 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : $dataparams . ' class="' . (($withpicto != 2) ? 'paddingright ' : '') . $classfortooltip . '"'), 0, 0, $notooltip ? 0 : 1);
289 }
290 } else {
291 if ($withpicto) {
292 require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
293
294 list($class, $module) = explode('@', $this->picto);
295 $upload_dir = $conf->$module->multidir_output[$conf->entity] . "/$class/" . dol_sanitizeFileName($this->ref);
296 $filearray = dol_dir_list($upload_dir, "files");
297 $filename = $filearray[0]['name'];
298 if (!empty($filename)) {
299 $pospoint = strpos($filearray[0]['name'], '.');
300
301 $pathtophoto = $class . '/' . $this->ref . '/thumbs/' . substr($filename, 0, $pospoint) . '_mini' . substr($filename, $pospoint);
302 if (!getDolGlobalString(strtoupper($module . '_' . $class) . '_FORMATLISTPHOTOSASUSERS')) {
303 $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo' . $module . '" alt="No photo" border="0" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $module . '&entity=' . $conf->entity . '&file=' . urlencode($pathtophoto) . '"></div></div>';
304 } else {
305 $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $module . '&entity=' . $conf->entity . '&file=' . urlencode($pathtophoto) . '"></div>';
306 }
307
308 $result .= '</div>';
309 } else {
310 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="' . (($withpicto != 2) ? 'paddingright ' : '') . 'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
311 }
312 }
313 }
314
315 if ($withpicto != 2) {
316 $result .= $this->ref;
317 }
318
319 $result .= $linkend;
320 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
321
322 global $action, $hookmanager;
323 $hookmanager->initHooks(array('partnershipdao'));
324 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
325 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
326 if ($reshook > 0) {
327 $result = $hookmanager->resPrint;
328 } else {
329 $result .= $hookmanager->resPrint;
330 }
331
332 return $result;
333 }
334
341 public function getLibStatut($mode = 0)
342 {
343 return $this->LibStatut($this->status, $mode);
344 }
345
346 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
347
355 public function LibStatut($status, $mode = 0)
356 {
357 // phpcs:enable
358 return $this->getPartnershipStatic()->LibStatut($status, $mode);
359 }
360}
$object ref
Definition info.php:79
Class to manage Dolibarr database access.
Class for Partnership.
Class for WebPortalPartnership.
getLibStatut($mode=0)
Return the label of the status.
LibStatut($status, $mode=0)
Return the status.
getTooltipContentArray($params)
getTooltipContentArray
__construct(DoliDB $db)
Constructor.
const ARRAY_STATUS_LABEL
Status list (short label)
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
getPartnershipStatic()
Get partnership for static method.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:162
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...