<commit_before><?php

/**
 * Mmi Framework (https://github.com/milejko/mmi.git)
 * 
 * @link       https://github.com/milejko/mmi.git
 * @copyright  Copyright (c) 2010-2016 <NAME> (http://milejko.com)
 * @license    http://milejko.com/new-bsd.txt New BSD License
 */

namespace CmsAdmin\Form;

/**
 * Formularz typu kategorii
 */
class CategoryType extends \Cms\Form\Form {

	public function init() {

		//nazwa
		$this->addElementText('name')
			->setRequired()
			->addFilterStringTrim()
			->addValidatorNotEmpty()
			->addValidatorRecordUnique(new \Cms\Orm\CmsCategoryTypeQuery, 'name', $this->getRecord()->id)
			->setLabel('nazwa');
		
		//szablon (moduł/kontroler/akcja)
		$this->addElementText('template')
			->setLabel('szablon')
			->addValidatorRegex('/^[a-zA-Z0-9]+\/[a-zA-Z0-9]+\/[a-zA-Z0-9]+$/', 'Szablon w formacie - moduł/kontroler/akcja')
			->setRequired();

		$relation = new \Cms\Model\AttributeGroupRelationModel('cmsCategory', $this->getRecord()->id);

		//grupy atrybutów
		$this->addElementSelect('attributeGroupId')
			->setLabel('grupa atrybutów')
			->setMultioptions([null => '---'] + (new \Cms\Orm\CmsAttributeGroupQuery)->orderAscName()->findPairs('id', 'name'))
			->setValue(current(array_keys($relation->getAttributeGroupRelations())));
		
		//zapis
		$this->addElementSubmit('submit')
			->setLabel('zapisz stronę');
	}
	
	public function beforeSave() {
		$this->getRecord()->key = (new \Mmi\Filter\Url)->filter($this->getRecord()->name);
		return true;
	}
	
	public function afterSave() {
		$relation = new \Cms\Model\AttributeGroupRelationModel('cmsCategory', $this->getRecord()->id);
		$relation->deleteAttributeGroupRelations();
		$relation->createAttributeGroupRelation($this->getElement('attributeGroupId')->getValue());
		return true;<commit_msg>multiple groups category type<commit_after><?php

/**
 * Mmi Framework (https://github.com/milejko/mmi.git)
 * 
 * @link       https://github.com/milejko/mmi.git
 * @copyright  Copyright (c) 2010-2016 <NAME> (http://milejko.com)
 * @license    http://milejko.com/new-bsd.txt New BSD License
 */

namespace CmsAdmin\Form;

/**
 * Formularz typu kategorii
 */
class CategoryType extends \Cms\Form\Form {

	public function init() {

		//nazwa
		$this->addElementText('name')
			->setRequired()
			->addFilterStringTrim()
			->addValidatorNotEmpty()
			->addValidatorRecordUnique(new \Cms\Orm\CmsCategoryTypeQuery, 'name', $this->getRecord()->id)
			->setLabel('nazwa');

		//szablon (moduł/kontroler/akcja)
		$this->addElementText('template')
			->setLabel('szablon')
			->addValidatorRegex('/^[a-zA-Z0-9]+\/[a-zA-Z0-9]+\/[a-zA-Z0-9]+$/', 'Szablon w formacie - moduł/kontroler/akcja')
			->setRequired();

		//grupy atrybutów
		$this->addElementMultiCheckbox('attributeGroupIds')
			->setLabel('grupa atrybutów')
			->setMultioptions((new \Cms\Orm\CmsAttributeGroupQuery)->orderAscName()->findPairs('id', 'name'))
			->setValue(array_keys((new \Cms\Model\AttributeGroupRelationModel('cms_category_type', $this->getRecord()->id))
					->getAttributeGroupRelations()));

		//zapis
		$this->addElementSubmit('submit')
			->setLabel('zapisz stronę');
	}

	/**
	 * Przed zapisem
	 * @return boolean
	 */
	public function beforeSave() {
		//kalkulacja klucza
		$this->getRecord()->key = (new \Mmi\Filter\Url)->filter($this->getRecord()->name);
		return true;
	}

	public function afterSave() {
		//tworzenie relacji
		(new \Cms\Model\AttributeGroupRelationModel('cms_category_type', $this->getRecord()->id))
			->createAttributeGroupRelations($this->getElement('attributeGroupIds')->getValue());
		return true;
{'fraction_non_alphanumeric': 0.19007803790412486, 'fraction_numerical': 0.007803790412486065, 'mean_word_length': 4.396992481203007, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 73, 'https://': 4, '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': '3849272', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1247, 'n_words': 178}