Explorar o código

#2991 Rateable fields

RomanL %!s(int64=6) %!d(string=hai) anos
pai
achega
e466872b84

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

@@ -27,6 +27,8 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
     protected $_sGhostTemplate = 'form_ghost_template.html';
     
     protected $_aTrackFieldsChanges;
+    
+    protected $_iContentId;
 
     public function __construct($aInfo, $oTemplate = false)
     {
@@ -146,6 +148,8 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
         
         $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())
             $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);
         }
         
+        
+        foreach($this->aInputs as $aInput) {
+            if ($aInput['rateable']){
+                BxDolFormQuery::addFormField($this->id, $aInput['name'], $iContentId, $aValsToAdd[$CNF['FIELD_AUTHOR']]);
+            }
+        }
+        
         return $iContentId;
     }
 
@@ -361,6 +372,8 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
         }
 
         // delete db record
+        
+        BxDolFormQuery::removeFormField($this->id, $iContentId);
 
         return parent::delete($iContentId);
     }
@@ -444,6 +457,26 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
 
         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)
     {

+ 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_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_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_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>
@@ -870,8 +871,9 @@
 	<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_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_type_block_end"><![CDATA[block end]]></string>
 	<string name="_adm_form_txt_field_type_block_header"><![CDATA[block header]]></string>