1
0
RomanL 6 жил өмнө
parent
commit
e4056a2f6e

+ 3 - 3
inc/classes/BxDolForm.php

@@ -1066,7 +1066,7 @@ class BxDolForm extends BxDol implements iBxDolReplaceable
             if (!isset($aInput['ghost_template']))
                 continue;
 
-            if (!(is_array($aInput['ghost_template']) && isset($aInput['ghost_template']['inputs'])) && !(is_object($aInput['ghost_template']) && $aInput['ghost_template'] instanceof BxDolFormNested))
+            if (!(is_array($aInput['ghost_template']) && isset($aInput['ghost_template']['inputs'])) && !(is_object($aInput['ghost_template']) && $aInput['ghost_template'] instanceof BxDolFormNestedGhost))
                 continue;
 
             $sName = $aInput['name'];
@@ -1082,7 +1082,7 @@ class BxDolForm extends BxDol implements iBxDolReplaceable
                 if (is_object($aInput['ghost_template'])) {
                     $oFormNested = clone($aInput['ghost_template']);
                 } else {
-                    $oFormNested = new BxDolFormNested($aInput['name'], $aInput['ghost_template'], $this->aParams['db']['submit_name'], $this->oTemplate);
+                    $oFormNested = new BxDolFormNestedGhost($aInput['name'], $aInput['ghost_template'], $this->aParams['db']['submit_name'], $this->oTemplate);
                 }
                 if ($iFileId && 0 != $iFileId)
                     $aNestedForms[$iFileId] = $oFormNested;
@@ -1096,7 +1096,7 @@ class BxDolForm extends BxDol implements iBxDolReplaceable
                 foreach ($oFormNested->aInputs as $r) {
                     $sName = str_replace('[]', '', $r['name']);
                     $aValue = $this->getSubmittedValue($sName, $this->aFormAttrs['method']);
-                    $aSpecificValues[$sName] = $aValue[$i];
+                    $aSpecificValues[$sName] = isset($aValue[$i]) ? $aValue[$i] : '';
                 }
                 $oFormNested->initChecker(array(), $aSpecificValues);
 

+ 21 - 33
inc/classes/BxDolFormNested.php

@@ -14,42 +14,30 @@
  */
 class BxDolFormNested extends BxTemplFormView
 {
-    /**
-     * Constructor
-     * @param $sName the name of form field from main form, where this nested form is inserted.
-     * @param $aForm form array, actually only form inout are needed, all other attributes are taken from parent form automatically.
-     * @param $sSubmitName main form submit_name; field name of submit form input to determine if form is submitted or not.
-     * @param $oTemplate optional template object
-     */
-    function __construct($sName, $aForm, $sSubmitName = false, $oTemplate = false)
+    public function __construct ($aInfo, $oTemplate)
     {
-        if (!isset($aForm['params']['nested_form_template']) || !$aForm['params']['nested_form_template'])
-            $aForm['params']['nested_form_template'] = 'uploader_nested_form_wrapper.html';
-
-        $aForm['form_attrs']['id'] = $sName . '_{file_id}';
-        $aForm['form_attrs']['method'] = 'specific';
-        $aForm['params']['remove_form'] = true;
-        $aForm['params']['csrf']['disable'] = true;
-        if ($sSubmitName)
-            $aForm['params']['db']['submit_name'] = $sSubmitName;
-        if (!isset($aForm['inputs'][$sName])) {
-            $aForm['inputs'][$sName] = array(
-                'type' => 'hidden',
-                'name' => $sName . '[]',
-                'value' => '{file_id}',
-            );
-        }
-
-        parent::__construct($aForm, $oTemplate);
+        parent::__construct($aInfo, $oTemplate);
     }
-
-    function genForm()
+    
+    function genInputStandard(&$aInput)
     {
-        $sNestedForm = parent::genForm();
-        $a = array (
-            'nested_form' => $sNestedForm,
-        );
-        return $this->oTemplate->parseHtmlByName($this->aParams['nested_form_template'], $a);
+        if($aInput['type'] != 'checkbox')
+            return parent::genInputStandard($aInput);
+
+        $aInputHidden = $aInput;
+        
+        $aInputHidden['type'] = 'hidden';
+        if (isset($aInput['checked']) and $aInput['checked'])
+            $aInputHidden['value'] = '1';
+        else
+            $aInputHidden['value'] = '0';
+        
+        $sRv = parent::genInputStandard($aInputHidden);
+        $aInput['name'] = 'chk_' . $aInput['name'];
+        $aInput['attrs']['onchange'] = 'BxDolForm.setCheckBoxValue(this)';
+        $sRv .= parent::genInputStandard($aInput);
+   
+        return $sRv;
     }
 }
 

+ 56 - 0
inc/classes/BxDolFormNestedGhost.php

@@ -0,0 +1,56 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaCore UNA Core
+ * @{
+ */
+
+/**
+ * Nested form. It is used in file uploaders to show uploaded file as nested form.
+ * @see BxDolUploader
+ * @see BxDolForm
+ */
+class BxDolFormNestedGhost extends BxTemplFormView
+{
+    /**
+     * Constructor
+     * @param $sName the name of form field from main form, where this nested form is inserted.
+     * @param $aForm form array, actually only form inout are needed, all other attributes are taken from parent form automatically.
+     * @param $sSubmitName main form submit_name; field name of submit form input to determine if form is submitted or not.
+     * @param $oTemplate optional template object
+     */
+    function __construct($sName, $aForm, $sSubmitName = false, $oTemplate = false)
+    {
+        if (!isset($aForm['params']['nested_form_template']) || !$aForm['params']['nested_form_template'])
+            $aForm['params']['nested_form_template'] = 'uploader_nested_form_wrapper.html';
+
+        $aForm['form_attrs']['id'] = $sName . '_{file_id}';
+        $aForm['form_attrs']['method'] = 'specific';
+        $aForm['params']['remove_form'] = true;
+        $aForm['params']['csrf']['disable'] = true;
+        if ($sSubmitName)
+            $aForm['params']['db']['submit_name'] = $sSubmitName;
+        if (!isset($aForm['inputs'][$sName])) {
+            $aForm['inputs'][$sName] = array(
+                'type' => 'hidden',
+                'name' => $sName . '[]',
+                'value' => '{file_id}',
+            );
+        }
+
+        parent::__construct($aForm, $oTemplate);
+    }
+
+    function genForm()
+    {
+        $sNestedForm = parent::genForm();
+        $a = array (
+            'nested_form' => $sNestedForm,
+        );
+        return $this->oTemplate->parseHtmlByName($this->aParams['nested_form_template'], $a);
+    }
+}
+
+/** @} */

+ 24 - 0
inc/classes/BxDolFormQuery.php

@@ -33,6 +33,30 @@ class BxDolFormQuery extends BxDolDb
         $this->_aObject = $aObject;
     }
 
+    static public function getFormObject ($sObject)
+    {
+        $oDb = BxDolDb::getInstance();
+
+        $sQuery = $oDb->prepare("SELECT * FROM `sys_objects_form` WHERE `object` = ?", $sObject);
+        return $oDb->fromMemory('sys_objects_form_' . $sObject, 'getRow', $sQuery);
+    }
+    
+    static public function getNestedFormObjects ($sParentObject)
+    {
+        $oDb = BxDolDb::getInstance();
+
+        $sQuery = $oDb->prepare("SELECT * FROM `sys_objects_form` WHERE `parent_form` = ?", $sParentObject);
+        return $oDb->fromMemory('sys_objects_form_' . $sObject, 'getAll', $sQuery);
+    }
+    
+    static public function deleteDataFromNestedForm ($sTableName, $iContentId)
+    {
+        $oDb = BxDolDb::getInstance();
+
+        $sQuery = $oDb->prepare("DELETE FROM  `" . $sTableName ."`  WHERE `content_id` = ?", $iContentId);
+        $oDb->query($sQuery);
+    }
+    
     static public function getFormArray ($sObject, $sDisplayName)
     {
         $oDb = BxDolDb::getInstance();

+ 2 - 2
inc/classes/BxDolUploader.php

@@ -78,11 +78,11 @@
  * file id field is added automatically as hidden input as well.
  *
  *
- * 3. Pass instance of BxDolFormNested class - use BxDolFormNested class or its custom subclass;
+ * 3. Pass instance of BxDolFormNestedGhost class - use BxDolFormNestedGhost class or its custom subclass;
  * to create instance use the same form array as in the previous variant, for example:
  *
  * @code
- * $oFormNested = new BxDolFormNested('attachment', $aFormNested, 'do_submit');
+ * $oFormNested = new BxDolFormNestedGhost('attachment', $aFormNested, 'do_submit');
  * @endcode
  *
  * - 'attachment' is the name of file form field from main form.

+ 9 - 0
inc/js/classes/BxDolForm.js

@@ -57,4 +57,13 @@ BxDolForm.prototype._getDefaultParams = function()
     };
 };
 
+BxDolForm.setCheckBoxValue = function (obj) {
+    var oHidden = $(obj).parent('div').find('INPUT[type=hidden]')
+    var val = 0;
+    if ($(obj).attr("checked") == 'checked') {
+        val = 1;
+    }
+    oHidden.val(val);
+}
+
 /** @} */

+ 1 - 2
install/sql/system.sql

@@ -3541,8 +3541,7 @@ CREATE TABLE `sys_form_fields_ids` (
   `rrate` float NOT NULL DEFAULT '0',
   `rvotes` int(11) NOT NULL DEFAULT '0',
   PRIMARY KEY (`id`),
-  KEY `system_form_fields_id` (`object_form`, `content_id`, `nested_content_id`),
-  KEY `system_form_fields_id_module` (`module`)
+  KEY `system_form_fields_id` (`object_form`, `content_id`, `nested_content_id`)
 );
 
 CREATE TABLE `sys_form_pre_lists` (

+ 15 - 1
studio/classes/BxDolStudioFormsField.php

@@ -23,7 +23,8 @@ class BxDolStudioFormsField extends BxDol
     protected $aParams = array();
     protected $aField = array();
     protected $iFieldNameMaxLen;
-
+    protected $aFormObject = array();
+    
     public function __construct($aParams = array(), $aField = array())
     {
         parent::__construct();
@@ -78,6 +79,14 @@ class BxDolStudioFormsField extends BxDol
         );
 
         $this->aParams = $aParams;
+        
+        $this->aFormObject = BxDolFormQuery::getFormObject ($this->aParams['object']); 
+        if ($this->isNested()){
+            $this->aTypes['nested_form']['add'] = 0;
+            $this->aTypes['file']['add'] = 0;
+            $this->aTypes['files']['add'] = 0;
+        }
+       
         $this->aField = $aField;
         $this->iFieldNameMaxLen = 32;
     }
@@ -97,6 +106,11 @@ class BxDolStudioFormsField extends BxDol
         return isset($this->aParams['table']) && !empty($this->aParams['table']);
     }
 
+    public function isNested()
+    {
+        return $this->aFormObject['parent_form'] != '' ? true : false;
+    }
+    
     /**
      * Checks whether the field exists in connected table.
      * @param type $sName - field name

+ 2 - 2
studio/classes/BxDolStudioFormsQuery.php

@@ -66,9 +66,9 @@ class BxDolStudioFormsQuery extends BxDolDb
                 $aMethod['params'][3] = array(
                 	'parent_form' => $aParams['parent_form']
                 );
-                $sWhereClause = "AND `tf`.`parent_form`=:parent_form";
+                $sWhereClause = "AND `tf`.`parent_form`=:parent_form AND `object` NOT IN (SELECT `value` FROM `sys_form_inputs` sfi WHERE `type`='nested_form' AND `object` = :parent_form)";
                 break;
-                
+             
             case 'all':
                 break;
         }

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

@@ -1037,6 +1037,10 @@ class BxBaseStudioFormsFieldBlockHeader extends BxBaseStudioFormsField
                 )
             )
         );
+        
+        if ($this->isNested()){
+            unset($this->aForm['inputs']['rateable']);
+        }
     }
 }
 

+ 3 - 0
template/css/forms.css

@@ -468,6 +468,9 @@
 	display: flex !important;
 	justify-content: flex-start;
 }
+.bx-form-row-view-ratevalue .bx-form-row-view-value{
+    flex-grow: 2;
+}
 .bx-form-row-view-wrapper-textarea > div {
     vertical-align:top;
 }

+ 2 - 1
template/form_view_nested_row.html

@@ -1 +1,2 @@
-<div class="bx-def-margin-leftright">__value__</div>
+<div class="bx-def-margin-leftright bx-def-margin-bottom">__value__</div>
+<div class="bx-db-divider bx-def-hr"></div>

+ 3 - 3
template/scripts/BxBaseFormView.php

@@ -1357,19 +1357,19 @@ BLAH;
         if (isset($aInput['ghost_template']) && is_object($aInput['ghost_template'])) { // form is not submitted and ghost template is BxDolFormNested object
 
             $oFormNested = $aInput['ghost_template'];
-            if ($oFormNested instanceof BxDolFormNested)
+            if ($oFormNested instanceof BxDolFormNestedGhost)
                 $sGhostTemplate = $oFormNested->genForm();
 
         } elseif (isset($aInput['ghost_template']) && is_array($aInput['ghost_template']) && isset($aInput['ghost_template']['inputs'])) { // form is not submitted and ghost template is form array
 
-            $oFormNested = new BxDolFormNested($aInput['name'], $aInput['ghost_template'], $this->aParams['db']['submit_name'], $this->oTemplate);
+            $oFormNested = new BxDolFormNestedGhost($aInput['name'], $aInput['ghost_template'], $this->aParams['db']['submit_name'], $this->oTemplate);
             $sGhostTemplate = $oFormNested->getCode();
 
         } elseif (isset($aInput['ghost_template']) && is_array($aInput['ghost_template']) && $aInput['ghost_template']) { // form is submitted and ghost template is array of BxDolFormNested objects
 
             $sGhostTemplate = array ();
             foreach ($aInput['ghost_template'] as $iFileId => $oFormNested)
-                if (is_object($oFormNested) && $oFormNested instanceof BxDolFormNested)
+                if (is_object($oFormNested) && $oFormNested instanceof BxDolFormNestedGhost)
                     $sGhostTemplate[$iFileId] = $oFormNested->genForm();
 
         } elseif (isset($aInput['ghost_template']) && is_string($aInput['ghost_template'])) { // ghost template is just string template, without nested form