Fisheye: Tag 1.1 refers to a dead (removed) revision in file `openacs-4/packages/views/tcl/views-procs-oracle.xql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.1 refers to a dead (removed) revision in file `openacs-4/packages/views/tcl/views-procs-postgresql.xql'. Fisheye: No comparison available. Pass `N' to diff? Index: openacs-4/packages/views/tcl/views-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/views/tcl/views-procs.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/packages/views/tcl/views-procs.tcl 23 Jul 2007 05:25:10 -0000 1.5 +++ openacs-4/packages/views/tcl/views-procs.tcl 2 Aug 2007 08:33:39 -0000 1.6 @@ -1,4 +1,4 @@ -# /packages/cop-base/tcl/ratings-procs.tcl +# /packages/views/tcl/views-procs.tcl ad_library { TCL library for recoding views @@ -26,15 +26,17 @@ @creation-date 2004-01-30 } { if { $type ne "" } { - if { [lsearch [list views unique_views last_viewed] $type] >= 0 } { + if { [lsearch [list views_count unique_views last_viewed] $type] >= 0 } { # if the type is on of the list it will conflict on the views::get procedure - error "views::record_view type cannot be views, unique_views or last_viewed" + error "views::record_view type cannot be views_count, unique_views or last_viewed" } - set views_by_type [db_string record_view_by_type "select views_by_type__record_view(:object_id, :viewer_id, :type)" -default 1] + #TYPE is PL/SQL reserver word in ORACLE + #set view_type $type + set views_by_type [db_exec_plsql record_view_by_type {}] } - if {[catch {db_string record_view "select views__record_view(:object_id, :viewer_id)" -default 1} views]} { - set views 0 + if {[catch {set views [db_exec_plsql record_view {}]} views]} { + set views 0 } return $views } @@ -45,28 +47,20 @@ Return an array (which you have to set with "array set your_array [views::get -object_id $object_id]") with the elements: @param object_id ID of the object for which you want to return the views } { - if {[db_0or1row views { - SELECT views, unique_views, to_char(last_viewed,'YYYY-MM-DD HH24:MI:SS') as last_viewed - FROM view_aggregates - WHERE object_id = :object_id - } -column_array ret] } { - db_foreach select_views_by_type { - select type, views - from view_aggregates_by_type - where object_id = :object_id - } { - set ret($type) $views + if {[db_0or1row views { } -column_array ret] } { + db_foreach select_views_by_type { } { + set ret($view_type) $views_count } return [array get ret] } - return {views {} unique_views {} last_viewed {}} + return {views_count {} unique_views {} last_viewed {}} } @@ -79,20 +73,9 @@ set user_id [ad_conn user_id] } if { $type ne "" } { - return [db_string get_viewed_by_type_p { - select count(*) - from views_by_type - where object_id = :object_id - and viewer_id = :user_id - and type = :type - } -default 0] + return [db_string get_viewed_by_type_p { } -default 0] } else { - return [db_string get_viewed_p { - select count(*) - from views - where object_id = :object_id - and viewer_id = :user_id - } -default 0] + return [db_string get_viewed_p { } -default 0] } } Fisheye: Tag 1.1 refers to a dead (removed) revision in file `openacs-4/packages/views/tcl/views-procs.xql'. Fisheye: No comparison available. Pass `N' to diff? Index: openacs-4/packages/views/tcl/test/views-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/views/tcl/test/views-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/views/tcl/test/views-procs.tcl 2 Aug 2007 08:33:39 -0000 1.1 @@ -0,0 +1,103 @@ +ad_library { + Test cases for views +} + +aa_register_case \ + -cats {api} \ + -procs {views::record_view views::get views::viewed_p} \ + view_api_test_without_type \ + { + A simple test that adds, retrieves and check a record + } { + aa_run_with_teardown \ + -rollback \ + -test_code { + set viewer_id_list [db_list get_viewer_id_list "select user_id from users where user_id != 0"] + set viewer_id [lindex [util::randomize_list $viewer_id_list] 0] + #Object_id not in views_by_type + set object_id_list [db_list get_object_id_list "select ao.object_id from acs_objects ao left outer join (select object_id from views_views where viewer_id != :viewer_id) vt on ao.object_id = vt.object_id"] + set object_id [lindex [util::randomize_list $object_id_list] 0] + + aa_false "User view object_id" [expr [views::viewed_p -object_id $object_id -user_id 0] > 0] + + aa_log "User_id is $viewer_id, object is $object_id" + + views::record_view -object_id $object_id -viewer_id $viewer_id + + set count_record [db_string count_record "select count(*) from views_views where object_id = :object_id and viewer_id = :viewer_id" -default 0] + + aa_true "Record add" [expr $count_record > 0] + + set count_views [db_string count_views "select views_count from views_views where object_id = :object_id and viewer_id = :viewer_id" -default 0] + + views::record_view -object_id $object_id -viewer_id $viewer_id + #Update count views + set count_record [db_string count_record "select count(*) from views_views where object_id = :object_id and viewer_id = :viewer_id" -default 0] + + aa_true "Update record but don't insert new row" [expr $count_record == 1] + + set count_views2 [db_string count_views2 "select views_count from views_views where object_id = :object_id and viewer_id = :viewer_id" -default 0] + + aa_true "Count_view is updated" [expr $count_views2 > $count_views] + + set get [views::get -object_id $object_id] + aa_log "Return of function views::get $get" + + aa_true "User view object_id" [expr [views::viewed_p -object_id $object_id -user_id $viewer_id] > 0] + + set all_views_count [db_string count_views_views "select sum(views_count) from views_views where object_id = :object_id"] + set view_count_aggregates [db_string get_views_count "select views_count from view_aggregates where object_id = :object_id"] + aa_equals "views_count on view_aggregates is equal to sum views_count on views_views" $view_count_aggregates $all_views_count + } + } + + +aa_register_case \ +-cats {api} \ +-procs {views::record_view views::get views::viewed_p} \ +view_api_test_with_type \ +{ + A simple test that adds, retrieves and check a record with type +} { + aa_run_with_teardown \ + -rollback \ + -test_code { + set viewer_id_list [db_list get_viewer_id_list "select user_id from users where user_id != 0"] + set viewer_id [lindex [util::randomize_list $viewer_id_list] 0] + #Object_id not in views_by_type + set object_id_list [db_list get_object_id_list "select ao.object_id from acs_objects ao left outer join (select object_id from views_by_type where viewer_id != :viewer_id) vt on ao.object_id = vt.object_id"] + set object_id [lindex [util::randomize_list $object_id_list] 0] + + set type test + + aa_false "User has viewed object_id" [expr [views::viewed_p -object_id $object_id -user_id $viewer_id -type $type] > 0] + + aa_log "User_id is $viewer_id, object is $object_id and type $type" + + views::record_view -object_id $object_id -viewer_id $viewer_id -type $type + + set count_record [db_string count_record "select count(*) from views_by_type where object_id = :object_id and viewer_id = :viewer_id" -default 0] + + aa_true "Record add" [expr $count_record > 0] + + set count_views [db_string count_views "select views_count from views_by_type where object_id = :object_id and viewer_id = :viewer_id" -default 0] + + views::record_view -object_id $object_id -viewer_id $viewer_id -type $type + #Update count views + set count_record [db_string count_record "select count(*) from views_by_type where object_id = :object_id and viewer_id = :viewer_id" -default 0] + + aa_true "Update record but don't insert new row" [expr $count_record == 1] + + set count_views2 [db_string count_views2 "select views_count from views_by_type where object_id = :object_id and viewer_id = :viewer_id" -default 0] + + aa_true "Count_view is updated" [expr $count_views2 > $count_views] + + set get [views::get -object_id $object_id] + aa_log "Return of function views::get $get" + + aa_true "User has viewed object_id" [expr [views::viewed_p -object_id $object_id -user_id $viewer_id -type $type] > 0] + set all_views_count [db_string count_views_views "select sum(views_count) from views_by_type where object_id = :object_id and view_type=:type"] + set view_count_aggregates [db_string get_views_count "select views_count from view_aggregates_by_type where object_id = :object_id and view_type=:type"] + aa_equals "views_count on view_aggregates is equal to sum views_count on views_views" $view_count_aggregates $all_views_count + } +}