Hello Bob
Thank you for responding. I think this may be beyond my abilities at the moment, but if I tell you what I have done so far perhaps you can point me in the right direction. Even if this is to advise me to finish my CodeAcademy php course before trying to do anything like this!
The data I want to check for duplicates is in:
Table: ext_user_data
Column: idCode
In this table there are also columns called:
id - This contains an id number issued on creation of a new user
userdata_id - This contains the MODX user id number, again this is issued on creation of a new user
I think the above is all standard for Class Extender
My main MODX table does not have any prefixes to the column names, just the default columns.
Before trying to make a plugin that triggers an email I thought I would make a page that would show me what the code you wrote would find. I seem to be running into problems though.
My code is as follows
<?php
$user = $modx->getUser();
print "MODX User Name: ";
echo $user->get('username');
print "<br />";
print "MODX User ID: ";
echo $user->get('id');
print "<br />";
/* Get userdata custom fields for the user here,
* and set $idCode variable to their idCode.
*/
/* Check for duplicates */
$results = $modx->getCollection('userData', array('idCode' => $idCode));
echo 'Below is the output from the $results array<pre>'; print_r($results); echo '</pre>';
if (count($results) > 1) {
/* Send email here */
print "the result is more than one so duplicates found <br />";
}
if (count($results) < 1) {
/* Send email here */
print "the result is less than one so <strong>no</strong> duplicates found <br />";
}
return '';
This produces the following
MODX User Name: userfour
MODX User ID: 249
Below is the output from the $results array
Array
(
)
the result is less than one so no duplicates found
The user name and id are correct for the logged in user. But the results array is empty and the report that no duplicates have been found is wrong as there are duplicate idCode entries.
Tinkering with the line that reads
$results = $modx->getCollection('userData', array('idCode' => $idCode));
has resulted in various error messages like
[2] => Unknown column 'userData.userData_idCode' in 'where clause'
If you have any advice I would be very grateful.
Best wishes,
Andy