This module can be used to implement a rating system based on external sources.
What that means is that the actual rate, vote or whatever action, happens on
an external application (for example on Facebook), and the results are fetched
into your system.
The module by itself provides a mechanism to register new external sources, that
are plugins and are managed using ctools, and it also gets the rating
results from the external sources. It has no frontend interface, so other modules
can and should use its API (actually, there are just a few functions at the moment
that can be called to register an entity for rating, to get a total rating, etc..).
Any type of entity can be rated. Moreover, there can be multiple ratings per
each entity (for example you can rate the same entity every day, so that you can
have a statistic per day for the ratings).
As mentioned, the module by itself does not have any frontend interface, it
has only a backend configuration. By default, it implements two external rating
sources: Facebook likes and Twitter tweets. To install the module, just go to the
Modules page and check the checkbox near it. After the module is installed,
a configuration form can be found here: Structure -> Entity External Rating.
From here, you can enable or disable certain plugins, and do some basic
configurations. Each plugin can have its own configuration form (click on the
edit link after each plugin name). The two default plugins have only the
API url that is used to get the ratings.
There is also an example module that demonstrates how to create a new plugin
in your custom modules.
The first step for using this module is to add entities into the rating queue.
You can do that using the function: entity_ext_rating_add_to_queue(). By doing
this you basically register an entity so that the module will try to get its rating
periodically at the next cronjobs. A very important parameter is the $rating_id.
This is different than the entity_id because you can have more ratings for the
same entity. Then, the $params contain any parameters that the external rating
system uses for rating. For example, for Facebook and Twitter, the URL is the
parameter. So, a real example of how to call the function:
<?php
entity_ext_rating_add_to_queue('node_100_1', 100, 'node', array('url' => 'http://www.example.com/node/100?day=1'), time()+86400);
?>
The last parameter is a timestamp that is used to determine when the entry will
be deleted from the queue, so no more calls will be made to the external rating
sources.
Then, you can get the total rating for a rating id, using the
entity_ext_rating_get_total_rating() function and you get get the html widgets
to be printed into the page, to allow your users to rate, vote, share, etc..
the entity.
The project page ca be found here: http://drupal.org/sandbox/vasi/1323440
Direct link to repository: git clone --branch master vasi@git.drupal.org:sandbox/vasi/1323440.git
The module is made right now only for Drupal 7, but back-porting to Drupal 6 should be really easy if needed.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | coder-result.txt | 3.94 KB | klausi |
Comments
Comment #1
klausiIt appears you are working in the "master" branch in git. You should really be working in a version specific branch. The most direct documentation on this is Moving from a master branch to a version branch. For additional resources please see the documentation about release naming conventions and creating a branch in git.
Review of the master branch:
This automated report was generated with PAReview.sh, your friendly project application review script. Please report any bugs to klausi.
manual review:
Comment #2
vasi1186 commentedHi,
I did the changes you highlighted in the previous comment, also made a dev branch that I am using now for working. One question for this: "all functions should be prefixed with your module/theme name to avoid name clashes". I actually could not find a function that does not start with "entity_ext_rating". Can you give me an example?
The other observations can be checked again.
Comment #3
attiks commentedAutomated test results:
Please note: The Coder module currently has an unresolved flaw which will prompt you to add file declarations to your .info file even when it's not necessary to do so. Please do not try to make this warning go away by declaring files which do not contain classes or interfaces.
Severity minor, Drupal Commenting Standards, Internationalization, Drupal Security Checks, Drupal SQL Standards, Drupal Coding Standards /entity_ext_rating.admin.inc: +23: [minor] There should be no trailing spaces +67: [critical] table names should be enclosed in {curly_brackets} Status Messages: Coder found 13 projects, 13 files, 1 critical warnings, 1 minor warnings, 0 warnings were flagged to be ignoredComment #4
vasi1186 commentedI made a commit where I tried to solve these minor warnings, but for some of them (for example 'All comments should end with a ".".') the problem is that there are comments that span multiple lines and I used '//' for commenting. Probably the solution would be to use the multiple line comments (/* */), but is this a real must? because I have seen in many places in the Drupal core the '//' comments on multiple lines.
Then, there is a warning: "table names should be enclosed in {curly_brackets}" in entity_ext_rating.admin.inc, but I actually do not use any table name there... On the other hand, I solved a lot of minor warnings, changed quite a lot the commenting style of the functions so I think you can check it again.
Thank you.
Comment #5
attiks commentedYou can ignore the warnings about the comments, our automated system is still a bit beta, the table name warning can also be ignored, since there's no table there, no idea what caused this to popup.
I had a quick look at the code, and it looks very solid, the problem is that it isn't easy to test, do you perhaps have a demo somewhere?
Comment #6
vasi1186 commentedI don't have yet a demo (actually I have one but not allowed yet to publish it) so I will make another demo tomorrow and then you can have a look. I'll come back when the demo is done.
Comment #7
klausiReview of the 7.x-1.x branch:
This automated report was generated with PAReview.sh, your friendly project application review script. Please report any bugs to klausi.
manual review:
Otherwise I'm pretty happy with the code base. Looks pretty clean and well documented. You seem to know all sorts of Drupal APIs already, so if you fix this minor issues you get a green light from me.
Comment #8
vasi1186 commentedHi again,
I created a demo page here: http://drupaldemos.net/entity_ext_rating
I know it is a bit hard to test the functionality... What you can see there is a view of articles that can be sorted by their rating. Now, the module itself is not integrated yet directly with the views module, so you cannot just put a filter from the view settings. The main purpose of the module at the moment is just to fetch the data from the different sources, and aggregate it afterwards. Then, you can do whatever you want with the results (I am thinking now to also write a module where I can show how this module can be used in live applications). What I did on the demo site was to create a field on the article content type, then update the field at cron with the data provided by the Entity External Rating module. In this way, I was able to create the filter. I also injected the rating widgets into the node full and teaser views. But these things I did from another custom module.
The ratings update occurs at cron, so for testing you will have to run the cron to have the latest results: http://drupaldemos.net/entity_ext_rating/cron.php?cron_key=20FQWMa1jQ1xA...
I've noticed that the facebook rates are updated in real time. If you click on the Like button, then run the cron, the values are immediately there. But, for twitter I saw that there are some strange delays sometimes... So, if you tweet, then also the counter for the button is not updated instantly, and the same happens with the results from their API. So, for twitter, the behavior can be quite strange in the beginning, but after a while, the results should be correct.
So, short summary for testing: click on facebook like and tweet buttons, then run the cron and then see the results (with the mention that the twitter results are not accurate immediately, so you may need to run the cron several times).
If you want to check the backend, I can make you an admin account. But, basically, from the backend you can just enable or disable certain plugins, edit the API URLs for them, and make some other small settings.
For the remaining issues, pointed in the last comment, I will try to solve them until tomorrow evening.
Comment #9
vasi1186 commentedI made again a commit with the latest changes that I made in the code. For
I actually used urlencode(drupal_strip_dangerous_protocols()) because otherwise I was not able to use any query parameters in the link. And as I saw, the check_url uses also drupal_strip_dangerous_protocols() to prevent xss.
Then, the hook_entity_ext_rating_plugins() is called because I use the ctools plugin feature, so it is not like a hook created by my module. My module actually defines another hook, that is invoke right after the ratings are fetched from the external sources, so I added it in the api file. Should I also add the hook_entity_ext_rating_plugins()?
I also don't know what to repair for the @see references... I checked the doxygen and it looks ok to me...
I will also try to change the project page, I know it looks a bit overwhelming, I will think to a shorter and more concise description of the project.
Comment #10
klausiReview of the 7.x-1.x branch:
This automated report was generated with PAReview.sh, your friendly project application review script. Please report any bugs to klausi.
manual review:
Otherwise I think this is RTBC.
Comment #11
vasi1186 commentedMade the changes in the api file and also for the @see comments, but the warning is still there. May be that the file that implements the class is declared in the .info file, and thus is not loaded unless the class is instantiated?
So I think the only remained issue so far is to change a bit the project description page, which I hope to finish these days.
Comment #12
gregglesThanks for your contribution, vasi1186! Welcome to the community of project contributors on drupal.org.
I've granted you the git vetted user role which will let you promote this to a full project and also create new projects as either sandbox or "full" projects depending on which you feel is best.
Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.
As you continue to work on your module, keep in minde: Commit messages - providing history and credit and Release naming conventions.
Comment #14
milenpat commentedHi, I'm a relative newbie but understand the basics of Drupal. I have a project that would really benefit from your module but have no clue how to impliment it without the use of Views. Is there any way you could give me a quick run down on how I can actually impliment entitny external rating.
Thanks in advance.
This is a really useful module!
Comment #15
vasi1186 commentedIf you want to use the module without Views, then all what you have to do in your custom module is:
1. add nodes (or whatever other entities) to the rating queue.
2. use the rating table in your custom queries.
3. Show the widgets somewhere on your pages.
For 1: you have to use this function:
For example:
The first parameter is a sort of key, you can generate it how you want, but if you want to track nodes, it should somehow contain the node id, to be sure it is unique.
The second parameter is the id of the entity, and the third is the entity type.
The forth parameter is an array with special settings for each plugin. Right now, the only setting used by all is the url, that has to be queried. I suggest you do not use the url() function to generate it, because if you have url aliases you may experience some issues. I think something like this should work:
The last parameter is a timestamp, that tell the system when it should stop querying the external system for new results. If is set to 0, it should query all the time.
For 2, just use the entity_ext_rating_total table to get the results.
For 3, to print the widgets, for example for a certain URL and some title (used by the Twitter plugin), you have this function:
Again, I suggest to not use the url() fuction to generate urls for nodes.
Hope this helps to understand how to use the module. If any other questsions, I'll be happy to answer them :)
Comment #16
vasi1186 commentedAlso, here is the project page ( https://drupal.org/project/entity_external_rating ) but probably you know it already.
Comment #17
patrickd commentedThis issue is closed
Please do not use it for further discussions, if you have questions open a new issue in the project's issue queue!
Comment #18
milenpat commentedHi thanks for the prompt reply. I appreciate it.
I'm clearly going to need to take a bit of time and have a play around custom modules etc. and see if I can figure out a way to get this working for me.
Thanks for the offer of further help. Will no doubt take you up on it at some point soon. Thanks.
Comment #19
milenpat commentedHi,
sorry but this beyond my skills at the moment.
Ideally I would like to integrate this module with views if possible.
The things I don't understand is what you mean by, "custom module" do I need create a futher module that takes the information from EER and then displays it on my selected nodes?
Or use it in conjunction with another module?
Or do I need to edit the module file in the EER folder get it to display in a block that I then place where needed?
From the info so far it seems that you use the field inputs when creating content types and then call up the widgets to display the results. I'm sorry but I don't know how to do this, and going through all the combinations on my content creation pages hasn't brought me any closer.
Further more I would like to some how integrate some kind of user points into the overall score delivered. Is this a complicted thing to do? How could I start getting somewhere on this.
Would be great if you could just clarify these things for me or at least point me in the direction of where I can find out how to get this done. I'd like to make it an integral part of my website.
Thanks in advance for any help.
Comment #20
milenpat commentedHi,
Could someone just drop a quick note about how to integrate this module into Views.
You say this done using custom module that populates fields in your content type.
How can you achieve this?
Thanks