Help for Attribute Type Select

Permalink 1 user found helpful
Hello everyone,

How do i filter using the values in my Select Attribute Type. This used to work like this in concrete5 version 5.4.0.5:

if ($cobj->getCollectionAttributeValue('kompetencer') == $c->getCollectionName()):


kompetencer is the Attribute Handle and $c->getCollectionName() is the select box values. I am filtering by headline. That is the reason why i use $c->getCollectionName(). How come this doesn't work in concrete5 version 5.4.1 ?

Thank you in advance

87up
 
RadiantWeb replied on at Permalink Best Answer Reply
RadiantWeb
try this

$ak = CollectionAttributeKey::getByHandle('kompetencer');
$value = $cobj->getCollectionAttributeValue($ak)->current()->value;
if( $value == $c->getCollectionName()){
     (do something)
}
87up replied on at Permalink Reply
87up
Yes it worked !...

Thank you so much. :)
87up replied on at Permalink Reply
87up
hello again,

i have changed my select attribute to allow multiple options to be chosen.
When 2 or more options are selected at the same time, only the first selected option is working. How do I make my filter check for all the selected options. ?

I used the code ChadStrat made, and modified it a bit to check if all the options are saved, but it doesn't work:

$ak = CollectionAttributeKey::getByHandle('kompetencer');
$values = explode("\n", $cobj->getCollectionAttributeValue($ak)->current()->value);
foreach ($values as $value) {
              $myValues[] = $value;
           echo $value;
}



Can anyone help me solve this problem. :)

Thank you in advance.
site replied on at Permalink Reply
site
A simple modification to your code should set things in order. getOptions() will return an array with the selected options. For further reference, in your concrete5 install, see 'concrete/models/attribute/types/select/controller.php' specifically the SelectAttributeTypeOptionList class is the object that you are working with.
$ak = CollectionAttributeKey::getByHandle('kompetencer');
$values = $cobj->getCollectionAttributeValue($ak)->getOptions();
foreach ($values as $value) {
              $myValues[] = $value;
           echo $value;
}