eventorganization_conferenceorbooth.lib.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. /* Copyright (C) ---Put here your own copyright and developer email---
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file lib/eventorganization_conferenceorbooth.lib.php
  19. * \ingroup eventorganization
  20. * \brief Library files with common functions for ConferenceOrBooth
  21. */
  22. /**
  23. * Prepare array of tabs for ConferenceOrBooth
  24. *
  25. * @param ConferenceOrBooth $object ConferenceOrBooth
  26. * @param int $with_project Add project id to URL
  27. * @return array Array of tabs
  28. */
  29. function conferenceorboothPrepareHead($object, $with_project = 0)
  30. {
  31. global $db, $langs, $conf;
  32. $langs->load("eventorganization");
  33. $h = 0;
  34. $head = array();
  35. $withProjectUrl='';
  36. if ($with_project>0) {
  37. $withProjectUrl = "&withproject=1";
  38. }
  39. $head[$h][0] = DOL_URL_ROOT.'/eventorganization/conferenceorbooth_card.php?id='.$object->id.$withProjectUrl;
  40. $head[$h][1] = $langs->trans("Card");
  41. $head[$h][2] = 'card';
  42. $h++;
  43. if (!empty($conf->global->MAIN_FEATURES_LEVEL) && $conf->global->MAIN_FEATURES_LEVEL >= 2) {
  44. $head[$h][0] = DOL_URL_ROOT.'/eventorganization/conferenceorbooth_contact.php?id='.$object->id.$withProjectUrl;
  45. $head[$h][1] = $langs->trans("ContactsAddresses");
  46. $head[$h][2] = 'contact';
  47. $h++;
  48. }
  49. /*
  50. $head[$h][0] = DOL_URL_ROOT.'/eventorganization/conferenceorboothattendee_list.php?conforboothid='.$object->id.$withProjectUrl;
  51. $head[$h][1] = $langs->trans("Attendees");
  52. $head[$h][2] = 'attendees';
  53. // Enable caching of conf or booth count attendees
  54. $nbAttendees = 0;
  55. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  56. $cachekey = 'count_attendees_conferenceorbooth_'.$object->id;
  57. $dataretrieved = dol_getcache($cachekey);
  58. if (!is_null($dataretrieved)) {
  59. $nbAttendees = $dataretrieved;
  60. } else {
  61. require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorboothattendee.class.php';
  62. $attendees=new ConferenceOrBoothAttendee($db);
  63. $result = $attendees->fetchAll('', '', 0, 0, array('t.fk_actioncomm'=>$object->id));
  64. if (!is_array($result) && $result<0) {
  65. setEventMessages($attendees->error, $attendees->errors, 'errors');
  66. } else {
  67. $nbAttendees = count($result);
  68. }
  69. dol_setcache($cachekey, $nbAttendees, 120); // If setting cache fails, this is not a problem, so we do not test result.
  70. }
  71. if ($nbAttendees > 0) {
  72. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbAttendees.'</span>';
  73. }
  74. $h++;
  75. */
  76. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  77. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  78. $upload_dir = $conf->eventorganization->dir_output."/conferenceorbooth/".dol_sanitizeFileName($object->ref);
  79. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  80. $nbLinks = Link::count($db, $object->element, $object->id);
  81. $head[$h][0] = dol_buildpath("/eventorganization/conferenceorbooth_document.php", 1).'?id='.$object->id.$withProjectUrl;
  82. $head[$h][1] = $langs->trans('Documents');
  83. if (($nbFiles + $nbLinks) > 0) {
  84. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  85. }
  86. $head[$h][2] = 'document';
  87. $h++;
  88. // Show more tabs from modules
  89. // Entries must be declared in modules descriptor with line
  90. //$this->tabs = array(
  91. // 'entity:+tabname:Title:@eventorganization:/eventorganization/mypage.php?id=__ID__'
  92. //); // to add new tab
  93. //$this->tabs = array(
  94. // 'entity:-tabname:Title:@eventorganization:/eventorganization/mypage.php?id=__ID__'
  95. //); // to remove a tab
  96. complete_head_from_modules($conf, $langs, $object, $head, $h, 'conferenceorbooth@eventorganization');
  97. complete_head_from_modules($conf, $langs, $object, $head, $h, 'conferenceorbooth@eventorganization', 'remove');
  98. return $head;
  99. }
  100. /**
  101. * Prepare array of tabs for ConferenceOrBooth Project tab
  102. *
  103. * @param $object Project Project
  104. * @return array
  105. */
  106. function conferenceorboothProjectPrepareHead($object)
  107. {
  108. global $db, $langs, $conf;
  109. $langs->load("eventorganization");
  110. $h = 0;
  111. $head = array();
  112. $head[$h][0] = dol_buildpath("/eventorganization/conferenceorbooth_list.php", 1).'?projectid='.$object->id;
  113. $head[$h][1] = $langs->trans("ConferenceOrBooth");
  114. $head[$h][2] = 'conferenceorbooth';
  115. // Enable caching of conf or booth count attendees
  116. $nbAttendees = 0;
  117. $nbConferenceOrBooth= 0;
  118. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  119. $cachekey = 'count_conferenceorbooth_project_'.$object->id;
  120. $dataretrieved = dol_getcache($cachekey);
  121. if (!is_null($dataretrieved)) {
  122. $nbAttendees = $dataretrieved;
  123. } else {
  124. require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorbooth.class.php';
  125. $conforbooth=new ConferenceOrBooth($db);
  126. $result = $conforbooth->fetchAll('', '', 0, 0, array('t.fk_project'=>$object->id));
  127. if (!is_array($result) && $result<0) {
  128. setEventMessages($conforbooth->error, $conforbooth->errors, 'errors');
  129. } else {
  130. $nbConferenceOrBooth = count($result);
  131. }
  132. dol_setcache($cachekey, $nbConferenceOrBooth, 120); // If setting cache fails, this is not a problem, so we do not test result.
  133. }
  134. if ($nbConferenceOrBooth > 0) {
  135. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbConferenceOrBooth.'</span>';
  136. }
  137. $h++;
  138. $head[$h][0] = dol_buildpath("/eventorganization/conferenceorboothattendee_list.php", 1).'?fk_project='.$object->id.'&withproject=1';
  139. $head[$h][1] = $langs->trans("Attendees");
  140. $head[$h][2] = 'attendees';
  141. // Enable caching of conf or booth count attendees
  142. $nbAttendees = 0;
  143. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  144. $cachekey = 'count_attendees_conferenceorbooth_project_'.$object->id;
  145. $dataretrieved = dol_getcache($cachekey);
  146. if (!is_null($dataretrieved)) {
  147. $nbAttendees = $dataretrieved;
  148. } else {
  149. require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorboothattendee.class.php';
  150. $attendees=new ConferenceOrBoothAttendee($db);
  151. $result = $attendees->fetchAll('', '', 0, 0, array('t.fk_project'=>$object->id));
  152. if (!is_array($result) && $result<0) {
  153. setEventMessages($attendees->error, $attendees->errors, 'errors');
  154. } else {
  155. $nbAttendees = count($result);
  156. }
  157. dol_setcache($cachekey, $nbAttendees, 120); // If setting cache fails, this is not a problem, so we do not test result.
  158. }
  159. if ($nbAttendees > 0) {
  160. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbAttendees.'</span>';
  161. }
  162. complete_head_from_modules($conf, $langs, $object, $head, $h, 'conferenceorboothproject@eventorganization');
  163. complete_head_from_modules($conf, $langs, $object, $head, $h, 'conferenceorboothproject@eventorganization', 'remove');
  164. return $head;
  165. }
  166. /**
  167. * Prepare array of tabs for ConferenceOrBoothAttendees
  168. *
  169. * @param ConferenceOrBoothAttendee $object ConferenceOrBoothAttendee
  170. * @return array Array of tabs
  171. */
  172. function conferenceorboothAttendeePrepareHead($object)
  173. {
  174. global $db, $langs, $conf;
  175. $langs->load("eventorganization");
  176. $h = 0;
  177. $head = array();
  178. $head[$h][0] = DOL_URL_ROOT."/eventorganization/conferenceorboothattendee_card.php?id=".((int) $object->id).($object->fk_actioncomm > 0 ? '&conforboothid='.((int) $object->fk_actioncomm) : '').($object->fk_project > 0 ? '&withproject=1&fk_project='.((int) $object->fk_project) : '');
  179. $head[$h][1] = $langs->trans("Card");
  180. $head[$h][2] = 'card';
  181. $h++;
  182. //TODO : Note and docuement
  183. complete_head_from_modules($conf, $langs, $object, $head, $h, 'conferenceorboothattendee@eventorganization');
  184. complete_head_from_modules($conf, $langs, $object, $head, $h, 'conferenceorboothattendee@eventorganization', 'remove');
  185. return $head;
  186. }