Просмотр исходного кода

#42 - messages module: messages preview in dashboard

Alex Trofimov 12 лет назад
Родитель
Сommit
558a62122e

+ 1 - 1
install/sql/system.sql

@@ -3199,7 +3199,7 @@ CREATE TABLE IF NOT EXISTS `sys_objects_page` (
 INSERT INTO `sys_objects_page` (`object`, `uri`, `title_system`, `title`, `module`, `layout_id`, `visible_for_levels`, `visible_for_levels_editable`, `url`, `meta_description`, `meta_keywords`, `meta_robots`, `cache_lifetime`, `cache_editable`, `deletable`, `override_class_name`, `override_class_file`) VALUES
 ('sys_home', 'home', '_sys_page_title_system_home', '_sys_page_title_home', 'system', 5, 2147483647, 1, '', '', '', '', 0, 1, 0, 'BxTemplPageHome', ''),
 ('sys_about', 'about', '_sys_page_title_system_about', '_sys_page_title_about', 'system', 5, 2147483647, 1, 'page.php?i=about', '', '', '', 0, 1, 0, '', ''),
-('sys_dashboard', 'dashboard', '_sys_page_title_system_dashboard', '_sys_page_title_dashboard', 'system', 5, 2147483647, 1, 'page.php?i=dashboard', '', '', '', 0, 1, 0, '', ''),
+('sys_dashboard', 'dashboard', '_sys_page_title_system_dashboard', '_sys_page_title_dashboard', 'system', 11, 2147483646, 1, 'page.php?i=dashboard', '', '', '', 0, 1, 0, '', ''),
 ('sys_create_account', 'create-account', '_sys_page_title_system_create_account', '_sys_page_title_create_account', 'system', 5, 2147483647, 1, 'page.php?i=create-account', '', '', '', 0, 1, 0, '', ''),
 ('sys_login', 'login', '_sys_page_title_system_login', '_sys_page_title_login', 'system', 5, 2147483647, 1, 'page.php?i=login', '', '', '', 0, 1, 0, '', ''),
 ('sys_forgot_password', 'forgot-password', '_sys_page_title_system_forgot_password', '_sys_page_title_forgot_password', 'system', 5, 2147483647, 1, 'page.php?i=forgot-password', '', '', '', 0, 1, 0, '', ''),

+ 1 - 1
modules/boonex/convos/classes/BxCnvAlertsResponse.php

@@ -28,7 +28,7 @@ class BxCnvAlertsResponse extends BxDolAlertsResponse
 
             switch ($oAlert->sAction) {
                 case 'commentPost':
-                    BxDolService::call($this->MODULE, 'trigger_comment_post', array($oAlert->iObject, $oAlert->iSender));
+                    BxDolService::call($this->MODULE, 'trigger_comment_post', array($oAlert->iObject, $oAlert->aExtras['comment_author_id'], $oAlert->aExtras['comment_id']));
                     break;
             }
 

+ 16 - 4
modules/boonex/convos/classes/BxCnvDb.php

@@ -51,9 +51,9 @@ class BxCnvDb extends BxBaseModTextDb
         return $this->query($sQuery);
     }
 
-    public function updateLastCommentTimeProfile($iConversationId, $iProfileId, $iTimestamp)
+    public function updateLastCommentTimeProfile($iConversationId, $iProfileId, $iCommentId, $iTimestamp)
     {
-        $sQuery = $this->prepare("UPDATE `" . $this->getPrefix() . "conversations` SET `last_reply_profile_id` = ?, `last_reply_timestamp` = ? WHERE `id` = ?", $iProfileId, $iTimestamp, $iConversationId);
+        $sQuery = $this->prepare("UPDATE `" . $this->getPrefix() . "conversations` SET `last_reply_profile_id` = ?, `last_reply_timestamp` = ?, `last_reply_comment_id` = ? WHERE `id` = ?", $iProfileId, $iTimestamp, $iCommentId, $iConversationId);
         return $this->query($sQuery);
     }
 
@@ -87,14 +87,26 @@ class BxCnvDb extends BxBaseModTextDb
         return true;
     }
 
-    public function getUnreadMessagesNum ($iProfileId)
+    public function getUnreadMessagesNum ($iProfileId, $iFolderId = BX_CNV_FOLDER_INBOX)
     {
         $sQuery = $this->prepare("SELECT SUM(`c`.`comments` - `f`.`read_comments`) 
             FROM `" . $this->getPrefix() . "conv2folder` as `f` 
             INNER JOIN `" . $this->getPrefix() . "conversations` AS `c` ON (`c`.`id` = `f`.`conv_id`)
-            WHERE `f`.`collaborator` = ? AND `f`.`folder_id` =1", $iProfileId);
+            WHERE `f`.`collaborator` = ? AND `f`.`folder_id` = ?", $iProfileId, $iFolderId);
         return $this->getOne($sQuery);
     }
+
+    public function getMessagesPreviews ($iProfileId, $iStart = 0, $iLimit = 4, $iFolderId = BX_CNV_FOLDER_INBOX)
+    {
+        $sQuery = $this->prepare("SELECT `c`.`id`, `c`.`text`, `c`.`author`, `cmts`.`cmt_text`, `c`.`last_reply_profile_id`, `c`.`comments`, (`c`.`comments` - `f`.`read_comments`) AS `unread_messages`, `last_reply_timestamp`
+            FROM `" . $this->getPrefix() . "conv2folder` as `f` 
+            INNER JOIN `" . $this->getPrefix() . "conversations` AS `c` ON (`c`.`id` = `f`.`conv_id`)
+            LEFT JOIN `" . $this->getPrefix() . "cmts` AS `cmts` ON (`cmts`.`cmt_id` = `c`.`last_reply_comment_id`)
+            WHERE `f`.`collaborator` = ? AND `f`.`folder_id` = ?
+            ORDER BY `c`.`last_reply_timestamp` DESC
+            LIMIT ?, ?", $iProfileId, $iFolderId, $iStart, $iLimit);
+        return $this->getAll($sQuery);
+    }
 }
 
 /** @} */ 

+ 13 - 2
modules/boonex/convos/classes/BxCnvModule.php

@@ -143,6 +143,7 @@ class BxCnvModule extends BxBaseModTextModule
      */
     public function actionFolder ($iFolderId) 
     {
+        // TODO: add to page builder
         bx_import('BxDolGrid');
         $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->CNF['OBJECT_GRID']);
         if (!$oGrid){
@@ -186,6 +187,16 @@ class BxCnvModule extends BxBaseModTextModule
         echo(json_encode($a));
     }
 
+    public function serviceMessagesPreviews ($iProfileId = 0)
+    {
+        if (!$iProfileId)
+            $iProfileId = bx_get_logged_profile_id();
+
+        $a = $this->_oDb->getMessagesPreviews($iProfileId);
+
+        return $this->_oTemplate->getMessagesPreviews($a);
+    }
+
     /**
      * Get number of unread messages for spme profile
      * @param $iProfileId - profile to get unread messages for, if omitted then currently logged is profile is used
@@ -202,7 +213,7 @@ class BxCnvModule extends BxBaseModTextModule
     /**
      * Update last comment time and author
      */
-    public function serviceTriggerCommentPost ($iContentId, $iProfileId, $iTimestamp = 0) 
+    public function serviceTriggerCommentPost ($iContentId, $iProfileId, $iCommentId, $iTimestamp = 0) 
     {
         if (!(int)$iContentId)
             return false;
@@ -216,7 +227,7 @@ class BxCnvModule extends BxBaseModTextModule
         if ($iProfileId == bx_get_logged_profile_id())
             $this->_oDb->updateReadComments($iProfileId, $aContentInfo[$this->_oConfig->CNF['FIELD_ID']], $aContentInfo[$this->_oConfig->CNF['FIELD_COMMENTS']]);
 
-        return $this->_oDb->updateLastCommentTimeProfile((int)$iContentId, (int)$iProfileId, $iTimestamp);
+        return $this->_oDb->updateLastCommentTimeProfile((int)$iContentId, (int)$iProfileId, (int)$iCommentId, $iTimestamp);
     }
 
     /**

+ 49 - 0
modules/boonex/convos/classes/BxCnvTemplate.php

@@ -118,6 +118,55 @@ class BxCnvTemplate extends BxBaseModTextTemplate
         
         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));
     }
+
+    function getMessagesPreviews ($a)
+    {
+        bx_import('BxDolProfile');
+        bx_import('BxDolProfileUndefined');
+        bx_import('BxDolPermalinks');
+
+        $oModule = BxDolModule::getInstance($this->MODULE);
+
+        $aVars = array(
+            'see_all_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($oModule->_oConfig->CNF['URL_HOME']),
+            'bx_repeat:messages' => array(),
+        );
+        foreach ($a as $r) {
+
+            $oProfileAuthor = BxDolProfile::getInstance($r['author']);
+            if (!$oProfileAuthor)
+                $oProfileAuthor = BxDolProfileUndefined::getInstance();
+
+            $oProfileLast = BxDolProfile::getInstance($r['last_reply_profile_id']);
+            if (!$oProfileLast)
+                $oProfileLast = BxDolProfileUndefined::getInstance();
+
+            $sText = strmaxtextlen($r['text'], 40);
+            $sTextCmt = strmaxtextlen($r['cmt_text'], 40);
+
+            $aVars['bx_repeat:messages'][] = array (
+                'id' => $r['id'],
+                'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $oModule->_oConfig->CNF['URI_VIEW_ENTRY'] . '&id=' . $r['id']),
+                'text' => $sText ? $sText : $oProfileAuthor->getDisplayName(),
+                'cmt_text' => $sTextCmt ? $sTextCmt : $oProfileLast->getDisplayName(),
+                'unread_messages' => $r['unread_messages'],
+                'last_reply_time' => bx_time_js($r['last_reply_timestamp'], BX_FORMAT_DATE),
+                'font_weight' => $r['unread_messages'] > 0 ? 'bold' : 'normal',
+                'desc' => $r['comments'] > 1 ? ($r['unread_messages'] > 0 ? _t('_bx_cnv_x_messages_x_new', $r['comments'] + 1, $r['unread_messages']) : _t('_bx_cnv_x_messages', $r['comments'] + 1)) : '',
+
+                'author_id' => $oProfileAuthor->id(),
+                'author_url' => $oProfileAuthor->getUrl(),
+                'author_title' => $oProfileAuthor->getDisplayName(),
+                'author_thumb_url' => $oProfileAuthor->getThumb(),
+
+                'last_replier_id' => $oProfileLast->id(),
+                'last_replier_url' => $oProfileLast->getUrl(),
+                'last_replier_title' => $oProfileLast->getDisplayName(),
+                'last_replier_thumb_url' => $oProfileLast->getThumb(),
+            );
+        }
+        return $this->parseHtmlByName('messages_previews.html', $aVars);
+    } 
 }
 
 /** @} */ 

+ 6 - 0
modules/boonex/convos/install/langs/en.xml

@@ -42,6 +42,7 @@
     <string name="_bx_cnv_page_title_sys_folder"><![CDATA[Convos in folder]]></string>
     <string name="_bx_cnv_page_title_folder"><![CDATA[Folder: {folder}]]></string>
     <string name="_bx_cnv_page_block_title_folder"><![CDATA[Folder: {folder}]]></string>
+    <string name="_bx_cnv_page_block_title_convos"><![CDATA[Convos]]></string>
 
     <string name="_bx_cnv_menu_set_title_view_entry"><![CDATA[View convo]]></string>
     <string name="_bx_cnv_menu_title_view_entry"><![CDATA[View convo]]></string>
@@ -92,4 +93,9 @@
     <string name="_bx_cnv_author_desc"><![CDATA[{0} (updated {1})]]></string>
     <string name="_bx_cnv_x_new_messages"><![CDATA[<b>{0} ({1} new)</b>]]></string>
 
+    <string name="_bx_cnv_x_messages"><![CDATA[{0} messages]]></string>
+    <string name="_bx_cnv_x_messages_x_new"><![CDATA[{0} messages <b>{1} new</b>]]></string>
+
+    <string name="_bx_cnv_see_all"><![CDATA[See all convos...]]></string>
+
 </resources>

+ 5 - 0
modules/boonex/convos/install/sql/enable.sql

@@ -30,6 +30,11 @@ INSERT INTO `sys_objects_transcoder_images` (`object`, `storage_object`, `source
 INSERT INTO `sys_transcoder_images_filters` (`transcoder_object`, `filter`, `filter_params`, `order`) VALUES 
 ('bx_convos_preview', 'Resize', 'a:4:{s:1:"w";s:3:"300";s:1:"h";s:3:"200";s:11:"crop_resize";s:1:"1";s:10:"force_type";s:3:"jpg";}', '0');
 
+-- PAGE: dash
+
+INSERT INTO `sys_pages_blocks`(`object`, `cell_id`, `module`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `active`, `order`) VALUES 
+('sys_dashboard', 3, 'bx_convos', '_bx_cnv_page_block_title_convos', 11, 2147483646, 'service', 'a:2:{s:6:\"module\";s:9:\"bx_convos\";s:6:\"method\";s:17:\"messages_previews\";}', 0, 1, 1, 0);
+
 
 -- PAGE: create entry
 

+ 1 - 0
modules/boonex/convos/install/sql/install.sql

@@ -11,6 +11,7 @@ CREATE TABLE IF NOT EXISTS `bx_convos_conversations` (
   `comments` int(11) NOT NULL default '0',
   `last_reply_timestamp` int(11) NOT NULL,
   `last_reply_profile_id` int(10) unsigned NOT NULL,
+  `last_reply_comment_id` int(11) NOT NULL,
   PRIMARY KEY (`id`),
   KEY `last_reply_timestamp` (`last_reply_timestamp`)
 );

+ 12 - 0
modules/boonex/convos/template/messages_previews.html

@@ -0,0 +1,12 @@
+
+<bx_repeat:messages>
+    <div class="bx-def-font-h3 bx-def-margin-top-auto"><a href="__url__" style="font-weight:__font_weight__;">__text__</a></div>
+    <div class="bx-def-margin-thd-top bx-def-font-middle bx-def-font-grayed">__desc__</div>
+    <div class="bx-def-unit bx-def-margin-thd-top">
+        <a href="__last_replier_url__" title="__last_replier_title__"><img class="bx-def-icon bx-def-icon-size" src="__last_replier_thumb_url__" /></a><div class="bx-def-unit-info bx-def-thumb-size-max-height bx-def-padding-sec-left"><div class="bx-def-font-middle" style="line-height:0.9em;">__cmt_text__</div><div class="bx-def-font-grayed bx-def-font-small">__last_reply_time__</div>
+        </div>
+    </div>
+</bx_repeat:messages>
+
+<div class="bx-def-margin-top"><b><a href="__see_all_url__"><bx_text:_bx_cnv_see_all /></a></b></div>
+