Answer the question
In order to leave comments, you need to log in
How to select resources by TV MIGX?
Good evening, I have resources with TV (MIGX) which uses checkbox and radio . The task is that I need to display resources depending on the values of these checkbox and radio .
For example, I need to display all the games that have " Action " selected in the Genre , and even better if it is possible to make a selection according to 2 criteria (For example, so that there are resources that have the genre Action and Racing , or Genre => Action and Activation Method = > Steam), but even if I can filter by 1 criterion, I will also be very happy.
And now let's move on to where the snag began.
I initially thought that everything was easy and just take the pdoResources snippet, connect TV to it via &includeTVs and use &tvFilters . But since TV is made via MIGX, it is stored in the database as JSON , and although the snippet converts it to an array, I don’t use the &tvFilters parameter and using &where is also not like JSON is stored in the database .
For example, what is in the database
[{"MIGX_id":"1","image":"http:\/\/cdn.akamai.steamstatic.com\/steam\/apps\/271590\/header.jpg?t=1459273772","alt_image":"GTAV","title_image":"GTAV","video":"1","janre":["\u042d\u043a\u0448\u0435\u043d ","\u0421\u0438\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u044b ","\u0424\u0430\u0439\u0442\u0438\u043d\u0433\u0438 ","\u0414\u0438\u0437\u0430\u0439\u043d "],"activation":"Origin","platform":"Windows ","region":"\u0412\u0435\u0441\u044c \u043c\u0438\u0440 ","rejim":"\u041c\u0443\u043b\u044c\u0442\u0438\u043f\u043b\u0435\u0435\u0440 ","news":"1"}]
[tovar_info] => Array
(
[0] => Array
(
[MIGX_id] => 1
[image] => http://cdn.akamai.steamstatic.com/steam/apps/271590/header.jpg?t=1459273772
[alt_image] => GTAV
[title_image] => GTAV
[video] => 1
[janre] => Array
(
[0] => Экшен
[1] => Симуляторы
[2] => Файтинги
[3] => Дизайн
)
[activation] => Origin
[platform] => Windows
[region] => Весь мир
[rejim] => Мультиплеер
[news] => 1
)
)
function migxFilter($array, $key, $val){
}
$val = $resource->getTVValue(2);
$val = $modx->fromJSON($val);
$pdo = $modx->getService('pdoFetch');
$parameters = array(
'showUnpublished' => 1,
'parents' => 2,
'templates' => 4,
'includeTVs' => 'Нужные TV',
);
$res = $pdo->getCollection('modResource', null, $parameters);
Array
(
[0] => Array
(
[id] => 3
[type] => document
[contentType] => text/html
[pagetitle] => Grand Theft Auto V
[longtitle] => Купить игру GTA 5 / ГТА 5 / Grand Theft Auto V для STEAM
[description] =>
[alias] => grand-theft-auto-v
[link_attributes] =>
[published] => 1
[pub_date] => 0
[unpub_date] => 0
[parent] => 4
[isfolder] => 0
[introtext] =>
[content] =>
[richtext] => 1
[template] => 4
[menuindex] => 0
[searchable] => 1
[cacheable] => 1
[createdby] => 1
[createdon] => 1468714413
[editedby] => 1
[editedon] => 1470168281
[deleted] => 0
[deletedon] => 0
[deletedby] => 0
[publishedon] => 1468714380
[publishedby] => 1
[menutitle] =>
[donthit] => 0
[privateweb] => 0
[privatemgr] => 0
[content_dispo] => 0
[hidemenu] => 1
[class_key] => modDocument
[context_key] => web
[content_type] => 1
[uri] => grand-theft-auto-v.html
[uri_override] => 0
[hide_children_in_tree] => 0
[show_in_tree] => 1
[properties] => Array
(
[autoredirector] => Array
(
[old_uri] => grand-theft-auto-v.html
)
)
[tovar_info] => Array
(
[0] => Array
(
[MIGX_id] => 1
[image] => http://cdn.akamai.steamstatic.com/steam/apps/271590/header.jpg?t=1459273772
[alt_image] => GTAV
[title_image] => GTAV
[video] => 1
[janre] => Array
(
[0] => Экшен
[1] => Симуляторы
[2] => Файтинги
[3] => Дизайн
)
[activation] => Origin
[platform] => Windows
[region] => Весь мир
[rejim] => Мультиплеер
[news] => 1
)
)
)
и т.д
)
function janr($array, $string){
if(!is_array($array)){
return false;
}
static $da = false;
foreach($array as $k=>$v){
if(is_array($v)){
janr($v, $string);
}else{
if(trim($v) === $string){
$da = true;
}
}
}
return $da;
}
foreach($res as $tovar){
$array = $tovar[tovar_info];
if(janr($array,"Ролевые")){
$pdo->getChunk(Чанк, $res) //Вывoдим Чанк этого ресурса
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question