示例#1
0
 /**
  * Lock a record by setting its locked_on and/or locked_by columns
  *
  * @param   integer $userId
  *
  * @return  $this  Self, for chaining
  */
 public function lock($userId = null)
 {
     if (!$this->getId()) {
         throw new \RuntimeException("Can't lock a not loaded DataModel");
     }
     if (!$this->hasField('locked_on') && !$this->hasField('locked_by')) {
         return $this;
     }
     if (method_exists($this, 'onBeforeLock')) {
         $this->onBeforeLock();
     }
     $this->behavioursDispatcher->trigger('onBeforeLock', array(&$this));
     $db = $this->getDbo();
     if ($this->hasField('locked_on')) {
         $date = new Date();
         $locked_on = $this->getFieldAlias('locked_on');
         $this->{$locked_on} = $date->toSql(false, $db);
     }
     if ($this->hasField('locked_by')) {
         if (empty($userId)) {
             $userManager = $this->container->userManager;
             $userId = $userManager->getUser()->getId();
         }
         $locked_by = $this->getFieldAlias('locked_by');
         $this->{$locked_by} = $userId;
     }
     $this->save();
     if (method_exists($this, 'onAfterLock')) {
         $this->onAfterLock();
     }
     $this->behavioursDispatcher->trigger('onAfterLock', array(&$this));
     return $this;
 }
示例#2
0
文件: Html.php 项目: edrdesigner/awf
 /**
  * Returns formatted date according to a given format and time zone.
  *
  * @param   string       $input      String in a format accepted by date(), defaults to "now".
  * @param   string       $format     The date format specification string (see {@link PHP_MANUAL#date}).
  * @param   mixed        $tz         Time zone to be used for the date.  Special cases: boolean true for user
  *                                   setting, boolean false for server setting.
  * @param   Application  $app        The application from which we'll retrieve settings, null to use the default app
  *
  * @return  string    A date translated by the given format and time zone.
  *
  * @see     strftime
  */
 public static function date($input = 'now', $format = null, $tz = true, Application $app = null)
 {
     if (!is_object($app)) {
         $app = Application::getInstance();
     }
     // Get some system objects.
     $config = $app->getContainer()->appConfig;
     $userManager = $app->getContainer()->userManager;
     $user = $userManager->getUser();
     // UTC date converted to user time zone.
     if ($tz === true) {
         // Get a date object based on UTC.
         $date = new Date($input, 'UTC');
         // Set the correct time zone based on the user configuration.
         $date->setTimeZone(new \DateTimeZone($user->getParameters()->get('timezone', $config->get('timezone'))));
     } elseif ($tz === false) {
         // Get a date object based on UTC.
         $date = new Date($input, 'UTC');
         // Set the correct time zone based on the server configuration.
         $date->setTimeZone(new \DateTimeZone($config->get('timezone', 'UTC')));
     } elseif ($tz === null) {
         $date = new Date($input);
     } else {
         // Get a date object based on UTC.
         $date = new Date($input, 'UTC');
         // Set the correct time zone based on the server configuration.
         $date->setTimeZone(new \DateTimeZone($tz));
     }
     // If no format is given use the default locale based format.
     if (!$format) {
         $format = Text::_('DATE_FORMAT_LC1');
     } elseif (Text::hasKey($format)) {
         $format = Text::_($format);
     }
     return $date->format($format, true);
 }