Changeset 271 for trunk/trax/vendor/trax

Show
Ignore:
Timestamp:
01/18/07 08:47:09 (5 years ago)
Author:
john
Message:

active_record.php

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/trax/vendor/trax/action_view/helpers/active_record_helper.php

    r250 r271  
    153153     *  @param mixed object_name  The name of a PHP class, or 
    154154     *                            an object instance of that class 
    155      *  @param string[] options Set of options: 'header_tag', 'id', 'class' 
     155     *  @param string[] options Set of options: 'header_tag', 'id', 'class', 'header_message', 'header_sub_message' 
    156156     *  @uses content_tag() 
    157157     *  @uses object_name 
     
    166166        $object = $this->controller_object->$object_name; 
    167167        if(!empty($object->errors)) { 
    168             $errors = ($num_errors = count($object->errors)) > 1 ? "$num_errors errors" : "$num_errors error"; 
     168            $id = isset($options['id']) ? $options['id'] : "ErrorExplanation"; 
     169            $class = isset($options['class']) ? $options['class'] : "ErrorExplanation"; 
     170            $header_tag = isset($options['header_tag']) ? $options['header_tag'] : "h2"; 
     171            $header_message = isset($options['header_message']) ?  
     172                $options['header_message'] : "%s prohibited this %s from being saved"; 
     173            $header_sub_message = isset($options['header_sub_message']) ? 
     174                $options['header_sub_message'] : "There were problems with the following fields:"; 
     175                
    169176            return $this->content_tag("div", 
    170177                $this->content_tag( 
    171                     (isset($options['header_tag']) ? $options['header_tag'] : "h2"), 
    172                     $errors .  
    173                     " prohibited this " . Inflector::humanize($object_name) . " from being saved" 
     178                    $header_tag, 
     179                    sprintf($header_message, Inflector::pluralize("error", count($object->errors)), Inflector::humanize($object_name)) 
    174180                ) . 
    175181                $this->content_tag("p", "There were problems with the following fields:") . 
    176182                $this->content_tag("ul", array_reduce($object->errors, create_function('$v,$w', 'return ($v ? $v : "") . content_tag("li", $w);'), '')), 
    177                 array("id" => (isset($options['id']) ? $options['id'] : "ErrorExplanation"), "class" => (isset($options['class']) ? $options['class'] : "ErrorExplanation")) 
     183                array("id" => $id, "class" => $class) 
    178184            ); 
    179185        }