roelc
committed
on 27 Apr 06
Use ec_pretty_price
openacs-4/.../dotlrn-ecommerce/lib/tree-chunk.tcl (+19 -3)
23 23 set package_id [ad_conn package_id]
24 24 set user_id [ad_conn user_id]
25 25
26 26 set cc_package_id [apm_package_id_from_key "dotlrn-catalog"]
27 27
28 28 set filters {}
29 29
30 30 set allow_free_registration_p [parameter::get -parameter AllowFreeRegistration -default 0]
31 31
32 32 # Generate filters based on categories
33 33 # set filters {
34 34 #     uncat_f {
35 35 #       label "[_ dotlrn-catalog.uncat]"
36 36 #       values { "Watch" }
37 37 #       where_clause { dc.course_id not in ( select object_id from category_object_map where category_id in \
38 38 #                                                ( select category_id from categories where tree_id =:tree_id ))
39 39 #       }
40 40 #     }
41 41 # }
42 42
  43 if { [exists_and_not_null show_hidden] } {
  44     set show_hidden_p $show_hidden
  45 } else {
  46     set show_hidden_p f
  47 }
  48
43 49 set filter_list [list category_f]
44 50
45 51 set form [rp_getform]
46 52
47 53 set category_trees [concat [category_tree::get_mapped_trees $cc_package_id] [category_tree::get_mapped_trees $package_id]]
48 54 set course_categories [list]
49 55 set section_categories [list]
50 56
51 57 foreach tree [category_tree::get_mapped_trees $cc_package_id] {
52 58     set tree_name [lindex $tree 1]
53 59     regsub -all { } $tree_name _ f
54 60     set f [string tolower $f]_f
55 61
56 62     lappend filter_list $f
57 63     set ff [ns_set get $form $f]
58 64
59 65     if { ! [empty_string_p $ff] } {
60 66         set $f $ff
61 67     }
62 68     lappend course_categories [lindex $tree 0]
 
102 108         set categories_show_hidden $show_hidden
103 109     } else {
104 110         set categories_show_hidden f
105 111     }
106 112
107 113     set used_categories [db_list used_categories {
108 114         select distinct category_id
109 115         from (
110 116
111 117               select category_id
112 118               from categories c
113 119               where exists (select 1
114 120                             from category_object_map m, cr_revisions r, dotlrn_ecommerce_section s, ec_custom_product_field_values v
115 121                             where category_id in (select category_id
116 122                                                   from categories
117 123                                                   where left_ind > c.left_ind
118 124                                                   and right_ind < c.right_ind)
119 125                             and m.object_id = r.revision_id
120 126                             and r.item_id = s.course_id
121 127                             and s.product_id = v.product_id
122                               and (v.display_section_p = 't' or :categories_show_hidden = 't'))
  128                             and (v.display_section_p is null or v.display_section_p = 't' or :show_hidden_p = 't'))
123 129
124 130               union
125 131
126 132               select category_id
127 133               from category_object_map m, cr_revisions r, dotlrn_ecommerce_section s, ec_custom_product_field_values v
128 134               where m.object_id = r.revision_id
129 135               and r.item_id = s.course_id
130 136               and s.product_id = v.product_id
131                 and (v.display_section_p = 't' or :categories_show_hidden = 't')
  137               and (v.display_section_p is null or v.display_section_p = 't' or :show_hidden_p = 't')
132 138
133 139               ) c
134 140     }]
135 141 }
136 142
137 143 foreach tree_id $category_trees {
138 144
139 145     set tree_id [lindex $tree_id 0]
140 146
141 147     set tree_list [category_tree::get_tree -all $tree_id]
142 148     set tree_length [llength $tree_list]
143 149
144 150     db_1row get_tree_name { }
145 151
146 152     # Create a list of values for the list filter
147 153     set $name [list]
148 154
149 155     foreach element $tree_list {
150 156         if { ! $show_used_categories_only_p || [lsearch $used_categories [lindex $element 0]] != -1 } {
151 157             set ident [lindex $element 3]
 
208 214     set tree_name [lindex $tree 1]
209 215     regsub -all { } $tree_name _ f
210 216     set f [string tolower $f]_f
211 217
212 218     lappend filters "$f" \
213 219         [list \
214 220              label "$tree_name" \
215 221              values "[set $tree_name]" \
216 222              where_clause "[set ${tree_name}_where_query]"
217 223         ]
218 224 }
219 225
220 226 set instructor_community_id [parameter::get -package_id [ad_conn package_id] -parameter InstructorCommunityId -default 0 ]
221 227 set _instructors [dotlrn_community::list_users $instructor_community_id]
222 228
223 229 set __instructors [list]
224 230 if { [llength $_instructors] == 0 } {
225 231     set _instructors 0
226 232     set instructors_filter ""
227 233 } else {
  234     set active_instructors [db_list get_active_instructors {
  235         select distinct r.user_id
  236         from dotlrn_ecommerce_section s, ec_custom_product_field_values v, dotlrn_member_rels_approved r
  237         where s.product_id = v.product_id
  238         and s.community_id = r.community_id
  239         and (v.display_section_p is null or v.display_section_p = 't' or :show_hidden_p = 't')
  240         and r.rel_type = 'dotlrn_ecom_instructor_rel'
  241     }]
228 242     foreach _instructor $_instructors {
229 243         lappend __instructors [ns_set get $_instructor user_id]
  244         if { ! $show_used_categories_only_p || [lsearch -integer -exact $active_instructors [ns_set get $_instructor user_id]] != -1 } {
230 245             lappend instructors_filter [list "[ns_set get $_instructor first_names] [ns_set get $_instructor last_name]" [ns_set get $_instructor user_id]]
231 246         }
232 247     }
  248 }
233 249
234 250 lappend filters instructor \
235 251     [list \
236 252          label "[_ dotlrn-ecommerce.Instructor]" \
237 253          values $instructors_filter \
238 254          where_clause_eval {subst {exists (select 1
239 255      from dotlrn_users u, dotlrn_member_rels_approved r
240 256      where u.user_id = r.user_id
241 257      and r.community_id = dec.community_id
242 258      and r.rel_type = 'dotlrn_ecom_instructor_rel'
243 259      and r.user_id in ([join $instructor ,]))}}]
244 260 # Section categories
245 261 #foreach section_tree [category_tree::get_mapped_trees $package_id] {
246 262 #    set tree_list [category_tree::get_tree -all $section_tree]
247 263 #}
248 264
249 265 #       age_description_f {
250 266 #           label "Age Description"
251 267 #           values { ${Age Description} }
252 268 #           where_clause { ${Age Description_where_query} }