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

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

AntonLV 2 лет назад
Родитель
Сommit
8c78e911ff

+ 87 - 0
modules/boonex/okta_connect/classes/BxOktaConStudioPage.php

@@ -26,6 +26,93 @@ class BxOktaConStudioPage extends BxTemplStudioModule
         $oModule = BxDolModule::getInstance('bx_oktacon'); 
         return _t('_bx_oktacon_information_block', BX_DOL_URL_ROOT . $oModule -> _oConfig -> getBaseUri() . 'handle');
     }
+
+    function getImport ()
+    {
+        $aForm = array(
+            'form_attrs' => ['enctype' => 'multipart/form-data'],
+            'params' => ['db' => ['submit_name' => 'do_submit']],
+            'inputs' => array(
+                'file' => array(
+                    'type' => 'file',
+                    'name' => 'file',
+                    'caption' => 'CSV File',
+                    'required' => true,
+                ),
+
+                'field_email' => array(
+                    'type' => 'text',
+                    'name' => 'field_email',
+                    'caption' => 'Email field',
+                    'required' => true,
+                ),
+
+                'field_remote_id' => array(
+                    'type' => 'text',
+                    'name' => 'field_remote_id',
+                    'caption' => 'Remote ID field',
+                    'required' => true,
+                ),
+
+                'do_submit' => array(
+                    'type' => 'submit',
+                    'name' => 'do_submit',
+                    'value' => 'Submit',
+                ),
+            ),
+        );
+
+        $oForm =new BxTemplFormView($aForm);
+
+        $oForm->initChecker(); // init form checker witout any data - adding new record
+        if ($oForm->isSubmittedAndValid()) {
+            $aFields = [];
+            $iEmail = false;
+            $iRemId = false;
+            $sOutput = '<style>.err { color:red; } .ok { color:green; } </style>';
+            if (!empty($_FILES["file"]["tmp_name"]) && ($handle = fopen($_FILES["file"]["tmp_name"], "r")) !== FALSE) {
+                $row = 1;
+                while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
+                    $num = count($data);
+                    if (1 === $row) {
+                        for ($c=0; $c < $num; $c++) {
+                            $aFields[$data[$c]] = $c;
+                        }
+                        $iEmail = isset($aFields[$_POST['field_email']]) ? $aFields[$_POST['field_email']] : false;
+                        $iRemId = isset($aFields[$_POST['field_remote_id']]) ? $aFields[$_POST['field_remote_id']] : false;
+                        if (!isset($aFields[$_POST['field_email']]) || !isset($aFields[$_POST['field_remote_id']])) {
+                            $sOutput = 'no matching fields were found';
+                            break;
+                        }
+                    }
+                    else {
+                        if (empty($data[$iEmail]) || empty($data[$iRemId])) {
+                            $sOutput .= "$row. EMPTY : <b class=\"err\">ERR - input data is empty</b><br />";
+                        } else { 
+                            $oAccount = BxDolAccount::getInstance(trim($data[$iEmail]));
+                            $oProfile = $oAccount ? BxDolProfile::getInstanceAccountProfile($oAccount->id()) : false;
+                            if (!$oAccount || !$oProfile) {
+                                $sOutput .= "$row. {$data[$iEmail]} : <b class=\"err\">ERR - no matching account or profile was found</b><br />";
+                            }
+                            else {
+                                $res = BxDolDb::getInstance()->query("INSERT IGNORE INTO `bx_oktacon_accounts` (`local_profile`, `remote_profile`) VALUES (:lp, :rp)", ['lp' => $oProfile->id(), 'rp' => $data[$iRemId]]);         
+                                if ($res)
+                                    $sOutput .= "$row. {$data[$iEmail]} :  <b class=\"ok\">OK</b> {$data[$iRemId]} => " . $oProfile->id() . " <br />";
+                                else
+                                    $sOutput .= "$row. {$data[$iEmail]} :  <b class=\"err\">ERR - DB insert query failed (maybe duplicate record)</b> {$data[$iRemId]} => " . $oProfile->id() . " <br />";
+                            }                            
+                        }
+                        $sOutput .= "<hr />";
+                    }
+                    $row++;
+                }
+                fclose($handle);
+                return $sOutput;
+            }
+        }
+
+        return $oForm->getCode();
+    }
 }
 
 /** @} */

+ 7 - 1
modules/boonex/timeline/classes/BxTimelineMenuItemCounters.php

@@ -56,7 +56,13 @@ class BxTimelineMenuItemCounters extends BxTimelineMenuItemActions
                 break;
         }
 
-        return $this->_oModule->getCmtsObject($sCommentsSystem, $iCommentsObject)->$sCommentsMethod($aCommentsParams);
+        $oObject = $this->_oModule->getCmtsObject($sCommentsSystem, $iCommentsObject);
+        if($this->_bIsApi)
+            return $this->_getMenuItemElementApi($aItem, $oObject->getElementApi(array_merge($aCommentsParams, [
+                'show_counter' => true,
+            ])));
+
+        return $oObject->$sCommentsMethod($aCommentsParams);
     }
 }
 

+ 8 - 0
modules/boonex/timeline/classes/BxTimelineTemplate.php

@@ -2044,6 +2044,14 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
         else
             $oMenuManage = $aEvent['menu_manage'];
 
+        if(empty($aEvent['menu_counters'])) {
+            $oMenuCounters = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_counters'));
+        }
+        else
+            $oMenuCounters = $aEvent['menu_counters'];
+
+        $aEvent['menu_counters'] = $oMenuCounters !== false && $oMenuCounters->setEvent($aEvent, $aParams) ? $oMenuCounters->getCodeAPI() : [];
+        
         $aEvent['menu_manage'] = $oMenuManage !== false && $oMenuManage->setEvent($aEvent) ? $oMenuManage->getShortCodeAPI() : [];
 
         if ($aParams['type'] != 'owner')