/** * Used by the SearchQuery Description generator * Enter description here ... * @param string $strValue */ public function GetValueDescriptionForCustomValue($strValue) { switch ($this->QueryNodeTypeId) { case QueryNodeType::AttributeNode: return AttributeOption::Load($strValue)->Name; default: return $strValue; } }
public function beforeValidate() { if ($this->attribute_option_id) { $option = AttributeOption::model()->findByPk($this->attribute_option_id); $this->attribute_value = $option ? $option->value : null; } if (!$this->attribute_value) { $this->addErrors(['attribute_value' => Yii::t('StoreModule.store', 'You must specify the attribute value')]); } return parent::beforeValidate(); }
public function afterSave() { if ($this->type == Attribute::TYPE_DROPDOWN) { // список новых значений опций атрибута, не пустые, без лишних пробелов по бокам, уникальные $newOptions = array_unique(array_filter(array_map('trim', explode("\n", $this->rawOptions)))); // в нижнем регистре, чтобы не надо было переназначать привязку атрибутов в товарах $newOptionsLower = array_map(function ($x) { return mb_strtolower($x, 'utf-8'); }, $newOptions); $oldOptionsLower = []; // список имен опций, которые уже сохранены // удалим те из них, которых нет, в остальных обновим значение и позицию foreach ((array) $this->options as $option) { /* @var $option AttributeOption */ $position = array_search(mb_strtolower($option->value), $newOptionsLower); // опция была удалена if ($position === false) { $option->delete(); } else { $oldOptionsLower[] = mb_strtolower($option->value, 'utf-8'); $option->value = $newOptions[$position]; // если поменяли регистр опции $option->position = $position; $option->save(); } } // добавим оставшиеся foreach (array_diff($newOptionsLower, $oldOptionsLower) as $position => $value) { $option = new AttributeOption(); $option->attribute_id = $this->id; $option->value = $newOptions[$position]; $option->position = $position; $option->save(); } } parent::afterSave(); }
protected function btnSave_Click($strFormId, $strControlId, $strParameter) { $this->mctAttribute->SaveAttribute(); if ($this->pnlAttributeOptions) { foreach ($this->pnlAttributeOptions->GetChildControls() as $txtAttributeOption) { if ($txtAttributeOption->ActionParameter) { $objAttributeOption = AttributeOption::Load($txtAttributeOption->ActionParameter); if ($objAttributeOption->AttributeId != $this->mctAttribute->Attribute->Id) { throw new Exception('Unlinked Attribute Option Found'); } if ($objAttributeOption->Name != trim($txtAttributeOption->Text)) { $objAttributeOption->Name = trim($txtAttributeOption->Text); $objAttributeOption->Save(); } } else { if ($strOptionName = trim($txtAttributeOption->Text)) { $objAttributeOption = new AttributeOption(); $objAttributeOption->Attribute = $this->mctAttribute->Attribute; $objAttributeOption->Name = $strOptionName; $objAttributeOption->Save(); } } } } $this->ReturnToList(); }
protected function CreateControlsForAttributes() { $this->txtAttributePreviousChurch = new QTextBox($this); $this->txtAttributePreviousChurch->Name = 'Previous Church'; $this->txtAttributeOccupation = new QTextBox($this); $this->txtAttributeOccupation->Name = 'Occupation'; $this->lstAttributeMethodJoin = new QListBox($this); $this->lstAttributeMethodJoin->Name = 'Method of Joining ALCF'; $this->lstAttributeMethodJoin->AddItem('- Select One -', null); $objAttribute = Attribute::QuerySingle(QQ::Equal(QQN::Attribute()->Name, "Method of Joining ALCF")); $attributeOptionArray = AttributeOption::LoadArrayByAttributeId($objAttribute->Id); foreach ($attributeOptionArray as $objAttributeOption) { $this->lstAttributeMethodJoin->AddItem($objAttributeOption->Name, $objAttributeOption->Id); } $this->lstAttributeEthnicity = new QListBox($this); $this->lstAttributeEthnicity->Name = 'Ethnicity'; $this->lstAttributeEthnicity->AddItem('- Select One -', null); $objAttribute = Attribute::QuerySingle(QQ::Equal(QQN::Attribute()->Name, "Ethnicity")); $attributeOptionArray = AttributeOption::LoadArrayByAttributeId($objAttribute->Id); foreach ($attributeOptionArray as $objAttributeOption) { $this->lstAttributeEthnicity->AddItem($objAttributeOption->Name, $objAttributeOption->Id); } $this->dtxAttributeDateAcceptedChrist = new QDateTimeTextBox($this); $this->dtxAttributeDateAcceptedChrist->Name = 'Date Accepted Christ'; $this->calAttributeDateAcceptedChrist = new QCalendar($this, $this->dtxAttributeDateAcceptedChrist); $this->chkAcceptedChristAtALCF = new QCheckBox($this); $this->chkAcceptedChristAtALCF->Name = 'Accepted Christ at ALCF?'; $this->chkAcceptedChristAtALCF->Text = 'Click if this person accepted Christ at ALCF'; }
echo $variant->attribute->title; ?> <input type="hidden" value="<?php echo $variant->attribute_id; ?> " name="ProductVariant[<?php echo $variant->id; ?> ][attribute_id]"/> </td> <td> <?php if ($variant->attribute->type == Attribute::TYPE_DROPDOWN) { ?> <?php $option = AttributeOption::model()->findByAttributes(['attribute_id' => $variant->attribute_id, 'value' => $variant->attribute_value]); echo $variant->attribute->renderField($option ? $option->id : null, 'ProductVariant[' . $variant->id . '][attribute_option_id]'); ?> <?php } else { ?> <?php echo $variant->attribute->renderField($variant->attribute_value, 'ProductVariant[' . $variant->id . '][attribute_value]'); ?> <?php } ?> </td> <td> <?php echo CHtml::dropDownList('ProductVariant[' . $variant->id . '][type]', $variant->type, $variant->getTypeList(), ['class' => 'form-control']);
public function afterSave() { // удаляем старые значения AttributeOption::model()->deleteAllByAttributes(['attribute_id' => $this->id]); if (in_array($this->type, [Attribute::TYPE_DROPDOWN])) { $newOptions = explode("\n", $this->rawOptions); $newOptions = array_filter($newOptions, function ($x) { return strlen(trim($x)); }); foreach (array_values((array) $newOptions) as $key => $op) { $option = new AttributeOption(); $option->attribute_id = $this->id; $option->value = trim($op); $option->position = $key; $option->save(); } } parent::afterSave(); }
protected function lstAttributeOptionsAsMultiple_Update() { if ($this->lstAttributeOptionsAsMultiple) { $this->objAttributeValue->UnassociateAllAttributeOptionsAsMultiple(); $objSelectedListItems = $this->lstAttributeOptionsAsMultiple->SelectedItems; if ($objSelectedListItems) { foreach ($objSelectedListItems as $objListItem) { $this->objAttributeValue->AssociateAttributeOptionAsMultiple(AttributeOption::Load($objListItem->Value)); } } } }
/** * Main utility method to aid with data binding. It is used by the default BindAllRows() databinder but * could and should be used by any custom databind methods that would be used for instances of this * MetaDataGrid, by simply passing in a custom QQCondition and/or QQClause. * * If a paginator is set on this DataBinder, it will use it. If not, then no pagination will be used. * It will also perform any sorting (if applicable). * * @param QQCondition $objConditions override the default condition of QQ::All() to the query, itself * @param QQClause[] $objOptionalClauses additional optional QQClause object or array of QQClause objects for the query * @return void */ public function MetaDataBinder(QQCondition $objCondition = null, $objOptionalClauses = null) { // Setup input parameters to default values if none passed in if (!$objCondition) { $objCondition = QQ::All(); } $objClauses = $objOptionalClauses ? $objOptionalClauses : array(); // We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below if ($this->Paginator) { $this->TotalItemCount = AttributeOption::QueryCount($objCondition, $objClauses); } // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add // the OrderByClause to the $objClauses array if ($objClause = $this->OrderByClause) { array_push($objClauses, $objClause); } // Add the LimitClause information, as well if ($objClause = $this->LimitClause) { array_push($objClauses, $objClause); } // Set the DataSource to be a Query result from AttributeOption, given the clauses above $this->DataSource = AttributeOption::QueryArray($objCondition, $objClauses); }
public static function GetSoapObjectFromObject($objObject, $blnBindRelatedObjects) { if ($objObject->objAttribute) { $objObject->objAttribute = Attribute::GetSoapObjectFromObject($objObject->objAttribute, false); } else { if (!$blnBindRelatedObjects) { $objObject->intAttributeId = null; } } if ($objObject->objPerson) { $objObject->objPerson = Person::GetSoapObjectFromObject($objObject->objPerson, false); } else { if (!$blnBindRelatedObjects) { $objObject->intPersonId = null; } } if ($objObject->dttDateValue) { $objObject->dttDateValue = $objObject->dttDateValue->__toString(QDateTime::FormatSoap); } if ($objObject->dttDatetimeValue) { $objObject->dttDatetimeValue = $objObject->dttDatetimeValue->__toString(QDateTime::FormatSoap); } if ($objObject->objSingleAttributeOption) { $objObject->objSingleAttributeOption = AttributeOption::GetSoapObjectFromObject($objObject->objSingleAttributeOption, false); } else { if (!$blnBindRelatedObjects) { $objObject->intSingleAttributeOptionId = null; } } return $objObject; }
/** * Deletes all associated AttributeOptions * @return void */ public function DeleteAllAttributeOptions() { if (is_null($this->intId)) { throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAttributeOption on this unsaved Attribute.'); } // Get the Database Object for this Class $objDatabase = Attribute::GetDatabase(); // Journaling if ($objDatabase->JournalingDatabase) { foreach (AttributeOption::LoadArrayByAttributeId($this->intId) as $objAttributeOption) { $objAttributeOption->Journal('DELETE'); } } // Perform the SQL Query $objDatabase->NonQuery(' DELETE FROM `attribute_option` WHERE `attribute_id` = ' . $objDatabase->SqlVariable($this->intId) . ' '); }
public static function GetSoapArrayFromArray($objArray) { if (!$objArray) { return null; } $objArrayToReturn = array(); foreach ($objArray as $objObject) { array_push($objArrayToReturn, AttributeOption::GetSoapObjectFromObject($objObject, true)); } return unserialize(serialize($objArrayToReturn)); }
public function up() { Yii::app()->setImport(['application.modules.store.models.*']); $pos = \Yii::app()->db->createCommand()->select('count(`id`)')->from('site_store_attribute_option')->where('attribute_id=7')->queryScalar(); $pos = $pos === NULL ? 0 : $pos; $m = AttributeOption::model()->findByAttributes(['attribute_id' => 7, 'value' => 'шт']); if ($m === NULL) { $this->insert('site_store_attribute_option', ['attribute_id' => 7, 'value' => 'шт', 'position' => $pos]); $pos = $pos + 1; } $m = AttributeOption::model()->findByAttributes(['attribute_id' => 7, 'value' => 'кг']); if ($m === NULL) { $this->insert('site_store_attribute_option', ['attribute_id' => 7, 'value' => 'кг', 'position' => $pos]); $pos = $pos + 1; } $m = AttributeOption::model()->findByAttributes(['attribute_id' => 7, 'value' => 'м3']); if ($m === NULL) { $this->insert('site_store_attribute_option', ['attribute_id' => 7, 'value' => 'м3', 'position' => $pos]); $pos = $pos + 1; } $m = AttributeOption::model()->findByAttributes(['attribute_id' => 7, 'value' => 'литр']); if ($m === NULL) { $this->insert('site_store_attribute_option', ['attribute_id' => 7, 'value' => 'литр', 'position' => $pos]); $pos = $pos + 1; } $pos = 0; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Австрия', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Албания', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Андорра', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Белоруссия', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Бельгия', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Болгария', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Босния и Герцеговина', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Ватикан', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Великобритания', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Венгрия', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Германия', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Греция', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Дания', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Ирландия', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Исландия', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Испания', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Италия', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Латвия', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Литва', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Лихтенштейн', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Люксембург', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Македония', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Мальта', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Молдавия', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Монако', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Нидерланды', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Норвегия', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Польша', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Португалия', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Россия', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Румыния', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Сан-Марино', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Сербия', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Словакия', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Словения', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Украина', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Финляндия', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Франция', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Хорватия', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Черногория', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Чехия', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Швейцария', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Швеция', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Эстония', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'Китай', 'position' => $pos]); $pos = $pos + 1; $this->insert('site_store_attribute_option', ['attribute_id' => 9, 'value' => 'США', 'position' => $pos]); $this->execute("\n\t\t\tALTER TABLE `site_store_category`\n\t\t\t\tADD COLUMN `type` ENUM('tovary','uslugi') NOT NULL DEFAULT 'tovary' AFTER `tiu_id_item`;\n\t\t"); $this->update('site_store_category', ['type' => 'uslugi'], 'slug="uslugi"'); }
<div class="row"> <div class="col-md-8"> <h5> <?php echo Yii::t('default', 'Цена:'); ?> <span><?php echo $data->getResultPrice(); ?> <?php //$valyuta = $data->attribute('valyuta'); $valyuta = $data->currency_id; if (!empty($valyuta)) { echo AttributeOption::model()->findByPk($valyuta)->value; } else { echo Yii::t('default', 'RUB'); } ?> </span> <?php if (Yii::app()->controller->action->id == 'search' && $name != '') { echo ' ' . Yii::t('default', 'за') . ' ' . $name->value; } ?> </h5> </div> <?php if (!Yii::app()->user->isGuest) { ?>
public function btnSave_Click($strFormId, $strControlId, $strParameter) { switch ($this->objAttributeValue->Attribute->AttributeDataTypeId) { case AttributeDataType::Checkbox: $this->objAttributeValue->BooleanValue = $this->chkValue->SelectedValue; $this->objAttributeValue->Save(); break; case AttributeDataType::Date: $this->objAttributeValue->DateValue = $this->dtxValue->DateTime; $this->objAttributeValue->Save(); break; case AttributeDataType::DateTime: $this->objAttributeValue->DatetimeValue = $this->dtxValue->DateTime; $this->objAttributeValue->Save(); break; case AttributeDataType::Text: $this->objAttributeValue->TextValue = trim($this->txtValue->Text); $this->objAttributeValue->Save(); break; case AttributeDataType::ImmutableSingleDropdown: $this->objAttributeValue->SingleAttributeOptionId = $this->lstValue->SelectedValue; $this->objAttributeValue->Save(); break; case AttributeDataType::ImmutableMultipleDropdown: $this->objAttributeValue->Save(); $this->objAttributeValue->UnassociateAllAttributeOptionsAsMultiple(); foreach ($this->lstValue->SelectedValues as $intOptionId) { $this->objAttributeValue->AssociateAttributeOptionAsMultiple(AttributeOption::Load($intOptionId)); } break; case AttributeDataType::MutableSingleDropdown: if ($this->lstValue->SelectedValue == -1) { $objAttributeOption = new AttributeOption(); $objAttributeOption->AttributeId = $this->objAttributeValue->AttributeId; $objAttributeOption->Name = trim($this->txtAddItem->Text); $objAttributeOption->Save(); $this->objAttributeValue->SingleAttributeOption = $objAttributeOption; $this->objAttributeValue->Save(); } else { $this->objAttributeValue->SingleAttributeOptionId = $this->lstValue->SelectedValue; $this->objAttributeValue->Save(); } break; case AttributeDataType::MutableMultipleDropdown: $this->objAttributeValue->Save(); $this->objAttributeValue->UnassociateAllAttributeOptionsAsMultiple(); foreach ($this->lstValue->SelectedItems as $objListItem) { $intOptionId = $objListItem->Value; if ($intOptionId > 0) { $this->objAttributeValue->AssociateAttributeOptionAsMultiple(AttributeOption::Load($intOptionId)); } else { if ($objListItem->Selected) { $objAttributeOption = new AttributeOption(); $objAttributeOption->AttributeId = $this->objAttributeValue->AttributeId; $objAttributeOption->Name = $objListItem->Name; $objAttributeOption->Save(); $this->objAttributeValue->AssociateAttributeOptionAsMultiple($objAttributeOption); } } } break; default: throw new Exception('Unhandled AttributeDataTypeId: ' . $this->objAttributeValue->Attribute->AttributeDataTypeId); } return $this->ReturnTo('#attributes'); }
</span> </section> <?php } ?> <?php if (!empty($product->country_id)) { //if (!empty($product->attribute('strana'))): ?> <section class="col-md-12 other"> <?php echo $attributes['strana']->title; ?> : <span><?php echo AttributeOption::getOptionName('strana', $product->country_id); ?> </span> </section> <?php } ?> </div> <div class="row item-buttons"> <?php if (preg_match('/response/', Yii::app()->request->pathInfo)) { ?> <?php if (Yii::app()->getUser()->getProfile() && $product->user->company_id != Yii::app()->getUser()->getProfile()->company_id) { ?> <section class="col-md-6 delivery-button">
/** * @param array $attributes * @return bool * @throws CDbException */ public function setMultipleValuesAttributes(array $attributes) { if (!$this->isMultipleValues()) { return true; } $transaction = Yii::app()->getDb()->beginTransaction(); try { foreach ($attributes as $attribute) { $model = new AttributeOption(); $model->setAttributes(['attribute_id' => $this->id, 'value' => trim($attribute)]); if (false === $model->save()) { throw new CDbException(); } } $transaction->commit(); return true; } catch (Exception $e) { $transaction->rollback(); return false; } }
protected function btnUnsubscribe_Click() { $objCommunicationListEntry = CommunicationListEntry::LoadByEmail($this->txtEmail->Text); $objEmailArray = Email::LoadArrayByAddress($this->txtEmail->Text); foreach ($objEmailArray as $objEmail) { $objPerson = Person::LoadByPrimaryEmailId($objEmail->Id); if ($objPerson != null) { $strUnsubscribedList = ''; $success = false; foreach ($this->chkBtnListArray as $objItem) { if ($objItem->Checked) { $this->objList = CommunicationList::LoadByToken($objItem->Name); if ($this->objList) { $bFound = false; if ($this->objList->IsPersonAssociated($objPerson)) { $this->objList->UnassociatePerson($objPerson); // If church newletter is the one being unsubscribed, document reason. if ($this->lstTerminationReason->SelectedValue == -1) { $objAttributeOption = new AttributeOption(); $objAttributeOption->AttributeId = $this->objAttributeValue->AttributeId; $objAttributeOption->Name = trim($this->txtOther->Text); $objAttributeOption->Save(); $objAttributeValue = AttributeValue::LoadByAttributeIdPersonId($this->objAttribute->Id, $objPerson->Id); if ($objAttributeValue) { $objAttributeValue->SingleAttributeOption = $objAttributeOption; $objAttributeValue->Save(); } else { $objAttributeValue = new AttributeValue(); $objAttributeValue->AttributeId = $this->objAttribute->Id; $objAttributeValue->PersonId = $objPerson->Id; $objAttributeValue->SingleAttributeOption = $objAttributeOption; $objAttributeValue->Save(); $objPerson->AssociateAttributeValue($objAttributeValue); } } else { $objAttributeValue = AttributeValue::LoadByAttributeIdPersonId($this->objAttribute->Id, $objPerson->Id); if ($objAttributeValue) { $objAttributeValue->SingleAttributeOptionId = $this->lstTerminationReason->SelectedValue; $objAttributeValue->Save(); } else { $objAttributeValue = new AttributeValue(); $objAttributeValue->AttributeId = $this->objAttribute->Id; $objAttributeValue->PersonId = $objPerson->Id; $objAttributeValue->SingleAttributeOptionId = $this->lstTerminationReason->SelectedValue; $objAttributeValue->Save(); $objPerson->AssociateAttributeValue($objAttributeValue); } } $strUnsubscribedList .= $objItem->Text . ','; $success = true; $bFound = true; } if (!$bFound) { $this->lblMessage->Text = '(Person Entry) You cannot Unsubscribe because you are not subscribed to the ' . $objItem->Text . ' Mailing List.'; $this->lblMessage->Visible = true; } } } } if ($success) { $strUnsubscribedList = substr($strUnsubscribedList, 0, strlen($strUnsubscribedList) - 1); QApplication::Redirect('/unsubscribe/success.php/' . urlencode($strUnsubscribedList) . '/' . $objPerson->Id); } } } if ($objCommunicationListEntry) { $strUnsubscribedList = ''; $success = false; $bChecked = false; foreach ($this->chkBtnListArray as $objItem) { if ($objItem->Checked) { $this->objList = CommunicationList::LoadByToken($objItem->Name); if ($this->objList) { $bFound = false; if ($objCommunicationListEntry != null) { if ($this->objList->IsCommunicationListEntryAssociated($objCommunicationListEntry)) { $this->objList->UnassociateCommunicationListEntry($objCommunicationListEntry); $strUnsubscribedList .= $objItem->Text . ','; $success = true; $bFound = true; } } if (!$bFound) { $this->lblMessage->Text = '(CommunicationsEntry) You cannot Unsubscribe because you are not subscribed to the ' . $objItem->Text . ' Mailing List.'; $this->lblMessage->Visible = true; } } } } if ($success) { $strUnsubscribedList = substr($strUnsubscribedList, 0, strlen($strUnsubscribedList) - 1); QApplication::Redirect('/unsubscribe/success.php/' . urlencode($strUnsubscribedList)); } } $bChecked = false; foreach ($this->chkBtnListArray as $objItem) { if ($objItem->Checked) { $bChecked = true; break; } } if (!$bChecked) { $this->lblMessage->Text = 'You must select a list to subscribe to.'; $this->lblMessage->Visible = true; } else { $this->lblMessage->Text = 'Failed to unsubscribe from the list. The email may not exist.'; $this->lblMessage->Visible = true; } }
/** * @param $id * @throws CHttpException */ public function actionAddOption($id) { if (Yii::app()->getRequest()->getIsPostRequest()) { $model = $this->loadModel($id); $option = new AttributeOption(); $option->setAttributes(['value' => Yii::app()->getRequest()->getPost('value'), 'attribute_id' => $model->id]); if (true === $option->save()) { Yii::app()->ajax->success(); } Yii::app()->ajax->failure(); } else { throw new CHttpException(400, Yii::t('StoreModule.store', 'Bad request. Please don\'t use similar requests anymore')); } }
/** * Static Helper Method to Create using PK arguments * You must pass in the PK arguments on an object to load, or leave it blank to create a new one. * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo * static helper methods. Finally, specify a CreateType to define whether or not we are only allowed to * edit, or if we are also allowed to create a new one, etc. * * @param mixed $objParentObject QForm or QPanel which will be using this AttributeOptionMetaControl * @param integer $intId primary key value * @param QMetaControlCreateType $intCreateType rules governing AttributeOption object creation - defaults to CreateOrEdit * @return AttributeOptionMetaControl */ public static function Create($objParentObject, $intId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) { // Attempt to Load from PK Arguments if (strlen($intId)) { $objAttributeOption = AttributeOption::Load($intId); // AttributeOption was found -- return it! if ($objAttributeOption) { return new AttributeOptionMetaControl($objParentObject, $objAttributeOption); } else { if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) { throw new QCallerException('Could not find a AttributeOption object with PK arguments: ' . $intId); } } // If EditOnly is specified, throw an exception } else { if ($intCreateType == QMetaControlCreateType::EditOnly) { throw new QCallerException('No PK arguments specified'); } } // If we are here, then we need to create a new record return new AttributeOptionMetaControl($objParentObject, new AttributeOption()); }
public function addOption($spec, $attr) { $options = AttributeOption::model()->findAllByAttributes(['attribute_id' => $attr->id]); $list = CHtml::listData($options, 'position', 'value'); if (!in_array($spec['value'], $list)) { end($list); $key = key($list); $option = new AttributeOption(); $option->attribute_id = $attr->id; $option->position = $key + 1; $option->value = $spec['value']; $option->save(); if (!$option->save()) { echo "\n"; echo "Error: save AttributeOption for id_product = {$spec['id_product']} \n"; echo "\n"; } } }