| 2 | | # $Id$ |
| 3 | | # |
| 4 | | # Copyright (c) 2005 John Peterson |
| 5 | | # |
| 6 | | # Permission is hereby granted, free of charge, to any person obtaining |
| 7 | | # a copy of this software and associated documentation files (the |
| 8 | | # "Software"), to deal in the Software without restriction, including |
| 9 | | # without limitation the rights to use, copy, modify, merge, publish, |
| 10 | | # distribute, sublicense, and/or sell copies of the Software, and to |
| 11 | | # permit persons to whom the Software is furnished to do so, subject to |
| 12 | | # the following conditions: |
| 13 | | # |
| 14 | | # The above copyright notice and this permission notice shall be |
| 15 | | # included in all copies or substantial portions of the Software. |
| 16 | | # |
| 17 | | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 20 | | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 21 | | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 22 | | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 23 | | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 | | |
| | 2 | /** |
| | 3 | * File containing ActiveRecordHelper class and support functions |
| | 4 | * |
| | 5 | * (PHP 5) |
| | 6 | * |
| | 7 | * @package PHPonTrax |
| | 8 | * @version $Id$ |
| | 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 | |
| | 31 | /** |
| | 32 | * |
| | 33 | * @package PHPonTrax |
| | 34 | */ |
| 41 | | # Returns an entire form with input tags and everything for a specified Active Record object. Example |
| 42 | | # (post is a new record that has a title using VARCHAR and a body using TEXT): |
| 43 | | # form("post") => |
| 44 | | # <form action='/post/create' method='post'> |
| 45 | | # <p> |
| 46 | | # <label for="post_title">Title</label><br /> |
| 47 | | # <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /> |
| 48 | | # </p> |
| 49 | | # <p> |
| 50 | | # <label for="post_body">Body</label><br /> |
| 51 | | # <textarea cols="40" id="post_body" name="post[body]" rows="20"> |
| 52 | | # Back to the hill and over it again! |
| 53 | | # </textarea> |
| 54 | | # </p> |
| 55 | | # <input type='submit' value='Create' /> |
| 56 | | # </form> |
| 57 | | # |
| 58 | | # It's possible to specialize the form builder by using a different action name and by supplying another |
| 59 | | # block renderer. Example (entry is a new record that has a message attribute using VARCHAR): |
| 60 | | # |
| 61 | | # form("entry", array('action' => "sign", 'input_block' => |
| 62 | | # 'foreach($record->content_columns() as $column_name => $column) $contents .= Inflector::humanize($column_name) . ": " . input($record, $column) . "<br />"')) => |
| 63 | | # |
| 64 | | # <form action='/post/sign' method='post'> |
| 65 | | # Message: |
| 66 | | # <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /><br /> |
| 67 | | # <input type='submit' value='Sign' /> |
| 68 | | # </form> |
| 69 | | # |
| 70 | | # It's also possible to add additional content to the form by giving it a block, such as: |
| 71 | | # |
| 72 | | # form("entry", array('action' => "sign", 'block' => |
| 73 | | # content_tag("b", "Department") . |
| 74 | | # collection_select("department", "id", $departments, "id", "name")) |
| 75 | | # ) |
| | 56 | /** |
| | 57 | * Returns an entire form with input tags and everything for a specified Active Record object. Example |
| | 58 | * (post is a new record that has a title using VARCHAR and a body using TEXT): |
| | 59 | * form("post") => |
| | 60 | * <form action='/post/create' method='post'> |
| | 61 | * <p> |
| | 62 | * <label for="post_title">Title</label><br /> |
| | 63 | * <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /> |
| | 64 | * </p> |
| | 65 | * <p> |
| | 66 | * <label for="post_body">Body</label><br /> |
| | 67 | * <textarea cols="40" id="post_body" name="post[body]" rows="20"> |
| | 68 | * Back to the hill and over it again! |
| | 69 | * </textarea> |
| | 70 | * </p> |
| | 71 | * <input type='submit' value='Create' /> |
| | 72 | * </form> |
| | 73 | * |
| | 74 | * It's possible to specialize the form builder by using a different action name and by supplying another |
| | 75 | * block renderer. Example (entry is a new record that has a message attribute using VARCHAR): |
| | 76 | * |
| | 77 | * form("entry", array('action' => "sign", 'input_block' => |
| | 78 | * 'foreach($record->content_columns() as $column_name => $column) $contents .= Inflector::humanize($column_name) . ": " . input($record, $column) . "<br />"')) => |
| | 79 | * |
| | 80 | * <form action='/post/sign' method='post'> |
| | 81 | * Message: |
| | 82 | * <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /><br /> |
| | 83 | * <input type='submit' value='Sign' /> |
| | 84 | * </form> |
| | 85 | * |
| | 86 | * It's also possible to add additional content to the form by giving it a block, such as: |
| | 87 | * |
| | 88 | * form("entry", array('action' => "sign", 'block' => |
| | 89 | * content_tag("b", "Department") . |
| | 90 | * collection_select("department", "id", $departments, "id", "name")) |
| | 91 | * ) |
| | 92 | */ |
| 91 | | /* # Returns a string containing the error message attached to the +method+ on the +object+, if one exists. |
| 92 | | # This error message is wrapped in a DIV tag, which can be specialized to include both a +prepend_text+ and +append_text+ |
| 93 | | # to properly introduce the error and a +css_class+ to style it accordingly. Examples (post has an error message |
| 94 | | # "can't be empty" on the title attribute): |
| 95 | | # |
| 96 | | # <?= error_message_on("post", "title") ?> => |
| 97 | | # <div class="formError">can't be empty</div> |
| 98 | | # |
| 99 | | # <?= error_message_on "post", "title", "Title simply ", " (or it won't work)", "inputError" ?> => |
| 100 | | # <div class="inputError">Title simply can't be empty (or it won't work)</div> */ |
| | 108 | /** |
| | 109 | * Returns a string containing the error message attached to the +method+ on the +object+, if one exists. |
| | 110 | * This error message is wrapped in a DIV tag, which can be specialized to include both a +prepend_text+ and +append_text+ |
| | 111 | * to properly introduce the error and a +css_class+ to style it accordingly. Examples (post has an error message |
| | 112 | * "can't be empty" on the title attribute): |
| | 113 | * |
| | 114 | * <?= error_message_on("post", "title") ?> => |
| | 115 | * <div class="formError">can't be empty</div> |
| | 116 | * |
| | 117 | * <?= error_message_on "post", "title", "Title simply ", " (or it won't work)", "inputError" ?> => |
| | 118 | * <div class="inputError">Title simply can't be empty (or it won't work)</div> |
| | 119 | */ |
| 110 | | # Returns a string with a div containing all the error messages for the object located as an instance variable by the name |
| 111 | | # of <tt>object_name</tt>. This div can be tailored by the following options: |
| 112 | | # |
| 113 | | # * <tt>header_tag</tt> - Used for the header of the error div (default: h2) |
| 114 | | # * <tt>id</tt> - The id of the error div (default: errorExplanation) |
| 115 | | # * <tt>class</tt> - The class of the error div (default: errorExplanation) |
| | 129 | /** |
| | 130 | * Returns a string with a div containing all the error messages for the object located as an instance variable by the name |
| | 131 | * of <tt>object_name</tt>. This div can be tailored by the following options: |
| | 132 | * |
| | 133 | * <tt>header_tag</tt> - Used for the header of the error div (default: h2) |
| | 134 | * <tt>id</tt> - The id of the error div (default: errorExplanation) |
| | 135 | * <tt>class</tt> - The class of the error div (default: errorExplanation) |
| | 136 | */ |