public function contains(SelectValueOption $option) { $id = $option->getSelectAttributeOptionID(); return count(array_filter($this->getOptions()->toArray(), function ($option) use($id) { return $option->getSelectAttributeOptionID() == $id; })) > 0; }
/** * @param Key $ak * @param $option * @param int $isEndUserAdded * @return Option */ public static function add($ak, $value, $isEndUserAdded = 0) { /** * @var $type SelectSettings */ $type = $ak->getAttributeKeySettings(); $list = $type->getOptionList(); $option = new SelectValueOption(); $option->setSelectAttributeOptionValue($value); $option->setIsEndUserAdded($isEndUserAdded); $option->setOptionList($list); $em = \Database::connection()->getEntityManager(); $em->persist($option); $em->flush(); return $option; }
/** * Sets select options for a particular attribute * If the $value == string, then 1 item is selected * if array, then multiple, but only if the attribute in question is a select multiple * Note, items CANNOT be added to the pool (even if the attribute allows it) through this process. * Items should now be added to the database if they don't exist already & if the allow checkbox is * checked under the attribute settings * Code from this bug - http://www.concrete5.org/index.php?cID=595692 */ public function createAttributeValue($value) { $this->load(); $options = array(); if ($value != null) { if (is_array($value) && $this->akSelectAllowMultipleValues) { foreach ($value as $v) { if ($v instanceof SelectValueOption) { $option = $v; } else { // Retrieve the option by value. Only get those that are assigned to this attribute key. $option = $this->getOptionByValue($v, $this->attributeKey); } if (!is_object($option) && $this->akSelectAllowOtherValues) { $option = new SelectValueOption(); $option->setIsEndUserAdded(true); $option->setSelectAttributeOptionValue($v); } if (is_object($option)) { $options[] = $option; } } } else { if (is_array($value)) { $value = $value[0]; } if ($value instanceof SelectValueOption) { $option = $value; } else { $option = $this->getOptionByValue($value, $this->attributeKey); } if (is_object($option)) { $options[] = $option; } } } $av = new SelectValue(); $av->setSelectedOptions($options); return $av; }
public function getTagLink(SelectValueOption $option = null) { $target = $this->get('target'); if (!is_object($target)) { $target = \Page::getCurrentPage(); } if ($option) { return \URL::page($target, 'tag', mb_strtolower($option->getSelectAttributeOptionDisplayValue())); } else { return \URL::page($target); } }