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

Merge branch 'master' of https://github.com/unaio/una

AntonLV 6 лет назад
Родитель
Сommit
077eebb3e8

+ 42 - 1
inc/classes/BxDolFormQuery.php

@@ -112,6 +112,7 @@ class BxDolFormQuery extends BxDolDb
             	'unique' => $a['unique'] ? true : false,
             	'unique' => $a['unique'] ? true : false,
                 'collapsed' => $a['collapsed'] ? true : false,
                 'collapsed' => $a['collapsed'] ? true : false,
                 'privacy' => $a['privacy'] ? true : false,
                 'privacy' => $a['privacy'] ? true : false,
+                'rateable' => $a['rateable'] ? true : false,
                 'html' => $a['html'],
                 'html' => $a['html'],
                 'attrs' => $a['attrs'] ? unserialize($a['attrs']) : false,
                 'attrs' => $a['attrs'] ? unserialize($a['attrs']) : false,
                 'tr_attrs' => $a['attrs_tr'] ? unserialize($a['attrs_tr']) : false,
                 'tr_attrs' => $a['attrs_tr'] ? unserialize($a['attrs_tr']) : false,
@@ -264,13 +265,53 @@ class BxDolFormQuery extends BxDolDb
 
 
         return $bResult;
         return $bResult;
     }
     }
+    
+    static public function addFormField($sObjectForm, $sFieldName, $iContentId, $iAuthorId)
+    {
+        $oDb = BxDolDb::getInstance();
+        $aBindings = array(
+            'object_form' => $sObjectForm,
+            'field_name' => $sFieldName,
+            'content_id' => $iContentId,
+            'author_id' => $iAuthorId
+        );
+        $oDb->query("INSERT `sys_form_fields_ids` SET `object_form`=:object_form, `field_name`=:field_name, `content_id`=:content_id, `author_id`=:author_id", $aBindings);
+    }
+    
+    static public function getFormField($sObjectForm, $sFieldName, $iContentId)
+    {
+        $oDb = BxDolDb::getInstance();
+        $aBindings = array(
+            'object_form' => $sObjectForm,
+            'field_name' => $sFieldName,
+            'content_id' => $iContentId
+        );
+        return $oDb->getOne("SELECT `id` FROM `sys_form_fields_ids` WHERE `object_form`=:object_form AND `field_name`=:field_name AND `content_id`=:content_id", $aBindings);
+    }
+    
+    static public function removeFormField($sObjectForm, $iContentId = 0)
+    {
+        $oDb = BxDolDb::getInstance();
+        if ($iContentId > 0){
+            $aBindings = array(
+                'object_form' => $sObjectForm,
+                'content_id' => $iContentId
+            );
+            $oDb->query("DELETE FROM `sys_form_fields_ids` WHERE  `object_form` = :object_form AND `content_id` = :content_id", $aBindings);
+        }
+        else{
+            $aBindings = array(
+                'object_form' => $sObjectForm
+            );
+            $oDb->query("DELETE FROM `sys_form_fields_ids` WHERE  `object_form` = :object_form", $aBindings);
+        }
+    }
 
 
     public function getFormInputs()
     public function getFormInputs()
     {
     {
         $sQuery = $this->prepare("SELECT * FROM `sys_form_inputs` WHERE `object` = ? ORDER BY `order` ASC", $this->_aObject['object']);
         $sQuery = $this->prepare("SELECT * FROM `sys_form_inputs` WHERE `object` = ? ORDER BY `order` ASC", $this->_aObject['object']);
         return $this->getAll($sQuery);
         return $this->getAll($sQuery);
     }
     }
-
 }
 }
 
 
 /** @} */
 /** @} */

+ 35 - 2
install/sql/system.sql

@@ -1240,7 +1240,8 @@ CREATE TABLE `sys_objects_vote` (
 
 
 INSERT INTO `sys_objects_vote` (`Name`, `TableMain`, `TableTrack`, `PostTimeout`, `MinValue`, `MaxValue`, `IsUndo`, `IsOn`, `TriggerTable`, `TriggerFieldId`, `TriggerFieldAuthor`, `TriggerFieldRate`, `TriggerFieldRateCount`, `ClassName`, `ClassFile`) VALUES 
 INSERT INTO `sys_objects_vote` (`Name`, `TableMain`, `TableTrack`, `PostTimeout`, `MinValue`, `MaxValue`, `IsUndo`, `IsOn`, `TriggerTable`, `TriggerFieldId`, `TriggerFieldAuthor`, `TriggerFieldRate`, `TriggerFieldRateCount`, `ClassName`, `ClassFile`) VALUES 
 ('sys_cmts', 'sys_cmts_votes', 'sys_cmts_votes_track', '604800', '1', '1', '0', '1', 'sys_cmts_ids', 'id', 'author_id', 'rate', 'votes', '', ''),
 ('sys_cmts', 'sys_cmts_votes', 'sys_cmts_votes_track', '604800', '1', '1', '0', '1', 'sys_cmts_ids', 'id', 'author_id', 'rate', 'votes', '', ''),
-('sys_cmts_reactions', 'sys_cmts_reactions', 'sys_cmts_reactions_track', '604800', '1', '1', '1', '1', 'sys_cmts_ids', 'id', 'author_id', 'rrate', 'rvotes', 'BxTemplVoteReactions', '');
+('sys_cmts_reactions', 'sys_cmts_reactions', 'sys_cmts_reactions_track', '604800', '1', '1', '1', '1', 'sys_cmts_ids', 'id', 'author_id', 'rrate', 'rvotes', 'BxTemplVoteReactions', ''),
+('sys_form_fields_reaction', 'sys_form_fields_reaction', 'sys_form_fields_reaction_track', '604800', '1', '1', '1', '1', 'sys_form_fields_ids', 'id', 'author_id', 'rrate', 'rvotes', 'BxTemplVoteReactions', '');
 
 
 -- --------------------------------------------------------
 -- --------------------------------------------------------
 
 
@@ -1501,6 +1502,26 @@ CREATE TABLE IF NOT EXISTS `sys_cmts_reactions_track` (
   KEY `vote` (`object_id`, `author_nip`)
   KEY `vote` (`object_id`, `author_nip`)
 );
 );
 
 
+CREATE TABLE IF NOT EXISTS `sys_form_fields_reaction` (
+  `object_id` int(11) NOT NULL default '0',
+  `reaction` varchar(32) NOT NULL default '',
+  `count` int(11) NOT NULL default '0',
+  `sum` int(11) NOT NULL default '0',
+  UNIQUE KEY `reaction` (`object_id`, `reaction`)
+);
+
+CREATE TABLE IF NOT EXISTS `sys_form_fields_reaction_track` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `object_id` int(11) NOT NULL default '0',
+  `author_id` int(11) NOT NULL default '0',
+  `author_nip` int(11) unsigned NOT NULL default '0',
+  `reaction` varchar(32) NOT NULL default '',
+  `value` tinyint(4) NOT NULL default '0',
+  `date` int(11) NOT NULL default '0',
+  PRIMARY KEY (`id`),
+  KEY `vote` (`object_id`, `author_nip`)
+);
+
 CREATE TABLE IF NOT EXISTS `sys_cmts_reports` (
 CREATE TABLE IF NOT EXISTS `sys_cmts_reports` (
   `object_id` int(11) NOT NULL default '0',
   `object_id` int(11) NOT NULL default '0',
   `count` int(11) NOT NULL default '0',
   `count` int(11) NOT NULL default '0',
@@ -3166,6 +3187,7 @@ CREATE TABLE IF NOT EXISTS `sys_form_inputs` (
   `collapsed` tinyint(4) NOT NULL DEFAULT '0',
   `collapsed` tinyint(4) NOT NULL DEFAULT '0',
   `html` tinyint(4) NOT NULL DEFAULT '0',
   `html` tinyint(4) NOT NULL DEFAULT '0',
   `privacy` tinyint(4) NOT NULL DEFAULT '0',
   `privacy` tinyint(4) NOT NULL DEFAULT '0',
+  `rateable` tinyint(4) NOT NULL DEFAULT '0',
   `attrs` text NOT NULL,
   `attrs` text NOT NULL,
   `attrs_tr` text NOT NULL,
   `attrs_tr` text NOT NULL,
   `attrs_wrapper` text NOT NULL,
   `attrs_wrapper` text NOT NULL,
@@ -3486,6 +3508,17 @@ INSERT INTO `sys_form_display_inputs` (`display_name`, `input_name`, `visible_fo
 ('sys_wiki_translate', 'close', 2147483647, 1, 7),
 ('sys_wiki_translate', 'close', 2147483647, 1, 7),
 ('sys_wiki_translate', 'buttons', 2147483647, 1, 8);
 ('sys_wiki_translate', 'buttons', 2147483647, 1, 8);
 
 
+CREATE TABLE `sys_form_fields_ids` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `object_form` varchar(64) NOT NULL default '',
+  `field_name` varchar(255) NOT NULL default '',
+  `content_id` int(11) NOT NULL DEFAULT '0',
+  `author_id` int(11) NOT NULL DEFAULT '0',
+  `nested_content_id` int(11) NOT NULL default '0',
+  `rrate` float NOT NULL DEFAULT '0',
+  `rvotes` int(11) NOT NULL DEFAULT '0',
+  PRIMARY KEY (`id`)
+);
 
 
 CREATE TABLE `sys_form_pre_lists` (
 CREATE TABLE `sys_form_pre_lists` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `id` int(11) NOT NULL AUTO_INCREMENT,
@@ -4695,6 +4728,7 @@ CREATE TABLE IF NOT EXISTS `sys_objects_page` (
   `cover_image` int(11) NOT NULL DEFAULT '0',
   `cover_image` int(11) NOT NULL DEFAULT '0',
   `type_id` int(11) NOT NULL DEFAULT '1',
   `type_id` int(11) NOT NULL DEFAULT '1',
   `layout_id` int(11) NOT NULL,
   `layout_id` int(11) NOT NULL,
+  `sticky_columns` tinyint(4) NOT NULL DEFAULT '0',
   `submenu` varchar(64) NOT NULL DEFAULT '',
   `submenu` varchar(64) NOT NULL DEFAULT '',
   `visible_for_levels` int(11) NOT NULL DEFAULT '2147483647',
   `visible_for_levels` int(11) NOT NULL DEFAULT '2147483647',
   `visible_for_levels_editable` tinyint(4) NOT NULL DEFAULT '1',
   `visible_for_levels_editable` tinyint(4) NOT NULL DEFAULT '1',
@@ -4709,7 +4743,6 @@ CREATE TABLE IF NOT EXISTS `sys_objects_page` (
   `deletable` tinyint(1) NOT NULL,
   `deletable` tinyint(1) NOT NULL,
   `override_class_name` varchar(255) NOT NULL,
   `override_class_name` varchar(255) NOT NULL,
   `override_class_file` varchar(255) NOT NULL,
   `override_class_file` varchar(255) NOT NULL,
-  `sticky_columns` tinyint(4) NOT NULL DEFAULT '0',
   PRIMARY KEY (`id`),
   PRIMARY KEY (`id`),
   UNIQUE KEY `object` (`object`),
   UNIQUE KEY `object` (`object`),
   UNIQUE KEY `uri` (`uri`(191))
   UNIQUE KEY `uri` (`uri`(191))

+ 33 - 0
modules/base/general/classes/BxBaseModGeneralFormEntry.php

@@ -27,6 +27,8 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
     protected $_sGhostTemplate = 'form_ghost_template.html';
     protected $_sGhostTemplate = 'form_ghost_template.html';
     
     
     protected $_aTrackFieldsChanges;
     protected $_aTrackFieldsChanges;
+    
+    protected $_iContentId;
 
 
     public function __construct($aInfo, $oTemplate = false)
     public function __construct($aInfo, $oTemplate = false)
     {
     {
@@ -146,6 +148,8 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
         
         
         $bValues = $aValues && !empty($aValues['id']);
         $bValues = $aValues && !empty($aValues['id']);
         
         
+        $this->_iContentId = isset($aValues['id']) ? $aValues['id'] : false;
+        
         if (!empty($CNF['FIELD_LOCATION_PREFIX']) && isset($this->aInputs[$CNF['FIELD_LOCATION_PREFIX']]) && isset($aValues[$CNF['FIELD_ID']]) && !empty($CNF['OBJECT_METATAGS']) && ($oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])) && $oMetatags->locationsIsEnabled())
         if (!empty($CNF['FIELD_LOCATION_PREFIX']) && isset($this->aInputs[$CNF['FIELD_LOCATION_PREFIX']]) && isset($aValues[$CNF['FIELD_ID']]) && !empty($CNF['OBJECT_METATAGS']) && ($oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])) && $oMetatags->locationsIsEnabled())
             $this->aInputs[$CNF['FIELD_LOCATION_PREFIX']]['value'] = $oMetatags->locationsString($aValues[$CNF['FIELD_ID']], false);
             $this->aInputs[$CNF['FIELD_LOCATION_PREFIX']]['value'] = $oMetatags->locationsString($aValues[$CNF['FIELD_ID']], false);
 
 
@@ -253,6 +257,13 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
                 $this->processMulticatAfter($CNF['FIELD_MULTICAT'], $iContentId);
                 $this->processMulticatAfter($CNF['FIELD_MULTICAT'], $iContentId);
         }
         }
         
         
+        
+        foreach($this->aInputs as $aInput) {
+            if ($aInput['rateable']){
+                BxDolFormQuery::addFormField($this->id, $aInput['name'], $iContentId, $aValsToAdd[$CNF['FIELD_AUTHOR']]);
+            }
+        }
+        
         return $iContentId;
         return $iContentId;
     }
     }
 
 
@@ -361,6 +372,8 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
         }
         }
 
 
         // delete db record
         // delete db record
+        
+        BxDolFormQuery::removeFormField($this->id, $iContentId);
 
 
         return parent::delete($iContentId);
         return parent::delete($iContentId);
     }
     }
@@ -444,6 +457,26 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
 
 
         return $s;
         return $s;
     }
     }
+    
+    function genViewRowWrapped(&$aInput)
+    {
+        if (!$aInput['rateable']){
+            return parent::genViewRowWrapped($aInput);
+        }
+        
+        $sValue = $this->genViewRowValue($aInput);
+        if (null === $sValue)
+            return '';
+        
+        $iId = BxDolFormQuery::getFormField($this->id, $aInput['name'], $this->_iContentId);
+        $oReaction = BxDolVote::getObjectInstance('sys_form_fields_reaction', $iId, true, BxDolTemplate::getInstance());
+        $sReactions = $oReaction->getElementInline(array('show_counter_empty' => true, 'show_counter' => true, 'show_counter_style' => 'compound', 'dynamic_mode' => $this->_bDynamicMode));
+        return $this->oTemplate->parseHtmlByName('form_view_row.html', array(
+            'type' => $aInput['type'], 
+            'caption' => isset($aInput['caption']) ? bx_process_output($aInput['caption']) : '',
+            'value' => $sValue . $sReactions
+        ));
+    }
 
 
     function setMetatagsKeywordsData($iId, $a, $o)
     function setMetatagsKeywordsData($iId, $a, $o)
     {
     {

+ 5 - 3
modules/boonex/english/data/langs/system/en.xml

@@ -736,7 +736,8 @@
 	<string name="_adm_form_dsc_field_collapsed"><![CDATA[Pack down the group of this field by default]]></string>
 	<string name="_adm_form_dsc_field_collapsed"><![CDATA[Pack down the group of this field by default]]></string>
 	<string name="_adm_form_dsc_field_html"><![CDATA[Select type of HTML editor]]></string>
 	<string name="_adm_form_dsc_field_html"><![CDATA[Select type of HTML editor]]></string>
 	<string name="_adm_form_dsc_field_info"><![CDATA[Enter field description (optional)]]></string>
 	<string name="_adm_form_dsc_field_info"><![CDATA[Enter field description (optional)]]></string>
-        <string name="_adm_form_dsc_field_privacy"><![CDATA[Check it if privacy settings can be changed for the field]]></string>
+  <string name="_adm_form_dsc_field_privacy"><![CDATA[Check it if privacy settings can be changed for the field]]></string>
+  <string name="_adm_form_dsc_field_rateable"><![CDATA[Make this field rateable]]></string>
 	<string name="_adm_form_dsc_field_required"><![CDATA[Check it if the field should have value]]></string>
 	<string name="_adm_form_dsc_field_required"><![CDATA[Check it if the field should have value]]></string>
 	<string name="_adm_form_dsc_field_unique"><![CDATA[Check it if the field should have unique value]]></string>
 	<string name="_adm_form_dsc_field_unique"><![CDATA[Check it if the field should have unique value]]></string>
 	<string name="_adm_form_dsc_field_value_button"><![CDATA[Enter button title here]]></string>
 	<string name="_adm_form_dsc_field_value_button"><![CDATA[Enter button title here]]></string>
@@ -870,8 +871,9 @@
 	<string name="_adm_form_txt_field_module"><![CDATA[Module]]></string>
 	<string name="_adm_form_txt_field_module"><![CDATA[Module]]></string>
 	<string name="_adm_form_txt_field_name"><![CDATA[Name]]></string>
 	<string name="_adm_form_txt_field_name"><![CDATA[Name]]></string>
 	<string name="_adm_form_txt_field_object"><![CDATA[Form]]></string>
 	<string name="_adm_form_txt_field_object"><![CDATA[Form]]></string>
-        <string name="_adm_form_txt_field_privacy"><![CDATA[Privacy]]></string>
-	<string name="_adm_form_txt_field_required"><![CDATA[Mandatory]]></string>
+  <string name="_adm_form_txt_field_privacy"><![CDATA[Privacy]]></string>
+  <string name="_adm_form_txt_field_rateable"><![CDATA[Rateable]]></string>
+  <string name="_adm_form_txt_field_required"><![CDATA[Mandatory]]></string>
 	<string name="_adm_form_txt_field_show_to_popup"><![CDATA[Show "{0}" form field to: ]]></string>
 	<string name="_adm_form_txt_field_show_to_popup"><![CDATA[Show "{0}" form field to: ]]></string>
         <string name="_adm_form_txt_field_type_block_end"><![CDATA[block end]]></string>
         <string name="_adm_form_txt_field_type_block_end"><![CDATA[block end]]></string>
 	<string name="_adm_form_txt_field_type_block_header"><![CDATA[block header]]></string>
 	<string name="_adm_form_txt_field_type_block_header"><![CDATA[block header]]></string>

+ 18 - 0
studio/template/scripts/BxBaseStudioFormsField.php

@@ -291,6 +291,10 @@ class BxBaseStudioFormsField extends BxDolStudioFormsField
                     case 'privacy':
                     case 'privacy':
                         $aForm['inputs'][$sKey]['checked'] = (int)$this->aField[$sKey];
                         $aForm['inputs'][$sKey]['checked'] = (int)$this->aField[$sKey];
                         break;
                         break;
+                        
+                    case 'rateable':
+                        $aForm['inputs'][$sKey]['checked'] = (int)$this->aField[$sKey];
+                        break;
 
 
                     case 'checker_func':
                     case 'checker_func':
                         $sCfValue = strtolower($this->aField[$sKey]);
                         $sCfValue = strtolower($this->aField[$sKey]);
@@ -999,6 +1003,20 @@ class BxBaseStudioFormsFieldBlockHeader extends BxBaseStudioFormsField
                         'pass' => 'Int',
                         'pass' => 'Int',
                     )
                     )
                 ),
                 ),
+                'rateable' => array(
+                    'type' => 'switcher',
+                    'name' => 'rateable',
+                    'caption' => _t('_adm_form_txt_field_rateable'),
+                    'info' => _t('_adm_form_dsc_field_rateable'),
+                    'value' => '1',
+                    'required' => '0',
+                    'attrs' => array(
+                        'id' => 'bx-form-field-rateable'
+                    ),
+                    'db' => array (
+                        'pass' => 'Int',
+                    )
+                ),
                 'controls' => array(
                 'controls' => array(
                     'name' => 'controls',
                     'name' => 'controls',
                     'type' => 'input_set',
                     'type' => 'input_set',