Forums / Install & configuration / is this possible with ezstarrating extension in 4.2?

is this possible with ezstarrating extension in 4.2?

Author Message

Stephane Persyn

Saturday 10 October 2009 4:37:48 pm

Hi,

I would like my site to show a list of hotels where any registered user can comment and rank while creating the comment.

Issue, is that starrating extension seems to be designed for any authorized user to be able to rate <b>without having to add a belonging comment</b>. On the other side, when editing/creating/modifying a class with a starrating attribute, providing a rank value is not possible.

I plan to use an "evaluation" class, which basically is the comment class, with an additionnal starrating attribute.
Also, the "hotel" class (container of evaluations) will also have a starrating attibute.

How can I setup ezpublish in order to make the following steps:

1/ make impossible to vote on the "Hotel" view level (read only), or if a user tries to vote directly, redirecting him to new "evaluation" creation before the vote is taken in account,
2/ when creating an "evaluation" to an "Hotel", provide a way for the user to set the starrating rank at the comment level (again, seems like it's not possible in edit mode).
3/ upon publishing the new comment created, have a way to "update" the starrating attribute of the parent node (the "Hotel") in accordance.

At the end, I want just to have the basic behaviour most of sites have: an article gets an average rank, calculated from all reviews/comments added by the users. Usually the ranking is set when the user creates his comment. Any anonymous user can then look at the hotel, see average rank, and if viewing comments(evaluations), he can see the actual rank given by each author of each comment.

Any idea, or any smart way to do this, with current starrating extension?

Piotrek Karaś

Saturday 10 October 2009 11:43:18 pm

Hello Stephane,

I haven't used the ezstarrating extension you mentioned so far, so cannot confirm its being useful here, but I don't expect it to be fit for your needs out of the box. As the matter of fact, I think it has a slightly different purpose.

If I understood correctly, you want to have a rating-review pairs for hotel objects and then aggregate the ratings from all those pairs. My solution would be a dedicated one, and quite easy (even though it may seem complicated).

I would simply create a simple review content class that would consist of at least the review textblock and rating selection (1-10 for example), but for the latter I would necessarily use a datatype that stores the selected number directly in data_int field of ezcontentobject_attribute table. I'm not sure if any built-in datatype does just that, so there might be a need for a very simple dedicated one. Having that, I would write a simple template operator that would actually wrap around an SQL query that would fetch and aggregate the ratings directly from the database. The SQL would like something like:

SELECT COUNT(coa.data_int) AS vote_count, SUM(coa.data_int) AS vote_sum
FROM ezcontentobject_attribute coa, ezcontentobject_tree cot, ezcontentobject co
WHERE co.id=cot.contentobject_id
AND co.id=coa.contentobject_id
AND co.status=1
AND cot.path_string LIKE '{$NODEPATH}%'
AND coa.contentclassattribute_id={$CCAID}
AND co.current_version=coa.version
...

where $NODEPATH would be a path of current hotel node for which reviews are aggregated, and $CCAID would be the ID of content class attribute that stores the actual rating.

This solution would be able to handle many more reviews than template based one and would avoid struggling with rating system adaptation. I hope this may be useful for you.

Cheers,
Piotrek

PS. The above SQL is just out of my head, it may have some problems to it, but that's definitely doable.

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Stephane Persyn

Sunday 11 October 2009 8:51:00 am

Thanks, Piotrek.

I will follow what you advise, as it makes more sense than to customize ezstarrating.

My next step is then to learn about template operator and datatypes writing, which may not seem easy for a newbie to Ezpoublsh, I will have obviously to get through the learning curve.

I will start with the ez technical manual on templates, but do you have any additional advice about which tutorial, article from ez or from contributor I can go on with?

Thanks again for your time taken to answer my post.

Stéphane

Piotrek Karaś

Sunday 11 October 2009 11:51:15 am

What you need for that solution is:
- learn how to create eZ Publish extensions in general
- learn how to provide custom datatypes
- learn how to provide custom template operators

Before you go on, study the technical documentation as much as possible, all the details become handy sooner or later. Google/search for tutorials and forum topics. Also, go to http://projects.ez.no and study few datatype/operator providing extensions of other contributors. Don't forget to study how the built in datatypes work in /kernel/classes/datatypes/{datatype}/{datatype}type.php.

Good luck

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Stephane Persyn

Tuesday 13 October 2009 8:31:33 am

Hey Piotrek.

I am not so successful with my brand new datatype :)

in any case you cand find a specific post I made on the developer section of the forum:
http://ez.no/developer/forum/developer/help_needed_on_debugging_my_first_basic_datatype

If you can ever get an eye on it. Seems very basic, but if I think I figures out the general philosophy, seems there are still some fundamental concepts I didn't get yet apparently :)

Stéphane.

realistic p

Wednesday 14 October 2009 1:16:55 am

Hi,

I tried and really work perfectly.

Thank You Very Much.

http://www.dogfencediy.com/reviews/innotek-ultrasmart-iuc-4100/
http://www.nile-cruise.com/
http://www.mynextfloridavacation.com/

Stephane Persyn

Friday 16 October 2009 12:56:51 pm

realistic p: what did work perfectly my datatype, or what I was looking to do with ezstarrating?

Cheers,

Stéphane