matthewg
committed
on 07 Jul 05
Removing comments from contact_rels table since ams takes care of attributes for rels
openacs-4/.../contacts/lib/history.tcl (+159)
  1 #    @author Matthew Geddert openacs@geddert.com
  2 #    @creation-date 2005-07-09
  3 #    @cvs-id $Id$
  4
  5 if { [string is false [contact::exists_p -party_id $party_id]] } {
  6     error "[_ contacts.lt_The_party_id_specifie]"
  7 }
  8
  9 if { [string is false [exists_and_not_null recent_on_top_p]] } {
  10     set recent_on_top_p [parameter::get_from_package_key -boolean -package_key "general-comments" -parameter "RecentOnTopP"]
  11 }
  12
  13 if { [string is false [exists_and_not_null recent_on_top_p]] } {
  14     error "[_ contacts.lt_The_parameter_RecentO]"
  15 } else {
  16     if { $recent_on_top_p } {
  17         set orderby_clause "creation_date desc"
  18     } else {
  19         set orderby_clause "creation_date asc"
  20     }
  21 }
  22 if { [string is false [exists_and_not_null size]] } {
  23     set size "normal"
  24 }
  25 switch $size {
  26     normal  {
  27         set textarea_size "cols 50 rows 6"
  28     }
  29     small   {
  30         set textarea_size "cols 35 rows 3"
  31     }
  32     default { error "[_ contacts.lt_You_have_specified_an_1]" }
  33 }
  34
  35 if { [string is false [exists_and_not_null form]] } {
  36     if { $recent_on_top_p } {
  37         set form "top"
  38     } else {
  39         set form "bottom"
  40     }
  41 }
  42 if { [lsearch [list top bottom none] $form] < 0 } {
  43     error "[_ contacts.lt_Invalid_input_you_spe]"
  44 }
  45
  46
  47
  48
  49
  50
  51 if { [exists_and_not_null limit] } {
  52     set limit_clause "limit $limit"
  53 } else {
  54     set limit_clause ""
  55 }
  56
  57
  58
  59
  60 set project_id "26798"
  61
  62 set tasks [list]
  63 db_foreach get_tasks {
  64     select pt.task_id,
  65            tasks__completion_date(ci.item_id) as completion_date,
  66            tasks__completion_user(ci.item_id) as completion_user,
  67            cr.title,
  68            cr.description as content
  69       from cr_items ci,
  70            pm_tasks_revisions ptr,
  71            pm_tasks pt left join pm_process_instance ppi on (pt.process_instance = ppi.instance_id ),
  72            cr_revisions cr,
  73            acs_objects ao
  74      where ci.parent_id = :project_id
  75        and ci.item_id = pt.task_id
  76        and ci.latest_revision = ptr.task_revision_id
  77        and ci.live_revision = ptr.task_revision_id
  78        and ptr.task_revision_id = cr.revision_id
  79        and cr.revision_id = ao.object_id
  80        and pt.status = '2'
  81        and pt.deleted_p = 'f'
  82        and task_id in ( select task_id from pm_task_assignment where party_id = :party_id and role_id = '1' )
  83 } {
  84     if { [exists_and_not_null truncate_len] } {
  85         set content_html [ad_html_text_convert -truncate_len $truncate_len -from "text/plain" -to "text/html" $content]
  86     } else {
  87         set content_html [ad_html_text_convert -from "text/plain" -to "text/html" $content]
  88     }
  89     lappend tasks [list $completion_date $task_id $completion_user [list $title $content_html] "/packages/tasks/lib/task-chunk"]
  90 }
  91
  92
  93
  94
  95
  96 set comments [list]
  97 db_foreach get_comments "
  98          select g.comment_id,
  99                 o.creation_user,
  100                 o.creation_date,
  101                 content,
  102                 r.title,
  103                 r.mime_type
  104            from general_comments g,
  105                 cr_revisions r,
  106                 acs_objects o
  107           where g.object_id = :party_id
  108             and r.revision_id = content_item__get_live_revision(g.comment_id)
  109             and o.object_id = g.comment_id
  110 " {
  111     if { [exists_and_not_null truncate_len] } {
  112         set comment_html [ad_html_text_convert -truncate_len $truncate_len -from $mime_type -to "text/html" $content]
  113     } else {
  114         set comment_html [ad_html_text_convert -from $mime_type -to "text/html" $content]
  115     }
  116     lappend comments [list $creation_date $comment_id $creation_user $comment_html]
  117 }
  118
  119 set hist [lsort -index 0 -decreasing [concat $tasks $comments]]
  120
  121 template::multirow create history date time object_id creation_user user_link include content
  122
  123 set result_number 1
  124 foreach item $hist {
  125     set timestamp      [lindex [split [lindex $item 0] "."] 0]
  126     set date          [lc_time_fmt $timestamp "%q"]
  127     set time          [string trimleft [lc_time_fmt $timestamp "%r"] "0"]
  128     set object_id     [lindex $item 1]
  129     set creation_user [lindex $item 2]
  130     set user_link     [contact::name -party_id $creation_user]
  131     set content       [lindex $item 3]
  132     set include       [lindex $item 4]
  133     template::multirow append history $date $time $object_id $creation_user $user_link $include $content
  134     if { [exists_and_not_null limit] } {
  135         incr result_number
  136         if { $result_number > $limit } {
  137             break
  138         }
  139     }
  140 }
  141
  142
  143
  144
  145
  146
  147
  148 ad_form -name comment_add \
  149    -action "[ad_conn package_url]comment-add" \
  150     -form "
  151         party_id:integer(hidden)
  152         return_url:text(hidden),optional
  153         {comment:text(textarea),nospell {label {}} {html {$textarea_size}} {after_html {<br />}}}
  154         {save:text(submit),optional {label {[_ contacts.Add_Comment]}}}
  155     " -on_request {
  156     } -after_submit {
  157     }
  158
  159 set user_id [ad_conn user_id]