Integrating My Events

cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Tue, 2005-09-20 17:43

My site has a heavy focus on events.

I have a table of events with Flyer images attached to them.

There is an Event Listing interface that people are constantly adding upcoming events to and then an archive of all past events.

What I would like to do is link each event to an subalbum within my Events Albums. These subalbums should be automatically generated when a user has images to upload for that event once it is past.

Is there a way I could use the Gallery 2 External Mapping mechanism to map to my EventID's?
It seems that would be the best way to ensure that only one album per EventID is created.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-09-20 17:51

edit:

yes you can. period :)

just use GalleryEmbed::addexternalIdMap($eventId, $albumId, 'GalleryAlbumItem');
and use loadEntityByExternalId($eventId, 'GalleryAlbumItem');

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Tue, 2005-09-20 19:00

wow. I really love gallery.

Would this create the gallery as well?

GalleryEmbed::addexternalIdMap($eventId, $albumId, 'GalleryAlbumItem');

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Tue, 2005-09-20 19:03

GalleryEmbed::addexternalIdMap($eventId, $albumId, 'GalleryAlbumItem');

Sould I make $eventID a string (ie. "Event233") or something to make it more identifiable?

I am anticipating possible conflicts if I were to use this same method for another kind of entity like portfolio galleries.

Or is there some way for loadEntityByExternalId to distinguish?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-09-20 19:22

- you can make eventId a string, you don't have to.
- GalleryEmbed::addExternalIdMapEntry(..,..,..) only adds a mapping in the map table

if i were you, i'd create your own function analogous to GalleryEmbed::createUser().
don't create it in GalleryEmbed.class, create it somewhere in your files.

first, you need to insert the events album id, the one where all your new event album will be created in, in the database:
add a row to the database table g2_PluginParameterMap: module, core, id.eventsAlbumId, 0, the id of the album.
alternatively, you can use GalleryCoreApi::setPluginParameter('module', 'core', 'id.eventsAlbumId', $eventsAlbum->getId()); which will do the same, insert a row in this db table.

    function createEventAlbum($eventId, $args) {
        /* Get the id of the events album, we need it as parentId for our new album */
        list($ret, $parentId) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.eventsAlbumId');
	if ($ret->isError()) {
	    return $ret->wrap(__FILE__, __LINE__);
	}

        list($ret, $abum) = GalleryCoreApi::createAlbum($parentId, $args['name'], $args['title'], $args['summary'], $args['description'], $args['keywords']);
	if ($ret->isError()) {
	    return $ret->wrap(__FILE__, __LINE__);
	}

	GalleryCoreApi::relativeRequireOnce('modules/core/classes/ExternalIdMap.class');
	$ret = ExternalIdMap::addMapEntry(array('externalId' => $eventId,
			      'entityType' => 'GalleryAlbumItem', 'entityId' => $album->getId()));
	if ($ret->isError()) {
	    return $ret->wrap(__FILE__, __LINE__);
	}
	return GalleryStatus::success();
    }

then you can use loadEntityByExternalId to load the album that corresponds to $eventId.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Tue, 2005-09-20 19:57

what would be the best way to load that $eventsAlbum in order to call this?

GalleryCoreApi::setPluginParameter('module', 'core', 'id.eventsAlbumId', $eventsAlbum->getId());

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-09-20 20:02

yep, i knew that you'd ask this.

i don't know if your integration is for a single website. if so, i'd use the manual way: find out the entity id of your events album that you already created, then insert the row in the database manually.

if you want to have an installer for your integration or if the events album doesn't exist yet, you can create a new album with the G2 api, then use $album->getId() and use this as the events album id.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Tue, 2005-09-20 20:27

main.php?g2_view=core.ShowItem&g2_itemId=1828

so i guess it's 1828.

I think I should avoid touching the g2_database manually and use the API instead.
I'm not quite sure of what goes where yet.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Tue, 2005-09-20 20:29

As I create these I'll want to make the Origination Date of the album the day the event happened.

I guess there is a way to do that too?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-09-20 20:32

if g2 shows the event album with the above url, yes, then 1828 is the correct id.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Tue, 2005-09-20 21:32

sorry. skipped one.

is there a way to hand the createAlbum function the Originatin Date?

or do I need another function to update it after I create it?

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Tue, 2005-09-20 21:33

is there a way to hand the createAlbum function the Originatin Date?

or do I need another function to update it after I create it?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-09-20 21:41

after the createAlbum() call, you have to:

$album->setOriginationTimestamp($unixtimestamp);
or / and
$album->setCreationTimestamp($unixtimestamp);

$unixtimestamp can be any unix timestamp... see php.net / google on how to generate a unit timestamp from a date etc.

list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($album->getId());
if ($ret->isError()) {
print $ret->getAsHtml();
exit;
}
$ret = $album->save();
if ($ret->isError()) {
GalleryCoreApi::releaseLocks($lockId);
print $ret->getAsHtml();
exit;
}
$ret = GalleryCoreApi::releaseLocks($lockId);
if ($ret->isError()) {
print $ret->getAsHtml();
exit;
}

the important lesson here is:
when ever you want to save a change in G2, you have to call $entity->save(); and you have to call acquireWriteLock before() and releaselocks() after it. that way we make sure, only one person is changing this entity (album) at a time.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Tue, 2005-09-20 23:36

Just to be clear....

Now that I have run:

GalleryCoreApi::setPluginParameter('module', 'core', 'id.eventsAlbumId', 1882);

After I create the gallery as you described and I do this :

ExternalIdMap::addMapEntry(array('externalId' => $eventId,
'entityType' => 'GalleryAlbumItem', 'entityId' => $album->getId()))

How does differentiate between an EventAlbum and a possible new series of externalId's that I can forsee coming later?

Down the road suppose now I have to add Portfolio Albums for special profiles in my CMS.
If some of the PorfolioID's are the same as the EventID's wouldn't that cause a problem?

I'm sure I'm probably missing something.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-09-20 23:50

you use now the externalIdMap for two things:
a) map CMS users to G2 users
b) map CMS events to G2 albums

how to differentiate? when loading an album, use loadEntityByExternalId($evenId, 'GalleryAlbumItem');
when loading a user, G2 uses internally use loadEntityByExternalId($cmsUserId, 'GalleryUser');

the key difference is the second argument.

ah i see, you want to introduce a third mapping. This would also be a $id, 'GalleryAlbumItem' mapping, so this would definitely conflict with the eventId mapping.
your options are:
- use another table (your own) to map portfolios with g2 albums
- make sure portfolioIds and eventIds use the same sequence of ids. (there's no event / portfolio with the same id).

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Wed, 2005-09-21 00:14

I was just making sure there wasn't some other way.

I think what I might do when i get to the portfolios is just make them start at 250k or something.
It will be a very long time before the events reach that.

Either that or I suppose the Portfolios could use a string as the $porfolioID like "Portfolio333" that's allowed right?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-09-21 00:17

ah right, the string solution is a good one.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Wed, 2005-09-21 01:32

What about setting permissions on these albums?

I'll want to make it so that all registered users can upload photos to it but not create subgalleries.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Wed, 2005-09-21 04:39

When trying to create a gallerly like this:

Quote:
list($ret, $album) = GalleryCoreApi::createAlbum($parentId, $args['name'], $args['title'], $args['summary'], $args['description'], $args['keywords']);

With these args:

Quote:
parentId: 1828
Array
(
[name] => BurningMan2005ThePsy
[title] => Burning Man 2005: The Psyche
[summary] => presented by burning man
[description] => Burning Man 2005: The Psyche presented by burning man on Mon, Aug 29 - 06 2005
[keywords] => Burning Man 2005 The Psyche burning man
[eventdate] => 2005-09-06
)

It seems to work in that I see no errors.
From the root the album claims to have an item within it.

However when I try to go into my Events parent gallery now I get this full page error:

Quote:

An error has occurred.

Error Detail -
Error (ERROR_MISSING_OBJECT) : Missing object for

* in modules/core/classes/GalleryStorage/DatabaseStorage.class at line 2121 (gallerystatus::error)
* in modules/core/classes/GalleryStorage/DatabaseStorage.class at line 305 (mysqldatabasestorage::_identifyentities)
* in modules/core/classes/GalleryStorage.class at line 118 (mysqldatabasestorage::loadentities)
* in modules/core/classes/helpers/GalleryEntityHelper_simple.class at line 82 (gallerystorage::loadentities)
* in modules/core/classes/GalleryCoreApi.class at line 2186 (galleryentityhelper_simple::loadentitiesbyid)
* in modules/core/classes/GalleryTheme.class at line 1164 (gallerycoreapi::loadentitiesbyid)
* in themes/matrix/theme.inc at line 75 (matrixtheme::loadcommontemplatedata)
* in modules/core/classes/GalleryTheme.class at line 900 (matrixtheme::showalbumpage)
* in modules/core/classes/GalleryView.class at line 285 (matrixtheme::loadtemplate)
* in main.php at line 287 (showitemview::doloadtemplate)
* in main.php at line 87
* in modules/core/classes/GalleryEmbed.class at line 153
* in /var/www/rheo/tribalharmonix.org/website/gallery/main.php at line 73 (galleryembed::handlerequest)

If I follow the model of checking for User Albums we discussed

Quote:
loadEntityByExternalId($galleryEventIDString,'GalleryAlbumItem')

(which seems to work fine when the ExternalId is in the table but errors out when it is not.)

I am able to load the gallery for the event I just created. But when I try to follow the link I get the same error above.

These are the properties a print_r shows me for the album..
is there a method in particular I should call to check what's going on?

Quote:
galleryalbumitem Object
(
[_theme] =>
[_orderBy] => originationTimestamp
[_orderDirection] => asc
[_canContainChildren] => 1
[_description] => Burning Man 2005: The Psyche presented by burning man on Mon, Aug 29 - 06 2005
[_keywords] => Burning Man 2005 The Psyche burning man
[_ownerId] =>
[_summary] => presented by burning man
[_title] => Burning Man 2005: The Psyche
[_viewedSinceTimestamp] => 1127277439
[_originationTimestamp] => 1125990000
[_pathComponent] => BurningMan2005ThePsy
[_parentId] => 1828
[_id] => 1959
[_creationTimestamp] => 1125990000
[_isLinkable] => 0
[_linkId] =>
[_linkedEntity] =>
[_modificationTimestamp] => 1127277439
[_serialNumber] => 2
[_entityType] => GalleryAlbumItem
[_onLoadHandlers] =>
[_persistentStatus] => stdClass Object
(
[flags] => 0
[modified] => Array
(
)

[originalValue] => Array
(
)

)

)

any ideas?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-09-21 15:00

do you check all your $ret values with if ($ret->isError()) { ... ? that's important.

@loadEntityByExternalId($galleryEventIDString,'GalleryAlbumItem') error when there's no map entry:
you can find out if it is a real error or if the event just has no album associated with it yet with
if ($ret->getErrorCode() & ERROR_MISSING_OBJECT) or something like that. i guess an example should be in GalleryEmbed.class somewhere.
a real error is bad, if there's just no mapping yet, you may just create an album at this point...

@error
i'm not quite sure right now, but IMO [_ownerId] => shouldn't be empty. ownerId should be something like '6' or so.
could you please post the code which is used from include embed.php up to the createAlbum call?

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Wed, 2005-09-21 16:07

According to what I can the album has been created.

I can @loadEntityByExternalId($galleryEventIDString,'GalleryAlbumItem') without an error.

Hence the above quoted "galleryalbumitem Object"

The above error comes when I try to link directly to the album or even to the upper level Parent Album.

It's as if the album has been created and it seems the map has been made (i did a select on the Map table).

But there is some aspect of it that has not been created yet or some support DB entry that has not been made.

Does this sound possible?

What table is ownerID in? Maybe I could update it manually?

This is my script (so far) for creating Event albums:

Quote:

<?php
include_once($DOCUMENT_ROOT . '/lib/global.inc');
$auth->requiredlevel=3;
$auth->checktoken($db);
require_once('../phpgallery/embed.php');

if (!($eventid > 0)) {
errorout("Need EventID");
}

$galleryActiveUser = '';

$ret = GalleryEmbed::init(array(
'embedUri' => "main.php", embedPath => "/gallery", 'relativeG2Path' => "../phpgallery",
'loginRedirect' => "{$_SERVER[QUERY_STRING]}&login=1", 'activeUserId' => $galleryActiveUser));
if ($ret->isError()) {
print $ret->getAsHtml(); #has error details..
exit;
}

function createEventAlbum($eventId, $args) {
/* Get the id of the events album, we need it as parentId for our new album */
list($ret, $parentId) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.eventsAlbumId');
if ($ret->isError()) {
return $ret->wrap(__FILE__, __LINE__);
}

print "<pre>";
print "parentId: $parentId\n";
print_r($args);
print "</pre>";
#exit;

list($ret, $album) = GalleryCoreApi::createAlbum($parentId, $args['name'], $args['title'], $args['summary'], $args['description'], $args['keywords']);
if ($ret->isError()) {
return $ret->wrap(__FILE__, __LINE__);
}

if (isset($args['eventdate'])) {

list($year,$month,$day)=explode("-",$args['eventdate']);

$unixtimestamp = mktime(0,0,0,$month,$day,$year);

$album->setOriginationTimestamp($unixtimestamp);
$album->setCreationTimestamp($unixtimestamp);

list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($album->getId());
if ($ret->isError()) {
print $ret->getAsHtml();
exit;
}
$ret = $album->save();
if ($ret->isError()) {
GalleryCoreApi::releaseLocks($lockId);
print $ret->getAsHtml();
exit;
}
$ret = GalleryCoreApi::releaseLocks($lockId);
if ($ret->isError()) {
print $ret->getAsHtml();
exit;
}

}

GalleryCoreApi::relativeRequireOnce('modules/core/classes/ExternalIdMap.class');
$ret = ExternalIdMap::addMapEntry(array('externalId' => $eventId,
'entityType' => 'GalleryAlbumItem', 'entityId' => $album->getId()));
if ($ret->isError()) {
return $ret->wrap(__FILE__, __LINE__);
}
return GalleryStatus::success();
}

$sql = "select *,DATE_FORMAT(EventBegin,\"%a, %b %d\") AS PrettyBegin,
DATE_FORMAT(EventEnd,\"%d\") AS PrettyEnd,
DATE_FORMAT(EventEnd,\"%Y\") AS PrettyYear
from Events
Where EventID = $eventid";

$result=$db->execsql($sql);
$edata=$result->getrow();

capitolize($edata[EventName]);

$name=eregi_replace("[^[:alnum:]]","",$edata[EventName]);
$name = substr($name, 0, 20);

$keywords = $edata[EventName] . " " . $edata[PromoGroup];
$keywords = eregi_replace("[^[:alnum:] ]","",$keywords);

$summary = 'presented by ' . $edata[PromoGroup];

$daterange = $edata[PrettyBegin];
$daterange .= ($edata[IncludeTo] == "Y") ? " - $edata[PrettyEnd]" : '';
$daterange .= " " . $edata[PrettyYear];

$description = $edata[EventName] . " " . $summary . " on " . $daterange;

$albumdatetime = ($edata[IncludeTo] == "Y") ? $edata[EventEnd] : $edata[EventBegin];

list($albumdate,$albumtime)=explode(" ",$albumdatetime);

$g2_eventdata = array('name'=> $name,
'title'=> $edata[EventName],
'summary'=> $summary,
'description'=>$description,
'keywords'=> $keywords,
'eventdate'=> $albumdate );

print "<pre>";
print_r($g2_eventdata);
print "</pre>";

$eventId = "Event" . $eventid;

$albumret = createEventAlbum($eventId, $g2_eventdata);

if ($albumret->isError()) {
print $albumret->getAsHtml(); #has error details..
exit;
}

print "<pre>";
print_r($albumret);
print "</pre>";

?>

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Wed, 2005-09-21 16:33

I set the $galleryActiveUser to 6 and created another Event Album.
No errors when I access the album now.

Of course this had the effect of giving it the usermap of User 6 in my database. oops.

This seems to be the cause of the trouble. This seems a really big error for just not having the ownerID set.

I want to make the OwnerID be the GalleryAdmin which i believe has the G2_UserID of 6.

How do I do that as that GalleryUser does not have a Map that I am aware of.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-09-21 16:42

ok, there's the error.

you called GalleryEmbed::init with activeUserId = '' which is the anonynmous user.
that's ok, but here comes the first error:

you didn't call ::init with 'fullInit' => true.

see docs/EMBEDDING:
you need to set 'fullInit' => true in the ::init call, unless you call ::handleRequest() directly after it.

second error:
you didn't login as administrator. you shouldn't do things like create an album with the anonymous user.
do it with the real owner. e.g. use ::init with activeUserId = $cmsUserId.
or do it as admin, activeUserId = $cmsAdminId.
but first make sure, your cms admin id is mapped to the g2 admin in the externalIdMap.

third error:
- you forgot to call GalleryEmbed::done(); at the end of the script, which is important. done() commits database transactions.

note:
- you have there some return $ret->wrap(__FILE__, __LINE__); lines. you won't see these errors in your browser. if you want to see the errors, do print $ret->getAsHtml();

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-09-21 16:44

ownerId is the id of a g2 user.
see table g2_User for g2 users and the g_Id which is the ownerId in the other table.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Wed, 2005-09-21 16:47

Now we're cooking!
Thanks alot!

I look forward to the full docs on all this one day.
Hopefully these threads will help decide what sort of stuff should be going in.

Ok. maybe a silly question but how do i map my cmsAdminId to the g2AdminId ?

Also I can't find the place to change the OwnerID's of the galleries that I created with no owner.
(Gallery won't let me browse to them to change as admin)

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-09-21 16:56

either manually or...
i don't have the source code available right now...

pseudo code:

1. get id of cms admin user
2. get id of g2 admin user
3. call GallerytEmbed::addExternalIdMapEntry

details for step 2:
- ::init again, fullInit
- list ($ret, $siteAdminGroupId') = GalleryCoreApi::getPluginParameter('module', 'core', 'id.siteAdminGroup') <--- this is probably incorrect, see modules/core/CoreModuleExtras.inc for the correct string, it's perhaps on a line between line 1000 and 2000 :) just search for 'id.
- check $ret
- GalleryCoreApi::getUsersForGroup <--- or something like that, see modules/core/classes/GalleryCoreApi.class
- pick any of the returned users etc.

a shorter but less general approach:
- GalleryCoreApi::getUserByUsername('admin'); or something like that

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Wed, 2005-09-21 17:01

I selected the "admin" user from the g2_User and found it to be g_ID = 6.
In my CMS it is userID = 1

I did this:

insert into g2_ExternalIdMap values (1,"GalleryUser",6);

Is that good?

How can I change the OwnerID for the Galleries I have already created which are currently OwnerID = NULL ..
The Gallery will not let me browse to them through the interface to change it.
This is causing serious problems.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-09-21 17:13

if the columns of externalIdMap are externalId, entityType, entityId in this order, then it's correct.

http://gallery.menalto.com/gallery/miscellaneous/aaf.png.html?g2_imageViewsIndex=1

ownerId is a property of GalleryItem

you could:

UPDATE g2_Item
SET g_OwnerId = '6'
WHERE g_OwnerId IS NULL;

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Wed, 2005-09-21 17:42

Ok. I've updated it there.
But it seems that was not the only problem.

Gallery still would't let me browse to the Events album.
I decided to just delete the album through the gallery interface.

I then reset the plugin paramter to the newly created Events Parent Album.

Quote:

GalleryCoreApi::setPluginParameter('module', 'core', 'id.eventsAlbumId', 1966);

I notice now thought that it didn't delete the ExternalIdMap entries which seems to be causing troubles when I try to Create an album for one of the previous events..

Can I remove them manually with an SQL "delete from g2_ExternalIdMap..." or should I use the API somehow?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-09-21 18:00

yep, it doesn't delete the entries in the externalIdMap.
a month ago i argued that this was ok, since the external application should be responsible for G2 objects, that are mapped to it.

but i guess i change my opinion.
could you please file a http://sf.net/projects/gallery/ bug such that i don't forget it.
we should check externalIdMap when we delete an entity and if there;s an entry, delete it.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Wed, 2005-09-21 18:05

I agree.

put one of these in the script

Quote:
$ret = ExternalIdMap::removeMapEntry(array('externalId' => $eventId,
'entityType' => 'GalleryAlbumItem'));

Just before the "addMapEntry" and recreated the events that already had a map.
seemed to work.
then i commented that line back out of my script.

Galleries seem to be created properly now. Thanks!

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Wed, 2005-09-21 19:25

Now what I would like to do is set the permissions on these galleries so that any registered user is allowed to upload images to them.
Can I do this as part of my script?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-09-21 21:33

yes you can.

the easiest would be if you set the permissions correctly for your parent "all events" album.
why?
because in G2, new sub items / sub album inherit the permissions of its parent album.
so you only have to set the permissions correctly for the "all events" album, and it will be ok.

i suggest following permissions:
- core.addDataItem
- core.viewAll
- comment.add
- comment.view

you can add them with the GUI.
if you want to use the API (for what ever reason):
see GalleryCoreApi for the permission functions.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Wed, 2005-09-21 22:20

The reason I thought it might be better to use the API is because I want people uploading Items to the sub albums but not to the parent album.

Perhaps I will try it this way for now and see how it goes though.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-09-21 23:50
Quote:
The reason I thought it might be better to use the API is because I want people uploading Items to the sub albums but not to the parent album.

yes, of course. this doesn't change anything. set the permissions manually to the "all events" album and everytime you create a new album for a specific event, the new "event xy" album will automatically have the same permissions as the "all events" album. that's how G2 works.
users will have the permission "add item" aka core.addDataItem, but they won't have permission "add album" aka core.addAlbumItem

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Thu, 2005-09-22 02:43

what I meant was that doing it this way will allow users to upload events directly to the "all events" album as well.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-09-22 09:37

you want users to allow creating their own event album?
yes, then you need to assign the permissions with the API. that is, you have to remove the add album permission from the newly created event albums.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Thu, 2005-09-22 17:17

No.. I don't want the users to create their own event album except through the interface I created.

I want them to upload pictures to the event sub albums.

I don't want them to upload pictures to the event parent album.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-09-22 17:39

then you don't need to use the API, all new event albums will automatically have the correct permissions.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Thu, 2005-09-22 18:11

But the parent album won't.

won't it allow users to upload photos directly to it?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-09-22 21:34

you're absolutely right. sorry. i'd set the permissions to the parent event album such that all permissions are there but the addDataItem permission. and then after creating a new event album, add the group permission core.addDataItem to the registered user group.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Thu, 2005-09-29 15:18

Currently users do not have the ability to remove their own pictures from the albums.

Is there a way I can allow them to delete their own photos however not the photos of others?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-09-29 15:22

you must give them the delete permission for their own items..., this is a manual task, unless you listen for entity save events and do the logic there.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Thu, 2005-09-29 15:47

listen for entity save events and do the logic there?
manually give them delete permission for their own items?

can you elaborate please?

I have 1700 Registered Users all of whom i wish to allow to add photos to an expanding group of galleries.
If they add a photo they should also have the ability to remove it.

How can I allow them this?
(without allowing them to remove the photos of others)

what is involved in creating an environment like this?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-09-29 16:01

g2 doesn't have special owner permissions. so you have to add the delete item permission manually after a photo has been added.

everytime an item is created / updated / ... in g2, there's a Entity:Save event.
You can create a G2 module that listens for this event.
in this handleEvent function, you have to check whether it is a GalleryAlbumItem, then make sure the user doesn't have the delete permission since you don't wanna give him the option to delete event albums, right?
if it's a GalleryDataItem, give the activeUser the delete permission for this item.

functions to assign / remove permissions are listed in GalleryCoreApi.class
other modules also have event listeners. just copy some code.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Thu, 2005-09-29 16:35

i'm wondering if maybe the owner of an item should be allowed to delete it by default?

would this be a difficult thing to add to G2?

is it a feature that is planned or being entertained?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-09-29 17:08

special owner permissions have been requested before. but noone's working on them and you won;t see them anytime soon.

and i think not all people would want the owner to be able to delete the an item. e.g. what about albums? deleting an album leads to deleted subitems, which didn't belong to you.
or some admins don't want to allow deleting items at all.
so it has to be an option anyway.
with the current permission system you have to do such things manually or event based, code once a module, then it just works.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Thu, 2005-09-29 18:07

this may be just my point of view.

but because it is i see it as a point of logic. :-)

i think that if you own the parent album you should have the freedom to delete the whole album even if others have uploaded or created sub albums.

this is the difference between owning something and having permission to use it.

if you don't think the user should be allowed to delete an album with sub albums then why is he the owner of it?
should be owned by admin or something in that case with the user only being allowed to add.

also, I don't know the first thing about creating G2 modules yet.
where can i go to learn?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-09-29 18:27

we use the "owner" information right now just for copying permissions from the old owner to the new owner when changing the owner of an item.
of course this could be extended somehow to offer the option that owners have special permissions per se.

but that's not the case right now. and it won't change anytime soon, since we're so busy.

we don't have module docs yet. writing a new module means taking a look at other forums and creating a new one.
your module would only need a single file. module.inc.
e.g. see modules/albumselect/module.inc, copy it to
modules/ownercandeleteitems/module.inc and start editing it.

change

class AlbumSelectModule extends GalleryModule {

    function AlbumSelectModule() {
	global $gallery;
	$this->setId('albumselect');
	$this->setName($gallery->i18n('Album Select'));

- change the class name, must be the same name as the module directory name
- change the constructor accrodingly
- change the setId line, must be the same name as the module directory name
- change $this->setCallbacks('getSiteAdminViews|registerEventListeners');
to $this->setCallbacks('registerEventListeners');

change

    function registerEventListeners() {
	$listener = new AlbumSelectModule();
	GalleryCoreApi::registerEventListener('Gallery::ViewableTreeChange', $listener);
	GalleryCoreApi::registerEventListener('Gallery::ItemOrder', $listener);
	GalleryCoreApi::registerEventListener('GalleryEntity::save', $listener);
    }

to

    function registerEventListeners() {
	$listener = new OwnerCanDeleteItems();
	GalleryCoreApi::registerEventListener('GalleryEntity::save', $listener);
    }

- remove the upgrade function
- remove the getSiteAdminViews function

- customize the handleEvent function, there you have to do the logic:

what you wanna do there:
- for GaleleryEntity::save events and if the entity type isa GalleryDataItem, make sure the owner of the item has delete permission

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Thu, 2005-09-29 18:33

wow.. ok.

thanks for your help.

i'll get to work and post here if i run into any hangups.