0byt3m1n1
Path:
/
data
/
applications
/
aps
/
gallery
/
2.2-08
/
htdocs
/
modules
/
members
/
classes
/
[
Home
]
File: GalleryMembersHelper.class
<?php /* * Gallery - a web based photo album viewer and editor * Copyright (C) 2000-2007 Bharat Mediratta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ /** * Utility functions useful in managing GalleryMembers * @package Members * @subpackage Classes * @author Robert Balousek <rbalousek@hotmail.com> * @version $Revision: 15513 $ * @static */ class GalleryMembersHelper { /** * Return the total number of items a user owns * * @param int $userId * @return array (object GalleryStatus a status code, * int ItemCount a users total item count) */ function fetchUserItemCount($userId) { global $gallery; list ($ret, $aclIds) = GalleryCoreApi::fetchAccessListIds('core.view', $gallery->getActiveUserId()); if ($ret) { return array($ret, null); } if (empty($aclIds)) { return array(null, 0); } $aclMarkers = GalleryUtilities::makeMarkers(count($aclIds)); $query = sprintf(' SELECT COUNT([GalleryItem::id]) FROM [GalleryItem], [GalleryAccessSubscriberMap] WHERE [GalleryItem::ownerId] = ? AND [GalleryAccessSubscriberMap::itemId] = [GalleryItem::id] AND [GalleryAccessSubscriberMap::accessListId] IN (%s) ', $aclMarkers); $data = array_merge(array((int)$userId), $aclIds); list ($ret, $searchResults) = $gallery->search($query, $data); if ($ret) { return array($ret, null); } $result = $searchResults->nextResult(); $numItems = (int)$result[0]; return array(null, $numItems); } /** * Return the last N items a user created * * @param int $userId * @param int $offset * @param int $count * @param string $orderDirection (optional) * @return array (object GalleryStatus a status code, * array (GalleryItem, GalleryItem, ...)) */ function fetchLastUserItems($userId, $offset, $count, $orderDirection=ORDER_DESCENDING) { global $gallery; switch($orderDirection) { case ORDER_ASCENDING: $direction = 'ASC'; break; case ORDER_DESCENDING: $direction = 'DESC'; break; default: return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER), null); } list ($ret, $aclIds) = GalleryCoreApi::fetchAccessListIds('core.view', $gallery->getActiveUserId()); if ($ret) { return array($ret, null); } if (empty($aclIds)) { return array(null, array()); } $aclMarkers = GalleryUtilities::makeMarkers(count($aclIds)); $query = sprintf(' SELECT [GalleryItem::id], [GalleryEntity::creationTimestamp] FROM [GalleryItem], [GalleryEntity], [GalleryAccessSubscriberMap] WHERE [GalleryItem::id] = [GalleryEntity::id] AND [GalleryItem::ownerId] = ? AND [GalleryAccessSubscriberMap::itemId] = [GalleryItem::id] AND [GalleryAccessSubscriberMap::accessListId] IN (%s) ORDER BY [GalleryEntity::creationTimestamp] ' . $direction . ' ', $aclMarkers); $data = array(); $data[] = (int)$userId; $data = array_merge($data, $aclIds); $options = array(); $options['limit'] = array('count' => (int)$count, 'offset' => (int)$offset); list ($ret, $searchResults) = $gallery->search($query, $data, $options); if ($ret) { return array($ret, null); } /* Get all of our item ids */ $itemIds = array(); while ($result = $searchResults->nextResult()) { $itemIds[] = (int)$result[0]; } /* Convert them to entities */ if (sizeof($itemIds) > 0) { list ($ret, $items) = GalleryCoreApi::loadEntitiesById($itemIds); if ($ret) { return array($ret, null); } } else { $items = array(); } return array(null, $items); } /** * Return true if the user has permission to view the Members Module * * @param int $userId * @return array (object GalleryStatus a status code, * boolean canViewMembersModule permission) */ function canViewMembersModule($userId) { list ($ret, $viewSelectedGroupId) = GalleryCoreApi::getPluginParameter('module', 'members', 'canViewMembersModule'); if ($ret) { return array($ret, null); } list ($ret, $result) = GalleryCoreApi::isUserInGroup($userId, $viewSelectedGroupId); if ($ret) { return array($ret, null); } return array(null, $result); } /** * Return true if the user has permission to view members email addresses * * @param int $userId * @return array (object GalleryStatus a status code, * boolean canViewProfileEmail permission) */ function canViewProfileEmail($userId) { $result = false; /* Can the user view email addresses in the member profile? */ list ($ret, $resultOne) = GalleryCoreApi::getPluginParameter('module', 'members', 'canViewEmailAddress'); if ($ret) { return array($ret, null); } list ($ret, $groupId) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.adminGroup'); if ($ret) { return array($ret, null); } /* Is the current user an admin? */ list ($ret, $resultTwo) = GalleryCoreApi::isUserInGroup($userId, $groupId); if ($ret) { return array($ret, null); } /* * User can see member email in the profile if they are an admin, * or if the module setting says they are allowed to. */ if ($resultOne || $resultTwo) { $result = true; } return array(null, $result); } /** * Return the calendar days since the user's creationTimestamp. * * @param int $userId * @return array (object GalleryStatus a status code, * int daysSinceCreation number in days) */ function daysSinceCreation($userId) { list ($ret, $user) = GalleryCoreApi::loadEntitiesById($userId); if ($ret) { return array($ret, null); } /* * The difference in the day of creationTimestamp and todays date, * divided by the number of seconds in a day, gives us a result in days */ $todayStamp = strtotime(date("F j, Y", time())); $creationStamp = strtotime(date("F j, Y", $user->getCreationTimestamp())); $age = (int)round(($todayStamp - $creationStamp) / (24 * 60 * 60)); return array(null, $age); } /** * Get the current member count * * @return array object GalleryStatus * int how many members are registered */ function getMembersCount() { list ($ret, $groupId) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.allUserGroup'); if ($ret) { return array($ret, null); } list ($ret, $totalUserCount) = GalleryCoreApi::fetchUserCount(null, $groupId); if ($ret) { return array($ret, null); } return array(null, (int)$totalUserCount); } } ?>