BxCnvTemplate.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Convos Convos
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /*
  12. * Module representation.
  13. */
  14. class BxCnvTemplate extends BxBaseModTextTemplate
  15. {
  16. /**
  17. * Constructor
  18. */
  19. function __construct(&$oConfig, &$oDb)
  20. {
  21. $this->MODULE = 'bx_convos';
  22. parent::__construct($oConfig, $oDb);
  23. }
  24. public function entryCollaborators ($aContentInfo, $iMaxVisible = 2)
  25. {
  26. $oModule = BxDolModule::getInstance($this->MODULE);
  27. $CNF = &$oModule->_oConfig->CNF;
  28. $aCollaborators = $this->_oDb->getCollaborators($aContentInfo[$CNF['FIELD_ID']]);
  29. // sort collaborators: first - current user, second - last replier, third - author, all others sorted by max number of posts
  30. $aCollaborators = $oModule->sortCollaborators($aCollaborators, $aContentInfo['last_reply_profile_id'], $aContentInfo[$CNF['FIELD_AUTHOR']]);
  31. $iCollaboratorsNum = count($aCollaborators);
  32. // prepare template variables
  33. $aVarsPopup = array (
  34. 'bx_repeat:collaborators' => array(),
  35. 'bx_if:collaborators_more' => array(
  36. 'condition' => false,
  37. 'content' => array(),
  38. ),
  39. );
  40. $aVars = array (
  41. 'bx_repeat:collaborators' => array(),
  42. 'bx_if:collaborators_more' => array(
  43. 'condition' => $iCollaboratorsNum > $iMaxVisible,
  44. 'content' => array(
  45. 'popup' => '',
  46. 'title_more' => _t('_bx_cnv_more', $iCollaboratorsNum - $iMaxVisible),
  47. 'id' => $this->MODULE . '-popup-' . $aContentInfo[$CNF['FIELD_ID']],
  48. ),
  49. ),
  50. );
  51. $i = 0;
  52. $aCollaborators = array_slice($aCollaborators, 0, 30, true);
  53. foreach ($aCollaborators as $iProfileId => $iReadComments) {
  54. $oProfile = BxDolProfile::getInstanceMagic($iProfileId);
  55. $aCollaborator = array (
  56. 'id' => $oProfile->id(),
  57. 'unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  58. 'class' => $aContentInfo[$CNF['FIELD_AUTHOR']] == $iProfileId ? 'bx-cnv-collaborator-author' : '',
  59. 'bx_if:last_replier' => array (
  60. 'condition' => ($aContentInfo['last_reply_profile_id'] == $iProfileId),
  61. 'content' => array (
  62. 'id' => $oProfile->id(),
  63. 'title' => bx_html_attribute(_t('_bx_cnv_collaborator_last_replier')),
  64. ),
  65. ),
  66. 'bx_if:author' => array (
  67. 'condition' => $aContentInfo[$CNF['FIELD_AUTHOR']] == $iProfileId,
  68. 'content' => array (
  69. 'id' => $oProfile->id(),
  70. 'title' => bx_html_attribute(_t('_bx_cnv_collaborator_author')),
  71. ),
  72. ),
  73. );
  74. if ($i < $iMaxVisible)
  75. $aVars['bx_repeat:collaborators'][] = $aCollaborator;
  76. if ($i >= $iMaxVisible)
  77. $aVarsPopup['bx_repeat:collaborators'][] = $aCollaborator;
  78. ++$i;
  79. }
  80. if ($aVarsPopup['bx_repeat:collaborators']) {
  81. $aVars['bx_if:collaborators_more']['content']['popup'] = BxTemplFunctions::getInstance()->transBox('', '<div class="bx-def-padding">' . $this->parseHtmlByName('collaborators.html', $aVarsPopup) . '</div>');
  82. }
  83. return $this->parseHtmlByName('collaborators.html', $aVars);
  84. }
  85. function getAuthorDesc ($aData, $oProfile)
  86. {
  87. $oModule = BxDolModule::getInstance($this->MODULE);
  88. if ($aData['last_reply_timestamp'] == $aData[$oModule->_oConfig->CNF['FIELD_ADDED']])
  89. return bx_time_js($aData[$oModule->_oConfig->CNF['FIELD_ADDED']], BX_FORMAT_DATE);
  90. return _t('_bx_cnv_author_desc', bx_time_js($aData[$oModule->_oConfig->CNF['FIELD_ADDED']], BX_FORMAT_DATE), bx_time_js($aData['last_reply_timestamp'], BX_FORMAT_DATE));
  91. }
  92. function getMessageLabel ($iCount, $r, $oProfileLast = null)
  93. {
  94. $oModule = BxDolModule::getInstance($this->MODULE);
  95. if (!$oProfileLast) {
  96. $oProfileLast = BxDolProfile::getInstance($r['last_reply_profile_id']);
  97. if (!$oProfileLast)
  98. $oProfileLast = BxDolProfileUndefined::getInstance();
  99. }
  100. if (!isset($r['unread_messages']))
  101. $r['unread_messages'] = $r['comments'] - $r['read_comments'];
  102. $bReadByAll = true;
  103. $aCollaborators = $oModule->_oDb->getCollaborators($r['id']);
  104. foreach ($aCollaborators as $iReadComments) {
  105. if ($r['comments'] - $iReadComments) {
  106. $bReadByAll = false;
  107. break;
  108. }
  109. }
  110. if (!isset($r['unread_messages']))
  111. $r['unread_messages'] = $r['comments'] - $r['read_comments'];
  112. return $this->parseHtmlByName('message_label.html', array (
  113. 'count' => $iCount,
  114. 'bx_if:unread_messages' => array (
  115. 'condition' => $r['unread_messages'] > 0,
  116. 'content' => array (
  117. 'unread_messages' => $r['unread_messages'],
  118. ),
  119. ),
  120. 'bx_if:viewer_is_last_replier' => array (
  121. 'condition' => !$bReadByAll && $oProfileLast->id() == bx_get_logged_profile_id(),
  122. 'content' => array (),
  123. ),
  124. 'bx_if:is_read_by_all' => array (
  125. 'condition' => $bReadByAll,
  126. 'content' => array (),
  127. ),
  128. ));
  129. }
  130. function getMessagesPreviews ($a)
  131. {
  132. if (empty($a))
  133. return MsgBox(_t('_Empty'));
  134. $oModule = BxDolModule::getInstance($this->MODULE);
  135. $aVars = array(
  136. 'see_all_url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink($oModule->_oConfig->CNF['URL_HOME'])),
  137. 'bx_repeat:messages' => array(),
  138. );
  139. foreach ($a as $r) {
  140. $oProfileAuthor = BxDolProfile::getInstance($r['author']);
  141. if (!$oProfileAuthor)
  142. $oProfileAuthor = BxDolProfileUndefined::getInstance();
  143. $oProfileLast = BxDolProfile::getInstance($r['last_reply_profile_id']);
  144. if (!$oProfileLast)
  145. $oProfileLast = BxDolProfileUndefined::getInstance();
  146. $sText = strmaxtextlen($r['text'], 90);
  147. $sTextCmt = strmaxtextlen($r['cmt_text'], 50);
  148. $aVars['bx_repeat:messages'][] = array (
  149. 'id' => $r['id'],
  150. 'url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $oModule->_oConfig->CNF['URI_VIEW_ENTRY'] . '&id=' . $r['id'])),
  151. 'text' => $sText ? $sText : $oProfileAuthor->getDisplayName(),
  152. 'cmt_text' => $sTextCmt,
  153. 'unread_messages' => $r['unread_messages'],
  154. 'last_reply_time_and_replier' => _t('_bx_cnv_x_date_by_x_replier', bx_time_js($r['last_reply_timestamp'], BX_FORMAT_DATE), $oProfileLast->getDisplayName()),
  155. 'font_weight' => $r['unread_messages'] > 0 ? 'bold' : 'normal',
  156. 'label' => $this->getMessageLabel($r['comments'] + 1, $r, $oProfileLast),
  157. 'author_id' => $oProfileAuthor->id(),
  158. 'author_url' => $oProfileAuthor->getUrl(),
  159. 'author_title' => $oProfileAuthor->getDisplayName(),
  160. 'author_title_attr' => bx_html_attribute($oProfileAuthor->getDisplayName()),
  161. 'author_thumb_url' => $oProfileAuthor->getThumb(),
  162. 'last_replier_id' => $oProfileLast->id(),
  163. 'last_replier_url' => $oProfileLast->getUrl(),
  164. 'last_replier_title' => $oProfileLast->getDisplayName(),
  165. 'last_replier_title_attr' => bx_html_attribute($oProfileLast->getDisplayName()),
  166. 'last_replier_thumb_url' => $oProfileLast->getThumb(),
  167. );
  168. }
  169. return $this->parseHtmlByName('messages_previews.html', $aVars);
  170. }
  171. function entryMessagePreviewInGrid ($r)
  172. {
  173. $oModule = BxDolModule::getInstance($this->MODULE);
  174. $oProfileLast = BxDolProfile::getInstance($r['last_reply_profile_id']);
  175. if (!$oProfileLast)
  176. $oProfileLast = BxDolProfileUndefined::getInstance();
  177. $sText = strmaxtextlen($r['text'], 100);
  178. $sTextCmt = $r['cmt_text'] ? strmaxtextlen($r['cmt_text'], 100) : '';
  179. if (!isset($r['unread_messages']))
  180. $r['unread_messages'] = $r['comments'] - $r['read_comments'];
  181. $aVars = array (
  182. 'url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $oModule->_oConfig->CNF['URI_VIEW_ENTRY'] . '&id=' . $r['id'])),
  183. 'text' => $sText ? $sText : _t('_Empty'),
  184. 'cmt_text' => $sTextCmt,
  185. 'last_reply_time_and_replier' => _t('_bx_cnv_x_date_by_x_replier', bx_time_js($r['last_reply_timestamp'], BX_FORMAT_DATE), $oProfileLast->getDisplayName()),
  186. 'bx_if:unread_messages' => array (
  187. 'condition' => $r['unread_messages'] > 0,
  188. 'content' => array (),
  189. ),
  190. );
  191. $aVars['bx_if:unread_messages2'] = $aVars['bx_if:unread_messages'];
  192. return $this->parseHtmlByName('message_preview_in_grid.html', $aVars);
  193. }
  194. function getAuthorAddon ($aData, $oProfile)
  195. {
  196. return '';
  197. }
  198. public function entryBreadcrumb($aContentInfo, $aTmplVarsItems = array())
  199. {
  200. $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
  201. $oPermalink = BxDolPermalinks::getInstance();
  202. $oAuthor = BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]);
  203. if(!$oAuthor)
  204. $oAuthor = BxDolProfileUndefined::getInstance();
  205. $sText = strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 50);
  206. $iFolder = $this->_oDb->getConversationFolder($aContentInfo[$CNF['FIELD_ID']], bx_get_logged_profile_id());
  207. $aTmplVarsItems = array(array(
  208. 'url' => bx_absolute_url($oPermalink->permalink($CNF['URL_FOLDER'] . $iFolder)),
  209. 'title' => _t($CNF['T']['txt_folder_' . $iFolder])
  210. ), array(
  211. 'url' => bx_absolute_url($oPermalink->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']])),
  212. 'title' => $sText ? $sText : $oAuthor->getDisplayName(),
  213. ));
  214. return parent::entryBreadcrumb($aContentInfo, $aTmplVarsItems);
  215. }
  216. }
  217. /** @} */