当前位置: 首页>>代码示例>>PHP>>正文


PHP Util::isDefaultExpireDateEnforced方法代码示例

本文整理汇总了PHP中OCP\Util::isDefaultExpireDateEnforced方法的典型用法代码示例。如果您正苦于以下问题:PHP Util::isDefaultExpireDateEnforced方法的具体用法?PHP Util::isDefaultExpireDateEnforced怎么用?PHP Util::isDefaultExpireDateEnforced使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OCP\Util的用法示例。


在下文中一共展示了Util::isDefaultExpireDateEnforced方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setExpirationDate

 /**
  * Set expiration date for a share
  * @param string $itemType
  * @param string $itemSource
  * @param string $date expiration date
  * @param int $shareTime timestamp from when the file was shared
  * @return boolean
  * @throws \Exception when the expire date is not set, in the past or further in the future then the enforced date
  */
 public static function setExpirationDate($itemType, $itemSource, $date, $shareTime = null)
 {
     $user = \OC_User::getUser();
     $l = \OC::$server->getL10N('lib');
     if ($date == '') {
         if (\OCP\Util::isDefaultExpireDateEnforced()) {
             $warning = 'Cannot clear expiration date. Shares are required to have an expiration date.';
             $warning_t = $l->t('Cannot clear expiration date. Shares are required to have an expiration date.');
             \OCP\Util::writeLog('OCP\\Share', $warning, \OCP\Util::WARN);
             throw new \Exception($warning_t);
         } else {
             $date = null;
         }
     } else {
         $date = self::validateExpireDate($date, $shareTime, $itemType, $itemSource);
     }
     $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `item_type` = ? AND `item_source` = ?  AND `uid_owner` = ? AND `share_type` = ?');
     $query->bindValue(1, $date, 'datetime');
     $query->bindValue(2, $itemType);
     $query->bindValue(3, $itemSource);
     $query->bindValue(4, $user);
     $query->bindValue(5, \OCP\Share::SHARE_TYPE_LINK);
     $query->execute();
     \OC_Hook::emit('OCP\\Share', 'post_set_expiration_date', array('itemType' => $itemType, 'itemSource' => $itemSource, 'date' => $date, 'uidOwner' => $user));
     return true;
 }
开发者ID:evanjt,项目名称:core,代码行数:35,代码来源:share.php

示例2: validateExpireDate

 /**
  * validate expire date if it meets all constraints
  *
  * @param string $expireDate well formate date string, e.g. "DD-MM-YYYY"
  * @param string $shareTime timestamp when the file was shared
  * @param string $itemType
  * @param string $itemSource
  * @return DateTime validated date
  * @throws \Exception
  */
 private static function validateExpireDate($expireDate, $shareTime, $itemType, $itemSource)
 {
     $l = \OC_L10N::get('lib');
     $date = new \DateTime($expireDate);
     $today = new \DateTime('now');
     // if the user doesn't provide a share time we need to get it from the database
     // fall-back mode to keep API stable, because the $shareTime parameter was added later
     $defaultExpireDateEnforced = \OCP\Util::isDefaultExpireDateEnforced();
     if ($defaultExpireDateEnforced && $shareTime === null) {
         $items = self::getItemShared($itemType, $itemSource);
         $firstItem = reset($items);
         $shareTime = (int) $firstItem['stime'];
     }
     if ($defaultExpireDateEnforced) {
         // initialize max date with share time
         $maxDate = new \DateTime();
         $maxDate->setTimestamp($shareTime);
         $maxDays = \OCP\Config::getAppValue('core', 'shareapi_expire_after_n_days', '7');
         $maxDate->add(new \DateInterval('P' . $maxDays . 'D'));
         if ($date > $maxDate) {
             $warning = 'Can not set expire date. Shares can not expire later then ' . $maxDays . ' after they where shared';
             $warning_t = $l->t('Can not set expire date. Shares can not expire later then %s after they where shared', array($maxDays));
             \OCP\Util::writeLog('OCP\\Share', $warning, \OCP\Util::WARN);
             throw new \Exception($warning_t);
         }
     }
     if ($date < $today) {
         $message = 'Can not set expire date. Expire date is in the past';
         $message_t = $l->t('Can not set expire date. Expire date is in the past');
         \OCP\Util::writeLog('OCP\\Share', $message, \OCP\Util::WARN);
         throw new \Exception($message_t);
     }
     return $date;
 }
开发者ID:WYSAC,项目名称:oregon-owncloud,代码行数:44,代码来源:share.php


注:本文中的OCP\Util::isDefaultExpireDateEnforced方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。