add: Calendar events from 7.4-prebranch

- Attachments
 - Setting view permissions
This commit is contained in:
Doug Bell 2007-05-28 22:27:31 +00:00
parent 07a40788bb
commit b519375126
6 changed files with 266 additions and 48 deletions

View file

@ -7,6 +7,8 @@
http://www.plainblack.com/rfe/request-for-enhancement/-1493348--js-confirmation-operation/databaselink/re--1493348--js-confirmation-operation/databaselink.pm#OUb5zN8bltGdPG_2LJZMGQ
- add: User profile data table is now a flat table, one column for each
field.
- add: Calendar events now allow attachments
- add: Calendar events now allow setting view permissions

View file

@ -23,6 +23,7 @@ my $session = start(); # this line required
# upgrade functions go here
fixProfileDataWithoutFields($session);
buildNewUserProfileTable($session);
addAttachmentsToEvents($session);
finish($session); # this line required
@ -154,6 +155,17 @@ sub buildNewUserProfileTable {
#----------------------------------------------------------------------------
sub addAttachmentsToEvents {
my $session = shift;
print "\tAdding an storageId column to the Event table..." unless $quiet;
$session->db->write(
"ALTER TABLE Event ADD COLUMN storageId VARCHAR(22) not null"
);
print "OK!\n" unless $quiet;
}
# ---- DO NOT EDIT BELOW THIS LINE ----

View file

@ -21,6 +21,7 @@ use Storable qw(nfreeze thaw);
use WebGUI::International;
use WebGUI::Asset::Template;
use WebGUI::Form;
use WebGUI::Storage::Image;
use base 'WebGUI::Asset';
@ -89,7 +90,7 @@ sub definition {
},
'relatedLinks' => {
fieldType => "Textarea",
fieldType => "HTMLarea",
defaultValue => undef,
},
'location' => {
@ -100,6 +101,11 @@ sub definition {
fieldType => "Text",
defaultValue => undef,
},
'storageId' => {
fieldType => "Image",
defaultValue => undef,
maxAttachments => 1,
},
'feedUid' => {
fieldType => "Text",
defaultValue => undef,
@ -165,16 +171,7 @@ sub canEdit {
}
sub update {
my $self = shift;
my $properties = shift;
# Make sure menuTitle has some text, and that it is <= 15 characters.
if (exists $properties->{menuTitle}) {
$properties->{menuTitle} ||= $properties->{title} || $self->getTitle;
$properties->{menuTitle} = substr($properties->{menuTitle}, 0, 15);
}
return $self->SUPER::update($properties);
}
@ -1143,6 +1140,20 @@ sub getRelatedLinks {
#-------------------------------------------------------------------
sub getStorageLocation {
my $self = shift;
unless (exists $self->{_storageLocation}) {
if ($self->get("storageId") eq "") {
$self->{_storageLocation} = WebGUI::Storage::Image->create($self->session);
$self->update({storageId=>$self->{_storageLocation}->getId});
} else {
$self->{_storageLocation} = WebGUI::Storage::Image->get($self->session,$self->get("storageId"));
}
}
return $self->{_storageLocation};
}
####################################################################
=head2 getTemplateVars
@ -1163,7 +1174,7 @@ sub getTemplateVars {
$var{'canEdit'} = $self->canEdit;
$var{"isPublic"} = 1
if $self->get("groupIdView") eq "7";
$var{"groupToView"} = $self->get("groupIdView"); # Todo: Remove this?
$var{"groupToView"} = $self->get("groupIdView");
# Start date/time
my $dtStart = $self->getDateTimeStart;
@ -1241,10 +1252,60 @@ sub getTemplateVars {
push @{$var{"relatedLinks"}}, { "linkUrl" => $_ }
for ($self->getRelatedLinks);
# Attachments
my $gotImage;
my $gotAttachment;
@{$var{'attachment_loop'}} = ();
unless ($self->get("storageId") eq "") {
my $storage = $self->getStorageLocation;
foreach my $filename (@{$storage->getFiles}) {
if (!$gotImage && $storage->isImage($filename)) {
$var{"image.url"} = $storage->getUrl($filename);
$var{"image.thumbnail"} = $storage->getThumbnailUrl($filename);
$gotImage = 1;
}
if (!$gotAttachment && !$storage->isImage($filename)) {
$var{"attachment.url"} = $storage->getUrl($filename);
$var{"attachment.icon"} = $storage->getFileIconUrl($filename);
$var{"attachment.name"} = $filename;
$gotAttachment = 1;
}
push(@{$var{"attachment_loop"}}, {
url=>$storage->getUrl($filename),
icon=>$storage->getFileIconUrl($filename),
filename=>$filename,
thumbnail=>$storage->getThumbnailUrl($filename),
isImage=>$storage->isImage($filename)
});
}
}
return %var;
}
#-------------------------------------------------------------------
=head2 indexContent ( )
Indexing the content of attachments and user defined fields. See WebGUI::Asset::indexContent() for additonal details.
=cut
sub indexContent {
my $self = shift;
my $indexer = $self->SUPER::indexContent;
$indexer->addKeywords($self->get("userDefined1"));
$indexer->addKeywords($self->get("userDefined2"));
$indexer->addKeywords($self->get("userDefined3"));
$indexer->addKeywords($self->get("userDefined4"));
$indexer->addKeywords($self->get("userDefined5"));
$indexer->addKeywords($self->get("location"));
my $storage = $self->getStorageLocation;
foreach my $file (@{$storage->getFiles}) {
$indexer->addFile($storage->getPath($file));
}
}
@ -1356,12 +1417,6 @@ sub processPropertiesFromFormPost {
# Events are always hidden from navigation
$self->update({ isHidden => 1 });
# If there is no security information, grab it from the parent
if (!$self->get("groupIdView")) {
$self->update({
groupIdView => $self->getParent->get("groupIdView"),
});
}
if (!$self->get("groupIdEdit")) {
my $groupIdEdit = $self->getParent->get("groupIdEventEdit")
|| $self->getParent->get("groupIdEdit")
@ -1477,13 +1532,31 @@ sub processPropertiesFromFormPost {
}
# Finally, commit this event
delete $self->{_storageLocation};
$self->requestAutoCommit;
return;
}
sub purge {
my $self = shift;
my $sth = $self->session->db->read("select storageId from Event where assetId=?",[$self->getId]);
while (my ($storageId) = $sth->array) {
my $storage = WebGUI::Storage::Image->get($self->session,$storageId);
$storage->delete if defined $storage;
}
$sth->finish;
return $self->SUPER::purge;
}
#-------------------------------------------------------------------
sub purgeRevision {
my $self = shift;
$self->getStorageLocation->delete;
return $self->SUPER::purgeRevision;
}
####################################################################
@ -1622,6 +1695,13 @@ sub view {
#-------------------------------------------------------------------
sub www_deleteFile {
my $self = shift;
$self->getStorageLocation->deleteFile($self->session->form->process("filename")) if $self->canEdit;
return $self->www_edit;
}
####################################################################
@ -1694,6 +1774,14 @@ sub www_edit {
size => 22,
});
# Group to View
$var->{"formGroupIdView"}
= WebGUI::Form::Group($session, {
name => "groupIdView",
value => $form->process("groupIdView") || $self->get("groupIdView"),
defaultValue => $self->getParent->get("groupIdView"),
});
# location
$var->{"formLocation"}
= WebGUI::Form::text($session, {
@ -1708,6 +1796,15 @@ sub www_edit {
value => $form->process("description") || $self->get("description"),
});
# File attachments
$var->{"formAttachments"}
= WebGUI::Form::Image($session, {
name => "storageId",
maxAttachments => 5,
value => $form->process("storageId") || $self->get("storageId"),
deleteFileUrl=>$self->getUrl("func=deleteFile;filename=")
});
### Start date
my $default_start;
@ -1801,7 +1898,7 @@ sub www_edit {
# related links
$var->{"formRelatedLinks"}
= WebGUI::Form::textarea($session, {
= WebGUI::Form::HTMLArea($session, {
name => "relatedLinks",
value => $form->process("relatedLinks") || $self->get("relatedLinks"),
});
@ -2140,3 +2237,4 @@ equal and then choose by assetId.
=cut
1;

View file

@ -575,7 +575,6 @@ sub getEvent {
$self->session->errorHandler->warn("WebGUI::Asset::Wobject::Calendar->getEvent :: Event '$assetId' not a child of calendar '".$self->getId."'"), return
unless $event->get("parentId") eq $self->getId;
return $event;
}
@ -726,17 +725,19 @@ Gets the first event in this calendar. Returns the Event object.
sub getFirstEvent {
my $self = shift;
my $lineage = $self->get("lineage");
my $eventAsset = $self->getLineage(['children'], {
includeOnlyClasses => ['WebGUI::Asset::Event'],
joinClass => 'WebGUI::Asset::Event',
whereClause => 'Event.startDate >= date( now() )',
orderByClause => 'Event.startdate asc, Event.startTime asc, revisionDate desc',
limit => 1,
returnObjects => 1,
})->[0];
my ($assetId) = $self->session->db->quickArray(<<ENDSQL);
SELECT asset.assetId
FROM asset
JOIN Event ON asset.assetId = Event.assetId
WHERE lineage LIKE "$lineage\%"
AND className = "WebGUI::Asset::Event"
ORDER BY startDate ASC, startTime ASC, revisionDate DESC
LIMIT 1
ENDSQL
return $eventAsset;
return $self->getEvent($assetId);
}
@ -973,7 +974,7 @@ sub view {
$var->{"urlSearch"} = $self->getSearchUrl;
$var->{"urlPrint"} = $self->getUrl("type=".$params->{type}.";start=".$params->{start}.";print=1");
$var->{"urlIcal"} = $self->getUrl(
sprintf "func=ical;type=%s;start=%s",
sprintf "func=ical;type=%s;start=%d",
$params->{type},
$params->{start},
);
@ -1032,7 +1033,8 @@ sub viewDay {
# The events
my $pos = -1;
my $last_hour = -1; # Keep track of hours for dividers
for my $event (@events) {
EVENT: for my $event (@events) {
next EVENT unless $event->canView();
my $dt = $event->getDateTimeStart;
my $hour = $dt->clone->truncate(to=>"hour")->hour;
@ -1119,7 +1121,7 @@ sub viewMonth {
my $dt = WebGUI::DateTime->new($self->session, $params->{start});
$dt->truncate( to => "month");
my $start = $dt->toMysql;
my $dtEnd = $dt->clone->add(months => 1);
my $dtEnd = $dt->clone->add(months => 1)->add(seconds => -1);
my $end = $dtEnd->toMysql;
my @events
@ -1158,7 +1160,8 @@ sub viewMonth {
until @{$var->{weeks}->[-1]->{days}} >= 7;
## The events
for my $event (@events) {
EVENT: for my $event (@events) {
next EVENT unless $event->canView();
# Get the WebGUI::DateTime objects
my $dt_event_start = $event->getDateTimeStart;
my $dt_event_end = $event->getDateTimeEnd;
@ -1305,7 +1308,8 @@ sub viewWeek {
# The events
for my $event (@events) {
EVENT: for my $event (@events) {
next EVENT unless $event->canView();
# Get the week this event is in, and add it to that week in
# the template variables
my $dt_event_start = $event->getDateTimeStart;
@ -1425,7 +1429,6 @@ sub www_edit {
my $i18n = WebGUI::International->new($session, 'Asset_Calendar');
return $session->privilege->insufficient() unless $self->canEdit;
return $session->privilege->locked() unless $self->canEditIfLocked;
$self->getAdminConsole->setHelp("Calendar add/edit", "Calendar");
@ -1544,7 +1547,8 @@ sub www_ical {
. qq{VERSION:2.0\r\n};
# VEVENT:
for my $event (@events) {
EVENT: for my $event (@events) {
next EVENT unless $event->canView();
$ical .= qq{BEGIN:VEVENT\r\n};
### UID
@ -1840,3 +1844,4 @@ toUserTimeZone methods of WebGUI::DateTime for to make less confusion.
=cut
1;

View file

@ -33,6 +33,12 @@ our $HELP = {
'name' => 'formDescription',
},
{
'name' => 'formGroupToView',
},
{
'name' => 'formAttachements',
},
{
'name' => 'formStartDate',
},
{
@ -89,9 +95,9 @@ our $HELP = {
],
variables => [
{
'name' => 'canEdit',
},
{
'name' => 'canEdit',
},
{
'name' => 'isPublic',
},
{
@ -227,12 +233,40 @@ our $HELP = {
'name' => 'urlSearch',
},
{
'name' => 'relatedLinks',
variables => [
'name' => 'image.url'
},
{
'name' => 'linkUrl',
'name' => 'image.thumbnail'
},
],
{
'name' => 'attachment.url'
},
{
'name' => 'attachment.icon'
},
{
'name' => 'attachment.name'
},
{
'name' => 'attachment_loop',
'variables' => [
{
'name' => 'url'
'description' => 'attachment_url'
},
{
'name' => 'icon'
},
{
'name' => 'filename'
},
{
'name' => 'thumbnail'
},
{
'name' => 'isImage'
}
]
},
],
related => [
@ -320,3 +354,4 @@ our $HELP = {
};
1;

View file

@ -49,6 +49,16 @@ our $I18N = {
lastUpdated => 1171067211,
},
'formGroupToView' => {
message => q|HTML form for picking which group can view this Event.|,
lastUpdated => 1177383777,
},
'formAttachments' => {
message => q|HTML form for adding or removing files from this Event.|,
lastUpdated => 1177383776,
},
'formStartDate' => {
message => q|HTML form for entering or editing the Event's start date.|,
lastUpdated => 1171067211,
@ -448,15 +458,71 @@ be useful, others may not.|,
lastUpdated => 1149829706,
},
'image.url' => {
message => q|The URL to the first image attached to the Post.|,
lastUpdated => 1177384150,
},
'image.thumbnail' => {
message => q|A thumbnail for the image attached to the Post.|,
lastUpdated => 1177384152,
},
'attachment.url' => {
message => q|The URL to download the first attachment attached to the Post.|,
lastUpdated => 1177384153,
},
'attachment.icon' => {
message => q|An icon showing the file type of this attachment.|,
lastUpdated => 1177384155,
},
'attachment.name' => {
message => q|The name of the first attachment found on the Post.|,
lastUpdated => 1177384156,
},
'attachment_loop' => {
message => q|A loop containing all file and image attachments to this Post.|,
lastUpdated => 1177384159,
},
'attachment_url' => {
message => q|The URL to download this attachment.|,
lastUpdated => 1177384161,
},
'icon' => {
message => q|The icon representing the file type of this attachment.|,
lastUpdated => 1177384169,
},
'filename' => {
message => q|The name of this attachment.|,
lastUpdated => 1177384171,
},
'thumbnail' => {
message => q|A thumbnail of this attachment, if applicable.|,
lastUpdated => 1177384174,
},
'isImage' => {
message => q|A conditional indicating whether this attachment is an image.|,
lastUpdated => 1177384177,
},
'canEdit' => {
message => q{This variable is true if the current user can edit this event.},
lastUpdated => 0,
},
'assetName' => {
message => q{Event},
lastUpdated => 1131394072,
},
'canEdit' => {
message => q{This variable is true if the current user can edit this event.},
lastUpdated => 0,
},
};
1;