add(array(
'pluginKey' => 'privatealbums',
'group' => self::CONTENT_GROUP,
'groupLabel' => OW::getLanguage()->text('privatealbums', 'wid_pw_title'),
'entityType' => self::ENTITY_TYPE_ALBUM,
'entityLabel' => 'Album',
'displayFormat' => 'content'
));
$event->add(array(
'pluginKey' => 'privatealbums',
'group' => self::CONTENT_GROUP,
'groupLabel' => OW::getLanguage()->text('privatealbums', 'wid_pw_title'),
'entityType' => self::ENTITY_TYPE_PHOTO,
'entityLabel' => 'Photo',
'displayFormat' => 'image_content'
));
}
public function onGetInfo( OW_Event $event ) // Collect display info --- Will be displayed in the moderation panel
{
$params = $event->getParams();
$route = OW::getRouter();
$out = array();
$itemStr = "";
file_put_contents("out.txt", json_encode($params));
if ( $params['entityType'] != self::ENTITY_TYPE_ALBUM && $params['entityType'] != self::ENTITY_TYPE_PHOTO)
{
return;
}
file_put_contents("out.txt", json_encode($params)." - passed");
switch($params['entityType'])
{
case self::ENTITY_TYPE_ALBUM:
foreach($params['entityIds'] as $id) $itemStr .= ",$id";
$itemStr = substr($itemStr, 1);
foreach ( OW::getDbo()->queryForList("SELECT * FROM `".OW_DB_PREFIX."pa_album` WHERE id IN ($itemStr)") as $album)
{
$info = array();
$info['userId'] = $album['userId'];
$info['title'] = ''.$album['title'].'';
$info['description'] = $album['description'];
$out[$album['id']] =$info;
}
break;
case self::ENTITY_TYPE_PHOTO:
foreach($params['entityIds'] as $id) $itemStr .= ",$id";
$itemStr = substr($itemStr, 1);
foreach ( OW::getDbo()->queryForList("SELECT * FROM `".OW_DB_PREFIX."pa_picture` WHERE id IN ($itemStr)") as $pic )
{
$album = OW::getDbo()->queryForRow("SELECT * FROM `".OW_DB_PREFIX."pa_album` WHERE id = ".$pic['albumId']);
$info = array();
$info['id'] = $pic['id'];
$info['userId'] = $album['userId'];
$info['text'] = ''.$album['title'].'';;
$info['description'] = $pic['description'];
$info['url'] = OW::getRouter()->urlForRoute('privatealbums.get.picture', array('id' => $pic['id'], 'type' => 'normal'));
$info['image'] = array(
'thumbnail' => OW::getRouter()->urlForRoute('privatealbums.get.picture', array('id' => $pic['id'], 'type' => 'thumb')),
'preview' => 'prev',
'view' => 'view',
'fullsize' => 'full'
);
$out[$pic['id']] =$info;
}
break;
}
$event->setData($out);
return $out;
}
public function onUpdateInfo( OW_Event $event )
{
$params = $event->getParams();
$data = $event->getData();
if ( $params['entityType'] != self::ENTITY_TYPE_ALBUM && $params['entityType'] != self::ENTITY_TYPE_PHOTO )
{
return; //If its not my Entity -> ignore it!
}
foreach ( $data as $itemId => $item )
{
//Set status
$status = $item['status'] == self::STATUS_APPROVAL ? self::STATUS_APPROVAL : self::STATUS_APPROVED;
OW::getDbo()->query("UPDATE `".OW_DB_PREFIX.$params['entityType']."` SET status = '".$status."' WHERE id = ".$itemId);
}
}
public function onDelete( OW_Event $event )
{
$params = $event->getParams();
switch($params['entityType'])
{
case self::ENTITY_TYPE_ALBUM:
foreach($params['entityIds'] as $id)
{
//Delete albums here
}
break;
case self::ENTITY_TYPE_PHOTO:
foreach($params['entityIds'] as $id)
{
//Delete photos here
}
break;
}
}
public function init()
{
OW::getEventManager()->bind(BOL_ContentService::EVENT_COLLECT_TYPES, array($this, 'onCollectTypes'));
OW::getEventManager()->bind(BOL_ContentService::EVENT_GET_INFO, array($this, 'onGetInfo'));
OW::getEventManager()->bind(BOL_ContentService::EVENT_UPDATE_INFO, array($this, 'onUpdateInfo'));
OW::getEventManager()->bind(BOL_ContentService::EVENT_DELETE, array($this, 'onDelete'));
}
}