<commit_before><?php


/**
 * @author <NAME>, w3concepts AG
 * @copyright Copyright &copy; 2010, w3concepts AG
 */

class Aitsu_Forms_Renderer_ExtJs {

	public static function render(Aitsu_Forms $form) {

		$out = 'new Ext.FormPanel({';

		$params = $form->getParams()->extjs->toArray();
		$params['title'] = $form->title;
		$params['url'] = $form->url;
		$params['id'] = $form->getUid();

		array_walk($params, array (
			'self',
			'_transform'
		));

		$out .= implode(', ', $params);

		$groups = $form->getGroups()->toArray();

		array_walk($groups, array (
			'self',
			'_transformGroups'
		));

		$out .= ', items: [' . implode(', ', $groups) . ']';

		$buttons = $form->getButtons()->toArray();

		array_walk($buttons, array (
			'self',
			'_transformButtons'
		), $form->getUid());

		$out .= ', buttons: [' . implode(', ', $buttons) . ']';

		$out .= '})';

		return $out;
	}

	protected static function _transform(& $value, $key) {

		$val = null;

		if ($value === true || $value == 'true') {
			$val = 'true';
		}
		elseif ($value === false || $value == 'false') {
			$val = 'false';
		}
		elseif (is_numeric($value)) {
			$val = $value;
		}
		elseif (is_array($value)) {
			array_walk($value, array (
				self,
				'_transform'
			));
			$val = '{' . implode(', ', $value) . '}';
		} else {
			$val = "'$value'";
		}

		$value = $key . ': ' . $val;
	}

	protected static function _transformGroups(& $value, $key) {

		$configs = array ();

		if (!empty ($value['type'])) {
			$configs[] = "xtype: '{$value['type']}'";
			$configs[] = "title: '{$value['legend']}'";

			if (isset ($value['extjs'])) {
				foreach ($value['extjs'] as $key => $val) {
					if (is_array($val)) {
						array_walk($val, array (
							'self',
							'_transform'
						));
						$configs[] = $key . ': {' . implode(', ', $val) . '}';
					} else {
						$configs[] = "$key: '$val'";
					}
				}
			}
		}

		if (!empty ($value['field'])) {
			$fields = $value['field'];

			array_walk($fields, array (
				'self',
				'_transformFields'
			));

			$configs[] = 'items: [' . implode(', ', $fields) . ']';

			$value = '{' . implode(', ', $configs) . '}';
		}
	}

	protected static function _transformFields(& $value, $key) {

		$configs = array ();

		$configs[] = "xtype: '{$value['type']}'";
		if (!empty($value['label'])) {
			$configs[] = "fieldLabel: '" . Aitsu_Translate :: translate($value['label']) . "'";
		}
		$configs[] = "name: '{$key}'";

		if (method_exists('Aitsu_Forms_Renderer_ExtJs', '_extraFieldAtts' . ucfirst($value['type']))) {
			call_user_func(array (
				'self',
				'_extraFieldAtts' . ucfirst($value['type'])
			), & $configs, $key, $value);
		}

		if (!empty ($value['value'])) {
			$configs[] = "value: '{$value['value']}'";
		}

		if (!empty ($value['option'])) {
			self :: _addOptions($configs, $value['type'], $value['option']);
		}

		if (isset ($value['extjs'])) {
			foreach ($value['extjs'] as $key => $val) {
				if (is_array($val)) {
					array_walk($val, array (
						self,
						'_transform'
					));
					$configs[] = $key . ': {' . implode(', ', $val) . '}';
				}
				elseif (is_numeric($val)) {
					$configs[] = "$key: $val";
				} else {
					$configs[] = "$key: '$val'";
				}
			}
		}

		$value = '{' . implode(', ', $configs) . '}';
	}

	protected static function _extraFieldAttsCombo(& $configs, $key, $field) {<commit_msg>Removed reference as this is deprecated.<commit_after><?php


/**
 * @author <NAME>, w3concepts AG
 * @copyright Copyright &copy; 2010, w3concepts AG
 */

class Aitsu_Forms_Renderer_ExtJs {

	public static function render(Aitsu_Forms $form) {

		$out = 'new Ext.FormPanel({';

		$params = $form->getParams()->extjs->toArray();
		$params['title'] = $form->title;
		$params['url'] = $form->url;
		$params['id'] = $form->getUid();

		array_walk($params, array (
			'self',
			'_transform'
		));

		$out .= implode(', ', $params);

		$groups = $form->getGroups()->toArray();

		array_walk($groups, array (
			'self',
			'_transformGroups'
		));

		$out .= ', items: [' . implode(', ', $groups) . ']';

		$buttons = $form->getButtons()->toArray();

		array_walk($buttons, array (
			'self',
			'_transformButtons'
		), $form->getUid());

		$out .= ', buttons: [' . implode(', ', $buttons) . ']';

		$out .= '})';

		return $out;
	}

	protected static function _transform(& $value, $key) {

		$val = null;

		if ($value === true || $value == 'true') {
			$val = 'true';
		}
		elseif ($value === false || $value == 'false') {
			$val = 'false';
		}
		elseif (is_numeric($value)) {
			$val = $value;
		}
		elseif (is_array($value)) {
			array_walk($value, array (
				self,
				'_transform'
			));
			$val = '{' . implode(', ', $value) . '}';
		} else {
			$val = "'$value'";
		}

		$value = $key . ': ' . $val;
	}

	protected static function _transformGroups(& $value, $key) {

		$configs = array ();

		if (!empty ($value['type'])) {
			$configs[] = "xtype: '{$value['type']}'";
			$configs[] = "title: '{$value['legend']}'";

			if (isset ($value['extjs'])) {
				foreach ($value['extjs'] as $key => $val) {
					if (is_array($val)) {
						array_walk($val, array (
							'self',
							'_transform'
						));
						$configs[] = $key . ': {' . implode(', ', $val) . '}';
					} else {
						$configs[] = "$key: '$val'";
					}
				}
			}
		}

		if (!empty ($value['field'])) {
			$fields = $value['field'];

			array_walk($fields, array (
				'self',
				'_transformFields'
			));

			$configs[] = 'items: [' . implode(', ', $fields) . ']';

			$value = '{' . implode(', ', $configs) . '}';
		}
	}

	protected static function _transformFields(& $value, $key) {

		$configs = array ();

		$configs[] = "xtype: '{$value['type']}'";
		if (!empty($value['label'])) {
			$configs[] = "fieldLabel: '" . Aitsu_Translate :: translate($value['label']) . "'";
		}
		$configs[] = "name: '{$key}'";

		if (method_exists('Aitsu_Forms_Renderer_ExtJs', '_extraFieldAtts' . ucfirst($value['type']))) {
			call_user_func(array (
				'self',
				'_extraFieldAtts' . ucfirst($value['type'])
			), $configs, $key, $value);
		}

		if (!empty ($value['value'])) {
			$configs[] = "value: '{$value['value']}'";
		}

		if (!empty ($value['option'])) {
			self :: _addOptions($configs, $value['type'], $value['option']);
		}

		if (isset ($value['extjs'])) {
			foreach ($value['extjs'] as $key => $val) {
				if (is_array($val)) {
					array_walk($val, array (
						self,
						'_transform'
					));
					$configs[] = $key . ': {' . implode(', ', $val) . '}';
				}
				elseif (is_numeric($val)) {
					$configs[] = "$key: $val";
				} else {
					$configs[] = "$key: '$val'";
				}
			}
		}

		$value = '{' . implode(', ', $configs) . '}';
	}

	protected static function _extraFieldAttsCombo(& $configs, $key, $field) {
{'fraction_non_alphanumeric': 0.24818813784943056, 'fraction_numerical': 0.0017748853719863926, 'mean_word_length': 3.068592057761733, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5548952', 'n_tokens_mistral': 3005, 'n_tokens_neox': 2479, 'n_words': 479}