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

Merge branch 'master' of https://github.com/boonex/dolphin

AntonLV 10 лет назад
Родитель
Сommit
4f8925d320

+ 32 - 0
modules/base/general/classes/BxBaseModGeneralAlertsResponse.php

@@ -0,0 +1,32 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    BaseGeneral Base classes for modules
+ * @ingroup     TridentModules
+ *
+ * @{
+ */
+
+class BxBaseModGeneralAlertsResponse extends BxDolAlertsResponse
+{
+    protected $MODULE;
+    protected $_oModule;
+
+    public function __construct()
+    {
+        parent::__construct();
+        $this->_oModule = BxDolModule::getInstance($this->MODULE);
+    }
+
+    public function response($oAlert)
+    {
+        $CNF = $this->_oModule->_oConfig->CNF;
+
+        if (isset($CNF['PARAM_SEARCHABLE_FIELDS']) && 'system' == $oAlert->sUnit && 'save_setting' == $oAlert->sAction)
+            $this->_oModule->_oDb->alterFulltextIndex();
+    }
+}
+
+/** @} */

+ 28 - 0
modules/base/general/classes/BxBaseModGeneralDb.php

@@ -33,6 +33,34 @@ class BxBaseModGeneralDb extends BxDolModuleDb
         $sQuery = $this->prepare ("SELECT COUNT(*) FROM `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` WHERE `" . $this->_oConfig->CNF['FIELD_AUTHOR'] . "` = ?", $iProfileId);
         return $this->getOne($sQuery);
     }
+
+    public function alterFulltextIndex ()
+    {
+        $CNF = $this->_oConfig->CNF;        
+
+        $bFulltextIndex = false;
+        $aIndexes = $this->getAll("SHOW INDEXES FROM `bx_persons_data`");
+
+        foreach ($aIndexes as $r) {
+            if ($CNF['TABLE_ENTRIES_FULLTEXT'] == $r['Key_name']) {
+                $bFulltextIndex = true;
+                break;
+            }
+        }
+
+        if ($bFulltextIndex)
+            $this->pdoExec("ALTER TABLE `" . $CNF['TABLE_ENTRIES'] . "` DROP INDEX `" . $CNF['TABLE_ENTRIES_FULLTEXT'] . "`");
+
+        if (!($aFields = explode(',', getParam($CNF['PARAM_SEARCHABLE_FIELDS']))))
+            return true;
+
+        $sFields = '';
+        foreach ($aFields as $s)
+            $sFields .= "`$s`,";
+
+        return $this->pdoExec("ALTER TABLE `" . $CNF['TABLE_ENTRIES'] . "` ADD FULLTEXT `" . $CNF['TABLE_ENTRIES_FULLTEXT'] . "` (" . trim($sFields, ', ') . ")");
+    }
+
 }
 
 /** @} */

+ 17 - 0
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -39,6 +39,23 @@ class BxBaseModGeneralModule extends BxDolModule
         return isset($this->_oConfig->CNF['ICON']) ? $this->_oConfig->CNF['ICON'] : '';
     }
 
+    public function serviceGetSearchableFields ()
+    {
+        $CNF = $this->_oConfig->CNF;
+
+        if (!isset($CNF['PARAM_SEARCHABLE_FIELDS']) || !isset($CNF['OBJECT_FORM_ENTRY']) || !isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']))
+            return array();
+
+        $aTextTypes = array('text', 'textarea');
+        $aTextFields = array();
+        $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
+        foreach ($oForm->aInputs as $r) {
+            if (in_array($r['type'], $aTextTypes))
+                $aTextFields[$r['name']] = $r['caption'];
+        }
+        return $aTextFields;
+    }
+    
 	public function serviceManageTools($sType = 'common')
     {
         $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getGridObject($sType));

+ 3 - 5
modules/base/profile/classes/BxBaseModProfileAlertsResponse.php

@@ -9,19 +9,17 @@
  * @{
  */
 
-class BxBaseModProfileAlertsResponse extends BxDolAlertsResponse
+class BxBaseModProfileAlertsResponse extends BxBaseModGeneralAlertsResponse
 {
-    protected $MODULE;
-    protected $_oModule;
-
     public function __construct()
     {
         parent::__construct();
-        $this->_oModule = BxDolModule::getInstance($this->MODULE);
     }
 
     public function response($oAlert)
     {
+        parent::response($oAlert);
+
         $CNF = $this->_oModule->_oConfig->CNF;
 
         // update picture field id when file is deleted

+ 2 - 0
modules/boonex/persons/classes/BxPersonsConfig.php

@@ -36,6 +36,7 @@ class BxPersonsConfig extends BxBaseModProfileConfig
 
             // database tables
             'TABLE_ENTRIES' => $aModule['db_prefix'] . 'data',
+            'TABLE_ENTRIES_FULLTEXT' => 'search_fields',
 
             // database fields
             'FIELD_ID' => 'id',
@@ -67,6 +68,7 @@ class BxPersonsConfig extends BxBaseModProfileConfig
             'PARAM_DEFAULT_ACL_LEVEL' => 'bx_persons_default_acl_level',
             'PARAM_NUM_RSS' => 'bx_persons_num_rss',
             'PARAM_NUM_CONNECTIONS_QUICK' => 'bx_persons_num_connections_quick',
+            'PARAM_SEARCHABLE_FIELDS' => 'bx_persons_searchable_fields',
 
             // objects
             'OBJECT_STORAGE' => 'bx_persons_pictures',

+ 2 - 1
modules/boonex/persons/classes/BxPersonsSearchResult.php

@@ -25,7 +25,7 @@ class BxPersonsSearchResult extends BxBaseModProfileSearchResult
             'table' => 'sys_profiles',
             'tableSearch' => 'bx_persons_data',
             'ownFields' => array(),
-            'searchFields' => array('fullname', 'description'),
+            'searchFields' => array(),
             'restriction' => array(
         		'account_id' => array('value' => '', 'field' => 'account_id', 'operator' => '='),
                 'perofileStatus' => array('value' => 'active', 'field' => 'status', 'operator' => '='),
@@ -70,6 +70,7 @@ class BxPersonsSearchResult extends BxBaseModProfileSearchResult
 
         $this->sFilterName = 'bx_persons_filter';
         $this->oModule = $this->getMain();
+        $this->aCurrent['searchFields'] = explode(',', getParam($this->oModule->_oConfig->CNF['PARAM_SEARCHABLE_FIELDS']));
 
         switch ($sMode) {
 

+ 1 - 0
modules/boonex/persons/install/langs/en.xml

@@ -7,6 +7,7 @@
 	<string name="_bx_persons_option_default_acl_level"><![CDATA[Default member's level to assign after person's profile creation]]></string>
 	<string name="_bx_persons_option_num_connections_quick"><![CDATA[Number of items in friends block]]></string>
 	<string name="_bx_persons_option_num_rss"><![CDATA[Number of items in RSS feed]]></string>
+	<string name="_bx_persons_option_searchable_fields"><![CDATA[Searchable fields]]></string>
 
 	<string name="_bx_persons_form_profile"><![CDATA[Persons]]></string>
 	<string name="_bx_persons_form_profile_display_add"><![CDATA[Add Person]]></string>

+ 3 - 1
modules/boonex/persons/install/sql/enable.sql

@@ -14,7 +14,8 @@ INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `e
 ('bx_persons_autoapproval', 'on', @iCategId, '_bx_persons_option_autoapproval', 'checkbox', '', '', '', 1),
 ('bx_persons_default_acl_level', '3', @iCategId, '_bx_persons_option_default_acl_level', 'select', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:15:"get_memberships";s:6:"params";a:2:{i:0;b:0;i:1;b:1;}s:5:"class";s:16:"TemplAclServices";}', '', '', 2),
 ('bx_persons_num_connections_quick', '4', @iCategId, '_bx_persons_option_num_connections_quick', 'digit', '', '', '', 10),
-('bx_persons_num_rss', '10', @iCategId, '_bx_persons_option_num_rss', 'digit', '', '', '', 12);
+('bx_persons_num_rss', '10', @iCategId, '_bx_persons_option_num_rss', 'digit', '', '', '', 12),
+('bx_persons_searchable_fields', 'fullname,description', @iCategId, '_bx_persons_option_searchable_fields', 'list', 'a:2:{s:6:"module";s:10:"bx_persons";s:6:"method";s:21:"get_searchable_fields";}', '', '', 20);
 
 -- PAGES
 
@@ -348,6 +349,7 @@ INSERT INTO `sys_alerts_handlers` (`name`, `class`, `file`, `service_call`) VALU
 SET @iHandler := LAST_INSERT_ID();
 
 INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
+('system', 'save_setting', @iHandlerId),
 ('bx_timeline', 'post_common', @iHandler),
 ('bx_persons_pictures', 'file_deleted', @iHandler),
 ('bx_persons', 'timeline_view', @iHandler),

+ 1 - 1
modules/boonex/persons/install/sql/install.sql

@@ -12,7 +12,7 @@ CREATE TABLE IF NOT EXISTS `bx_persons_data` (
   `views` int(11) NOT NULL default '0',
   `allow_view_to` int(11) NOT NULL DEFAULT '3',
   PRIMARY KEY (`id`),
-  FULLTEXT KEY `fullname` (`fullname`)
+  FULLTEXT KEY `search_fields` (`fullname`,`description`)
 );
 
 -- TABLE: STORAGES & TRANSCODERS

+ 2 - 1
modules/boonex/russian/data/langs/bx_persons/ru.xml

@@ -6,7 +6,8 @@
 	<string name="_bx_persons_option_autoapproval"><![CDATA[Автоматически активировать всех персон после создания]]></string>
 	<string name="_bx_persons_option_default_acl_level"><![CDATA[Уровень, по умолчанию назначаемый созданному персональному профилю]]></string>
 	<string name="_bx_persons_option_num_connections_quick"><![CDATA[Число элементов в блоке друзей]]></string>
-	<string name="_bx_persons_option_num_rss"><![CDATA[Число элементов в ленте RSS]]></string>
+    <string name="_bx_persons_option_num_rss"><![CDATA[Число элементов в ленте RSS]]></string>
+    <string name="_bx_persons_option_searchable_fields"><![CDATA[Поля для поиска]]></string>
 
 	<string name="_bx_persons_form_profile"><![CDATA[Персоны]]></string>
 	<string name="_bx_persons_form_profile_display_add"><![CDATA[Добавление персоны]]></string>