dolibarr 24.0.0-beta
mymodule_myobject.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) ---Replace with your own copyright and developer email---
3 * Copyright (C) 2025 Frédéric France <frederic.france@free.fr>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
32{
33 global $db, $langs, $conf;
34
35 $langs->load("mymodule@mymodule");
36
37 // BEGIN MODULEBUILDER TABFLAG CONTACT
38 $showtabofpagecontact = getDolGlobalInt('MAIN_MYMODULE_SHOW_PAGE_OF_CONTACT');
39 // END MODULEBUILDER TABFLAG CONTACT
40 // BEGIN MODULEBUILDER TABFLAG NOTE
41 $showtabofpagenote = getDolGlobalInt('MAIN_MYMODULE_SHOW_PAGE_OF_NOTE');
42 // END MODULEBUILDER TABFLAG NOTE
43 // BEGIN MODULEBUILDER TABFLAG DOCUMENT
44 $showtabofpagedocument = getDolGlobalInt('MAIN_MYMODULE_SHOW_PAGE_OF_DOCUMENT');
45 // END MODULEBUILDER TABFLAG DOCUMENT
46 // BEGIN MODULEBUILDER TABFLAG AGENDA
47 $showtabofpageagenda = getDolGlobalInt('MAIN_MYMODULE_SHOW_PAGE_OF_AGENDA');
48 // END MODULEBUILDER TABFLAG AGENDA
49
50 $h = 0;
51 $head = array();
52
53 $head[$h][0] = dolBuildUrl(dol_buildpath("/mymodule/myobject_card.php", 1), ['id' => $object->id]);
54 $head[$h][1] = $langs->trans("MyObject");
55 $head[$h][2] = 'card';
56 $h++;
57
58 // BEGIN MODULEBUILDER TAB CONTACT
59 if ($showtabofpagecontact) {
60 $head[$h][0] = dolBuildUrl(dol_buildpath("/mymodule/myobject_contact.php", 1), ['id' => $object->id]);
61 $head[$h][1] = $langs->trans("Contacts");
62 $head[$h][2] = 'contact';
63 $h++;
64 }
65 // END MODULEBUILDER TAB CONTACT
66
67 // BEGIN MODULEBUILDER TAB NOTE
68 if ($showtabofpagenote) {
69 if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
70 $nbNote = 0;
71 if (!empty($object->note_private)) {
72 $nbNote++;
73 }
74 if (!empty($object->note_public)) {
75 $nbNote++;
76 }
77 $head[$h][0] = dolBuildUrl(dol_buildpath('/mymodule/myobject_note.php', 1), ['id' => $object->id]);
78 $head[$h][1] = $langs->trans('Notes');
79 if ($nbNote > 0) {
80 $head[$h][1] .= (!getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER') ? '<span class="badge marginleftonlyshort">'.$nbNote.'</span>' : '');
81 }
82 $head[$h][2] = 'note';
83 $h++;
84 }
85 }
86 // END MODULEBUILDER TAB NOTE
87
88 // BEGIN MODULEBUILDER TAB DOCUMENT
89 if ($showtabofpagedocument) {
90 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
91 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
92 $upload_dir = $conf->mymodule->dir_output."/myobject/".dol_sanitizeFileName($object->ref);
93 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
94 $nbLinks = Link::count($db, $object->element, $object->id);
95 $head[$h][0] = dolBuildUrl(dol_buildpath("/mymodule/myobject_document.php", 1), ['id' => $object->id]);
96 $head[$h][1] = $langs->trans('Documents');
97 if (($nbFiles + $nbLinks) > 0) {
98 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
99 }
100 $head[$h][2] = 'document';
101 $h++;
102 }
103 // END MODULEBUILDER TAB DOCUMENT
104
105 // BEGIN MODULEBUILDER TAB AGENDA
106 if ($showtabofpageagenda) {
107 $head[$h][0] = dolBuildUrl(dol_buildpath("/mymodule/myobject_agenda.php", 1), ['id' => $object->id]);
108 $head[$h][1] = $langs->trans("Events");
109 $head[$h][2] = 'agenda';
110 $h++;
111 }
112 // END MODULEBUILDER TAB AGENDA
113
114 // Show more tabs from modules
115 // Entries must be declared in modules descriptor with line
116 //$this->tabs = array(
117 // 'entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'
118 //); // to add new tab
119 //$this->tabs = array(
120 // 'entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'
121 //); // to remove a tab
122 complete_head_from_modules($conf, $langs, $object, $head, $h, 'myobject@mymodule');
123
124 complete_head_from_modules($conf, $langs, $object, $head, $h, 'myobject@mymodule', 'remove');
125
126 return $head;
127}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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:64
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
myobjectPrepareHead($object)
Prepare array of tabs for MyObject.