Пример #1
0
 /**
  * Attempts to pluralize the "$singular" word unless "$count" is 1.
  */
 function pluralize($count, $singular, $plural = null)
 {
     if ($count == 1) {
         return $singular;
     } elseif (!empty($plural)) {
         return $plural;
     } else {
         return AkInflector::conditionalPlural($count, $singular);
     }
 }
Пример #2
0
 /**
  * Returns a string with a div containing all the error messages for the object located as an instance variable by the name
  * of <tt>object_name</tt>. This div can be tailored by the following options:
  *
  * * <tt>header_tag</tt> - Used for the header of the error div (default: h2)
  * * <tt>id</tt> - The id of the error div (default: errorExplanation)
  * * <tt>class</tt> - The class of the error div (default: errorExplanation)
  *
  * NOTE: This is a pre-packaged presentation of the errors with embedded strings and a certain HTML structure. If what
  * you need is significantly different from the default presentation, it makes plenty of sense to access the $object->getErrors()
  * instance yourself and set it up. View the source of this method to see how easy it is.
  */
 public function error_messages_for($object_name, $options = array())
 {
     $object = $this->_controller->{$object_name};
     if ($object->hasErrors()) {
         $error_list = '<ul>';
         foreach ($object->getFullErrorMessages() as $field => $errors) {
             foreach ($errors as $error) {
                 $error_list .= AkTagHelper::content_tag('li', $error);
             }
         }
         $error_list .= '</ul>';
         return AkTagHelper::content_tag('div', AkTagHelper::content_tag(!empty($options['header_tag']) ? $options['header_tag'] : 'h2', $this->t('%number_of_errors %errors prohibited this %object_name from being saved', array('%number_of_errors' => $object->countErrors(), '%errors' => $this->t(AkInflector::conditionalPlural($object->countErrors(), 'error')), '%object_name' => $this->t(AkInflector::humanize($object->getModelName()))))) . AkTagHelper::content_tag('p', $this->t('There were problems with the following fields:')) . $error_list, array('id' => !empty($options['id']) ? $options['id'] : 'errorExplanation', 'class' => !empty($options['class']) ? $options['class'] : 'errorExplanation'));
     }
 }