*/ /** * This ItemAddOption enforces disk quotas * * @package Quotas * @subpackage UserInterface */ class DiskQuotaOption extends ItemAddOption { /** * @see ItemAddOption::isAppropriate */ function isAppropriate() { return array(null, true); } /** * @see ItemAddOption::handleRequestAfterAdd */ function handleRequestAfterAdd($form, $items) { GalleryCoreApi::requireOnce('modules/quotas/classes/GalleryQuotasHelper.class'); global $gallery; $warnings = array(); $errors = array(); /* user's disk quota in KB */ list ($ret, $quotaExists, $userDiskQuota) = GalleryQuotasHelper::getUserDiskQuota($gallery->getActiveUserId()); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null, null); } /* if user has a quota */ if ($quotaExists) { $excludedIds = array(); for ($j = 0; $j < count($items); $j++) { $excludedIds[] = $items[$j]->getId(); } list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'quotas'); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null, null); } for ($i = 0; $i < count($items); $i++) { $warnings[$i] = array(); /* we should come here only if we are adding a data item, not sub-album */ $albumId = $items[$i]->getParentId(); /* calculate the item ids of the newly added items */ array_shift($excludedIds); /* user's disk usage in Bytes */ list ($ret, $userDiskUsage) = GalleryQuotasHelper::getUserDiskUsage( $gallery->getActiveUserId(), $excludedIds); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null, null); } /* make disk usage into KB */ $userDiskUsage /= 1024.00; if ($userDiskUsage > $userDiskQuota) { list ($ret, $userDiskQuotaHumanReadable, $userDiskQuotaHumanReadableUnit) = GalleryQuotasHelper::humanReadableFromKilobytes($userDiskQuota); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null, null); } $warnings[$i][] = $module->translate( array('text' => 'Warning: You have reached your disk quota (%s %s), ' . 'this item will not be added.', 'arg1' => $userDiskQuotaHumanReadable, 'arg2' => $userDiskQuotaHumanReadableUnit)); $gallery->addShutdownAction( array('GalleryCoreApi', 'deleteEntityById'), array($items[$i]->getId())); } else { list ($ret, $userDiskQuotaHumanReadable, $userDiskQuotaHumanReadableUnit) = GalleryQuotasHelper::humanReadableFromKilobytes($userDiskQuota); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null, null); } list ($ret, $userDiskUsageHumanReadable, $userDiskUsageHumanReadableUnit) = GalleryQuotasHelper::humanReadableFromKilobytes($userDiskUsage); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null, null); } $warnings[$i][] = $module->translate( array('text' => 'You are using %s %s of your allotted %s %s.', 'arg1' => $userDiskUsageHumanReadable, 'arg2' => $userDiskUsageHumanReadableUnit, 'arg3' => $userDiskQuotaHumanReadable, 'arg4' => $userDiskQuotaHumanReadableUnit)); } } } return array(null, $errors, $warnings); } } ?>