Listing MODX Articles with at least one common tag - modx

Is it possible to use the getResources snippet to find related articles that have at least one common tag with the active resource?
[[getResources?
&parents=`xxx, xxx`
&showHidden=`1`
&limit=`10`
&tpl=`relatedArticle-tpl`
&depth=`1`
&includeContent=`1`
&includeTVs=`1`
&processTVs=`1`
&sortby=`publishedon`
&tvFilters=`something here`
]]
The TV [[*articletags]] of the active resource should contain at least one common tag with a matching resource.

This is the way how I implemented question:
[[getResources?
&parents=`x,x`
&showHidden=`1`
&limit=`10`
&tpl=`latestArticle`
&depth=`1`
&includeContent=`1`
&includeTVs=`1`
&resources=`-[[*id]]`
&processTVs=`0`
&sortby=`publishedon`
&tvFilters=`[[tvFilterForRelatedArticles]]`
]]
And the snippet to make a TV filter:
$tags = $modx->resource->getTVValue('articlestags');
$categories = $modx->resource->getTVValue('category');
$tagsArray = explode(",", $tags);
$categoriesArray = explode(",", $categories);
$result = "";
foreach ($tagsArray as $tag)
$result .= "articlestags==%".$tag."%||";
foreach ($categoriesArray as $category)
$result .= "category==%".$category."%||";
return substr($result, 0, -1);
Not sure if this is the simplest way to achieve my target. Feel free to comment if there is a better solution.

Related

Need to apply an if condition based on a check in Powershell

I am new to Powershell. I am actually getting the details of the azure data factory linked services but after get I need to use contains to check if the element exists. In python I would just check if string in a list but powershell not quite sure. Please check the code below.
$output = Get-AzDataFactoryV2LinkedService -ResourceGroupName $ResourceGroupName -DataFactoryName "xxxxxxxx" | Format-List
The output of the below is :
sample output given below
LinkedServiceName : abcdef
ResourceGroupName : ghijk
DataFactoryName : lmnopq
Properties : Microsoft.Azure.Management.DataFactory.Models.AzureDatabricksLinkedService
So now I try to do this:
if ($output.Properties -contains "Microsoft.Azure.Management.DataFactory.Models.AzureDatabricksLinkedService") {
Write-Output "test output"
}
But $output.Properties gives us the properties of that json.
I need to check if "Microsoft.Azure.Management.DataFactory.Models.AzureDatabricksLinkedService" exists in output variable and perform the required operations. Please help me on this.
The -contains operator requires a collection and an element. Here's a basic example of its proper use:
$collection = #(1,2,3,4)
$element1 = 5
$element2 = 3
if ($collection -contains $element1) {'yes'} else {'no'}
if ($collection -contains $element2) {'yes'} else {'no'}
What you've done is ask PowerShell to look in an object that isn't a collection for an element of type [string] and value equal to the name of that same object.
What you need to do is inspect this object:
$output.Properties | format-list *
Then once you figure out what needs to be present inside of it, create a new condition.
$output.Properties.something -eq 'some string value'
...assuming that your value is a string, for example.
I would recommend watching some beginner tutorials.

How do I remove a property from Azure Table Storage with powershell?

I tried this code to remove property from table:
$propertiesToRemove = #("Prop1", "Prop2")
$row = Get-AzTableRow -Table $cloudTable -PartitionKey "PK" -RowKey $id
$propertiesToRemove | %{ $row.PSObject.Properties.Remove($_) }
Update-AzTableRow -Table $cloudTable -entity $row
but it leaves them untouched. How do I do this with powershell?
Assuming you're using AzureRmStorageTable, I don't think it is possible to remove properties from a table because Update-AzTableRow performs an InsertOrMerge operation instead of either Replace or InsertOrReplace operation.
From the source code:
return ($Table.Execute([Microsoft.Azure.Cosmos.Table.TableOperation]::InsertOrMerge($updatedEntity)))

Wordpress Woocommerce Variable Products

When setting up a variable type product in woocommerce based on product attributes, for the respective product, the front-end store provides a dropdown box where the user can pick the product attribute (ie lets say shirt size S, M or L).
At the moment that dropdown box is propagated by the attribute names, can someone please let me know where is the function located where I can make this dropdown be propagated by the names PLUS the particular attribute description?
So for instance, if the size attribute has name 'S' and description 'Small', I want the dropdown to say 'S [Small]', rather than just 'S', which is how it would be presented at the moment.
there's a filter available for this... but currently, version 2.5.2, you can only check for its name. Which for me, not so flexible. But at least we have this...
try pasting this code to your functions.php
add_filter('woocommerce_variation_option_name','rei_variation_option_name',10,1) ;
function rei_variation_option_name($name){
if ($name == 'S') {
$name = 'Small';
}
if ($name == 'M') {
$name = 'Medium';
}
if ($name == 'L') {
$name = 'Large';
}
return $name;
}
Please take note that this is just for displaying it. Database has not been change.
The solution I used, is this:
wc-template-functions.php, function wc_dropdown_variation_attribute_options
Modify:
$html .= '<option value="' . esc_attr( $term->slug ) . '" ' . selected( sanitize_title( $args['selected'] ), $term->slug, false ) . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $term->name ) ) . '</option>';
to
$html .= '<option value="' . esc_attr( $term->slug ) . '" ' . selected( sanitize_title( $args['selected'] ), $term->slug, false ) . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $term) ) . '</option>';
Then in functions.php, implement the following:
add_filter('woocommerce_variation_option_name','variation_option_name_description',10,1) ;
function variation_option_name_description($term){
return $term->name.' ['.$term->description.']';
}
Thanks to Reigel for steering me in the right direction.

How to get a list of all user groups in Modx Revolution

Trying to get a list of group names from modx revolution, digging through the API and docs, but not having much luck finding a function that does this.
How can I get a list of groups [names & ids] in a snippet from a modx revolution instance>?
<?php
$where = array();
$userGroups = $modx->getCollection('modUserGroup', $where);
foreach ($userGroups as $userGroup) {
print $userGroup->get('name');
}
You can do it without the loop.
<?php
$q = $modx->newQuery('modUserGroup');
$q->select(['name']);
$q->prepare();
$q->stmt->execute();
$userGroups = $q->stmt->fetchAll(PDO::FETCH_COLUMN);
print_r($userGroups);
<?php
//Group IDs array
print_r($modx->user->getUserGroups());
//Group Names array
print_r($modx->user->getUserGroupNames());

Propel Nested Set in combination with Pagination

$root = AnimeCommentQuery::create()->findRoot(2);
$html = "<ul>{$root->getComment()}";
foreach ($root->getDescendants() as $post)
{
$html .= '<li style="padding-left: '.$post->getLevel().' em;">';
$html .= $post->getComment();
$html .= ' by '.$post->getIbfMembersRelatedByInsertBy()->getName();
$html .= "</li>";
}
$html .= "</ul>";
echo $html;
I want to paginate the posts but I am not able to do this by:
$root = AnimeCommentQuery::create()->findRoot(2)->paginate(2, 1);
OR
$root = AnimeCommentQuery::create()->paginate(2, 1)->findRoot(2);
Can it be done with standard Pagination from propel? And how?
Don't know if this is too late....
First off, you can't use the paginate and find in the same query, they're both termination methods.
I think what you need is something like this:
$comments = AnimeCommentQuery::create()->inTree(2)->orderByBranch()->paginate(2,1);
Then foreach your way through that Collection.
Now you'll have to be a bit clever with when to close and open lists, checking current Level etc. And top and bottom of page 2+ will take a bit of consideration too. Good Luck!
The Nested Set API is worth studying further http://www.propelorm.org/behaviors/nested-set.html#complete_api, got a fair bit in.
Also consider using a ->joinWith() to get your getIbfMembersRelatedByInsertBy() prepopulated in the main query.

Resources