Exemplo n.º 1
0
 function toeObjectToArray($data)
 {
     if (!is_array($data) and !is_object($data)) {
         return $data;
     }
     //$data;
     $result = array();
     $data = (array) $data;
     foreach ($data as $key => $value) {
         if (is_object($value)) {
             $value = (array) $value;
         }
         if (is_array($value)) {
             $result[$key] = toeObjectToArray($value);
         } else {
             $result[$key] = $value;
         }
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Displays the config options for given module
  * 
  * @param string $module 
  * @param array $addDefaultOptions - if you want to add some additionsl options - specify it here
  */
 public function drawConfig($module, $additionalOptions = array())
 {
     if (!frameCsp::_()->getModule($module)) {
         return false;
     }
     // check for xml file with params structure
     if (frameCsp::_()->getModule($module)->isExternal()) {
         $config_xml = frameCsp::_()->getModule($module)->getModDir() . 'mod.xml';
     } else {
         $config_xml = CSP_MODULES_DIR . $module . DS . 'mod.xml';
     }
     if (!file_exists($config_xml)) {
         // if there is no configuration file for this $module
         return langCsp::_('There are no configuration options for this module');
     }
     $output = '';
     // reading params structure
     $configOptions = $this->prepareConfigOptions($config_xml);
     // reading params from database
     //bugodel2nia..............
     if (is_string($this->value)) {
         $params = Utils::jsonDecode($this->value);
     } elseif (is_object($this->value) || is_array($this->value)) {
         $params = toeObjectToArray($this->value);
     }
     //if (!empty($params)) {
     if (!empty($configOptions)) {
         $i = 0;
         if (empty($params)) {
             $params = array('0' => array());
         }
         if (is_array($additionalOptions) && !empty($additionalOptions)) {
             $configOptions = array_merge($configOptions, $additionalOptions);
         }
         foreach ($params as $param) {
             $output .= '<div class="module_options">';
             foreach ($configOptions as $key => $value) {
                 $fieldValue = '';
                 $output .= '<div class="module_option">';
                 $method = $configOptions[$key]['type'];
                 $name = 'params[' . $i . '][' . $key . ']';
                 $options = array();
                 // if the values attribute is set
                 if ($configOptions[$key]['values'] != '') {
                     $extract_options = explode(',', $configOptions[$key]['values']);
                     if (count($extract_options) > 1) {
                         foreach ($extract_options as $item => $string) {
                             if (strpos($string, '=>')) {
                                 $keyVal = array_map('trim', explode('=>', $string));
                                 $options[$keyVal[0]] = $keyVal[1];
                             } else {
                                 $options[$string] = $string;
                             }
                         }
                     } else {
                         $fieldValue = $configOptions[$key]['default'];
                     }
                     // if helper is needed to render the object
                 } elseif ($configOptions[$key]['helper'] != '') {
                     $helper_name = $configOptions[$key]['helper'];
                     // is helper from current module or other?
                     if ($configOptions[$key]['module'] != '') {
                         $hmodule = $configOptions[$key]['module'];
                     } else {
                         $hmodule = $module;
                     }
                     // calling the helper class
                     $helper = frameCsp::_()->getModule($hmodule)->getHelper();
                     if ($helper) {
                         // calling the helper method for current option
                         if (method_exists($helper, $helper_name)) {
                             $options = $helper->{$helper_name}();
                         }
                     }
                 }
                 if (isset($param[$key])) {
                     $fieldValue = $param[$key];
                 } else {
                     if ($fieldValue == '') {
                         $fieldValue = $configOptions[$key]['default'];
                     }
                 }
                 // filling the parameters to build html element
                 $htmlParams = array('value' => $fieldValue, 'optionsCsp' => $options);
                 if ($method == 'checkbox') {
                     $htmlParams['value'] = 1;
                     $htmlParams['checked'] = (bool) $fieldValue;
                 }
                 if (!empty($configOptions[$key]['htmlParams']) && is_array($configOptions[$key]['htmlParams'])) {
                     $htmlParams = array_merge($htmlParams, $configOptions[$key]['htmlParams']);
                 }
                 // output label and html element
                 $output .= '<label>' . langCsp::_($configOptions[$key]['label']);
                 if ($configOptions[$key]['description'] != '') {
                     $output .= '<a class="toeOptTip" tip="' . langCsp::_($configOptions[$key]['description']) . '"></a>';
                 }
                 $output .= '</label><br />';
                 $output .= htmlCsp::$method($name, $htmlParams) . '<br />';
                 $output .= '</div>';
             }
             $i++;
             $output .= '</div>';
         }
     }
     return $output;
 }