Browse Source

Ticket #3028 - point 2.

AntonLV 6 years ago
parent
commit
b41fcdc3f0

+ 2 - 0
modules/boonex/ads/classes/BxAdsConfig.php

@@ -90,6 +90,7 @@ class BxAdsConfig extends BxBaseModTextConfig
             'PARAM_SEARCHABLE_FIELDS' => 'bx_ads_searchable_fields',
             'PARAM_PER_PAGE_BROWSE_SHOWCASE' => 'bx_ads_per_page_browse_showcase',
             'PARAM_LIFETIME' => 'bx_ads_lifetime',
+            'PARAM_USE_IIN' => 'bx_ads_internal_interested_notification',
             'PARAM_CATEGORY_LEVEL_MAX' => 1,
 
             // objects
@@ -179,6 +180,7 @@ class BxAdsConfig extends BxBaseModTextConfig
                 'txt_sample_reaction_single' => '_bx_ads_txt_sample_reaction_single',
                 'txt_sample_score_up_single' => '_bx_ads_txt_sample_score_up_single',
                 'txt_sample_score_down_single' => '_bx_ads_txt_sample_score_down_single',
+                'txt_sample_interest_single' => '_bx_ads_txt_sample_interest_single',
                 'form_field_author' => '_bx_ads_form_entry_input_author',
             	'grid_action_err_delete' => '_bx_ads_grid_action_err_delete',
             	'grid_txt_account_manager' => '_bx_ads_grid_txt_account_manager',

+ 34 - 0
modules/boonex/ads/classes/BxAdsDb.php

@@ -255,6 +255,40 @@ class BxAdsDb extends BxBaseModTextDb
         )) > 0;
     }
 
+    public function getInterested($aParams)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
+
+        $sSelectClause = "`tit`.*";
+        $sJoinClause = $sWhereClause = $sGroupClause = "";
+        $sOrderClause = "`tit`.`id` ASC";
+
+        switch($aParams['type']) {
+            case 'id':
+                $aMethod['name'] = 'getRow';
+                $aMethod['params'][1] = array(
+                    'id' => $aParams['id']
+                );
+
+                $sWhereClause = " AND `tit`.`id`=:id";
+                break;
+        }
+
+        if(!empty($sGroupClause))
+            $sGroupClause = "GROUP BY " . $sGroupClause;
+
+        if(!empty($sOrderClause))
+            $sOrderClause = "ORDER BY " . $sOrderClause;
+
+        $aMethod['params'][0] = "SELECT " . $sSelectClause . " 
+            FROM `" . $CNF['TABLE_INTERESTED_TRACK'] . "` AS `tit`" . $sJoinClause . " 
+            WHERE 1" . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause;
+
+        return call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
+    }
+    
     public function insertInterested($aParamsSet)
     {
         $CNF = &$this->_oConfig->CNF;

+ 68 - 9
modules/boonex/ads/classes/BxAdsModule.php

@@ -61,19 +61,28 @@ class BxAdsModule extends BxBaseModTextModule
         if($this->_oDb->isInterested($iContentId, $iViewer))
             return echoJson(array('msg' => _t('_bx_ads_txt_err_duplicate')));
 
-        if(!$this->_oDb->insertInterested(array('entry_id' => $iContentId, 'profile_id' => $iViewer)))
+        $iInterestId = $this->_oDb->insertInterested(array('entry_id' => $iContentId, 'profile_id' => $iViewer));
+        if(!$iInterestId)
             return echoJson(array('msg' => _t('_bx_ads_txt_err_cannot_perform_action')));
 
-        sendMailTemplate($CNF['ETEMPLATE_INTERESTED'], 0, $iContentAuthor, array(
-            'viewer_name' => $oViewer->getDisplayName(),
-            'viewer_url' => $oViewer->getUrl(),
-            'ad_name' => $aContentInfo[$CNF['FIELD_TITLE']],
-            'ad_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
-                'i' => $CNF['URI_VIEW_ENTRY'], 
-                $CNF['FIELD_ID'] => $iContentId
-            ))
+        bx_alert($this->getName(), 'doInterest', $iContentId, $iViewer, array(
+            'subobject_id' => $iInterestId, 
+            'subobject_author_id' => $iViewer, 
+
+            'object_author_id' => $iContentAuthor
         ));
 
+        if(getParam($CNF['PARAM_USE_IIN']) == 'on')
+            sendMailTemplate($CNF['ETEMPLATE_INTERESTED'], 0, $iContentAuthor, array(
+                'viewer_name' => $oViewer->getDisplayName(),
+                'viewer_url' => $oViewer->getUrl(),
+                'ad_name' => $aContentInfo[$CNF['FIELD_TITLE']],
+                'ad_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
+                    'i' => $CNF['URI_VIEW_ENTRY'], 
+                    $CNF['FIELD_ID'] => $iContentId
+                ))
+            ));
+
         return echoJson(array('msg' => _t('_bx_ads_txt_msg_author_notified')));
     }
 
@@ -290,6 +299,56 @@ class BxAdsModule extends BxBaseModTextModule
         return $aBlock;
     }
 
+    public function serviceGetNotificationsData()
+    {
+        $sModule = $this->_aModule['name'];
+
+        $sEventPrivacy = $sModule . '_allow_view_event_to';
+        if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
+            $sEventPrivacy = '';
+
+        $aResult = parent::serviceGetNotificationsData();
+        $aResult['handlers'] = array_merge($aResult['handlers'], array(
+            array('group' => $sModule . '_interest', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doInterest', 'module_name' => $sModule, 'module_method' => 'get_notifications_interest', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy)
+        ));
+
+        $aResult['settings'] = array_merge($aResult['settings'], array(
+            array('group' => 'interest', 'unit' => $sModule, 'action' => 'doInterest', 'types' => array('personal'))
+        ));
+
+        $aResult['alerts'] = array_merge($aResult['alerts'], array(
+            array('unit' => $sModule, 'action' => 'doInterest')
+        ));
+
+        return $aResult; 
+    }
+    
+    public function serviceGetNotificationsInterest($aEvent)
+    {
+    	$CNF = &$this->_oConfig->CNF;
+
+    	$iContentId = (int)$aEvent['object_id'];
+    	$aContentInfo = $this->_oDb->getContentInfoById($iContentId);
+        if(empty($aContentInfo) || !is_array($aContentInfo))
+            return array();
+
+        $iInterestedId = (int)$aEvent['subobject_id'];
+        $aInterestedInfo = $this->_oDb->getInterested(array('type' => 'id', 'id' => $iInterestedId));
+        if(empty($aInterestedInfo) || !is_array($aInterestedInfo))
+            return array();
+
+        $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId);
+
+        return array(
+            'entry_sample' => $CNF['T']['txt_sample_single'],
+            'entry_url' => $sEntryUrl,
+            'entry_caption' => $aContentInfo[$CNF['FIELD_TITLE']],
+            'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
+            'subentry_sample' => $CNF['T']['txt_sample_interest_single'],
+            'subentry_url' => '',
+            'lang_key' => '_bx_ads_txt_ntfs_subobject_interested', //may be empty or not specified. In this case the default one from Notification module will be used.
+        );
+    }
 
     /**
      * Common methods.

+ 4 - 0
modules/boonex/ads/install/langs/en.xml

@@ -11,6 +11,7 @@
     <string name="_bx_ads_option_rss_num"><![CDATA[Number of items in RSS feed]]></string>
     <string name="_bx_ads_option_searchable_fields"><![CDATA[Searchable fields for keyword search]]></string>
     <string name="_bx_ads_option_lifetime"><![CDATA[Deactivate automatically after (in days)]]></string>
+    <string name="_bx_ads_option_internal_interested_notification"><![CDATA[Use internal notification about Interested action]]></string>
 
     <string name="_bx_ads_form_category"><![CDATA[Category]]></string>
     <string name="_bx_ads_form_category_display_add"><![CDATA[Add Category]]></string>
@@ -374,6 +375,7 @@
     <string name="_bx_ads_txt_sample_reaction_single"><![CDATA['{0}' reaction to ad]]></string>
     <string name="_bx_ads_txt_sample_score_up_single"><![CDATA[score up vote to ad]]></string>
     <string name="_bx_ads_txt_sample_score_down_single"><![CDATA[score down vote to ad]]></string>
+    <string name="_bx_ads_txt_sample_interest_single"><![CDATA[interested in ad]]></string>
     <string name="_bx_ads_txt_display_title_add"><![CDATA[{0}: Add]]></string>
     <string name="_bx_ads_txt_display_title_edit"><![CDATA[{0}: Edit]]></string>
     <string name="_bx_ads_txt_display_title_view"><![CDATA[{0}: View]]></string>
@@ -391,4 +393,6 @@
     <string name="_bx_ads_txt_poll_answer_vote_do_by"><![CDATA[Voted for]]></string>
     <string name="_bx_ads_txt_poll_answer_vote_counter"><![CDATA[{0} votes]]></string>
     <string name="_bx_ads_txt_poll_answer_vote_percent"><![CDATA[({0}%)]]></string>
+
+    <string name="_bx_ads_txt_ntfs_subobject_interested"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> {subentry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
 </resources>

+ 2 - 1
modules/boonex/ads/install/sql/enable.sql

@@ -17,7 +17,8 @@ INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `c
 ('bx_ads_per_page_browse_showcase', '32', @iCategId, '_sys_option_per_page_browse_showcase', 'digit', '', '', '', 15),
 ('bx_ads_rss_num', '10', @iCategId, '_bx_ads_option_rss_num', 'digit', '', '', '', 20),
 ('bx_ads_searchable_fields', 'title,text', @iCategId, '_bx_ads_option_searchable_fields', 'list', '', '', 'a:2:{s:6:"module";s:6:"bx_ads";s:6:"method";s:21:"get_searchable_fields";}', 30),
-('bx_ads_lifetime', '30', @iCategId, '_bx_ads_option_lifetime', 'digit', '', '', '', 40);
+('bx_ads_lifetime', '30', @iCategId, '_bx_ads_option_lifetime', 'digit', '', '', '', 40),
+('bx_ads_internal_interested_notification', '', @iCategId, '_bx_ads_option_internal_interested_notification', 'checkbox', '', '', '', 50);
 
 
 -- PAGE: create entry

+ 4 - 0
modules/boonex/russian/data/langs/bx_ads/ru.xml

@@ -11,6 +11,7 @@
     <string name="_bx_ads_option_rss_num"><![CDATA[Количество элементов в ленте RSS]]></string>
     <string name="_bx_ads_option_searchable_fields"><![CDATA[Поля для поиска по ключевому слову]]></string>
     <string name="_bx_ads_option_lifetime"><![CDATA[Автоматически деактивировать по истечении (в днях)]]></string>
+    <string name="_bx_ads_option_internal_interested_notification"><![CDATA[Использовать встроенную нотификацию о действии 'Интересно']]></string>
 
     <string name="_bx_ads_form_category"><![CDATA[Категория]]></string>
     <string name="_bx_ads_form_category_display_add"><![CDATA[Добавить категорию]]></string>
@@ -374,6 +375,7 @@
     <string name="_bx_ads_txt_sample_reaction_single"><![CDATA[реакция '{0}' к объявлению]]></string>
     <string name="_bx_ads_txt_sample_score_up_single"><![CDATA[голос за объявление]]></string>
     <string name="_bx_ads_txt_sample_score_down_single"><![CDATA[голос против объявления]]></string>
+    <string name="_bx_ads_txt_sample_interest_single"><![CDATA[проявил интерес к]]></string>
     <string name="_bx_ads_txt_display_title_add"><![CDATA[{0}: Добавить]]></string>
     <string name="_bx_ads_txt_display_title_edit"><![CDATA[{0}: Редактировать]]></string>
     <string name="_bx_ads_txt_display_title_view"><![CDATA[{0}: Просмотреть]]></string>
@@ -391,4 +393,6 @@
     <string name="_bx_ads_txt_poll_answer_vote_do_by"><![CDATA[Проголосовали за]]></string>
     <string name="_bx_ads_txt_poll_answer_vote_counter"><![CDATA[{0} голосов]]></string>
     <string name="_bx_ads_txt_poll_answer_vote_percent"><![CDATA[({0}%)]]></string>
+    
+    <string name="_bx_ads_txt_ntfs_subobject_interested"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> {subentry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
 </resources>