Hello Everyone,
I have been using modx for a couple of weeks now having mostly worked on Joomla and Wordpress in the past and I am amazed at how powerful it is. I am currently having a bit of an issue which is probably me doing something stupid so I will explain the whole end goal before going into my small issue in case you can think of an easier way of doing it.
I am working on a site that is for a large amount of stories each story has template variables that say what characters and which volumes they belong to, Then I am storing the Id's of the stories a user has read in their extended fields.
I can then get these extended field ID's and use it to display what the user has read to them and also how much of a character they have read, which is the bit I am currently working on.
So.. On the Character 1 Page I want it to display all the stories that have this character in and then say how much of this character a user has read. (please excuse any sloppy coding as I will tidy this all up with more chunks later!)
[[!getResources? &parents=`15` &includeTVs=`1` &processTVs=`1` &tpl=`Characters` &tvFilters=`Characters==%Character 1%`]]
<br />
total number of stories with this character in: [[+total]]
[[!Profile]]
<br />
<p>Custom Field: [[+stories_read]]</p>
<br />
Amount of this character read: [[!user_char_read? &input1=[[+stories_read]] &input2=[[!getResources? &parents=`15` &includeTVs=`1` &processTVs=`1` &tpl=`characters_idonly` &tvFilters=`Characters==%Character 1%`]]]]
]
The first bit that shows how many stories contain character 1 is working fine but the second bit is not working properly, I am passing the two inputs off to a snippet which is below (currently displaying results with a print that will be removed as well, also only showing inputs and outputs for debugging)
Snippet: stories_read
$id = $modx->resource->get('id');
$profile = $modx->user->getOne('Profile');
$extended = $profile->get('extended');
if (substr_count($extended['stories_read'],$id) > 0)
{
print $extended['stories_read'];
}
else
{
print $extended['stories_read'] . ", " . $id;
}
Snippet: user_char_read
<?php
$output1 = explode(", ", $input1);
$output3 = substr($input2, 0, -1);
$output2 = explode(", ", $output3);
$result = array_intersect($output1, $output2);
echo '<br /> in1 '; print_r ($input1);
echo '<br /> out1 '; print_r ($output1);
echo '<br /> in2 '; print_r ($input2);
echo '<br /> out2 '; print_r ($output2);
echo '<br /> out3 '; print_r ($output3);
echo '<br /> result '; print_r ($result);
And for further info here is the template chunk
[b]chunk: characters_idonly[/b]
[[+id]],
So the issue is that I have two arrays that look completely identical when I look at the output of each one but all this is producing is an intersected array with one value in it where it should have 3, I have attached the result as an image
If anyone could help me it would be greatly appreciated or if I am going about this completely the wrong way then a nudge in the right direction.
Many Thanks,
David