AntonLV 9 лет назад
Родитель
Сommit
c930346232

+ 39 - 0
modules/base/general/classes/BxBaseModGeneralFormsEntryHelper.php

@@ -71,6 +71,45 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
         return $this->_oModule->_oTemplate->entryText($aContentInfo);
     }
 
+    public function addData ($iProfile, $aValues)
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        // check and display form
+        $oForm = $this->getObjectFormAdd();
+        if (!$oForm)
+            return array('code' => 1, 'message' => '_sys_txt_error_occured');
+
+        $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
+        $oForm->aParams['csrf']['disable'] = true;
+        if(!empty($oForm->aParams['db']['submit_name']))
+            $aValues[$oForm->aParams['db']['submit_name']] = $oForm->aInputs[$oForm->aParams['db']['submit_name']]['value'];
+
+        $oForm->initChecker(array(), $aValues);
+        if (!$oForm->isSubmittedAndValid())
+            return array('code' => 2, 'message' => '_sys_txt_error_occured');
+
+        // insert data into database
+        $aValsToAdd = array ();
+        if(isset($CNF['FIELD_AUTHOR']))
+            $aValsToAdd[$CNF['FIELD_AUTHOR']] = $iProfile;
+
+        $iContentId = $oForm->insert($aValsToAdd);
+        if (!$iContentId) {
+            if (!$oForm->isValid())
+                return array('code' => 2, 'message' => '_sys_txt_error_occured');
+            else
+                return array('code' => 3, 'message' => '_sys_txt_error_entry_creation');
+        }
+
+        $sResult = $this->onDataAddAfter(BxDolProfile::getInstance($iProfile)->getAccountId(), $iContentId);
+        if($sResult)
+            return array('code' => 4, 'message' => $sResult);
+
+        list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
+        return array('code' => 0, 'message' => '', 'content' => $aContentInfo);
+    }
+
     public function addDataForm ()
     {
         $CNF = &$this->_oModule->_oConfig->CNF;

+ 13 - 1
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -142,8 +142,20 @@ class BxBaseModGeneralModule extends BxDolModule
         return new $sClass($this);
     }
 
+	/**
+     * Add entry using provided fields' values.
+     * @return HTML string
+     */
+    public function serviceEntityAdd ($iAccount, $aValues)
+    {
+        bx_import('FormsEntryHelper', $this->_aModule);
+        $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
+        $oFormsHelper = new $sClass($this);
+        return $oFormsHelper->addData($iAccount, $aValues);
+    }
+
     /**
-     * Add entry form
+     * Create entry form
      * @return HTML string
      */
     public function serviceEntityCreate ()