• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Assign data to user

HexWebspace

New Member
Hi All. Havent been here for a while, hope everyone is good!

I've got a bit of a project I'm working on using Fabrik.

So, There's a standalone PHP page that feeds enquiry data into a FABRIK table.

This data needs to be assigned to the correct joomla user depending on the postcode contained in the data. And ONLY the assigned user must be able to see this data!

The correctly assigned user must then recieve an email letting them know that here is a new enquiry.

Any thoughts on the best way to accomplish this?

Thanks
Ivan
 
You must include the Joomla userid of your user in one column/element of your Fabrik table.
Then you can set a prefilter
http://fabrikar.com/forums/index.ph...#show-records-belonging-to-the-logged-on-user

The emailing has to be done where/when the data is filled into the table (so in your standalone PHP page).
Or you may add a Fabrik scheduled task testing every x days/hours/minutes... if there's new data (which you must mark accordingly) and sending the emails.
 
Hi Truester

Thanks, but I don't think I was clear with this.

I know how to filter data shown by the user that created the entry. However, this needs to be different.

I'll try to explain more clearly...

There is a standalone PHP page, which contains basic enquiry forms, one of the form fields is the customers postcode.

This then inserts data into a table which fabrik is also connected to.

I need this data to be assigned to a Joomla user depending on which postcode the customer is from (Eg if John is in DH postcode that is covered by DURHAM SYSTEMS so the data will be assigned to them and nobody else.

I'm trying to think of a way that fabrik can assign this data by matching the given postcode to a joomla user.

Also, the emailing will have to be done once a joomla user is assigned as the email needs to only go to that particular user.

Thanks
Ivan
 
Fabrik can only do something if you are running some Fabrik, so if you are loading a list or loading or submitting a form or running a scheduled task.

There are a lot of php hooks (plugins) you can use but it's up to you to collect or calculate and store the additional data you need and to trigger actions you want to do.

So e.g. who/what should trigger the email when?

You can build complex prefilters with type Query or Eval for connecting the Joomla user id of the logged-in user with additional data.
 
Thanks Truester, but that doesnt really answer my question at all.

The relevant data is being inserted into the table externally, but from that point I need Fabrik to take over.

I can no doubt work out how to do the rest (trigger emails to correct user etc) but I cant figure out how to assign to a user based on the data that is in the postcode field.

Thanks
Ivan
 
So what is the unique relation between a logged-in user (in Joomla defined by his userId, unique email address, unique Joomla username), the data in the Fabrik table (and/or the data in your other table)?
Fabrik doesn't "know" this, you have to define.
How do you know?
 
The unique data is the postcode.

So lets say on joomla user table BOBS SHOP has postcode area NE assigned.

The table that is fed into from the external website also contains the postcode that the customer enquiry has come from. Lets call it the ENQUIRY table.

The ENQUIRY table contains all enquiries, but I need to find a way to assign any enquiries that are from NE postcode to BOBS SHOP.

As BOBS SHOP didnt create this enquiry im not sure how to create the logic to do this.
 
The only way around this I can think of is to have a different table for every postcode area (with each table pre assigned to relevant joomla user), and then somehow get the external website to post to the correct table corresponding to the postcode entered in the enquiry, might be able to achieve this with PHP but seems like a far too complex way of doing it.. Just looking for ideas. Thanks
 
So the Enquiry table is the one Fabrik is linked to?

You can add a column joomla_user_id and insert the appropriate Joomla user (the one who has e.g. NE assigned; assigned how?) via your external website (something like SELECT id FROM joomla-prefix_users WHERE whatever = 'NE')
 
Ah! I see your point. So do the logic outside of fabrik to assign to correct user?

I just thought there may have been a way of bringing all data in centrally to main enquiry table and then running something in Fabrik (possibly via cron) to proccess ownership etc.

Thought there may have been a nice clean function for this
 
As I said: you can do it also with a cron (scheduled task) or inside the prefilter (if it's only for display) or ... or...
 
Is your Postcode to J! user ID relationship ever going to change? Or will a given postcode always be that ID, forever and ever amen?

-- hugh
 
In case it's not obvious, if the relationship might change, ie. the company that serves a given postcode might change at some point, then you have a problem of a whole kettle of fish of a different stripe. You wouldn't be able to statically assign the user ID to the record in Fabrik, you'd have to do it in the pre-filter itself. For example, if your external table with the postcode to J! user ID lookup is in postcode_users and has fields 'postcode' and 'user_id', your pre-filter might look like:

Field: postcode
Condition: IN
Value: SELECT postcode FROM postcode_users WHERE user_id = '{$my->id}'
Type: query
Apply to: Public

In fact, that might be the better way to do it regardless, rather than inserting the user ID into the Fabrik data.

Although of course then you have the issue of controlling edit access, if you don't have a 'user' element on the data. Although people wouldn't see records in the list, they could edit any of them by just guessing the rowid and creating a component link by hand to form view. So if that's a concern, you'd have to add a 'caneditrow' plugin to the list, which does something similar to the prequery. Code might be something like ...

Code:
$postcode = '{yourtable___postcode_raw}';
if (!empty($postcode)) {
   $db = JFactory::getDbo();
   $query = $db->getQuery(true);
   $query->select('user_id')->from('postcode_users')->where('postcode = ' . $db->quote($postcode));
   $db->setQuery(true);
   return (int)JFactory::getUser()->get('id') === (int)$db->loadResult();
}

return false;

And maybe duplicate that for a candeleterow and canviewrow plugin.

It'd be heavy on database access when displaying lots of rows in a list, so you would probably want to stick that code in the new Fabrik Custom helper, as a static function, which can cache results, so you only hit the database once.

-- hugh
 
Another thing to note about this approach is that it could be slightly tweaked (the caneditrow stuff) ...

Code:
$postcode = '{yourtable___postcode_raw}';
if (!empty($postcode)) {
   $db = JFactory::getDbo();
   $query = $db->getQuery(true);
   $query->select('user_id')->from('postcode_users')->where('postcode = ' . $db->quote($postcode));
   $db->setQuery(true);
   $userIds = $db->loadColumn('user_id');
   return in_array(JFactory::getUser()->get('id'), $userIds);
}

return false;

... so you can allow for multiple users per postcode, so if you have two or more companies serving a postcode, that's not a problem - they could both see and edit the data.

-- hugh
 
Hi Hugh, long time!

Thanks for that info, a lot to think about with this. I've not used Fabrik for a good while now so just getting my head around it again.

The business model for this is that each company that signs up would have a 'patch', which could be one or several postcodes.

Security is an issue, although the type of businesses involved tend not to be tech savvy they're certainly not above getting someone who is to try and backward engineer theor way to more customers!

There surely must be a simpler method of achieving this, just at this moment in time I cant think of one.

To further complicate matters, when a potential client makes an enquiry they will recieve an SMS letting them know the contact details of the company they will be dealing with, at the same time the relevant company needs to recieve an email with details of the enquiry.

I'm not expecting to complete this within a week or two, Ive given myself 4 months.

Thanks
Ivan
 
There surely must be a simpler method of achieving this, just at this moment in time I cant think of one.

As I said, it depends on whether a) the user ID associated with a postcode will ever change, and b) whether you need more than one user ID per postcode. If neither of those conditions will ever arise, then you can just insert the mapped user ID from your external sciprt, into the table Fabrik uses, and do normal user ID ACl's.

But if either of those conditions might ever be true, then you'd have to do it the way I described.

-- hugh
 
Is it possible I can get a price to get a one to one consultation on this project? I will eventually get my head around the technical coding side, but someone with more Fabrik experience than me may be better at designing the initial structure.
Thanks
Ivan
 
Really, it depends on the answers to the questions I posed in my last post. If the answers to a) and b) are both no, then it's quite simple, you just have a lookup table that maps postcode to J! user ID, and use that to insert the user ID when you add the record to the Fabrik table in your stand-alone external script. Obviously I can help with that if needed, but it's very simple ... just a single query to look up the user ID from the postcode, and include that in the record you insert into the main data table.

If you think the answer to one of the questions might be "yes" (now or in the future), then yes, you'd probably need some help setting up the Fabrik side of things to filter by postcode.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top