Пример #1
0
 /**
  * Get an array of custom field types for use with `Form::select`.
  *
  * @return array[]
  */
 public static function typesSelectOptions()
 {
     $options = [];
     foreach (static::types() as $type) {
         $options[] = ['label' => Language::translate($type), 'value' => $type];
     }
     return $options;
 }
Пример #2
0
 /**
  * Returns an array formatted for the Form::select() method.
  *
  * @return array
  */
 public static function selectOptions($valueField = 'id')
 {
     $open = Language::translate('open');
     $closed = Language::translate('closed');
     $options = [$open => [], $closed => []];
     foreach (static::all() as $status) {
         $option = ['label' => $status['name'], 'value' => $status[$valueField]];
         if ($status->status) {
             $options[$open][] = $option;
         } else {
             $options[$closed][] = $option;
         }
     }
     return $options;
 }
Пример #3
0
 /**
  * @return boolean
  */
 public function validate()
 {
     $validator = new ModelValidator(static::$_validations, $this);
     if (!$validator->validate()) {
         foreach ($validator->errors as $field => $errors) {
             foreach ($errors as $error => $options) {
                 if (is_numeric($error)) {
                     $error = $options;
                     $options = [];
                 }
                 $name = Language::translate($field);
                 $this->addError($field, Language::translate("errors.validations.{$error}", ['field' => $name] + $options));
             }
         }
     }
     return !count($this->_errors);
 }
Пример #4
0
 /**
  * Returns contains/doesn't contain options for the `Form::select` helper.
  *
  * @return array
  */
 public static function containsFilterSelectOptions()
 {
     return [['label' => Language::translate('contains'), 'value' => ''], ['label' => Language::translate('doesnt_contain'), 'value' => '!']];
 }
Пример #5
0
 /**
  * Returns the HTML for a modal header.
  *
  * @param string $title
  *
  * @return string
  */
 public static function modalHeader($title)
 {
     $header = ['<div class="modal-header">', '    <button type="button" class="close" data-dismiss="modal">', '        <span aria-hidden="true">&times;</span>', '        <span class="sr-only">' . Language::translate('close') . '</span>', '    </button>', '    <h4 class="modal-title">' . $title . '</h4>', '</div>'];
     return implode(PHP_EOL, $header);
 }
Пример #6
0
 /**
  * Create a new account activation notification.
  *
  * @param  User $user
  *
  * @return Notification
  */
 public static function accountActivation(User $user, $activationCode)
 {
     $message = new static(Language::translate('notifications.account_activation.subject', ['title' => setting('title')]), View::render('notifications/account_activation.txt.php', ['user' => $user, 'activationCode' => $activationCode]));
     $message->setTo($user->email, $user->name);
     return $message;
 }
Пример #7
0
 /**
  * Returns an array of milestone statuses formatted for the Form::select() helper.
  *
  * @return array
  */
 public static function statusSelectOptions()
 {
     return [['label' => Language::translate('active'), 'value' => 1], ['label' => Language::translate('completed'), 'value' => 2], ['label' => Language::translate('cancelled'), 'value' => 0]];
 }
Пример #8
0
 /**
  * Returns the content for the ticket listing headers.
  *
  * @param string $column The column to get the content for.
  *
  * @return mixed
  */
 public static function headerFor($column)
 {
     switch ($column) {
         case 'ticket_id':
             return Language::translate('id');
             break;
         case 'summary':
         case 'status':
         case 'owner':
         case 'type':
         case 'component':
         case 'milestone':
         case 'version':
         case 'assigned_to':
         case 'updates':
         case 'votes':
         case 'priority':
         case 'severity':
             return Language::translate($column);
         case 'created_at':
             return Language::translate('created');
             break;
         case 'updated_at':
             return Language::translate('updated');
             break;
     }
     // If we're still here, it may be a custom field
     if ($column = CustomField::find($column)) {
         return $column->name;
     }
     // Nothing!
     return '';
 }
Пример #9
0
function d($format, $date)
{
    return Language::date($format, $date);
}
Пример #10
0
 /**
  * Adds a validation error for the specified field.
  *
  * @param string $field
  * @param mixed  $data
  * @param string $index
  */
 public function addValidationError($field, $validation, array $options = [], $index = null)
 {
     $this->addError($field, Language::translate("errors.validations.{$validation}", ['field' => Language::translate($field)] + $options));
 }
Пример #11
0
 /**
  * Returns time ago in words of the given date.
  *
  * @param string  $original
  * @param boolean $detailed
  *
  * @return string
  */
 public static function agoInWords($original, $detailed = false)
 {
     // Check what kind of format we're dealing with, timestamp or datetime
     // and convert it to a timestamp if it is in datetime form.
     if (!is_numeric($original)) {
         $original = static::toUnix($original);
     }
     $now = time();
     // Get the time right now...
     // Time chunks...
     $chunks = array(array(60 * 60 * 24 * 365, 'year', 'years'), array(60 * 60 * 24 * 30, 'month', 'months'), array(60 * 60 * 24 * 7, 'week', 'weeks'), array(60 * 60 * 24, 'day', 'days'), array(60 * 60, 'hour', 'hours'), array(60, 'minute', 'minutes'), array(1, 'second', 'seconds'));
     // Get the difference
     $difference = $now > $original ? $now - $original : $original - $now;
     // Loop around, get the time from
     for ($i = 0, $c = count($chunks); $i < $c; $i++) {
         $seconds = $chunks[$i][0];
         $name = $chunks[$i][1];
         $names = $chunks[$i][2];
         if (0 != ($count = floor($difference / $seconds))) {
             break;
         }
     }
     // Format the time from
     $from = Language::current()->translate("time.x_{$name}", array($count));
     // Get the detailed time from if the detail variable is true
     if ($detailed && $i + 1 < $c) {
         $seconds2 = $chunks[$i + 1][0];
         $name2 = $chunks[$i + 1][1];
         $names2 = $chunks[$i + 1][2];
         if (0 != ($count2 = floor(($difference - $seconds * $count) / $seconds2))) {
             $from = Language::current()->translate('time.x_and_x', $from, Language::current()->translate("time.x_{$name2}", array($count2)));
         }
     }
     // Return the time from
     return $from;
 }
Пример #12
0
/**
 * Returns the time ago in words with the 'ago' suffix.
 *
 * @param string $timestamp
 *
 * @return string
 */
function timeAgoInWords($timestamp)
{
    return $timestamp ? Language::translate('time.x_ago', [Time::agoInWords($timestamp)]) : null;
}