Index: openacs-4/packages/ratings/ratings.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ratings/ratings.info,v diff -u -r1.1 -r1.1.4.1 --- openacs-4/packages/ratings/ratings.info 19 May 2004 19:00:02 -0000 1.1 +++ openacs-4/packages/ratings/ratings.info 29 Jul 2005 23:08:24 -0000 1.1.4.1 @@ -8,7 +8,7 @@ t ratings - + Jeff Davis Multidimensional ratings on arbitrary acs_objects. Xarg @@ -17,7 +17,7 @@ http://www.gnu.org/copyleft/gpl.html 0 - + Index: openacs-4/packages/ratings/lib/ratings.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ratings/lib/ratings.tcl,v diff -u -r1.1 -r1.1.2.1 --- openacs-4/packages/ratings/lib/ratings.tcl 14 Jun 2004 14:17:54 -0000 1.1 +++ openacs-4/packages/ratings/lib/ratings.tcl 29 Jul 2005 23:08:24 -0000 1.1.2.1 @@ -45,25 +45,32 @@ display_template {@ratings.rated;noquote@} } -if {[empty_string_p $object_id]} { +if {![empty_string_p $object_id]} { lappend elements object_title { label {Item} display_template {@ratings.object_title@ (ratings)} } } +lappend elements dimension { + label { Dimension } + display_template {@ratings.description@ } +} + if { 0 } { lappend elements extra { label {Debug} display_template {o.title:@ratings.obj_title@ url:@ratings.url_one@ type:@ratings.object_type@} } } if {$admin_p} { - set bulk [list "Delete ratings" delete] + set bulk [list "Delete ratings" delete] } else { set bulk {} } + + template::list::create \ -name ratings \ -multirow ratings \ @@ -92,12 +99,13 @@ set now [clock_to_ansi [clock seconds]] db_multirow -extend {rated rating_img user_url user_ratings_url object_ratings_url url_one} ratings ratings " - SELECT r.rating_id, u.first_names || ' ' || u.last_name as name, u.user_id, u.email, r.owner_id, r.rating, to_char(o.last_modified,'YYYY-MM-DD HH24:MI:SS') as rated_on, acs_object__name(o2.object_id) as object_title, r.object_id, o2.title as obj_title, o2.object_type - FROM acs_users_all u, ratings r, acs_objects o, acs_objects o2 + SELECT r.rating_id, r.dimension_id, rd.description, u.first_names || ' ' || u.last_name as name, u.user_id, u.email, r.owner_id, r.rating, to_char(o.last_modified,'YYYY-MM-DD HH24:MI:SS') as rated_on, acs_object__name(o2.object_id) as object_title, r.object_id, o2.title as obj_title, o2.object_type + FROM acs_users_all u, ratings r, acs_objects o, acs_objects o2, rating_dimensions rd WHERE r.owner_id = u.user_id $clause and o.object_id = r.rating_id and o2.object_id = r.object_id + and r.dimension_id = rd.dimension_id [template::list::orderby_clause -orderby -name "ratings"]" { set rating_img [ratings::icon::html_fragment -rating $rating] set user_url [acs_community_member_url -user_id $user_id] Index: openacs-4/packages/ratings/sql/postgresql/ratings-data.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ratings/sql/postgresql/ratings-data.sql,v diff -u -r1.1 -r1.1.4.1 --- openacs-4/packages/ratings/sql/postgresql/ratings-data.sql 19 May 2004 19:00:03 -0000 1.1 +++ openacs-4/packages/ratings/sql/postgresql/ratings-data.sql 29 Jul 2005 23:08:24 -0000 1.1.4.1 @@ -11,3 +11,4 @@ -- http://www.fsf.org/copyleft/gpl.html select rating_dimension__new ('Quality','quality','Overall rating of an item.',1,5,'','best'); + Index: openacs-4/packages/ratings/sql/postgresql/ratings-datamodel.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ratings/sql/postgresql/ratings-datamodel.sql,v diff -u -r1.2 -r1.2.2.1 --- openacs-4/packages/ratings/sql/postgresql/ratings-datamodel.sql 21 May 2004 22:53:02 -0000 1.2 +++ openacs-4/packages/ratings/sql/postgresql/ratings-datamodel.sql 29 Jul 2005 23:08:24 -0000 1.2.2.1 @@ -25,7 +25,8 @@ range_low integer default 1, range_high integer default 5, label_low text default 'worst', - label_high text default 'best' + label_high text default 'best', + title varchar(100) ); comment on table rating_dimensions is ' @@ -34,27 +35,28 @@ create table ratings ( - rating_id integer - constraint ratings_rating_id_fk - references acs_objects(object_id) - constraint ratings_rating_id_pk - primary key, - dimension_id integer - constraint ratings_dimension_id_fk - references rating_dimensions(dimension_id) on delete cascade, - object_id integer - constraint ratings_object_id_fk - references acs_objects(object_id) on delete cascade - constraint ratings_object_id_nn - not null, - rating integer - constraint ratings_rating_nn - not null, - owner_id integer - constraint ratings_owner_id_fk - references parties(party_id) on delete cascade - constraint ratings_owner_id_nn - not null + rating_id integer + constraint ratings_rating_id_fk + references acs_objects(object_id) + constraint ratings_rating_id_pk + primary key, + dimension_id integer + constraint ratings_dimension_id_fk + references rating_dimensions(dimension_id) on delete cascade, + object_id integer + constraint ratings_object_id_fk + references acs_objects(object_id) on delete cascade + constraint ratings_object_id_nn + not null, + rating integer + constraint ratings_rating_nn + not null, + owner_id integer + constraint ratings_owner_id_fk + references parties(party_id) on delete cascade + constraint ratings_owner_id_nn + not null, + context_object_id integer ); comment on table ratings is ' Index: openacs-4/packages/ratings/sql/postgresql/ratings-procs.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ratings/sql/postgresql/ratings-procs.sql,v diff -u -r1.3 -r1.3.2.1 --- openacs-4/packages/ratings/sql/postgresql/ratings-procs.sql 21 May 2004 22:53:02 -0000 1.3 +++ openacs-4/packages/ratings/sql/postgresql/ratings-procs.sql 29 Jul 2005 23:08:24 -0000 1.3.2.1 @@ -23,7 +23,6 @@ p_range_high alias for $6; p_label_low alias for $7; p_label_high alias for $8; - p_package_id alias for $9; p_creation_date alias for $10; -- default now() p_creation_user alias for $11; -- default null @@ -41,8 +40,8 @@ p_context_id, ''t''); - insert into rating_dimensions (dimension_id,dimension_key,description,range_low,range_high,label_low,label_high) - values (v_dimension_id,p_dimension_key,p_description,p_range_low,p_range_high,p_label_low,p_label_high); + insert into rating_dimensions (dimension_id,dimension_key,description,range_low,range_high,label_low,label_high,title) + values (v_dimension_id,p_dimension_key,p_description,p_range_low,p_range_high,p_label_low,p_label_high,p_title); return v_dimension_id; @@ -82,6 +81,9 @@ raise NOTICE ''rating_dimension__delete object_id % does not exist or is not a rating_dimension'',p_dimension_id; return 0; end if; + + delete from rating_dimensions where dimension_id = p_dimension_id; + end;' language 'plpgsql'; Fisheye: Tag 1.1 refers to a dead (removed) revision in file `openacs-4/packages/ratings/sql/postgresql/upgrade/upgrade-0.1d-0.1d1.sql'. Fisheye: No comparison available. Pass `N' to diff? Index: openacs-4/packages/ratings/tcl/rating-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ratings/tcl/rating-procs.tcl,v diff -u -r1.4.2.1 -r1.4.2.2 --- openacs-4/packages/ratings/tcl/rating-procs.tcl 27 Jun 2005 15:28:06 -0000 1.4.2.1 +++ openacs-4/packages/ratings/tcl/rating-procs.tcl 29 Jul 2005 23:08:24 -0000 1.4.2.2 @@ -156,16 +156,22 @@ ad_proc -public ratings::rate { {-dimension_key "quality"} - -object_id - -user_id - -rating + -object_id:required + -user_id:required + -rating:required + {-nomem_p "f"} } { Sets the rating for object_id for user user_id. @author Jeff Davis davis@xarg.net @creation-date 2004-01-30 } { - array set dim [ratings::dimensions::get -dimension_key $dimension_key] + if { $nomem_p } { + array set dim [ratings::dimensions::get_nomem $dimension_key] + } else { + array set dim [ratings::dimensions::get -dimension_key $dimension_key] + } + set dimension_id $dim(dimension_id) set vars [list \ @@ -279,3 +285,110 @@ +ad_proc -public ratings::dimension_form { + -object_id:required + {-dimensions_key_list ""} + {-return_url ""} + {-context_object_id ""} +} { + Returns a form to include on an adp page, displaying a group of stars with a checkbox acording to the max and + min ranges especified when creating the dimension. If dimension_key_list is not provided then it will create a form + with all dimensions. If it is provided then it will create a form for just the dimension_key's on the list. + + @param object_id The object you want to rate. + @param dimension_key_list the rating dimension_key's. + @param return_url The url to return after the form is submited. + @param context_object_id The context object to group ratings. + +} { + set output "" + set dimensions_num [llength $dimensions_key_list] + # For each dimension we receive, we are going to use it's value to restrict the query + if { [expr [llength $dimensions_key_list] > 1] } { + set dimensions_query "(" + foreach item $dimensions_key_list { + append dimensions_query "'" + append dimensions_query "$item'," + } + append dimensions_query "'[lindex $dimensions_key_list 0]')" + set extra_query "where dimension_key in $dimensions_query" + } elseif {[string equal [llength $dimensions_key_list] 1] } { + set extra_query "where dimension_key = '$dimensions_key_list'" + } else { + set extra_query "" + } + + set dimensions "" + db_foreach get_dimensions " " { + append dimensions "${dimension_key}-" + } + + append output "" + set count 0 + # For each dimension we create a new form to rate all dimensions. + append output "" + db_foreach get_dimensions " " { + append output "" + append output "" + incr count + } + append output "
" + append output "" + append output "" + append output "" + append output "" + append output "${title}:

" + # We create the options using the values specified when the dimension was created. + for { set i $range_low } { $i <= $range_high } { incr i } { + append output "" + append output "[ratings::icon::html_fragment -icon_key stars -rating $i]
" + } + append output "
" + append output "
    
" + return $output +} + +ad_proc -public ratings::get_list { + {-context_object_id ""} + -object_id:required +} { + Returns a list of elements of the form { rating_id value } for one object_id. If context_object_id + was provided then retursn the pairs in that context_id, else, it returns all pairs for + that object_id. + + @param context_object_id The object_id that groups diferent ratings. + @param object_id The object_id that was rated. + @return the list { rating_id value } for the object_id. + + @author Miguel Marin (miguelmarin@viaro.net) + @creation-date 2005-07-29 +} { + set extra_query "" + if { ![empty_string_p $context_object_id] } { + set extra_query "and context_object_id = $context_object_id" + } + return [db_list_of_lists get_rating_id " "] +} + +ad_proc -public ratings::get_average { + -context_object_id:required + -object_id:required + {-dimension_key ""} +} { + Returns the average rating for one on the same context_object_id and object_id. If dimension_key is specified + then returns only the average for that dimension. + + @param context_object_id The object_id that groups diferent ratings. + @param object_id The object_id that was rated. + @param dimension_key The dimension to get the average. + @returns a average rating value. + + @author Miguel Marin (miguelmarin@viaro.net) + @creation-date 2005-07-29 +} { + set extra_query "" + if { ![empty_string_p $dimension_key] } { + set extra_query "and dimension_id = ( select dimension_id from rating_dimensions where dimension_key = '$dimension_key' )" + } + return [db_string get_average_rating " "] +} Fisheye: Tag 1.1 refers to a dead (removed) revision in file `openacs-4/packages/ratings/tcl/rating-procs.xql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.1 refers to a dead (removed) revision in file `openacs-4/packages/ratings/www/add-dimension-postgresql.xql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.1 refers to a dead (removed) revision in file `openacs-4/packages/ratings/www/add-dimension.adp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.1 refers to a dead (removed) revision in file `openacs-4/packages/ratings/www/add-dimension.tcl'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.1 refers to a dead (removed) revision in file `openacs-4/packages/ratings/www/add-dimension.xql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.1 refers to a dead (removed) revision in file `openacs-4/packages/ratings/www/all-ratings.adp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.1 refers to a dead (removed) revision in file `openacs-4/packages/ratings/www/all-ratings.tcl'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.1 refers to a dead (removed) revision in file `openacs-4/packages/ratings/www/delete-dimension-postgresql.xql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.1 refers to a dead (removed) revision in file `openacs-4/packages/ratings/www/delete-dimension.tcl'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.1 refers to a dead (removed) revision in file `openacs-4/packages/ratings/www/index.adp'. Fisheye: No comparison available. Pass `N' to diff? Index: openacs-4/packages/ratings/www/rate.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ratings/www/rate.tcl,v diff -u -r1.3 -r1.3.2.1 --- openacs-4/packages/ratings/www/rate.tcl 21 May 2004 07:48:05 -0000 1.3 +++ openacs-4/packages/ratings/www/rate.tcl 29 Jul 2005 23:08:24 -0000 1.3.2.1 @@ -11,17 +11,27 @@ dimension_key:notnull rating:integer,notnull {return_url:trim {}} + {nomem_p "f"} + {context_object_id ""} } + set user_id [auth::require_login] + + set rating_id [ratings::rate -dimension_key $dimension_key \ -object_id $object_id \ -user_id $user_id \ - -rating $rating] + -rating $rating \ + -nomem_p $nomem_p] +if { ![empty_string_p $context_object_id] } { + db_dml update_context_id { update ratings set context_object_id = :context_object_id where rating_id = :rating_id } +} + if {[empty_string_p $return_url]} { set return_url [get_referrer] } -ad_returnredirect -message "Your rating is now $rating for this item." $return_url +ad_returnredirect -message "Your rating is now $rating for this item $dimension_key." $return_url