/** * Convert to database query * @param mixed $data if array given - convert it into string where key - is column name, value - database value to set; * if key == "additionalCondition" then we will just add value to string * if string givven - just return it without changes * @param string $delim delimiter to use in query, recommended - ',', 'AND', 'OR' * @return string query string */ public function _getQueryString($data, $delim = ',', $validate = false) { $res = ''; if (is_array($data) && !empty($data)) { foreach ($data as $k => $v) { if (array_key_exists($k, $this->_fields) || $k == $this->_id) { $val = $v; if (isset($this->_fields[$k]) && $this->_fields[$k]->adapt['dbTo']) { $val = fieldAdapterGmp::_($val, $this->_fields[$k]->adapt['dbTo'], fieldAdapterGmp::DB); } if ($validate) { if (isset($this->_fields[$k]) && is_object($this->_fields[$k])) { $objForValidation = clone $this->_fields[$k]; $objForValidation->setValue($val); if ($errors = validatorGmp::_($objForValidation)) { $this->_addError($errors); } } } if (isset($this->_fields[$k])) { switch ($this->_fields[$k]->type) { case 'int': case 'tinyint': $res .= $k . ' = ' . (int) $val . ' ' . $delim . ' '; break; case 'float': $res .= $k . ' = ' . (double) $val . ' ' . $delim . ' '; break; case 'decimal': $res .= $k . ' = ' . (double) $val . ' ' . $delim . ' '; break; case 'free': //Just set it as it is $res .= $k . ' = ' . $val . ' ' . $delim . ' '; break; default: $res .= $k . ' = \'' . $val . '\' ' . $delim . ' '; break; } } else { $res .= $k . ' = \'' . $val . '\' ' . $delim . ' '; } } elseif ($k == 'additionalCondition') { //just add some string to query $res .= $v . ' ' . $delim . ' '; } } $res = substr($res, 0, -(strlen($delim) + 1)); } elseif (is_string($data)) { $res = $data; } return $res; }
/** * Function to process field params */ public function processParams($tag, $id) { return ''; if ($this->name == "params") { if (is_array($this->value) || is_object($this->value)) { $params = $this->value; } else { $params = json_decode($this->value); } $add_option = ''; switch ($tag) { case 5: $add_option = __('Add Checkbox', GMP_LANG_CODE); $options_tag = ''; $image_tag = ' style="display:none"'; break; case 9: $add_option = __('Add Item', GMP_LANG_CODE); $options_tag = ''; $image_tag = ' style="display:none"'; break; case 12: $add_option = __('Add Item', GMP_LANG_CODE); $options_tag = ''; $image_tag = ' style="display:none"'; break; case 10: $options_tag = ''; $add_option = __('Add Radio Button', GMP_LANG_CODE); $image_tag = ' style="display:none"'; break; case 8: $image_tag = ''; $options_tag = ' style="display:none"'; break; default: $options_tag = ' style="display:none"'; $image_tag = ' style="display:none"'; break; } if ($tag > 0 || $id == 0) { $output .= '<div class="options options_tag"' . $options_tag . '>'; $output .= '<span class="add_option">' . $add_option . '</span>'; $output .= fieldAdapterGmp::_($id, 'getExtraFieldOptions', fieldAdapterGmp::STR); $output .= '</div>'; $output .= '<div class="options image_tag"' . $image_tag . '>' . __('Dimensions', GMP_LANG_CODE) . ':<br />'; $params->width ? $width = $params->width : ''; $params->height ? $height = $params->height : ''; $output .= __('width', GMP_LANG_CODE) . ':<br />'; $output .= htmlGmp::text('params[width]', array('value' => $width)) . '<br />'; $output .= __('height', GMP_LANG_CODE) . ':<br />'; $output .= htmlGmp::text('params[height]', array('value' => $height)) . '<br />'; $output .= '</div>'; } if ($this->adapt['htmlParams']) { $output .= fieldAdapterGmp::_($this, $this->adapt['htmlParams'], fieldAdapterGmp::STR); } else { $output .= '<a href="javascript:void(0);" class="set_properties">' . __('Click to set field "id" and "class"', GMP_LANG_CODE) . '</a>'; $output .= '<div class="attributes" style="display:none;">' . __('Attributes', GMP_LANG_CODE) . ':<br />'; $output .= fieldAdapterGmp::_($params, 'getFieldAttributes', fieldAdapterGmp::STR); $output .= '</div>'; } return $output; } }