Class ::xo::db::chat_room (public)
::xo::db::Class ::xo::db::chat_room
Defined in
- Testcases:
-
No testcase defined.
Source code:
namespace eval ::xo::db {}
::nsf::object::alloc ::xo::db::Class ::xo::db::chat_room {set :__default_metaclass ::xotcl::Class
set :__default_superclass ::xotcl::Object
set :abstract_p f
set :auto_save false
array set :db_constraints {logout_messages_p {{default true}} pretty_name not_null messages_time_window {{default 600}} auto_transcript_p {{default false}} auto_flush_p {{default true}} archive_p {{default true}} avatar_p {{default true}} login_messages_p {{default true}} active_p {{default true}}}
array set :db_slot {logout_messages_p ::xo::db::chat_room::slot::logout_messages_p description ::xo::db::chat_room::slot::description pretty_name ::xo::db::chat_room::slot::pretty_name messages_time_window ::xo::db::chat_room::slot::messages_time_window auto_transcript_p ::xo::db::chat_room::slot::auto_transcript_p auto_flush_p ::xo::db::chat_room::slot::auto_flush_p archive_p ::xo::db::chat_room::slot::archive_p room_id ::xo::db::chat_room::slot::room_id avatar_p ::xo::db::chat_room::slot::avatar_p login_messages_p ::xo::db::chat_room::slot::login_messages_p active_p ::xo::db::chat_room::slot::active_p}
set :id_column room_id
set :name_method {}
set :object_type chat_room
set :object_type_key 0000000000110101
set :pretty_name #chat.Room#
set :pretty_plural #chat.Rooms#
set :security_inherit_p t
set :sql_package_name ::xo::db::chat_room
set :supertype acs_object
set :table_name chat_rooms
set :with_table true}
::xo::db::chat_room instproc count_messages {} {
set room_id ${:room_id}
::xo::dc get_value count_messages {
select count(*) from chat_msgs
where room_id = :room_id
}
}
::xo::db::chat_room instproc save_new {-creation_user args} {
if {![info exists :context_id]} {
set :context_id ${:package_id}
}
set args [list]
foreach var {package_id context_id creation_ip creation_user} {
if {[info exists :${var}] && "-${var}" ni $args} {
lappend args -${var} [set :${var}]
}
}
::xo::dc transaction {
set room_id [next {*}$args]
:grant_creator
}
return $room_id
}
::xo::db::chat_room instproc grant_moderator -party_id:required {
permission::grant -party_id $party_id -object_id ${:room_id} -privilege chat_room_moderate
}
::xo::db::chat_room instproc transcript_messages {} {
set room_id ${:room_id}
set contents [list]
::xo::dc foreach get_archives_messages {
select msg,
creation_user,
to_char(creation_date, 'DD.MM.YYYY hh24:mi:ss') as creation_date
from chat_msgs
where room_id = :room_id
and msg is not null
order by creation_date
} {
if {$creation_user > 0} {
set user_name [::chat::Package get_user_name -user_id $creation_user]
if {$user_name eq ""} {
set user_name Unknown
}
} else {
set user_name "system"
}
lappend contents "\[$creation_date\] ${user_name}: $msg"
}
return $contents
}
::xo::db::chat_room instproc delete_messages {} {
set room_id ${:room_id}
::xo::dc dml delete_messages {
delete from chat_msgs where room_id = :room_id
}
}
::xo::db::chat_room instproc post_message {{-msg ""} {-creation_user ""} {-creation_ip ""}} {
if {!${:archive_p}} {
return
}
set room_id ${:room_id}
set message_id [db_nextval acs_object_id_seq]
::xo::dc dml save_message {
insert into chat_msgs (
msg_id,
room_id,
msg,
creation_user,
creation_ip,
creation_date)
values (
:message_id,
:room_id,
:msg,
:creation_user,
:creation_ip,
current_timestamp
)
}
}
::xo::db::chat_room instproc revoke_user -party_id:required {
::xo::dc transaction {
foreach privilege {read write} {
permission::revoke -party_id $party_id -object_id ${:room_id} -privilege chat_${privilege}
}
}
}
::xo::db::chat_room instproc delete args {
set room_id ${:room_id}
foreach transcript_id [::xo::dc list get_transcripts {
select transcript_id from chat_transcripts
where room_id = :room_id
}] {
::acs::dc call acs_object delete -object_id $transcript_id
}
next
}
::xo::db::chat_room instproc grant_creator {} {
if {${:creation_user} ne ""} {
foreach privilege {edit view delete} {
permission::grant -party_id ${:creation_user} -object_id ${:room_id} -privilege chat_room_${privilege}
}
permission::grant -party_id ${:creation_user} -object_id ${:room_id} -privilege chat_transcript_create
}
}
::xo::db::chat_room instproc insert {} {
set __table_name [[self class] table_name]
set __id [[self class] id_column]
set :$__id ${:object_id}
:log "ID insert in $__table_name, id = $__id = [set :$__id]"
next
foreach {__slot_name __slot} [[self class] array get db_slot] {
if {[info exists :$__slot_name]} {
set $__slot_name [set :$__slot_name]
lappend __vars $__slot_name
lappend __atts [$__slot column_name]
}
}
::xo::dc dml insert_$__table_name "insert into $__table_name
([join $__atts ,]) values (:[join $__vars ,:])"
}
::xo::db::chat_room instproc revoke_moderator -party_id:required {
set parties $party_id
foreach party_id $parties {
permission::revoke -party_id $party_id -object_id ${:room_id} -privilege chat_room_moderate
}
}
::xo::db::chat_room instproc grant_user -party_id:required {
::xo::dc transaction {
foreach privilege {read write} {
permission::grant -party_id $party_id -object_id ${:room_id} -privilege chat_${privilege}
}
}
}
::xo::db::chat_room instproc unban_user -party_id:required {
permission::revoke -party_id $party_id -object_id ${:room_id} -privilege chat_ban
}
::xo::db::chat_room instproc flush {} {
if {${:auto_transcript_p}} {
:create_transcript
}
:delete_messages
}
::xo::db::chat_room instproc update {} {
::xo::dc transaction {
next
:instvar object_id pretty_name description logout_messages_p archive_p auto_flush_p auto_transcript_p messages_time_window avatar_p active_p login_messages_p
::xo::dc dml update_chat_rooms {update chat_rooms
set pretty_name = :pretty_name,description = :description,logout_messages_p = :logout_messages_p,archive_p = :archive_p,auto_flush_p = :auto_flush_p,auto_transcript_p = :auto_transcript_p,messages_time_window = :messages_time_window,avatar_p = :avatar_p,active_p = :active_p,login_messages_p = :login_messages_p where room_id = :object_id
}
}
}
::xo::db::chat_room instproc create_transcript {-pretty_name -description -creation_user {-creation_ip ""}} {
if {![info exists pretty_name]} {
set today [clock format [clock seconds] -format "%d.%m.%Y"]
set pretty_name "#chat.transcript_of_date# $today"
}
if {![info exists description]} {
set description "#chat.automatically_created_transcript#"
}
if {![info exists creation_user]} {
set creation_user ${:creation_user}
}
set contents [:transcript_messages]
if {[llength $contents] > 0} {
set t [::xo::db::chat_transcript new -volatile -creation_user $creation_user -creation_ip $creation_ip -pretty_name $pretty_name -description $description -package_id ${:package_id} -room_id ${:room_id} -contents [join $contents \n]]
$t save_new
return [$t transcript_id]
} else {
return 0
}
}
::xo::db::chat_room instproc ban_user -party_id:required {
permission::grant -party_id $party_id -object_id ${:room_id} -privilege chat_ban
}
::xo::db::chat_room instparametercmd room_id
::xo::db::chat_room instparametercmd description
::xo::db::chat_room instparametercmd messages_time_window
::xo::db::chat_room instparametercmd pretty_name
::xo::db::chat_room instparametercmd logout_messages_p
::xo::db::chat_room instparametercmd archive_p
::xo::db::chat_room instparametercmd auto_flush_p
::xo::db::chat_room instparametercmd auto_transcript_p
::xo::db::chat_room instparametercmd active_p
::xo::db::chat_room instparametercmd avatar_p
::xo::db::chat_room instparametercmd login_messages_p
::nsf::relation::set ::xo::db::chat_room superclass ::xo::db::Object
::nx::slotObj -container slot ::xo::db::chat_room
::nsf::object::alloc ::xo::db::Attribute ::xo::db::chat_room::slot::archive_p {set :accessor public
set :column_name archive_p
set :configurable true
set :convert false
set :create_acs_attribute true
set :create_table_attribute true
set :datatype boolean
set :default true
set :defaultmethods {}
set :disposition alias
set :domain ::xo::db::chat_room
set :incremental false
set :manager ::xo::db::chat_room::slot::archive_p
set :max_n_values 1
set :methodname archive_p
set :min_n_values 1
set :multiplicity 1..1
set :name archive_p
set :per-object false
set :position 0
set :pretty_name #xo.chat_room-archive_p#
set :pretty_plural {}
set :references {}
set :required false
set :sqltype boolean
set :substdefault 0b111
set :trace none
: init}
::nsf::object::alloc ::xo::db::Attribute ::xo::db::chat_room::slot::auto_transcript_p {set :accessor public
set :column_name auto_transcript_p
set :configurable true
set :convert false
set :create_acs_attribute true
set :create_table_attribute true
set :datatype boolean
set :default false
set :defaultmethods {}
set :disposition alias
set :domain ::xo::db::chat_room
set :incremental false
set :manager ::xo::db::chat_room::slot::auto_transcript_p
set :max_n_values 1
set :methodname auto_transcript_p
set :min_n_values 1
set :multiplicity 1..1
set :name auto_transcript_p
set :per-object false
set :position 0
set :pretty_name #xo.chat_room-auto_transcript_p#
set :pretty_plural {}
set :references {}
set :required false
set :sqltype boolean
set :substdefault 0b111
set :trace none
: init}
::nsf::object::alloc ::xo::db::Attribute ::xo::db::chat_room::slot::messages_time_window {set :accessor public
set :column_name messages_time_window
set :configurable true
set :convert false
set :create_acs_attribute true
set :create_table_attribute true
set :datatype integer
set :default 600
set :defaultmethods {}
set :disposition alias
set :domain ::xo::db::chat_room
set :incremental false
set :manager ::xo::db::chat_room::slot::messages_time_window
set :max_n_values 1
set :methodname messages_time_window
set :min_n_values 1
set :multiplicity 1..1
set :name messages_time_window
set :per-object false
set :position 0
set :pretty_name #xo.chat_room-messages_time_window#
set :pretty_plural {}
set :references {}
set :required false
set :sqltype integer
set :substdefault 0b111
set :trace none
: init}
::nsf::object::alloc ::xo::db::Attribute ::xo::db::chat_room::slot::auto_flush_p {set :accessor public
set :column_name auto_flush_p
set :configurable true
set :convert false
set :create_acs_attribute true
set :create_table_attribute true
set :datatype boolean
set :default true
set :defaultmethods {}
set :disposition alias
set :domain ::xo::db::chat_room
set :incremental false
set :manager ::xo::db::chat_room::slot::auto_flush_p
set :max_n_values 1
set :methodname auto_flush_p
set :min_n_values 1
set :multiplicity 1..1
set :name auto_flush_p
set :per-object false
set :position 0
set :pretty_name #xo.chat_room-auto_flush_p#
set :pretty_plural {}
set :references {}
set :required false
set :sqltype boolean
set :substdefault 0b111
set :trace none
: init}
::nsf::object::alloc ::xo::db::Attribute ::xo::db::chat_room::slot::room_id {set :accessor public
set :column_name room_id
set :configurable true
set :convert false
set :create_acs_attribute false
set :create_table_attribute true
set :datatype integer
set :defaultmethods {}
set :disposition alias
set :domain ::xo::db::chat_room
set :incremental false
set :manager ::xo::db::chat_room::slot::room_id
set :max_n_values 1
set :methodname room_id
set :min_n_values 1
set :multiplicity 1..1
set :name room_id
set :per-object false
set :position 0
set :pretty_name ID
set :pretty_plural {}
set :references {}
set :required false
set :sqltype integer
set :trace none
: init}
::nsf::object::alloc ::xo::db::Attribute ::xo::db::chat_room::slot::active_p {set :accessor public
set :column_name active_p
set :configurable true
set :convert false
set :create_acs_attribute true
set :create_table_attribute true
set :datatype boolean
set :default true
set :defaultmethods {}
set :disposition alias
set :domain ::xo::db::chat_room
set :incremental false
set :manager ::xo::db::chat_room::slot::active_p
set :max_n_values 1
set :methodname active_p
set :min_n_values 1
set :multiplicity 1..1
set :name active_p
set :per-object false
set :position 0
set :pretty_name #xo.chat_room-active_p#
set :pretty_plural {}
set :references {}
set :required false
set :sqltype boolean
set :substdefault 0b111
set :trace none
: init}
::nsf::object::alloc ::xo::db::Attribute ::xo::db::chat_room::slot::description {set :accessor public
set :column_name description
set :configurable true
set :convert false
set :create_acs_attribute true
set :create_table_attribute true
set :datatype text
set :defaultmethods {}
set :disposition alias
set :domain ::xo::db::chat_room
set :incremental false
set :manager ::xo::db::chat_room::slot::description
set :max_n_values 1
set :methodname description
set :min_n_values 1
set :multiplicity 1..1
set :name description
set :per-object false
set :position 0
set :pretty_name #xo.chat_room-description#
set :pretty_plural {}
set :references {}
set :required false
set :sqltype varchar(2000)
set :trace none
: init}
::nsf::object::alloc ::xo::db::Attribute ::xo::db::chat_room::slot::avatar_p {set :accessor public
set :column_name avatar_p
set :configurable true
set :convert false
set :create_acs_attribute true
set :create_table_attribute true
set :datatype boolean
set :default true
set :defaultmethods {}
set :disposition alias
set :domain ::xo::db::chat_room
set :incremental false
set :manager ::xo::db::chat_room::slot::avatar_p
set :max_n_values 1
set :methodname avatar_p
set :min_n_values 1
set :multiplicity 1..1
set :name avatar_p
set :per-object false
set :position 0
set :pretty_name #xo.chat_room-avatar_p#
set :pretty_plural {}
set :references {}
set :required false
set :sqltype boolean
set :substdefault 0b111
set :trace none
: init}
::nsf::object::alloc ::xo::db::Attribute ::xo::db::chat_room::slot::login_messages_p {set :accessor public
set :column_name login_messages_p
set :configurable true
set :convert false
set :create_acs_attribute true
set :create_table_attribute true
set :datatype boolean
set :default true
set :defaultmethods {}
set :disposition alias
set :domain ::xo::db::chat_room
set :incremental false
set :manager ::xo::db::chat_room::slot::login_messages_p
set :max_n_values 1
set :methodname login_messages_p
set :min_n_values 1
set :multiplicity 1..1
set :name login_messages_p
set :per-object false
set :position 0
set :pretty_name #xo.chat_room-login_messages_p#
set :pretty_plural {}
set :references {}
set :required false
set :sqltype boolean
set :substdefault 0b111
set :trace none
: init}
::nsf::object::alloc ::xo::db::Attribute ::xo::db::chat_room::slot::pretty_name {set :accessor public
set :column_name pretty_name
set :configurable true
set :convert false
set :create_acs_attribute true
set :create_table_attribute true
set :datatype text
set :defaultmethods {}
set :disposition alias
set :domain ::xo::db::chat_room
set :incremental false
set :manager ::xo::db::chat_room::slot::pretty_name
set :max_n_values 1
set :methodname pretty_name
set :min_n_values 1
set :multiplicity 1..1
set :name pretty_name
set :not_null true
set :per-object false
set :position 0
set :pretty_name #xo.chat_room-pretty_name#
set :pretty_plural {}
set :references {}
set :required false
set :sqltype varchar(100)
set :trace none
: init}
::nsf::object::alloc ::xo::db::Attribute ::xo::db::chat_room::slot::logout_messages_p {set :accessor public
set :column_name logout_messages_p
set :configurable true
set :convert false
set :create_acs_attribute true
set :create_table_attribute true
set :datatype boolean
set :default true
set :defaultmethods {}
set :disposition alias
set :domain ::xo::db::chat_room
set :incremental false
set :manager ::xo::db::chat_room::slot::logout_messages_p
set :max_n_values 1
set :methodname logout_messages_p
set :min_n_values 1
set :multiplicity 1..1
set :name logout_messages_p
set :per-object false
set :position 0
set :pretty_name #xo.chat_room-logout_messages_p#
set :pretty_plural {}
set :references {}
set :required false
set :sqltype boolean
set :substdefault 0b111
set :trace none
: init}
XQL Not present:Generic, PostgreSQL, Oracle
[
hide source ]
| [
make this the default ]