PHPonTrax
[ class tree: PHPonTrax ] [ index: PHPonTrax ] [ all elements ]

Source for file active_record_helper.php

Documentation is available at active_record_helper.php

  1. <?php
  2. /**
  3.  *  File containing ActiveRecordHelper class and support functions
  4.  *
  5.  *  (PHP 5)
  6.  *
  7.  *  @package PHPonTrax
  8.  *  @version $Id: active_record_helper.php 277 2007-01-22 11:55:57Z john $
  9.  *  @copyright (c) 2005 John Peterson
  10.  *
  11.  *   Permission is hereby granted, free of charge, to any person obtaining
  12.  *   a copy of this software and associated documentation files (the
  13.  *   "Software"), to deal in the Software without restriction, including
  14.  *   without limitation the rights to use, copy, modify, merge, publish,
  15.  *   distribute, sublicense, and/or sell copies of the Software, and to
  16.  *   permit persons to whom the Software is furnished to do so, subject to
  17.  *   the following conditions:
  18.  *
  19.  *   The above copyright notice and this permission notice shall be
  20.  *   included in all copies or substantial portions of the Software.
  21.  *
  22.  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23.  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24.  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25.  *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26.  *   LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27.  *   OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28.  *   WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29.  *
  30.  *  @package PHPonTrax
  31.  */
  32.  
  33. /**
  34.  *  @todo Document this class
  35.  */
  36. class ActiveRecordHelper extends Helpers {
  37.     
  38.     /**
  39.      *  Whether to generate scaffolding HTML
  40.      *
  41.      *  Set to true in {@link form_scaffolding.phtml}.  If true
  42.      *  generate HTML scaffold otherwise generate final HTML
  43.      *  @var boolean 
  44.      */
  45.     public $scaffolding = false;
  46.  
  47.     /**
  48.      *  Returns a default input tag for the type of object returned by the method. Example
  49.      *  (title is a VARCHAR column and holds "Hello World"):
  50.      *   input("post", "title") =>
  51.      *     <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />
  52.      *  @uses to_tag()
  53.      */
  54.     function input($object_name$attribute_name$options array()) {
  55.         return $this->to_tag($object_name$attribute_name$options);        
  56.     }
  57.     
  58.     /**
  59.      *  @todo Document this method
  60.      *  @uses to_scaffold_tag()
  61.      */
  62.     function input_scaffolding($object_name$attribute_name$options array()) {
  63.         return $this->to_scaffold_tag($object_name$attribute_name$options);        
  64.     }
  65.  
  66.     /**
  67.      * Returns an entire form with input tags and everything for a specified Active Record object. Example
  68.      * (post is a new record that has a title using VARCHAR and a body using TEXT):
  69.      *   form("post") =>
  70.      *     <form action='/post/create' method='post'>
  71.      *       <p>
  72.      *         <label for="post_title">Title</label><br />
  73.      *         <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />
  74.      *       </p>
  75.      *       <p>
  76.      *         <label for="post_body">Body</label><br />
  77.      *         <textarea cols="40" id="post_body" name="post[body]" rows="20">
  78.      *           Back to the hill and over it again!
  79.      *         </textarea>
  80.      *       </p>
  81.      *       <input type='submit' value='Create' />
  82.      *     </form>
  83.      *
  84.      *  It's possible to specialize the form builder by using a different action name and by supplying another
  85.      *  block renderer. Example (entry is a new record that has a message attribute using VARCHAR):
  86.      *
  87.      *   form("entry", array('action' => "sign", 'input_block' =>
  88.      *        'foreach($record->content_columns() as $column_name => $column) $contents .= Inflector::humanize($column_name) . ": " . input($record, $column) . "<br />"')) =>
  89.      *
  90.      *     <form action='/post/sign' method='post'>
  91.      *       Message:
  92.      *       <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /><br />
  93.      *       <input type='submit' value='Sign' />
  94.      *     </form>
  95.      *
  96.      *  It's also possible to add additional content to the form by giving it a block, such as:
  97.      *
  98.      *   form("entry", array('action' => "sign", 'block' =>
  99.      *     content_tag("b", "Department") .
  100.      *     collection_select("department", "id", $departments, "id", "name"))
  101.      *   )
  102.      *  @uses all_input_tags()
  103.      *  @uses content_tag()
  104.      *  @uses Helpers::object()
  105.      */
  106.     function form($record_name$options array()) {
  107.         $record $this->object($record_name);
  108.         $options["action"$options[":action"$options[":action"$record->is_new_record("add" "save";
  109.         $action url_for(array(':action' => $options[':action']':id' => $record->id));
  110.         $submit_value (isset($options['submit_value']$options['submit_value'ucfirst(preg_replace('/[^\w]/'''$options[':action'])));
  111.  
  112.         $contents '';
  113.         if(!$record->is_new_record()) $contents .= hidden_field($record_name'id');
  114.         $contents .= $this->all_input_tags($record$record_name$options);
  115.         if(isset($options['block'])) $contents .= eval($options['block']);
  116.         $contents .= "<br>".submit_tag($submit_value)."<br><br>";
  117.  
  118.         return $this->content_tag('form'$contentsarray('action' => $action'method' => 'post'));
  119.     }
  120.  
  121.     /**
  122.      *  Returns a string containing the error message attached to the +method+ on the +object+, if one exists.
  123.      *  This error message is wrapped in a DIV tag, which can be specialized to include both a +prepend_text+ and +append_text+
  124.      *  to properly introduce the error and a +css_class+ to style it accordingly. Examples (post has an error message
  125.      *  "can't be empty" on the title attribute):
  126.      *
  127.      *   <?= error_message_on("post", "title") ?> =>
  128.      *     <div class="formError">can't be empty</div>
  129.      *
  130.      *   <?= error_message_on "post", "title", "Title simply ", " (or it won't work)", "inputError" ?> =>
  131.      *     <div class="inputError">Title simply can't be empty (or it won't work)</div>
  132.      *  @uses attribute_name
  133.      *  @uses controller_object
  134.      *  @uses content_tag()
  135.      *  @uses object_name
  136.      */
  137.     function error_message_on($object_name$attribute_name$prepend_text ""$append_text ""$css_class "formError"{
  138.         $this->object_name = $object_name;
  139.         $this->attribute_name = $attribute_name;
  140.         $object $this->controller_object->$object_name;
  141.         if($errors $object->errors[$attribute_name]{
  142.             return $this->content_tag("div"$prepend_text (is_array($errorscurrent($errors$errors$append_textarray('class' => $css_class));
  143.         }
  144.     }
  145.  
  146.     /**
  147.      *  Returns a string with a div containing all the error messages for the object located as an instance variable by the name
  148.      *  of <tt>object_name</tt>. This div can be tailored by the following options:
  149.      *
  150.      * <tt>header_tag</tt> - Used for the header of the error div (default: h2)
  151.      * <tt>id</tt> - The id of the error div (default: errorExplanation)
  152.      * <tt>class</tt> - The class of the error div (default: errorExplanation)
  153.      *  @param mixed object_name  The name of a PHP class, or
  154.      *                             an object instance of that class
  155.      *  @param string[] options Set of options: 'header_tag', 'id', 'class', 'header_message', 'header_sub_message'
  156.      *  @uses content_tag()
  157.      *  @uses object_name
  158.      *  @uses Inflector::humanize()
  159.      */
  160.     function error_messages_for($object_name$options array()) {
  161.         if(is_object($object_name)) {
  162.             $object_name get_class($object_name);
  163.             //echo "object name:".$object_name;
  164.         }
  165.         $this->object_name = $object_name;
  166.         $object $this->controller_object->$object_name;
  167.         if(!empty($object->errors)) {
  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.                
  176.             return $this->content_tag("div",
  177.                 $this->content_tag(
  178.                     $header_tag,
  179.                     sprintf($header_messageInflector::pluralize("error"count($object->errors))Inflector::humanize($object_name))
  180.                 .
  181.                 $this->content_tag("p"$header_sub_message.
  182.                 $this->content_tag("ul"array_reduce($object->errorscreate_function('$v,$w''return ($v ? $v : "") . content_tag("li", $w);')'')),
  183.                 array("id" => $id"class" => $class)
  184.             );
  185.         }
  186.     }
  187.  
  188.     /**
  189.      *  @todo Document this method
  190.      *  @uses default_input_block()
  191.      */
  192.     function all_input_tags($record$record_name$options{
  193.         //if($record_name) $this->object_name = $record_name;
  194.         $input_block (isset($options['input_block']$options['input_block'$this->default_input_block());
  195.         $contents '';
  196.         if(is_array($record->content_columns)) {
  197.             foreach($record->content_columns as $column{
  198.                 //$contents .= "<p><label for=\"".$record_name."_".$column['name']."\">";
  199.                 //$contents .= Inflector::humanize($column['name']) . ":</label><br />";
  200.                 //$contents .= input($record_name, $column['name']) . "</p>\n";
  201.                 if(!in_array($column['name']$record->primary_keys)) {
  202.                     eval($input_block"\n";    
  203.                 }         
  204.             }
  205.         
  206.         return $contents;
  207.     }
  208.  
  209.     /**
  210.      *  @todo Document this method
  211.      *  @uses scaffolding
  212.      *  @uses input_scaffolding()
  213.      */
  214.     function default_input_block({
  215.         if($this->scaffolding{
  216.             return '$contents .= "<p><label for=\"{$record_name}_{$column[\'name\']}\">" . Inflector::humanize($column[\'name\']) . ":</label><br/>\n<?= " . input_scaffolding($record_name, $column[\'name\']) . " ?></p>\n";';
  217.         else {
  218.             return '$contents .= "<p><label for=\"{$record_name}_{$column[\'name\']}\">" . Inflector::humanize($column[\'name\']) . ":</label><br/>\n" . input($record_name, $column[\'name\']) . "</p>\n";';
  219.         }
  220.     }
  221.     
  222.     /**
  223.      *  @todo Document this method
  224.      *
  225.      *  @param string object_name    Name of an ActiveRecord subclass
  226.      *  @param string attribute_name Name of an attribute of $object_name
  227.      *  @param string[] options
  228.      *  @uses attribute_name
  229.      *  @uses column_type()
  230.      *  @uses error_wrapping()
  231.      *  @uses object_name
  232.      *  @uses DateHelper::to_date_select_tag()
  233.      *  @uses FormHelper::to_boolean_select_tag()
  234.      *  @uses FormHelper::to_input_field_tag()
  235.      *  @uses FormHelper::to_text_area_tag()
  236.      *  @uses to_datetime_select_tag()
  237.      *  @uses object()
  238.      */
  239.     function to_tag($object_name$attribute_name$options array()) {
  240.         $this->object_name = $object_name;
  241.         $this->attribute_name = $attribute_name;
  242.         $form new FormHelper($object_name$attribute_name);
  243.         switch($this->column_type()) {
  244.         case 'string':
  245.         case 'varchar':
  246.         case 'varchar2':
  247.             $field_type (eregi("password"$this->attribute_name"password" "text");
  248.             $results $form->to_input_field_tag($field_type$options);
  249.             break;
  250.  
  251.         case 'text':
  252.         case 'blob':
  253.             $results $form->to_text_area_tag($options);
  254.             break;
  255.  
  256.         case 'integer':
  257.         case 'int':
  258.         case 'number':
  259.         case 'float':
  260.         case 'real':
  261.             $results $form->to_input_field_tag("text"$options);
  262.             break;
  263.  
  264.         case 'date':
  265.             $form new DateHelper($object_name$attribute_name);
  266.             $results $form->to_date_select_tag($options);
  267.             break;
  268.  
  269.         case 'datetime':
  270.         case 'timestamp':
  271.             $results $this->to_datetime_select_tag($options);
  272.             break;
  273.  
  274.         case 'boolean':
  275.         case 'bool':
  276.             $results $form->to_boolean_select_tag($options);
  277.             break;
  278.  
  279.         }
  280.         if(count($this->object()->errors)) {
  281.             $results $this->error_wrapping($results$this->object()->errors[$this->attribute_name]);
  282.         }
  283.         return $results;      
  284.     }
  285.  
  286.     /**
  287.      *  @todo Document this method
  288.      *
  289.      *  @uses attribute_name
  290.      *  @uses column_type()
  291.      *  @uses error_wrapping
  292.      *  @uses object()
  293.      *  @uses object_name
  294.      */
  295.     function to_scaffold_tag($object_name$attribute_name$options array()) {
  296.         $this->object_name = $object_name;
  297.         $this->attribute_name = $attribute_name;
  298.         switch($this->column_type()) {
  299.         case 'string':
  300.         case 'varchar':
  301.         case 'varchar2':
  302.             $field_type (eregi("password"$this->attribute_name"password" "text");
  303.             $results $field_type."_field(\"$object_name\", \"$attribute_name\")";
  304.             break;
  305.  
  306.         case 'text':
  307.         case 'blob':
  308.             $results "text_area(\"$object_name\", \"$attribute_name\")";
  309.             break;
  310.  
  311.         case 'integer':
  312.         case 'int':
  313.         case 'number':
  314.         case 'float':
  315.         case 'real':
  316.             $results "text_field(\"$object_name\", \"$attribute_name\")";
  317.             break;
  318.  
  319.         case 'date':
  320.             $results "date_select(\"$object_name\", \"$attribute_name\")";
  321.             break;
  322.  
  323.         case 'year':
  324.             $results "year_select(\"$object_name\", \"$attribute_name\")";
  325.             break;
  326.  
  327.         case 'datetime':
  328.         case 'timestamp':
  329.             $results "datetime_select(\"$object_name\", \"$attribute_name\")";
  330.             break;
  331.  
  332.         case 'time':
  333.             $results "time_select(\"$object_name\", \"$attribute_name\")";
  334.             break;
  335.  
  336.         case 'boolean':
  337.         case 'bool':
  338.             $results "boolean_select(\"$object_name\", \"$attribute_name\")";
  339.             break;
  340.  
  341.         default:
  342.             echo "No case statement for ".$this->column_type()."\n";
  343.         }
  344.         if(count($this->object()->errors)) {
  345.             $results $this->error_wrapping($results
  346.                               $this->object()->errors[$this->attribute_name]);
  347.         }
  348.         return $results;
  349.     }
  350.  
  351.     /**
  352.      *  @todo Document this method
  353.      *
  354.      *  @uses tag()
  355.      */
  356.     function tag_without_error_wrapping({
  357.         $args func_get_args();
  358.         return call_user_func_array(array(parent'tag')$args);
  359.     }
  360.  
  361.     /**
  362.      *  @todo Document this method
  363.      *
  364.      *  @uses error_wrapping()
  365.      *  @uses object()
  366.      *  @uses tag_without_error_wrapping()
  367.      */
  368.     function tag($name$options array()) {
  369.         if(count($this->object()->errors)) {
  370.             return $this->error_wrapping($this->tag_without_error_wrapping($name$options)$this->object()->errors[$this->attribute_name]);
  371.         else {
  372.             return $this->tag_without_error_wrapping($name$options);
  373.         }
  374.     }
  375.  
  376.     /**
  377.      *  @todo Document this method
  378.      *
  379.      *  @uses content_tag()
  380.      */
  381.     function content_tag_without_error_wrapping({
  382.         $args func_get_args();
  383.         return call_user_func_array('content_tag'$args);
  384.     }
  385.  
  386.     /**
  387.      *  @todo Document this method
  388.      *
  389.      *  @uses object()
  390.      *  @uses error_wrapping()
  391.      *  @uses content_tag_without_error_wrapping()
  392.      */
  393.     function content_tag($name$value$options array()) {
  394.         if (count($this->object()->errors)) {
  395.             return $this->error_wrapping(
  396.           $this->content_tag_without_error_wrapping($name$value$options),
  397.             array_key_exists($this->attribute_name,$this->object()->errors)
  398.             ? true false);
  399.         else {
  400.             return $this->content_tag_without_error_wrapping($name$value,
  401.                                                              $options);
  402.         }
  403.     }
  404.  
  405.     /**
  406.      *  @todo Document this method
  407.      *
  408.      *  @uses object_name
  409.      *  @uses attribute_name
  410.      *  @uses DateHelper::to_date_select_tag()
  411.      */
  412.         $form new DateHelper($this->object_name$this->attribute_name);
  413.         $args func_get_args();
  414.         return call_user_func_array(array($form'to_date_select_tag')$args);
  415.     }
  416.  
  417.     /**
  418.      *  @todo Document this method
  419.      */
  420.     function to_date_select_tag($options array()) {
  421.         if (count($this->object()->errors)) {
  422.             return $this->error_wrapping($this->to_date_select_tag_without_error_wrapping($options)$this->object()->errors[$this->attribute_name]);
  423.         else {
  424.             return $this->to_date_select_tag_without_error_wrapping($options);
  425.         }
  426.     }
  427.  
  428.     /**
  429.      *  @todo Document this method
  430.      *
  431.      *  @uses attribute_name
  432.      *  @uses object_name
  433.      *  @uses DateHelper::to_datetime_select_tag()
  434.      */
  435.         $form new DateHelper($this->object_name$this->attribute_name);
  436.         $args func_get_args();
  437.         return call_user_func_array(array($form'to_datetime_select_tag'),
  438.                                     $args);
  439.     }
  440.  
  441.     /**
  442.      *  @todo Document this method
  443.      *
  444.      *  @uses attribute_name
  445.      *  @uses error_wrapping()
  446.      *  @uses object()
  447.      *  @uses to_datetime_select_tag_without_error_wrapping
  448.      */
  449.     function to_datetime_select_tag($options array()) {
  450.         if (count($this->object()->errors)) {
  451.             return $this->error_wrapping($this->to_datetime_select_tag_without_error_wrapping($options)$this->object()->errors[$this->attribute_name]);
  452.         else {
  453.             return $this->to_datetime_select_tag_without_error_wrapping($options);
  454.         }
  455.     }
  456.  
  457.     /**
  458.      *  @todo Document this method
  459.      *
  460.      *  @uses attribute_name
  461.      *  @uses object()
  462.      */
  463.     function error_message({
  464.         return $this->object()->errors[$this->attribute_name];
  465.     }
  466.  
  467.     /**
  468.      *  @todo Document this method
  469.      *
  470.      *  @uses attribute_name
  471.      *  @uses object()
  472.      *  @uses ActiveRecord::column_type()
  473.      */
  474.     function column_type({
  475.         return $this->object()->column_type($this->attribute_name);
  476.     }
  477.     
  478.     /**
  479.      * Paging html functions
  480.      *  @todo Document this API
  481.      */
  482.     function pagination_limit_select($object_name_or_object$default_text "per page:"{
  483.  
  484.         if(is_object($object_name_or_object)) {
  485.             $object $object_name_or_object;
  486.         else {
  487.             $object $this->object($object_name_or_object);  
  488.         }
  489.  
  490.         if(!is_object($object)) {
  491.             return null;    
  492.         }
  493.  
  494.         if($object->pages 0{
  495.             $html .= "
  496.                 <select name=\"per_page\" onChange=\"document.location = '?".escape_javascript($object->paging_extra_params)."&per_page=' + this.options[this.selectedIndex].value;\">
  497.                     <option value=\"$object->rows_per_page\" selected>$default_text</option>
  498.                     <option value=10>10</option>
  499.                     <option value=20>20</option>
  500.                     <option value=50>50</option>
  501.                     <option value=100>100</option>
  502.                     <option value=999999999>ALL</option>
  503.                 </select>
  504.             ";
  505.         }
  506.         return $html;
  507.     }
  508.  
  509.     /**
  510.      *  @todo Document this API
  511.      *
  512.      *  @return string HTML to link to previous and next pages
  513.      *  @uses $display
  514.      *  @uses $page
  515.      *  @uses $pages
  516.      *  @uses $paging_extra_params
  517.      *  @uses rows_per_page
  518.      */
  519.     function pagination_links($object_name_or_object{
  520.         
  521.         if(is_object($object_name_or_object)) {
  522.             $object $object_name_or_object;
  523.         else {
  524.             $object $this->object($object_name_or_object);  
  525.         }
  526.  
  527.         if(!is_object($object)) {
  528.             return null;    
  529.         }
  530.            
  531.         //$html  = "<pre>".print_r($object,1);
  532.         /* Print the first and previous page links if necessary */
  533.         if(($object->page != 1&& ($object->page)) {
  534.             $html .= link_to("<<"
  535.                                   "?$object->paging_extra_params&page=1&per_page=$object->rows_per_page",
  536.                                   array(
  537.                                     "class" => "pageList",
  538.                                     "title" => "First page"
  539.                                   ))." ";
  540.         }
  541.         if(($object->page-10{
  542.             $html .= link_to("<"
  543.                                   "?$object->paging_extra_params&page=".($object->page-1)."&per_page=$object->rows_per_page",
  544.                                   array(
  545.                                     "class" => "pageList",
  546.                                     "title" => "Previous Page"                                    
  547.                                   ));
  548.         }
  549.         
  550.         if($object->pages $object->display{
  551.             $object->display $object->pages;
  552.         }
  553.         
  554.         if($object->page == $object->pages{
  555.             if(($object->pages $object->display== 0{
  556.                 $start 1;
  557.             else {
  558.                 $start $object->pages $object->display;
  559.             }
  560.             $end $object->pages;
  561.         else {
  562.             if($object->page >= $object->display{
  563.                 $start $object->page ($object->display 2);
  564.                 $end   $object->page (($object->display 21);
  565.             else {
  566.                 $start 1;
  567.                 $end   $object->display;
  568.             }
  569.         }
  570.  
  571.         if($end >= $object->pages{
  572.             $end $object->pages;
  573.         }
  574.                 
  575.         /* Print the numeric page list; make the current page unlinked and bold */
  576.         if($end != 1{
  577.             for($i=$start$i<=$end$i++{
  578.                 if($i == $object->page{
  579.                     $html .= "<span class=\"pageList\"><b>".$i."</b></span>";
  580.                 else {
  581.                     $html .= link_to($i,
  582.                                           "?$object->paging_extra_params&page=$i&per_page=$object->rows_per_page",
  583.                                           array(
  584.                                             "class" => "pageList",
  585.                                             "title" => "Page $i"                                           
  586.                                           ));
  587.                 }
  588.                 $html .= " ";
  589.             }
  590.         }
  591.  
  592.         /* Print the Next and Last page links if necessary */
  593.         if(($object->page+1<= $object->pages{
  594.             $html .= link_to(">",
  595.                                   "?$object->paging_extra_params&page=".($object->page+1)."&per_page=$object->rows_per_page",
  596.                                   array(
  597.                                     "class" => "pageList",
  598.                                     "title" => "Next Page"                                    
  599.                                   ));
  600.         }
  601.         if(($object->page != $object->pages&& ($object->pages != 0)) {
  602.             $html .= link_to(">>",
  603.                                   "?$object->paging_extra_params&page=".$object->pages."&per_page=$object->rows_per_page",
  604.                                   array(
  605.                                     "class" => "pageList",
  606.                                     "title" => "Last Page"                                    
  607.                                   ));
  608.         }
  609.         $html .= "\n";
  610.  
  611.         return $html;
  612.     }    
  613.         
  614.     function pagination_range_text($object_name_or_object$format "Showing %d - %d of %d items."{
  615.         if(is_object($object_name_or_object)) {
  616.             $object $object_name_or_object;
  617.         else {
  618.             $object $this->object($object_name_or_object);
  619.         }
  620.  
  621.         if(!is_object($object)) {
  622.             return null;
  623.         }
  624.         $end $object->rows_per_page $object->page;
  625.         $start $end ($object->rows_per_page 1);
  626.         if($end >= $object->pagination_count{
  627.             $end $object->pagination_count;
  628.         }
  629.  
  630.         return $object->pagination_count sprintf($format$start$end$object->pagination_countnull;
  631.     }    
  632.  
  633. }
  634.  
  635. /**
  636.  *  Avialble functions for use in views
  637.  * error_message_on($object, $attribute_name, $prepend_text = "", $append_text = "", $css_class = "formError")
  638.  *  @uses ActiveRecordHelper::error_message_on()
  639.  */
  640. function error_message_on({
  641.     $ar_helper new ActiveRecordHelper();
  642.     $args func_get_args();
  643.     return call_user_func_array(array($ar_helper'error_message_on')$args);
  644. }
  645.  
  646. /**
  647.  *  error_messages_for($object_name, $options = array())
  648.  *  @uses ActiveRecordHelper::error_messages_for()
  649.  */
  650. function error_messages_for({
  651.     $ar_helper new ActiveRecordHelper();
  652.     $args func_get_args();
  653.     return call_user_func_array(array($ar_helper'error_messages_for')$args);
  654. }
  655.  
  656. /**
  657.  *  form($record_name, $options = array())
  658.  *  @uses ActiveRecordHelper::form()
  659.  */
  660. function form({
  661.     $ar_helper new ActiveRecordHelper();
  662.     $args func_get_args();
  663.     return call_user_func_array(array($ar_helper'form')$args);
  664. }
  665.  
  666. /**
  667.  *  Returns a default input tag for the type of object returned by the method. Example
  668.  *  (title is a VARCHAR column and holds "Hello World"):
  669.  *   input("post", "title") =>
  670.  *    <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />
  671.  *  @uses ActiveRecordHelper::input()
  672.  */
  673. function input({
  674.     $ar_helper new ActiveRecordHelper();
  675.     $args func_get_args();
  676.     return call_user_func_array(array($ar_helper'input')$args);
  677. }
  678.  
  679. /**
  680.  *
  681.  *  @uses ActiveRecordHelper::input_scaffolding()
  682.  */
  683. function input_scaffolding({
  684.     $ar_helper new ActiveRecordHelper();
  685.     $args func_get_args();
  686.     return call_user_func_array(array($ar_helper'input_scaffolding')$args);
  687. }
  688.  
  689. /**
  690.  *
  691.  *  @uses ActiveRecordHelper::pagination_limit_select()
  692.  */
  693.     $ar_helper new ActiveRecordHelper();
  694.     $args func_get_args();
  695.     return call_user_func_array(array($ar_helper'pagination_limit_select')$args);
  696. }
  697.  
  698. /**
  699.  *
  700.  *  @uses ActiveRecordHelper::pagination_links()
  701.  */
  702. function pagination_links({
  703.     $ar_helper new ActiveRecordHelper();
  704.     $args func_get_args();
  705.     return call_user_func_array(array($ar_helper'pagination_links')$args);
  706. }
  707.  
  708. /**
  709.  *
  710.  *  @uses ActiveRecordHelper::pagination_range_text()
  711.  */
  712. function pagination_range_text({
  713.     $ar_helper new ActiveRecordHelper();
  714.     $args func_get_args();
  715.     return call_user_func_array(array($ar_helper'pagination_range_text')$args);
  716. }
  717.  
  718. // -- set Emacs parameters --
  719. // Local variables:
  720. // tab-width: 4
  721. // c-basic-offset: 4
  722. // c-hanging-comment-ender-p: nil
  723. // indent-tabs-mode: nil
  724. // End:
  725. ?>

Documentation generated on Mon, 21 May 2007 22:28:06 -0600 by phpDocumentor 1.3.2