Ejemplo n.º 1
0
 /**
  * @see	\wcf\system\importer\IImporter::import()
  */
 public function import($oldID, array $data, array $additionalData = array())
 {
     $data['packageID'] = 1;
     // set temporary option name
     $data['optionName'] = StringUtil::getRandomID();
     if ($data['optionType'] == 'boolean' || $data['optionType'] == 'integer') {
         if (isset($data['defaultValue'])) {
             $data['defaultValue'] = intval($data['defaultValue']);
         }
     }
     // create category
     $this->createCategory($data['categoryName']);
     // save option
     $action = new UserOptionAction(array(), 'create', array('data' => $data));
     $returnValues = $action->executeAction();
     $userOption = $returnValues['returnValues'];
     // update generic option name
     $editor = new UserOptionEditor($userOption);
     $editor->update(array('optionName' => 'option' . $userOption->optionID));
     // save name
     $sql = "INSERT IGNORE INTO\twcf" . WCF_N . "_language_item\n\t\t\t\t\t\t(languageID, languageItem, languageItemValue, languageItemOriginIsSystem, languageCategoryID, packageID)\n\t\t\tVALUES\t\t\t(?, ?, ?, ?, ?, ?)";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array(LanguageFactory::getInstance()->getDefaultLanguageID(), 'wcf.user.option.option' . $userOption->optionID, $additionalData['name'], 0, $this->languageCategoryID, 1));
     ImportHandler::getInstance()->saveNewID('com.woltlab.wcf.user.option', $oldID, $userOption->optionID);
     return $userOption->optionID;
 }
Ejemplo n.º 2
0
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     parent::save();
     $this->objectAction = new UserOptionAction(array(), 'create', array('data' => array_merge($this->additionalFields, array('optionName' => StringUtil::getRandomID(), 'categoryName' => $this->categoryName, 'optionType' => $this->optionType, 'defaultValue' => $this->defaultValue, 'showOrder' => $this->showOrder, 'outputClass' => $this->outputClass, 'validationPattern' => $this->validationPattern, 'selectOptions' => $this->selectOptions, 'required' => $this->required, 'askDuringRegistration' => $this->askDuringRegistration, 'searchable' => $this->searchable, 'editable' => $this->editable, 'visible' => $this->visible, 'packageID' => 1, 'additionalData' => $this->optionType == 'select' ? serialize(array('allowEmptyValue' => true)) : ''))));
     $this->objectAction->executeAction();
     $returnValues = $this->objectAction->getReturnValues();
     $userOption = $returnValues['returnValues'];
     // save language vars
     I18nHandler::getInstance()->save('optionName', 'wcf.user.option.option' . $userOption->optionID, 'wcf.user.option');
     I18nHandler::getInstance()->save('optionDescription', 'wcf.user.option.option' . $userOption->optionID . '.description', 'wcf.user.option');
     $editor = new UserOptionEditor($userOption);
     $editor->update(array('optionName' => 'option' . $userOption->optionID));
     $this->saved();
     // reset values
     $this->optionName = $this->optionDescription = $this->categoryName = $this->optionType = $this->defaultValue = $this->validationPattern = $this->selectOptions = $this->outputClass = '';
     $this->optionType = 'text';
     $this->required = $this->searchable = $this->showOrder = $this->askDuringRegistration = 0;
     $this->editable = 3;
     $this->visible = 15;
     I18nHandler::getInstance()->reset();
     // show success
     WCF::getTPL()->assign('success', true);
 }
 /**
  * @see	wcf\system\package\plugin\AbstractOptionPackageInstallationPlugin::saveOption()
  */
 protected function saveOption($option, $categoryName, $existingOptionID = 0)
 {
     // default values
     $optionName = $optionType = $defaultValue = $validationPattern = $outputClass = $selectOptions = $enableOptions = $permissions = $options = '';
     $required = $editable = $visible = $searchable = $disabled = $askDuringRegistration = 0;
     $showOrder = null;
     // get values
     if (isset($option['name'])) {
         $optionName = $option['name'];
     }
     if (isset($option['optiontype'])) {
         $optionType = $option['optiontype'];
     }
     if (isset($option['defaultvalue'])) {
         $defaultValue = $option['defaultvalue'];
     }
     if (isset($option['validationpattern'])) {
         $validationPattern = $option['validationpattern'];
     }
     if (isset($option['required'])) {
         $required = intval($option['required']);
     }
     if (isset($option['askduringregistration'])) {
         $askDuringRegistration = intval($option['askduringregistration']);
     }
     if (isset($option['editable'])) {
         $editable = intval($option['editable']);
     }
     if (isset($option['visible'])) {
         $visible = intval($option['visible']);
     }
     if (isset($option['searchable'])) {
         $searchable = intval($option['searchable']);
     }
     if (isset($option['showorder'])) {
         $showOrder = intval($option['showorder']);
     }
     if (isset($option['outputclass'])) {
         $outputClass = $option['outputclass'];
     }
     if (isset($option['selectoptions'])) {
         $selectOptions = $option['selectoptions'];
     }
     if (isset($option['enableoptions'])) {
         $enableOptions = $option['enableoptions'];
     }
     if (isset($option['disabled'])) {
         $disabled = intval($option['disabled']);
     }
     $showOrder = $this->getShowOrder($showOrder, $categoryName, 'categoryName');
     if (isset($option['permissions'])) {
         $permissions = $option['permissions'];
     }
     if (isset($option['options'])) {
         $options = $option['options'];
     }
     // check if optionType exists
     $className = 'wcf\\system\\option\\' . StringUtil::firstCharToUpperCase($optionType) . 'OptionType';
     if (!class_exists($className)) {
         throw new SystemException("unable to find class '" . $className . "'");
     }
     // collect additional tags and their values
     $additionalData = array();
     foreach ($option as $tag => $value) {
         if (!in_array($tag, self::$reservedTags)) {
             $additionalData[$tag] = $value;
         }
     }
     // get optionID if it was installed by this package already
     $sql = "SELECT\t*\n\t\t\tFROM \twcf" . WCF_N . "_" . $this->tableName . "\n\t\t\tWHERE \toptionName = ?\n\t\t\tAND\tpackageID = ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array($optionName, $this->installation->getPackageID()));
     $result = $statement->fetchArray();
     // build data array
     $data = array('categoryName' => $categoryName, 'optionType' => $optionType, 'defaultValue' => $defaultValue, 'validationPattern' => $validationPattern, 'selectOptions' => $selectOptions, 'enableOptions' => $enableOptions, 'required' => $required, 'askDuringRegistration' => $askDuringRegistration, 'editable' => $editable, 'visible' => $visible, 'outputClass' => $outputClass, 'searchable' => $searchable, 'showOrder' => $showOrder, 'disabled' => $disabled, 'permissions' => $permissions, 'options' => $options, 'additionalData' => serialize($additionalData));
     // update option
     if (!empty($result['optionID']) && $this->installation->getAction() == 'update') {
         $userOption = new UserOption(null, $result);
         $userOptionEditor = new UserOptionEditor($userOption);
         $userOptionEditor->update($data);
     } else {
         // append option name
         $data['optionName'] = $optionName;
         $data['packageID'] = $this->installation->getPackageID();
         UserOptionEditor::create($data);
     }
 }
	/**
	 * @see	wcf\system\package\plugin\AbstractOptionPackageInstallationPlugin::saveOption()
	 */
	protected function saveOption($option, $categoryName, $existingOptionID = 0) {
		// default values
		$optionName = $optionType = $validationPattern = $outputClass = $selectOptions = $enableOptions = $permissions = $options = '';
		$required = $editable = $visible = $searchable = $isDisabled = $askDuringRegistration = 0;
		$defaultValue = $showOrder = null;
		
		// get values
		if (isset($option['name'])) $optionName = $option['name'];
		if (isset($option['optiontype'])) $optionType = $option['optiontype'];
		if (isset($option['defaultvalue'])) $defaultValue = $option['defaultvalue'];
		if (isset($option['validationpattern'])) $validationPattern = $option['validationpattern'];
		if (isset($option['required'])) $required = intval($option['required']);
		if (isset($option['askduringregistration'])) $askDuringRegistration = intval($option['askduringregistration']);
		if (isset($option['editable'])) $editable = intval($option['editable']);
		if (isset($option['visible'])) $visible = intval($option['visible']);
		if (isset($option['searchable'])) $searchable = intval($option['searchable']);
		if (isset($option['showorder'])) $showOrder = intval($option['showorder']);
		if (isset($option['outputclass'])) $outputClass = $option['outputclass'];
		if (isset($option['selectoptions'])) $selectOptions = $option['selectoptions'];
		if (isset($option['enableoptions'])) $enableOptions = $option['enableoptions'];
		if (isset($option['isdisabled'])) $isDisabled = intval($option['isdisabled']);
		$showOrder = $this->getShowOrder($showOrder, $categoryName, 'categoryName');
		if (isset($option['permissions'])) $permissions = $option['permissions'];
		if (isset($option['options'])) $options = $option['options'];
		
		// collect additional tags and their values
		$additionalData = array();
		foreach ($option as $tag => $value) {
			if (!in_array($tag, self::$reservedTags)) $additionalData[$tag] = $value;
		}
		
		// get optionID if it was installed by this package already
		$sql = "SELECT	*
			FROM	wcf".WCF_N."_".$this->tableName."
			WHERE	optionName = ?
			AND	packageID = ?";
		$statement = WCF::getDB()->prepareStatement($sql);
		$statement->execute(array(
			$optionName,
			$this->installation->getPackageID()
		));
		$result = $statement->fetchArray();
		
		// build data array
		$data = array(
			'categoryName' => $categoryName,
			'optionType' => $optionType,
			'defaultValue' => $defaultValue,
			'validationPattern' => $validationPattern,
			'selectOptions' => $selectOptions,
			'enableOptions' => $enableOptions,
			'required' => $required,
			'askDuringRegistration' => $askDuringRegistration,
			'editable' => $editable,
			'visible' => $visible,
			'outputClass' => $outputClass,
			'searchable' => $searchable,
			'showOrder' => $showOrder,
			'isDisabled' => $isDisabled,
			'permissions' => $permissions,
			'options' => $options,
			'additionalData' => serialize($additionalData)
		);
		
		// update option
		if (!empty($result['optionID']) && $this->installation->getAction() == 'update') {
			$userOption = new UserOption(null, $result);
			$userOptionEditor = new UserOptionEditor($userOption);
			$userOptionEditor->update($data);
		}
		// insert new option
		else {
			// append option name
			$data['optionName'] = $optionName;
			$data['packageID'] = $this->installation->getPackageID();
			UserOptionEditor::create($data);
		}
	}