× All questions about EDocman extension

Auto-assign ownership of docs using User ID (auto update 'user_ids' DB column)

  • B Loc
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
More
2 weeks 6 days ago #131679 by B Loc
I use Membership Pro and Edocman along with Easy Profile on my site (I also use Payment Form and Events Booking on different sites – you make great products!!). I’m close to finding a way to automatically assign individual Edocman documents to new members (not groups) when registering and automatically allowing/restricting access to individual documents both in Edocman and on their Easy Profile page based on conditions...I just can’t figure out the last part of code.

I use the Membership Pro registration form and map fields to Easy Profile. The problem I have is that as part of a member’s subscription, they choose multiple Edocman documents when registering. The documents don’t have specific relation to their subscription plan or assigned Joomla group so I can't auto-assign ownership based on group/plan. So after registration, we have to manually add each user ID in the backend as an additional owner of each document after they register. With hundreds of documents and hundreds of users this does not work well.

To automate the process, I created a multi-select list in Membership Pro on the registration form which is mapped to a matching multi-select list in Easy Profile. Easy Profile allows database queries to populate the multi-select options so in my multi-select list the options are directly populated by #_edocman_documents as:

Value|Text =
Edocman ID of document|Edocman title of document

I then created a separate custom field in Easy Profile to map the array values of the selected options (Edocman IDs). I added PHP code to trigger the Edocman content plugin and also added additional code to show thumbnails, etc. Now when users select documents from the multi-select list, the document titles, thumbnails, and download links are generated automatically for each user and shown on their profile page.

There are two problems. First, although the download link is auto-generated, in order for the user to actually download the document, they still need ownership access individually assigned through Edocman. Second, I would like users to also automatically have access to individual documents in Edocman itself when they register, not just their profile page in Easy Profile.

To do this I would like to trigger the update of the Edocman “user_ids” database field to add the new member ID when the documents are selected from the Easy Profile select list so they can download it. Since Easy Profile and Edocman both use Joomla ID it shouldn’t be too complicated, but I haven’t been able to figure out the actual code for this. Can you help me with the language? The matching database for both info is below. Thanks for the great products and great support!!

Edocman
Table: “#_edocman_table”
Column: “user_ids” (Joomla IDs of the owners)
Row: “id” (Document ID)

Easy Profile
Table: “#_jsn_users”
Column: “id” (Joomla user ID)
Column: “select_field” (select field)
Value of “select_field”: ["1","2","3","4","5"] (Edocman Document IDs which are retuned as the “value” of “value|text” in the select field)

When a user registers or updates profile in Easy Profile, I would like to map the values from Easy Profile “id” column to Edocman “user_ids” column where Easy Profile “select_field” column values = Edocman “id” row values

Please Log in or Create an account to join the conversation.

  • B Loc
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
More
2 weeks 6 days ago #131692 by B Loc
After working with the code below some more, the Edocman owner field seems to now be auto-filled with the Easy Profile user when they select documents and update their profile. 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 if this is the best way. 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('select_field');

if(in_array(1,$value))
{
$db = JFactory::getDbo();
$query ='UPDATE #_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#_edocman_documents SET user_ids= '.$db->quote($user). ' WHERE id = ' . ($value[0]);
$db->setQuery($query);
$db->execute();
};

Please Log in or Create an account to join the conversation.

More
2 weeks 5 days ago #131698 by Mr. Dam
Hi,
Do you have simpler explanation? It's too difficult to understand.
Thanks
Dam

Please Log in or Create an account to join the conversation.

  • B Loc
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
More
2 weeks 5 days ago #131699 by B Loc
Yes, when a user registers, they select Edocman documents from a multiselect box. I want to automatically map the user id of the new member to the user_ids field in Edocman admin area where the admin adds user ids as owners of documents. The documents cannot be assigned based on subscription plan or user group. I don't want to manually add every single new user id since I have hundreds of users and hundreds of documents to assign.

Right now using the code above, I am able to automatically map the new member's user id to the Edocman user_ids database field, but instead of the user id, the form is populated as "JsnUser." How can I make this work? And is the option of auto adding user ids as owners of documents on registration a feature that you would consider adding?

Please Log in or Create an account to join the conversation.

More
2 weeks 5 days ago #131701 by Mr. Dam
Simply, you want to add one new User ID into column: User_ids in table: #__edocman_documents, right?
Dam

Please Log in or Create an account to join the conversation.

  • B Loc
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
More
1 week 6 days ago - 1 week 6 days ago #131935 by B Loc
I wanted the user ID to be added to the user_ids (owner) column in #__edocman_documents on some trigger without me having to do it manually. I have gotten this to work with the code below.

But I'm wondering if it can be done with Membership Pro too? Is this a feature you could add? I've read other posts where other users of Membership Pro have asked for the same feature.

For anyone else who may come across this thread, the code below works and adds the user id into the owner column when a user selects a document during registration or updating their profile. It might also be helpful in other instances when trying to map and update data to/from an external database field:

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

{
$value = (array) json_decode($data);
$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;
$query = 'UPDATE #__edocman_documents SET user_ids= '.$db->quote($ids). ' WHERE id = ' . (int)$val;
$db->setQuery($query);
$db->execute();
}
}
Last edit: 1 week 6 days ago by B Loc.

Please Log in or Create an account to join the conversation.

Moderators: Mr. Dam