Support

  1. blocdaddy
  2. Support
  3. Thursday, January 30 2020, 09:36 AM
I use Easy Profile along with Membership Pro and Edocman from JoomdDonation to manage my subscription/membership site. Right now I’m trying to find a way to automatically assign individual Edocman documents to members on their Easy Profile page based on conditions when they register.

When users sign up, they choose certain digital documents as part of their subscription. They can choose from more than 400 electronic documents that have been assigned multiple times to different users. I use Edocman to manage the group and individual owners of the documents. Right now, users select the documents they want from a multi-select list in Easy Profile when they register and then I have to manually add the documents to their accounts in Edocman. Then I manually add a custom module to their Easy Profile page which lists their assigned documents.

What I’ve been trying to do to make the process much faster is set up a custom multi-select field in Easy Profile with alias “practice_fields” which lists all documents. I used the DB parameters to populate the list options directly from the Edocman database. I also tried using basic value/options format like:

1|Document1
2|Document2

Edocman has a content plugin similar to Easy Profile which generates a direct download link to documents and is referenced by document ID. For example, I can call “Document 30” by referencing {edocmanlink 30}. I have created a separate delimiter field with alias “edocman_links.” The “edocman_links” field would be triggered by the member selecting a document from “practice_fields” during registration and then would automatically generate the link/icon to the Edocman document on the member’s profile page using the Edocman content plugin. I’ve been trying to make this work using PHP with the JsnUser API and “if” statements (using the Sorcerer plugin from Regular Labs) to generate the different links to documents. Basically, I would like to have a single delimiter field with references to 400 list options and 400 corresponding documents that would be shown or hidden based on the member's selection. I know I could accomplish the same thing more easily by simply creating 400 delimiter fields and then setting conditions, but I’d much rather have it all in one field. Also, I thought maybe it might be better to use database queries or SQL Custom Where statements, but I haven’t gotten those to work either. Below is a random sample of the code I’ve been trying to use with the “edocman_links” field based on my searches in the forum and hopefully gives you an idea of what I’m trying to do. The Edocman link is generated by the code so I know that the content plugin at least works. But the link is not affected by inputting different values/fields. I can put any value or field in the code and the Edocman link always shows up and is never hidden or changes. I have very little PHP coding experience so I’m sure I’m missing something simple or stupid. If you think there is an easier way that would be great too!


require_once(JPATH_SITE.'/components/com_jsn/helpers/helper.php');
$user=JsnHelper::getUser;
$user->getValue('practice_fields');
if($user->getValue('practice_fields')=1) {
echo '{edocmanlink 30}'; }


require_once( JPATH_SITE.'/components/com_jsn/helpers/helper.php');
$user=JsnHelper::getUser;
$value_of_select=$user->getValue('practice_fields');
$output_of_select=$user->getField('practice_fields');
if($output_of_select="Litigation") {
echo '{edocmanlink 30}';
}


require_once(JPATH_SITE.'/components/com_jsn/helpers/helper.php');
$user=JsnHelper::getUser;
$user->getField('practice_fields');
if ($user->getField('practice_fields')=Litigation)) {
echo "{edocmanlink 30}";
}


require_once(JPATH_SITE.'/components/com_jsn/helpers/helper.php');
$user=JsnHelper::getUser;
$user->getValue('practice_fields');
if($user->getValue('practice_fields') {
echo "{edocmanlink 1}";
}

Accepted Answer
admin Accepted Answer
Admin
Hi,
The only other thing I changed was "(int) $user->id" to "(int)$val" in the second query since "id" in the query refers to the document ID column. Not sure if that was right or not
Yes, this is correct :) , it is my error

Probably the error is in the table name, you have wrote pdid__edocman_documents instead pdid_edocman_documents
In my code I have used #__edocman_documents, this because in each query Joomla replace automatically this code #__ with table prefix
  1. more than a month ago
  2. Support
  3. # Permalink
blocdaddy Accepted Answer
As an update to my first post...

Using the code below, I am closer to doing what I was trying to explain in my first post:


require_once(JPATH_SITE.'/components/com_jsn/helpers/helper.php');
$user=JsnHelper::getUser();
if($user->getField('practice_fields')=='Top 40 under 40 (2020)')
echo '<img src="/images/PLOA-40under40.png" alt="Top40" />','{edocmanlink 1}','{user name}';
if($user->getField('practice_fields')=='$500 Million Recovered')
echo '<img src="/images/150million1.png" alt="150million" />','{edocmanlink 2}','{user name}';


Now when a logged-in user selects ONE option from the multiple select field, the selection is mapped to the delimiter field and the corresponding Edocman thumbnail and download button are shown on the profile page. Only the mapped selection is shown in the delimiter field and all other links in the code are hidden.

But even if other users have different options mapped from the select field on their profile page, the logged-in user sees his/her own delimiter fields on all other members’ pages.

And when logged out, nothing shows in the delimiter field even though all permissions are set to public for all fields.

When a user selects TWO or more options from the multiple select field, nothing shows in the delimiter field at all on the profile page. However, the selections do still show on users’ profile page in the “practice_fields” field. And in the "practice_fields" field, the selections also correctly match the different users both when the person viewing the profile is logged-in or a visitor unlike the delimiter field.

I’ve also tried using:

$user=JsnHelper::getUser($user->id);
$user=JsnHelper::getUser($user_id);


And with users who choose multiple values, I’ve tried:

‘[Top 40 under 40 (2020)]’
'[“$500 Million Recovered”]'


Is there a way to fix these problems? And because I have limited coding experience, is the method I’m using above the best way to accomplish what I’m trying to do? Should I use database queries or something else instead?

Thanks!!
  1. more than a month ago
  2. Support
  3. # 1
blocdaddy Accepted Answer
Content Protected
  1. more than a month ago
  2. Support
  3. # 2
admin Accepted Answer
Admin
Hi,
sorry for late reply :)
But even if other users have different options mapped from the select field on their profile page, the logged-in user sees his/her own delimiter fields on all other members’ pages.
This happen because the function JsnHelper::getUser() return the current logged in user, to get the current displayed user data then you can use something like this:
global $JSNLIST_DISPLAYED_ID;
if($JSNLIST_DISPLAYED_ID) $owner_id=$JSNLIST_DISPLAYED_ID;
else $owner_id=JRequest::getVar( 'id' , JFactory::getUser()->id );
$user = JsnHelper::getUser($owner_id)


When a user selects TWO or more options from the multiple select field, nothing shows in the delimiter field at all on the profile page.
This happen because if there is a multiple value then it return a list of document titles

Is there a way to fix these problems? And because I have limited coding experience, is the method I’m using above the best way to accomplish what I’m trying to do? Should I use database queries or something else instead?
No, the best way is to use directly the IDs of the documents, so instead using getField the best way is to use getValue function, this function will return an array that contain a list of document IDs
$JSNLIST_DISPLAYED_ID;
if($JSNLIST_DISPLAYED_ID) $owner_id=$JSNLIST_DISPLAYED_ID;
else $owner_id=JRequest::getVar( 'id' , JFactory::getUser()->id );
$user = JsnHelper::getUser($owner_id)

$value = (array) $user->getField('practice_fields');
if(count($value)) foreach($value = $val){
/*HERE THE CODE TO GET DOCUMENT TITLE AND IMAGE
FROM EDOCMAN AND RETURN THE CONTENT TO SHOW, $val VARIABLE
CONTAIN THE ID OF THE EDOCMAN DOCUMENT */
}


Instead if you does not have enough skills with PHP and Edocman APIs then you could works with your way like:
$JSNLIST_DISPLAYED_ID;
if($JSNLIST_DISPLAYED_ID) $owner_id=$JSNLIST_DISPLAYED_ID;
else $owner_id=JRequest::getVar( 'id' , JFactory::getUser()->id );
$user = JsnHelper::getUser($owner_id)

$value = (array) $user->getValue('practice_fields'); /* NOTE: I HAVE USED getValue INSTEAD getField */
if(in_array(1,$value))
echo '<img src="/images/PLOA-40under40.png" alt="Top40" />','{edocmanlink 1}','{user name}';
if(in_array(2,$value))
echo '<img src="/images/150million1.png" alt="150million" />','{edocmanlink 2}','{user name}';
.....
  1. more than a month ago
  2. Support
  3. # 3
blocdaddy Accepted Answer
Thanks for the reply!

I ended up using getValue function and the document links are generated based on the array value of select field options and only visible on the user's page.

But that's where the new problem happens with ownership of the document. Is there a way to map the User ID field as set out in my last response above?
  1. more than a month ago
  2. Support
  3. # 4
admin Accepted Answer
Admin
Hi,
sorry but you should ask this to Edocman support team and put a code like this

if(in_array(1,$value))
{
/* Code to add the user id to the document if it's is not already available */
echo '<img src="/images/PLOA-40under40.png" alt="Top40" />','{edocmanlink 1}','{user name}';
}

Edocman should have a parameter for each document called "User Ids", this parameter allow you to give access to specific user id
  1. more than a month ago
  2. Support
  3. # 5
blocdaddy Accepted Answer
After working with the code below, the Edocman owner field is now populated with the Easy Profile user when they update their profile and select documents. However, no matter which user adds the documents, the user ID is shown as "JsnUser" instead of the actual numeric ID. Based on the code below can you tell what I'm doing wrong? Also, is there a more elegant way to include the queries for the documents -- I have more than 400 and will need to include 400+ queries. Thanks!


defined('_JEXEC') or die;

class PlgJsnSkeleton extends JPlugin {

public function triggerProfileUpdate($user,&$data,$changed,$isNew){

global $JSNLIST_DISPLAYED_ID;

if($JSNLIST_DISPLAYED_ID) $owner_id = $JSNLIST_DISPLAYED_ID;

else $owner_id = JRequest::getVar( 'id' , JFactory::getUser()->id );

$user = JsnHelper::getUser($owner_id);

$value = (array)$user->getValue('practice_fields');

if(in_array(1,$value))
{
$db = JFactory::getDbo();
$query ='UPDATE pdid_edocman_documents SET user_ids= '.$db->quote($user). ' WHERE id = ' . ($value[1]);
$db->setQuery($query);
$db->execute();

if(in_array(2,$value))

$db = JFactory::getDbo();
$query ='UPDATE pdid_edocman_documents SET user_ids= '.$db->quote($user). ' WHERE id = ' . ($value[0]);
$db->setQuery($query);
$db->execute();
};
  1. more than a month ago
  2. Support
  3. # 6
admin Accepted Answer
Admin
Hi,
shown as "JsnUser" instead of the actual numeric ID
In your queries you should replace this
$db->quote($user)
with this
$db->quote($user->id)


Anyway the queries are not correct because you set user_ids column with the current user id and delete the previous value. The column user_ids should contain a list of authorized user ids like 100,232,485,392....

You should use something like this:

defined('_JEXEC') or die;

class PlgJsnSkeleton extends JPlugin {

public function triggerProfileUpdate($user,&$data,$changed,$isNew){

$value = (array) json_decode($data['practice_fields']);

$db = JFactory::getDbo();

if(count($value)) foreach($value as $val){
$query ='SELECT user_ids FROM #__edocman_documents WHERE id = ' . (int)$val;
$db->setQuery($query);
$ids = $db->loadResult();
$ids_array = (array) explode(',',$ids);
if( !in_array($user->id, ids_array) ) $ids = $ids . ',' . $user->id; /* Add the ID of the user if it is not available */
$query ='UPDATE #__edocman_documents SET user_ids= '.$db->quote($ids). ' WHERE id = ' . (int) $user->id;
$db->setQuery($query);
$db->execute();
}


Sorry I have not tested this code, but should works...But you will have another problem to solve, this function will add the user id in the list of user ids of the document but it does not remove it...so when a user remove some document from the field then he still have access.
  1. more than a month ago
  2. Support
  3. # 7
blocdaddy Accepted Answer
Content Protected
  1. more than a month ago
  2. Support
  3. # 8
blocdaddy Accepted Answer
Content Protected
  1. more than a month ago
  2. Support
  3. # 9
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.

Request Support

Support is currently Online

Support Availability

Working days: Monday to Friday. The support staff is not available on weekends; in the most of cases tickets will not be answered during that time.

Reply time: Depending on the complexity of your support issue it's usually between a few minutes and 24 hours for paid members and about one week for free members. When we expect longer delays we will notify you.

Guidelines

Before you post: read the documentation and search the forums for an answer to your question.

When you post: include Site Details if you request a support (you can use the form below the reply in Site Details tab).

Auto Solved Question: If after a week the author of the post does not reply to a request by moderator, the question will be marked as resolved.

Language: only English

Search Users

Easy Profile® is not affiliated with or endorsed by Open Source Matters or the Joomla Project. Joomla is Free Software released under the GNU/GPL License.