[Helma-user] Collection items dependent of logged-in user? Not satisfied...
Andy Hessling
andy.hessling at googlemail.com
Thu Aug 24 05:30:12 CEST 2006
Hi Julian,
Thanks for your reply, I understand what you're saying. But it does
not satifsy my needs - Hannes maybe you have an idea:
I have three prototypes, pages and tags.
DB tables:
Page: ID, url
Tag: ID, value
User: ID, name
In one additional mysql table I store the page-tag-mappings that say
which pages have which tags attached to them, and which user did that.
PageTagMapping: ID, PageID, TagID, UserID
This table restrains the tags that are attached to the Page object,
using the additionalTable command for the collection "tags" of a page
object.
// from Page's type.property:
tags = collection(Tag)
tags.filter.additionalTables = PAGETAGMAPPING
tags.filter = PAGETAGMAPPING.PageID = ${ID} AND PAGETAGMAPPING.TagID = TAGS.ID
That works all nicely, I can select a Page in JavaScript, and loop
over its attached tags. Note that Pages and Tags are independent of
the user, only the PageTagMapping is dependent of it. Now, what I'd
like to do is to loop over a page's tags that were created by a
specific user (say, the currently logged-in user):
var samplePage = root.pages.get(0); // get some page
var samplePageTag = samplePage.tags.get(0); // this works, get the first tag
var samplePageTagOfCurrentUser = samplePage.currentUserTags.get(0); //
that's what I'd like to be able to do.
so, is there any way to insert a JS variable's content into the
type.properties file? Like:
currentUserTags.filter = PAGETAGMAPPING.UserID = ${session.user}
Any thoughts?
Thanks,
Andy
Andy, I asked that question a while back. It took me a while to get
use to this, but helma handles user related data restriction a little
differently.
Instead of restrict the user in type.properties
you access all the data through session.user object instead
for example. On a job tracking system in allow user to only access
jobs belong to the logged in user,
User/type.properties
-------------------------------
_id = USER_ID
_name = USERNAME
username = USERNAME
password = PASSWORD
jobs = collection(Job)
jobs.local = USER_ID
jobs.foreign = JOB_USER_ID
jobs.order = JOB_NAME ASC
Jobs/type.properties
-------------------------------
_id = JOB_ID
job_name = JOB_NAME
job_description = JOB_DESCRIPTION
user = object(User)
user.local = JOB_USER_ID
user.foreign = USER_ID
After the user login, using session.login() function, session.user is
the currently logged in user object
To access only jobs for the currently logged in user,
var currentUserJobs = session.user.jobs;
var str = "";
for (var i=0; i< currentUserJobs.size(); i++) {
var job = currentUserJobs.get(i);
str += job.renderSkinAsString("link");
}
Hope that make sense. So instead of trying to construct SQL
statement with filters, in helma it is recommended that you use
relationship to map every thing as child or grand child of the
Logged in User object.
Julian
On Aug 18, 2006, at 11:23 AM, Andy Hessling wrote:
> Hi,
>
> I have a question regarding the MySQL filter functionality/best
> practice in types.properties. These filters work just fine, I have
> collections of objects attached to my HopObject and can narrow down
> the selection of these objects by having a filter specify column
> constraints in the local/foreign table, or have static constraints
> like "not null". Now, is there any way I can access JS variable
> contents inside this type.properties file? I want to make the
> collection dependent on the current user that is logged in my system.
> If I could reference the session object for example, that could work.
> Comparing the columns "userID" in the collection's DB table with the
> user ID of the user whos currently logged in.
>
> Any thoughts?
>
>
> Thanks,
> Andy
> _______________________________________________
> Helma-user mailing list
> Helma-user at helma.org
> http://helma.org/mailman/listinfo/helma-user
More information about the Helma-user
mailing list