Changeset 138

Show
Ignore:
Timestamp:
02/23/06 20:09:13 (6 years ago)
Author:
john
Message:

added in phpDoc commenting tests docs - Walt

Location:
trunk/trax
Files:
28 modified

Legend:

Unmodified
Added
Removed
  • trunk/trax/app/application_mailer.php

    r117 r138  
    11<?php 
    2 # The filters added to this controller will be run for all controllers in the application. 
    3 # Likewise will all the methods added be available for all controllers. 
     2/** 
     3 *  Filters for all controllers 
     4 * 
     5 *  The filters added to this controller will be run for all 
     6 *  controllers in the application.  Likewise will all the methods 
     7 *  added be available for all controllers. 
     8 * 
     9 *  @package PHPonTrax 
     10 */ 
     11 
     12/** 
     13 *  @package PHPonTrax 
     14 */ 
    415class ApplicationMailer extends ActionMailer {   
    516    
  • trunk/trax/app/controllers/application.php

    r117 r138  
    11<?php 
    2 # The filters added to this controller will be run for all controllers in the application. 
    3 # Likewise will all the methods added be available for all controllers. 
     2/** 
     3 *  File containing the ApplicationController class 
     4 * 
     5 *  @package PHPonTrax 
     6 */ 
     7 
     8/** 
     9 *  Controller for an application 
     10 * 
     11 *  The filters added to this controller will be run for all 
     12 *  controllers in the application.  Likewise will all the methods 
     13 *  added be available for all controllers. 
     14 *  @package PHPonTrax 
     15 */ 
    416class ApplicationController extends ActionController { 
    517 
  • trunk/trax/app/helpers/application_helper.php

    r117 r138  
    11<?php 
    2 # Anything added to this helper will be available to all templates in the application. 
    3  
     2/** 
     3 *  Helpers for the whole application 
     4 * 
     5 *  Anything added to this helper will be available to all templates in 
     6 *  the application. 
     7 * 
     8 *  @package PHPonTrax 
     9 */ 
    410?> 
  • trunk/trax/config/environment.php

    r121 r138  
    11<?php 
    2  
     2/** 
     3 *  @package PHPonTrax 
     4 */ 
    35# include path for your php libs (PEAR etc) 
    46define("PHP_LIB_ROOT",          "/usr/local/lib/php"); 
  • trunk/trax/config/environments/development.php

    r117 r138  
    11<?php 
    2 // put all the global 'development' settings for this application in this file 
    3  
    4  
     2/** 
     3 * Put all the global 'development' settings for this application in this file 
     4 * 
     5 *  @package PHPonTrax 
     6 */ 
    57?> 
  • trunk/trax/config/environments/production.php

    r117 r138  
    11<?php 
    2 // put all the global 'production' settings for this application in this file 
    3  
     2/** 
     3 *  Put all the global 'production' settings for this application in this file 
     4 * 
     5 *  @package PHPonTrax 
     6 */ 
    47 
    58?> 
  • trunk/trax/config/environments/test.php

    r117 r138  
    11<?php 
    2 // put all the global 'test' settings for this application in this file 
     2/** 
     3 *  Put all the global 'test' settings for this application in this file 
     4 * 
     5 *  @package PHPonTrax 
     6 */ 
    37 
    48 
  • trunk/trax/config/routes.php

    r117 r138  
    11<?php                        
    2 # Add your own custom routes here. 
    3 # The priority is based upon order of creation: first created -> highest priority. 
    4  
    5 # Here's a sample route: 
    6 # $router->connect( "products/:id", array(":controller" => "catalog", ":action" => "view") ); 
    7  
    8 # You can have the root of your site routed by hooking up "". 
    9 # Just remember to delete public_html/index.html. 
    10 # $router->connect( "", array(":controller" => "welcome") ); 
    11  
    12 # Install the default route as the lowest priority. 
     2/** 
     3 *  Add your own custom routes here. 
     4 *  The priority is based upon order of creation: first created -> 
     5 *  highest priority.  
     6 * 
     7 *  Here's a sample route: 
     8 *  $router->connect( "products/:id", 
     9 *                    array(":controller" => "catalog", 
     10 "                    :action" => "view") );  
     11 * 
     12 *  You can have the root of your site routed by hooking up "". 
     13 *  Just remember to delete public_html/index.html. 
     14 *  $router->connect( "", array(":controller" => "welcome") ); 
     15 * 
     16 *  Install the default route as the lowest priority. 
     17 * 
     18 *  @package PHPonTrax 
     19 */ 
    1320$router->connect( ":controller/:action/:id" ); 
    1421 
  • trunk/trax/script/generate.php

    r117 r138  
    11#! /usr/local/bin/php 
    22<?php 
    3 # $Id$ 
    4 # 
    5 # Copyright (c) 2005 John Peterson 
    6 # 
    7 # Permission is hereby granted, free of charge, to any person obtaining 
    8 # a copy of this software and associated documentation files (the 
    9 # "Software"), to deal in the Software without restriction, including 
    10 # without limitation the rights to use, copy, modify, merge, publish, 
    11 # distribute, sublicense, and/or sell copies of the Software, and to 
    12 # permit persons to whom the Software is furnished to do so, subject to 
    13 # the following conditions: 
    14 # 
    15 # The above copyright notice and this permission notice shall be 
    16 # included in all copies or substantial portions of the Software. 
    17 # 
    18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
    19 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
    20 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
    21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
    22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
    23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
    24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
    25  
     3/** 
     4 *  Command line script to generate a Trax application 
     5 * 
     6 *  (PHP 5) 
     7 * 
     8 *  @package PHPonTrax 
     9 *  @version $Id$ 
     10 *  @copyright (c) 2005 John Peterson 
     11 * 
     12 *  Permission is hereby granted, free of charge, to any person obtaining 
     13 *  a copy of this software and associated documentation files (the 
     14 *  "Software"), to deal in the Software without restriction, including 
     15 *  without limitation the rights to use, copy, modify, merge, publish, 
     16 *  distribute, sublicense, and/or sell copies of the Software, and to 
     17 *  permit persons to whom the Software is furnished to do so, subject to 
     18 *  the following conditions: 
     19 * 
     20 *  The above copyright notice and this permission notice shall be 
     21 *  included in all copies or substantial portions of the Software. 
     22 * 
     23 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
     24 *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
     25 *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
     26 *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
     27 *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
     28 *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
     29 *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
     30 * 
     31 * 
     32 *  <p>Sets up the Trax environment, creates a {@link TraxGenerator} 
     33 *  object and calls its run() method to process the command line 
     34 *  arguments to the script</p> 
     35 * 
     36 *  <p>Invoked from the command line by</p> 
     37 *  <p> 
     38 *  <samp>php script/generate.php</samp> <i>command [ arguments... ]</i> 
     39 *  </p> 
     40 * 
     41 *  <p>See the {@link TraxGenerator} class definition for valid values 
     42 *  of <i>command [ arguments... ]</i></p> 
     43 */ 
    2644if (substr(PHP_OS, 0, 3) == 'WIN') { 
    2745    ini_set("include_path",ini_get("include_path").";".dirname(dirname(__FILE__))."/lib");  
     
    2947    ini_set("include_path",ini_get("include_path").":".dirname(dirname(__FILE__)) . "/lib"); 
    3048}  
     49 
     50/** 
     51 *  Load definitions of the Trax environment from {@link environment.php} 
     52 */ 
    3153require_once(dirname(dirname(__FILE__)) . "/config/environment.php"); 
     54 
     55/** 
     56 *  Load definition of the {@link TraxGenerator} class 
     57 */ 
    3258require_once("trax_generator.php"); 
    3359 
  • trunk/trax/vendor/trax/action_controller.php

    r128 r138  
    11<?php 
    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 ActionController class 
     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 *  Action controller 
     33 * 
     34 *  <p><b>Filters</b></p> 
     35 * 
     36 *  <p>Filters enable controllers to run shared pre and post 
     37 *  processing code for its actions. These filters can be used to do 
     38 *  authentication, caching, or auditing before the intended action is 
     39 *  performed. Or to do localization or output compression after the 
     40 *  action has been performed.</p> 
     41 * 
     42 *  <p>Filters have access to the request, response, and all the 
     43 *  instance variables set by other filters in the chain or by the 
     44 *  action (in the case of after filters). Additionally, it's possible 
     45 *  for a pre-processing <samp>before_filter</samp> to halt the processing 
     46 *  before the intended action is processed by returning false or 
     47 *  performing a redirect or render.  This is especially useful for 
     48 *  filters like authentication where you're not interested in 
     49 *  allowing the action to be  performed if the proper credentials are 
     50 *  not in order.</p> 
     51 * 
     52 *  <p><b>Filter inheritance</b></p> 
     53 * 
     54 *  <p>Controller inheritance hierarchies share filters downwards, but 
     55 *  subclasses can also add new filters without affecting the 
     56 *  superclass. For example:</p> 
     57 * 
     58 *  <pre> 
     59 *   class BankController extends ActionController 
     60 *   { 
     61 *     $this->before_filter = audit(); 
     62 * 
     63 *     private function audit() { 
     64 *       <i>record the action and parameters in an audit log</i> 
     65 *     } 
     66 *   } 
     67 * 
     68 *   class VaultController extends BankController 
     69 *   { 
     70 *     $this->before_filter = verify_credentials(); 
     71 * 
     72 *     private function verify_credentials() { 
     73 *       <i>make sure the user is allowed into the vault</i> 
     74 *     } 
     75 *   } 
     76 *  </pre> 
     77 * 
     78 *  <p>Now any actions performed on the BankController will have the 
     79 *  audit method called before. On the VaultController, first the 
     80 *  audit method is called, then the verify_credentials method. If the 
     81 *  audit method returns false, then verify_credentials and the 
     82 *  intended action are never called.</p> 
     83 * 
     84 *  <p><b>Filter types</b></p> 
     85 * 
     86 *  <p>A filter can take one of three forms: method reference 
     87 *  (symbol), external class, or inline method (proc). The first is the 
     88 *  most common and works by referencing a protected or private method 
     89 *  somewhere in the inheritance hierarchy of the controller by use of 
     90 *  a symbol. In the bank example above, both BankController and 
     91 *  VaultController use this form.</p> 
     92 * 
     93 *  <p>Using an external class makes for more easily reused generic 
     94 *  filters, such as output compression. External filter classes are 
     95 *  implemented by having a static +filter+ method on any class and 
     96 *  then passing this class to the filter method. Example:</p> 
     97 * 
     98 *  <pre> 
     99 *   class OutputCompressionFilter 
     100 *   { 
     101 *     static functionfilter(controller) { 
     102 *       controller.response.body = compress(controller.response.body) 
     103 *     } 
     104 *   } 
     105 * 
     106 *   class NewspaperController extends ActionController 
     107 *   { 
     108 *     $this->after_filter = OutputCompressionFilter; 
     109 *   } 
     110 *  </pre> 
     111 * 
     112 *  <p>The filter method is passed the controller instance and is 
     113 *  hence granted access to all aspects of the controller and can 
     114 *  manipulate them as it sees fit.</p> 
     115 * 
     116 *  <p>The inline method (using a proc) can be used to quickly do 
     117 *  something small that doesn't require a lot of explanation.  Or 
     118 *  just as a quick test. It works like this:</p> 
     119 * 
     120 *  <pre> 
     121 *   class WeblogController extends ActionController 
     122 *   { 
     123 *     before_filter { |controller| false if controller.params["stop_action"] } 
     124 *   } 
     125 *  </pre> 
     126 * 
     127 *  <p>As you can see, the block expects to be passed the controller 
     128 *  after it has assigned the request to the internal variables.  This 
     129 *  means that the block has access to both the request and response 
     130 *  objects complete with convenience methods for params, session, 
     131 *  template, and assigns. Note: The inline method doesn't strictly 
     132 *  have to be a block; any object that responds to call and returns 1 
     133 *  or -1 on arity will do (such as a Proc or an Method object).</p> 
     134 * 
     135 *  <p><b>Filter chain skipping</b></p> 
     136 * 
     137 *  <p>Some times its convenient to specify a filter chain in a superclass  
     138 *  that'll hold true for the majority of the subclasses, but not necessarily 
     139 *  all of them. The subclasses that behave in exception can then specify 
     140 *  which filters they would like to be relieved of. Examples</p> 
     141 * 
     142 *  <pre> 
     143 *   class ApplicationController extends ActionController 
     144 *   { 
     145 *     $this->before_filter = authenticate(); 
     146 *   } 
     147 * 
     148 *   class WeblogController extends ApplicationController 
     149 *   { 
     150 *      // will run the authenticate() filter 
     151 *   } 
     152 *  </pre> 
     153 * 
     154 *  <p><b>Filter conditions</b></p> 
     155 * 
     156 *  <p>Filters can be limited to run for only specific actions. This 
     157 *  can be expressed either by listing the actions to exclude or 
     158 *  the actions to include when executing the filter. Available 
     159 *  conditions are +:only+ or +:except+, both of which accept an 
     160 *  arbitrary number of method references. For example:</p> 
     161 * 
     162 *  <pre> 
     163 *   class Journal extends ActionController 
     164 *   { 
     165 *     // only require authentication if the current action is edit or delete 
     166 *     before_filter :authorize, :only => [ :edit, :delete ] 
     167 *     
     168 *     private function authorize() { 
     169 *      // redirect to login unless authenticated 
     170 *     } 
     171 *   } 
     172 *  </pre> 
     173 *  
     174 *  <p>When setting conditions on inline method (proc) filters the 
     175 *  condition must come first and be placed in parentheses.</p> 
     176 * 
     177 *  <pre> 
     178 *   class UserPreferences extends ActionController 
     179 *   { 
     180 *     before_filter(:except => :new) { ? some proc ... } 
     181 *  * ... 
     182 *   } 
     183 *  </pre> 
     184 * 
     185 *  @package PHPonTrax 
     186 */ 
    25187class ActionController { 
    26188 
     
    340502    } 
    341503 
     504    /** 
     505     *  Execute the before filters 
     506     */ 
    342507    function execute_before_filters() { 
    343508        if(count($this->controller_object->before_filters) > 0) {  
     
    350515    } 
    351516 
     517    /** 
     518     *  Append a before filter to the filter chain 
     519     * 
     520     *  @param mixed $filter_function_name  String with the name of 
     521     *  one filter function, or array of strings with the names of 
     522     *  several filter functions. 
     523     */ 
    352524    function add_before_filter($filter_function_name) { 
    353525        if(is_string($filter_function_name) && !empty($filter_function_name)) { 
     
    374546    } 
    375547 
     548 
     549    /** 
     550     *  Append an after filter to the filter chain 
     551     * 
     552     *  @param mixed $filter_function_name  String with the name of 
     553     *  one filter function, or array of strings with the names of 
     554     *  several filter functions. 
     555     */ 
    376556    function add_after_filter($filter_function_name) { 
    377557        if(is_string($filter_function_name) && !empty($filter_function_name)) { 
     
    394574    } 
    395575 
     576    /** 
     577     *  Rendering partials 
     578     *  
     579     *  <p>Partial rendering is most commonly used together with Ajax 
     580     *  calls that only update one or a few elements on a page without 
     581     *  reloading. Rendering of partials from the controller makes it 
     582     *  possible to use the same partial template in both the 
     583     *  full-page rendering (by calling it from within the template) 
     584     *  and when sub-page updates happen (from the controller action 
     585     *  responding to Ajax calls). By default, the current layout is 
     586     *  not used.</p> 
     587     * 
     588     *  <ul> 
     589     *    <li><samp>render_partial("win");</samp><br> 
     590     *      Renders the partial 
     591     *      located at app/views/controller/_win.r(html|xml)</li> 
     592     * 
     593     *    <li><samp>render_partial("win", 
     594     *       array("locals" => array("name" => "david")));</samp><br> 
     595     *      Renders the same partial but also makes a local variable 
     596     *      available to it</li> 
     597     *      
     598     *    <li><samp>render_partial("win", 
     599     *      array("collection" => array(...)));</samp><br> 
     600     *      Renders a collection of the same partial by making each 
     601     *      element of the collection available through the local variable 
     602     *      "win" as it builds the complete response </li> 
     603     * 
     604     *    <li><samp>render_partial("win", array("collection" => @wins, 
     605     *      "spacer_template" => "win_divider"));</samp><br> 
     606     *      Renders the same collection of partials, but also renders 
     607     *      the win_divider partial in between each win partial.</li> 
     608     *  </ul> 
     609     *  @param string $path Path to file containing partial view 
     610     *  @param string[] $options Options array 
     611     */ 
    396612    function render_partial($path, $options = array()) { 
    397613        if(strstr($path, "/")) { 
     
    479695    } 
    480696 
     697    /** 
     698     *  Raise an ActionControllerError exception 
     699     * 
     700     *  @param string $error_message Error message 
     701     *  @param string $error_heading Error heading 
     702     *  @param string $error_code    Error code 
     703     *  @throws ActionControllerError 
     704     */ 
    481705    function raise($error_message, $error_heading, $error_code = "404") { 
    482706        throw new ActionControllerError("Error Message: ".$error_message, $error_heading, $error_code); 
    483707    } 
    484708 
     709    /** 
     710     *  Generate an HTML page describing an error 
     711     */ 
    485712    function process_with_exception(&$exception) { 
    486713        $error_code = $exception->error_code; 
  • trunk/trax/vendor/trax/action_mailer.php

    r117 r138  
    11<?php 
    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 for ActionMailer class 
     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 */ 
    2534include_once( "Mail.php" ); 
    2635include_once( "Mail/mime.php" ); 
    2736 
     37/** 
     38 * 
     39 *  @package PHPonTrax 
     40 */ 
    2841class ActionMailer { 
    2942 
  • trunk/trax/vendor/trax/action_view.php

    r117 r138  
    11<?php 
    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. 
     2/** 
     3 *  File to include ActionView files 
     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 */ 
    2430 
    25 # Include the base helper class 
     31/** 
     32 * Include the base helper class 
     33 */ 
    2634include_once(TRAX_LIB_ROOT . "/action_view/helpers.php"); 
    27 # Include all the sub helper classes 
     35 
     36/** 
     37 * Include all the sub helper classes 
     38 */ 
    2839include_once(TRAX_LIB_ROOT . "/action_view/helpers/url_helper.php"); 
    2940include_once(TRAX_LIB_ROOT . "/action_view/helpers/form_helper.php"); 
  • trunk/trax/vendor/trax/action_view/helpers.php

    r128 r138  
    11<?php 
    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. 
     2/** 
     3 *  File containing the Helpers class and associated 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 */ 
    2430 
     31/** 
     32 * 
     33 *  @package PHPonTrax 
     34 */ 
    2535class Helpers { 
    2636 
     37    /** 
     38     * 
     39     */ 
    2740    function __construct() { 
    2841        $this->controller_name = $GLOBALS['current_controller_name']; 
     
    3144    } 
    3245 
     46    /** 
     47     * 
     48     */ 
    3349    function tag_options($options) { 
    3450        if(count($options)) { 
     
    4359    } 
    4460 
    45     # Example: tag("br"); 
    46     # Results: <br /> 
    47     # Example: tag("input", array("type" => "text")); 
    48     # <input type="text" /> 
     61    /** 
     62     *  Generate an HTML or XML tag with optional attributes 
     63     * 
     64     *  Example: tag("br"); 
     65     *   Results: <br /> 
     66     *  Example: tag("input", array("type" => "text")); 
     67     * <input type="text" /> 
     68     */ 
    4969    function tag($name, $options = array(), $open = false) { 
    5070        $html = "<$name "; 
     
    5474    } 
    5575 
    56     # Example: content_tag("p", "Hello world!"); 
    57     # Result: <p>Hello world!</p> 
    58     # Example: content_tag("div", content_tag("p", "Hello world!"), array("class" => "strong")) => 
    59     # Result:<div class="strong"><p>Hello world!</p></div> 
     76    /** 
     77     *  Generate an open/close pair of tags with content between 
     78     * 
     79     *  Example: content_tag("p", "Hello world!"); 
     80     *  Result: <p>Hello world!</p> 
     81     *  Example: content_tag("div", content_tag("p", "Hello world!"), array("class" => "strong")) => 
     82     *  Result:<div class="strong"><p>Hello world!</p></div> 
     83     */ 
    6084    function content_tag($name, $content, $options = array()) { 
    6185        $html .= "<$name "; 
     
    6589    } 
    6690 
    67     # Returns the URL for the set of $options provided. 
     91    /** 
     92     *  Return the URL for the set of $options provided. 
     93     */ 
    6894    function url_for($options = array()) { 
    6995        $url_base = null; 
     
    132158} 
    133159 
    134  
    135 ################################################################################################ 
    136 ## Avialble functions for use in views 
    137 ################################################################################################ 
     160/** 
     161 *  Avialble functions for use in views 
     162 */ 
    138163function content_tag() { 
    139164    $helper = new Helpers(); 
     
    142167} 
    143168 
     169/** 
     170 * 
     171 */ 
    144172function url_for($options = array()) { 
    145173    $helper = new Helpers(); 
  • trunk/trax/vendor/trax/action_view/helpers/active_record_helper.php

    r128 r138  
    11<?php 
    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 */ 
    2535class ActiveRecordHelper extends Helpers { 
    2636     
    2737    public $scaffolding = 0; 
    2838 
    29     # Returns a default input tag for the type of object returned by the method. Example 
    30     # (title is a VARCHAR column and holds "Hello World"): 
    31     #   input("post", "title") => 
    32     #     <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /> 
     39    /** 
     40     *  Returns a default input tag for the type of object returned by the method. Example 
     41     *  (title is a VARCHAR column and holds "Hello World"): 
     42     *   input("post", "title") => 
     43     *     <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /> 
     44     */ 
    3345    function input($object_name, $attribute_name, $options = array()) { 
    3446        return $this->to_tag($object_name, $attribute_name, $options);         
    3547    } 
    3648     
     49    /** 
     50     * 
     51     */ 
    3752    function input_scaffolding($object_name, $attribute_name, $options = array()) { 
    3853        return $this->to_scaffold_tag($object_name, $attribute_name, $options);         
    3954    } 
    4055 
    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     */ 
    7693    function form($record_name, $options = array()) { 
    7794        $record = $this->object($record_name); 
     
    89106    } 
    90107 
    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     */ 
    101120    function error_message_on($object_name, $attribute_name, $prepend_text = "", $append_text = "", $css_class = "formError") { 
    102121        $this->object_name = $object_name; 
     
    108127    } 
    109128 
    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     */ 
    116137    function error_messages_for($object_name, $options = array()) { 
    117138        if(is_object($object_name)) { 
     
    136157    } 
    137158 
     159    /** 
     160     * 
     161     */ 
    138162    function all_input_tags($record, $record_name, $options) { 
    139163        //if($record_name) $this->object_name = $record_name; 
     
    153177    } 
    154178 
     179    /** 
     180     * 
     181     */ 
    155182    function default_input_block() { 
    156183        if($this->scaffolding) { 
     
    161188    } 
    162189     
     190    /** 
     191     * 
     192     */ 
    163193    function to_tag($object_name, $attribute_name, $options = array()) { 
    164194        $this->object_name = $object_name; 
     
    200230    } 
    201231 
     232    /** 
     233     * 
     234     */ 
    202235    function to_scaffold_tag($object_name, $attribute_name, $options = array()) { 
    203236        $this->object_name = $object_name; 
     
    237270    } 
    238271 
     272    /** 
     273     * 
     274     */ 
    239275    function object($object_name = null) { 
    240276        $object_name = $object_name ? $object_name : $this->object_name; 
     
    244280    } 
    245281 
     282    /** 
     283     * 
     284     */ 
    246285    function tag_without_error_wrapping() { 
    247286        $args = func_get_args(); 
     
    249288    } 
    250289 
     290    /** 
     291     * 
     292     */ 
    251293    function tag($name, $options = array()) { 
    252294        if(count($this->object()->errors)) { 
     
    257299    } 
    258300 
     301    /** 
     302     * 
     303     */ 
    259304    function content_tag_without_error_wrapping() { 
    260305        $args = func_get_args(); 
     
    262307    } 
    263308 
     309    /** 
     310     * 
     311     */ 
    264312    function content_tag($name, $value, $options = array()) { 
    265313        if (count($this->object()->errors)) { 
     
    270318    } 
    271319 
     320    /** 
     321     * 
     322     */ 
    272323    function to_date_select_tag_without_error_wrapping() { 
    273324        $form = new DateHelper($this->object_name, $this->attribute_name); 
     
    276327    } 
    277328 
     329    /** 
     330     * 
     331     */ 
    278332    function to_date_select_tag($options = array()) { 
    279333        if (count($this->object()->errors)) { 
     
    284338    } 
    285339 
     340    /** 
     341     * 
     342     */ 
    286343    function to_datetime_select_tag_without_error_wrapping() { 
    287344        $form = new DateHelper($this->object_name, $this->attribute_name); 
     
    290347    } 
    291348 
     349    /** 
     350     * 
     351     */ 
    292352    function to_datetime_select_tag($options = array()) { 
    293353        if (count($this->object()->errors)) { 
     
    298358    } 
    299359 
     360    /** 
     361     * 
     362     */ 
    300363    function error_wrapping($html_tag, $has_error) { 
    301364        return ($has_error ? '<span class="fieldWithErrors">' . $html_tag . '</span>' : $html_tag); 
    302365    } 
    303366 
     367    /** 
     368     * 
     369     */ 
    304370    function error_message() { 
    305371        return $this->object()->errors[$this->attribute_name]; 
    306372    } 
    307373 
     374    /** 
     375     * 
     376     */ 
    308377    function column_type() { 
    309378        $column = $this->object()->column_for_attribute($this->attribute_name); 
     
    313382} 
    314383 
    315 ################################################################################################ 
    316 ## Avialble functions for use in views 
    317 ################################################################################################ 
    318 # error_message_on($object, $attribute_name, $prepend_text = "", $append_text = "", $css_class = "formError") 
     384/** 
     385 * Avialble functions for use in views 
     386 * error_message_on($object, $attribute_name, $prepend_text = "", $append_text = "", $css_class = "formError") 
     387 */ 
    319388function error_message_on() { 
    320389    $ar_helper = new ActiveRecordHelper(); 
     
    323392} 
    324393 
    325 # error_messages_for($object_name, $options = array()) 
     394/** 
     395 * error_messages_for($object_name, $options = array()) 
     396 */ 
    326397function error_messages_for() { 
    327398    $ar_helper = new ActiveRecordHelper(); 
     
    330401} 
    331402 
    332 # form($record_name, $options = array()) 
     403/** 
     404 *  form($record_name, $options = array()) 
     405 */ 
    333406function form() { 
    334407    $ar_helper = new ActiveRecordHelper(); 
     
    337410} 
    338411 
    339 # Returns a default input tag for the type of object returned by the method. Example 
    340 # (title is a VARCHAR column and holds "Hello World"): 
    341 #   input("post", "title") => 
    342 #     <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /> 
     412/** 
     413 *  Returns a default input tag for the type of object returned by the method. Example 
     414 *  (title is a VARCHAR column and holds "Hello World"): 
     415 *   input("post", "title") => 
     416 *    <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /> 
     417 */ 
    343418function input() { 
    344419    $ar_helper = new ActiveRecordHelper(); 
     
    347422} 
    348423 
     424/** 
     425 * 
     426 */ 
    349427function input_scaffolding() { 
    350428    $ar_helper = new ActiveRecordHelper(); 
  • trunk/trax/vendor/trax/action_view/helpers/date_helper.php

    r131 r138  
    11<?php 
    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 the DateHelper 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 */ 
    2535class DateHelper extends Helpers { 
    2636    public $selected_years = array(); 
     37    /** 
     38     * 
     39     */ 
    2740    function __construct($object_name = null, $attribute_name = null) { 
    2841        parent::__construct(); 
     
    3144    } 
    3245 
     46    /** 
     47     * 
     48     */ 
    3349    private function value() { 
    3450        if(!$value = $this->check_request_for_value()) { 
     
    6682    } 
    6783 
     84    /** 
     85     * 
     86     */ 
    6887    private function object($object_name = null) { 
    6988        $object_name = $object_name ? $object_name : $this->object_name; 
     
    7190    } 
    7291 
     92    /** 
     93     * 
     94     */ 
    7395    private function select_html($type, $options, $prefix = null, $include_blank = false, $discard_type = false) { 
    7496        $select_html  = "<select name=\"$prefix";        
     
    85107    } 
    86108 
     109    /** 
     110     * 
     111     */ 
    87112    private function leading_zero_on_single_digits($number) { 
    88113        return $number > 9 ? $number : "0$number"; 
     
    93118    } 
    94119         
    95     #   datetime_select("post", "written_on") 
    96     #   datetime_select("post", "written_on", array("start_year" => 1995)) 
     120    /** 
     121     *   datetime_select("post", "written_on") 
     122     *   datetime_select("post", "written_on", array("start_year" => 1995)) 
     123     */ 
    97124    function datetime_select($options = array()) {      
    98125        return $this->to_datetime_select_tag($options); 
    99126    }  
    100127     
    101     #   datetime_select("post", "written_on") 
    102     #   datetime_select("post", "written_on", array("start_year" => 1995)) 
     128    /** 
     129     *   datetime_select("post", "written_on") 
     130     *   datetime_select("post", "written_on", array("start_year" => 1995)) 
     131     */ 
    103132    function date_select($options = array()) {    
    104133        return $this->to_date_select_tag($options); 
     
    125154    }                
    126155 
    127     # Returns a set of html select-tags (one for year, month, and day) pre-selected with the +date+. 
     156    /** 
     157     * Returns a set of html select-tags (one for year, month, and day) pre-selected with the +date+. 
     158     */ 
    128159    function select_date($date = null, $options = array()) { 
    129160        $date = is_null($date) ? date("Y-m-d") : $date; 
     
    133164    } 
    134165 
    135     # Returns a set of html select-tags (one for year, month, day, hour, and minute) preselected the +datetime+. 
     166    /** 
     167     * Returns a set of html select-tags (one for year, month, day, hour, and minute) preselected the +datetime+. 
     168     */ 
    136169    function select_datetime($datetime = null, $options = array()) { 
    137170        $datetime = is_null($datetime) ? date("Y-m-d H:i:s") : $datetime; 
     
    143176    } 
    144177 
    145     # Returns a set of html select-tags (one for hour and minute) 
     178    /** 
     179     * Returns a set of html select-tags (one for hour and minute) 
     180     */ 
    146181    function select_time($datetime = null, $options = array()) { 
    147182        $datetime = is_null($datetime) ? date("Y-m-d H:i:s") : $datetime; 
     
    151186    } 
    152187 
    153     # Returns a select tag with options for each of the seconds 0 through 59 with the current second selected. 
    154     # The <tt>second</tt> can also be substituted for a second number. 
    155     # Override the field name using the <tt>:field_name</tt> option, 'second' by default. 
     188    /** 
     189     *  Returns a select tag with options for each of the seconds 0 through 59 with the current second selected. 
     190     *  The <tt>second</tt> can also be substituted for a second number. 
     191     *  Override the field name using the <tt>:field_name</tt> option, 'second' by default. 
     192     */ 
    156193    function select_second($datetime, $options = array()) { 
    157194        $second_options = ""; 
     
    175212    } 
    176213 
    177     # Returns a select tag with options for each of the minutes 0 through 59 with the current minute selected. 
    178     # Also can return a select tag with options by <tt>minute_step</tt> from 0 through 59 with the 00 minute selected 
    179     # The <tt>minute</tt> can also be substituted for a minute number. 
    180     # Override the field name using the <tt>:field_name</tt> option, 'minute' by default. 
     214    /** 
     215     *  Returns a select tag with options for each of the minutes 0 through 59 with the current minute selected. 
     216     *  Also can return a select tag with options by <tt>minute_step</tt> from 0 through 59 with the 00 minute selected 
     217     *  The <tt>minute</tt> can also be substituted for a minute number. 
     218     *  Override the field name using the <tt>:field_name</tt> option, 'minute' by default. 
     219     */ 
    181220    function select_minute($datetime, $options = array()) { 
    182221        $minute_options = ""; 
     
    200239    } 
    201240 
    202     # Returns a select tag with options for each of the hours 0 through 23 with the current hour selected. 
    203     # The <tt>hour</tt> can also be substituted for a hour number. 
    204     # Override the field name using the <tt>:field_name</tt> option, 'hour' by default. 
     241    /** 
     242     *  Returns a select tag with options for each of the hours 0 through 23 with the current hour selected. 
     243     *  The <tt>hour</tt> can also be substituted for a hour number. 
     244     *  Override the field name using the <tt>:field_name</tt> option, 'hour' by default. 
     245     */ 
    205246    function select_hour($datetime, $options = array()) { 
    206247        $hour_options = ""; 
     
    225266    } 
    226267 
    227     # Returns a select tag with options for each of the days 1 through 31 with the current day selected. 
    228     # The <tt>date</tt> can also be substituted for a hour number. 
    229     # Override the field name using the <tt>:field_name</tt> option, 'day' by default. 
     268    /** 
     269     *  Returns a select tag with options for each of the days 1 through 31 with the current day selected. 
     270     *  The <tt>date</tt> can also be substituted for a hour number. 
     271     *  Override the field name using the <tt>:field_name</tt> option, 'day' by default. 
     272     */ 
    230273    function select_day($datetime, $options = array()) { 
    231274        $day_options = ""; 
     
    249292    } 
    250293 
    251     # Returns a select tag with options for each of the months January through December with the current month selected. 
    252     # The month names are presented as keys (what's shown to the user) and the month numbers (1-12) are used as values 
    253     # (what's submitted to the server). It's also possible to use month numbers for the presentation instead of names -- 
    254     # set the <tt>:use_month_numbers</tt> key in +options+ to true for this to happen. If you want both numbers and names, 
    255     # set the <tt>:add_month_numbers</tt> key in +options+ to true. Examples: 
    256     # 
    257     #   select_month(Date.today)                             # Will use keys like "January", "March" 
    258     #   select_month(Date.today, :use_month_numbers => true) # Will use keys like "1", "3" 
    259     #   select_month(Date.today, :add_month_numbers => true) # Will use keys like "1 - January", "3 - March" 
    260     # 
    261     # Override the field name using the <tt>:field_name</tt> option, 'month' by default. 
     294    /** 
     295     *  Returns a select tag with options for each of the months January through December with the current month selected. 
     296     *  The month names are presented as keys (what's shown to the user) and the month numbers (1-12) are used as values 
     297     *  (what's submitted to the server). It's also possible to use month numbers for the presentation instead of names -- 
     298     *  set the <tt>:use_month_numbers</tt> key in +options+ to true for this to happen. If you want both numbers and names, 
     299     *  set the <tt>:add_month_numbers</tt> key in +options+ to true. Examples: 
     300     * 
     301     *   select_month(Date.today)                             # Will use keys like "January", "March" 
     302    *   select_month(Date.today, :use_month_numbers => true) # Will use keys like "1", "3" 
     303    *   select_month(Date.today, :add_month_numbers => true) # Will use keys like "1 - January", "3 - March" 
     304    * 
     305    *  Override the field name using the <tt>:field_name</tt> option, 'month' by default. 
     306   */ 
    262307    function select_month($date, $options = array()) { 
    263308        $month_options = ""; 
     
    287332    } 
    288333 
    289     # Returns a select tag with options for each of the five years on each side of the current, which is selected. The five year radius 
    290     # can be changed using the <tt>:start_year</tt> and <tt>:end_year</tt> keys in the +options+. Both ascending and descending year 
    291     # lists are supported by making <tt>:start_year</tt> less than or greater than <tt>:end_year</tt>. The <tt>date</tt> can also be 
    292     # substituted for a year given as a number. Example: 
    293     # 
    294     #   select_year(Date.today, :start_year => 1992, :end_year => 2007)  # ascending year values 
    295     #   select_year(Date.today, :start_year => 2005, :end_year => 1900)  # descending year values 
    296     # 
    297     # Override the field name using the <tt>:field_name</tt> option, 'year' by default. 
     334    /** 
     335     * Returns a select tag with options for each of the five years on each side of the current, which is selected. The five year radius 
     336     * can be changed using the <tt>:start_year</tt> and <tt>:end_year</tt> keys in the +options+. Both ascending and descending year 
     337     * lists are supported by making <tt>:start_year</tt> less than or greater than <tt>:end_year</tt>. The <tt>date</tt> can also be 
     338     * substituted for a year given as a number. Example: 
     339     * 
     340     *   select_year(Date.today, :start_year => 1992, :end_year => 2007)  # ascending year values 
     341    *   select_year(Date.today, :start_year => 2005, :end_year => 1900)  # descending year values 
     342    * 
     343    * Override the field name using the <tt>:field_name</tt> option, 'year' by default. 
     344    */ 
    298345    function select_year($date, $options = array()) { 
    299346        $year_options = ""; 
     
    320367    } 
    321368 
     369    /** 
     370     * 
     371     */ 
    322372    function to_date_select_tag($options = array()) { 
    323373        $defaults = array('discard_type' => true); 
     
    364414    } 
    365415 
     416    /** 
     417     * 
     418     */ 
    366419    function to_datetime_select_tag($options = array()) { 
    367420        $defaults = array('discard_type' => true); 
     
    405458} 
    406459 
    407 ################################################################################################ 
    408 ## Avialble functions for use in views 
    409 ################################################################################################ 
    410 # select_date($date = null, $options = array()) 
     460/** 
     461  * Avialble functions for use in views 
     462  *  select_date($date = null, $options = array()) 
     463  */ 
    411464function select_date() { 
    412465    $date_helper = new DateHelper(); 
     
    415468} 
    416469 
    417 # select_datetime($datetime = null, $options = array()) 
     470/** 
     471 *  Select_datetime($datetime = null, $options = array()) 
     472 */ 
    418473function select_datetime() { 
    419474    $date_helper = new DateHelper(); 
     
    422477} 
    423478 
    424 # select_expiration_date($datetime = null, $options = array()) 
     479/** 
     480 * select_expiration_date($datetime = null, $options = array()) 
     481 */ 
    425482function select_expiration_date() { 
    426483    $date_helper = new DateHelper(); 
     
    429486} 
    430487 
     488/** 
     489 * 
     490 */ 
    431491function datetime_select($object, $attribute, $options = array()) { 
    432492    $date_helper = new DateHelper($object, $attribute); 
     
    434494} 
    435495 
     496/** 
     497 * 
     498 */ 
    436499function date_select($object, $attribute, $options = array()) { 
    437500    $date_helper = new DateHelper($object, $attribute); 
  • trunk/trax/vendor/trax/action_view/helpers/form_helper.php

    r132 r138  
    11<?php 
    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 the FormHelper class 
     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 */ 
    2535class FormHelper extends Helpers { 
    2636 
     37    /** 
     38     * 
     39     */ 
    2740    function __construct($object_name, $attribute_name) { 
    2841        parent::__construct(); 
     
    3548    } 
    3649 
     50    /** 
     51     * 
     52     */ 
    3753    function value() { 
    3854        if(!$value = $_REQUEST[$this->object_name][$this->attribute_name]) { 
     
    4561    } 
    4662 
     63    /** 
     64     * 
     65     */ 
    4766    function object($object_name = null) { 
    4867        $object_name = $object_name ? $object_name : $this->object_name; 
     
    5069    } 
    5170 
     71    /** 
     72     * 
     73     */ 
    5274    function tag_name() { 
    5375        return "{$this->object_name}[{$this->attribute_name}]"; 
    5476    } 
    5577 
     78    /** 
     79     * 
     80     */ 
    5681    function tag_name_with_index($index) { 
    5782        return "{$this->object_name}[{$index}][{$this->attribute_name}]"; 
    5883    } 
    5984 
     85    /** 
     86     * 
     87     */ 
    6088    function tag_id() { 
    6189        return "{$this->object_name}_{$this->attribute_name}"; 
    6290    } 
    6391 
     92    /** 
     93     * 
     94     */ 
    6495    function tag_id_with_index($index) { 
    6596        return "{$this->object_name}_{$index}_{$this->attribute_name}"; 
    6697    } 
    6798 
     99    /** 
     100     * 
     101     */ 
    68102    function add_default_name_and_id($options) { 
    69103        if(array_key_exists("index", $options)) { 
     
    81115    } 
    82116 
     117    /** 
     118     * 
     119     */ 
    83120    function to_input_field_tag($field_type, $options = array()) { 
    84121        $default_size = $options["maxlength"] ? $options["maxlength"] : $this->default_field_options['size']; 
     
    96133    } 
    97134 
     135    /** 
     136     * 
     137     */ 
    98138    function to_radio_button_tag($tag_value, $options = array()) { 
    99139        $options = array_merge($this->default_radio_options, $options); 
     
    111151    } 
    112152 
     153    /** 
     154     * 
     155     */ 
    113156    function to_text_area_tag($options = array()) { 
    114157        if ($options["size"]) { 
     
    123166    } 
    124167 
     168    /** 
     169     * 
     170     */ 
    125171    function to_check_box_tag($options = array(), $checked_value = "1", $unchecked_value = "0") { 
    126172        $options["type"] = "checkbox"; 
     
    153199    } 
    154200 
     201    /** 
     202     * 
     203     */ 
    155204    function to_boolean_select_tag($options = array()) { 
    156205        $options = $this->add_default_name_and_id($options); 
     
    179228 
    180229 
    181 ################################################################################################ 
    182 ## Avialble functions for use in views 
    183 ################################################################################################ 
    184 # Example: text_field("post", "title"); 
    185 # Result: <input type="text" id="post_title" name="post[title]" value="$post->title" /> 
     230/** 
     231 * Avialble functions for use in views 
     232 *  Example: text_field("post", "title"); 
     233 *  Result: <input type="text" id="post_title" name="post[title]" value="$post->title" /> 
     234 */ 
    186235function text_field($object, $field, $options = array()) { 
    187236    $form = new FormHelper($object, $field); 
     
    189238} 
    190239 
    191 # Works just like text_field, but returns a input tag of the "password" type instead. 
    192 # Example: password_field("user", "password"); 
    193 # Result: <input type="password" id="user_password" name="user[password]" value="$user->password" /> 
     240/** 
     241 *  Works just like text_field, but returns a input tag of the "password" type instead. 
     242 * Example: password_field("user", "password"); 
     243 *  Result: <input type="password" id="user_password" name="user[password]" value="$user->password" /> 
     244 */ 
    194245function password_field($object, $field, $options = array()) { 
    195246    $form = new FormHelper($object, $field); 
     
    197248} 
    198249 
    199 # Works just like text_field, but returns a input tag of the "hidden" type instead. 
    200 # Example: hidden_field("post", "title"); 
    201 # Result: <input type="hidden" id="post_title" name="post[title]" value="$post->title" /> 
     250/** 
     251 *  Works just like text_field, but returns a input tag of the "hidden" type instead. 
     252 *  Example: hidden_field("post", "title"); 
     253 *  Result: <input type="hidden" id="post_title" name="post[title]" value="$post->title" /> 
     254 */ 
    202255function hidden_field($object, $field, $options = array()) { 
    203256    $form = new FormHelper($object, $field); 
     
    205258} 
    206259 
    207 # Works just like text_field, but returns a input tag of the "file" type instead, which won't have any default value. 
     260/** 
     261 * Works just like text_field, but returns a input tag of the "file" type instead, which won't have any default value. 
     262 */ 
    208263function file_field($object, $field, $options = array()) { 
    209264    $form = new FormHelper($object, $field); 
     
    211266} 
    212267 
    213 # Example: text_area("post", "body", array("cols" => 20, "rows" => 40)); 
    214 # Result: <textarea cols="20" rows="40" id="post_body" name="post[body]">$post->body</textarea> 
     268/** 
     269 *  Example: text_area("post", "body", array("cols" => 20, "rows" => 40)); 
     270 *  Result: <textarea cols="20" rows="40" id="post_body" name="post[body]">$post->body</textarea> 
     271 */ 
    215272function text_area($object, $field, $options = array()) { 
    216273    $form = new FormHelper($object, $field); 
     
    218275} 
    219276 
    220 # Returns a checkbox tag tailored for accessing a specified attribute (identified by $field) on an object 
    221 # assigned to the template (identified by $object). It's intended that $field returns an integer and if that 
    222 # integer is above zero, then the checkbox is checked. Additional $options on the input tag can be passed as an 
    223 # array with $options. The $checked_value defaults to 1 while the default $unchecked_value 
    224 # is set to 0 which is convenient for boolean values. Usually unchecked checkboxes don't post anything. 
    225 # We work around this problem by adding a hidden value with the same name as the checkbox. 
     277/** 
     278 * Returns a checkbox tag tailored for accessing a specified attribute (identified by $field) on an object 
     279 * assigned to the template (identified by $object). It's intended that $field returns an integer and if that 
     280 * integer is above zero, then the checkbox is checked. Additional $options on the input tag can be passed as an 
     281 * array with $options. The $checked_value defaults to 1 while the default $unchecked_value 
     282 * is set to 0 which is convenient for boolean values. Usually unchecked checkboxes don't post anything. 
     283 * We work around this problem by adding a hidden value with the same name as the checkbox. 
    226284# 
    227 # Example: Imagine that $post->validated is 1: 
    228 #   check_box("post", "validated"); 
    229 # Result: 
    230 #   <input type="checkbox" id="post_validate" name="post[validated] value="1" checked="checked" /> 
    231 #   <input name="post[validated]" type="hidden" value="0" /> 
     285 * Example: Imagine that $post->validated is 1: 
     286 *   check_box("post", "validated"); 
     287 * Result: 
     288 *   <input type="checkbox" id="post_validate" name="post[validated] value="1" checked="checked" /> 
     289 *   <input name="post[validated]" type="hidden" value="0" /> 
    232290# 
    233 # Example: Imagine that $puppy->gooddog is no: 
    234 #   check_box("puppy", "gooddog", array(), "yes", "no"); 
    235 # Result: 
    236 #     <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog] value="yes" /> 
    237 #     <input name="puppy[gooddog]" type="hidden" value="no" /> 
     291 * Example: Imagine that $puppy->gooddog is no: 
     292 *   check_box("puppy", "gooddog", array(), "yes", "no"); 
     293 * Result: 
     294 *     <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog] value="yes" /> 
     295 *     <input name="puppy[gooddog]" type="hidden" value="no" /> 
     296*/ 
    238297function check_box($object, $field, $options = array(), $checked_value = "1", $unchecked_value = "0") { 
    239298    $form = new FormHelper($object, $field); 
     
    241300} 
    242301 
    243 # Returns a radio button tag for accessing a specified attribute (identified by $field) on an object 
    244 # assigned to the template (identified by $object). If the current value of $field is $tag_value the 
    245 # radio button will be checked. Additional $options on the input tag can be passed as a 
    246 # hash with $options. 
    247 # Example: Imagine that $post->category is "trax": 
    248 #   radio_button("post", "category", "trax"); 
    249 #   radio_button("post", "category", "java"); 
    250 # Result: 
    251 #     <input type="radio" id="post_category" name="post[category] value="trax" checked="checked" /> 
    252 #     <input type="radio" id="post_category" name="post[category] value="java" /> 
     302/** 
     303 * Returns a radio button tag for accessing a specified attribute (identified by $field) on an object 
     304 * assigned to the template (identified by $object). If the current value of $field is $tag_value the 
     305 * radio button will be checked. Additional $options on the input tag can be passed as a 
     306 * hash with $options. 
     307 * Example: Imagine that $post->category is "trax": 
     308 *   radio_button("post", "category", "trax"); 
     309 *   radio_button("post", "category", "java"); 
     310 * Result: 
     311 *     <input type="radio" id="post_category" name="post[category] value="trax" checked="checked" /> 
     312 *     <input type="radio" id="post_category" name="post[category] value="java" /> 
     313*/ 
    253314function radio_button($object, $field, $tag_value, $options = array()) { 
    254315    $form = new FormHelper($object, $field); 
     
    256317} 
    257318 
     319/** 
     320 * 
     321 */ 
    258322function boolean_select($object, $field, $options = array()) { 
    259323    $form = new FormHelper($object, $field); 
  • trunk/trax/vendor/trax/action_view/helpers/form_options_helper.php

    r117 r138  
    11<?php 
    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  
    25 # All the countries included in the country_options output. 
     2/** 
     3 *  File containing the FormOptionsHelper 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 * All the countries included in the country_options output. 
     33 */ 
    2634if(!$GLOBALS['COUNTRIES']) { 
    2735    $GLOBALS['COUNTRIES'] =  
     
    7280} 
    7381 
     82/** 
     83 * 
     84 *  @package PHPonTrax 
     85 */ 
    7486class FormOptionsHelper extends FormHelper { 
    7587     
    76     # Accepts a container (hash, array, enumerable, your type) and returns a string of option tags. Given a container 
    77     # where the elements respond to first and last (such as a two-element array), the "lasts" serve as option values and 
    78     # the "firsts" as option text. Hashes are turned into this form automatically, so the keys become "firsts" and values 
    79     # become lasts. If +selected+ is specified, the matching "last" or element will get the selected option-tag.  +Selected+ 
    80     # may also be an array of values to be selected when using a multiple select. 
    81     # 
    82     # Examples (call, result): 
    83     #   options_for_select([["Dollar", "$"], ["Kroner", "DKK"]]) 
    84     #     <option value="$">Dollar</option>\n<option value="DKK">Kroner</option> 
    85     # 
    86     #   options_for_select([ "VISA", "MasterCard" ], "MasterCard") 
    87     #     <option>VISA</option>\n<option selected="selected">MasterCard</option> 
    88     # 
    89     #   options_for_select({ "Basic" => "$20", "Plus" => "$40" }, "$40") 
    90     #     <option value="$20">Basic</option>\n<option value="$40" selected="selected">Plus</option> 
    91     # 
    92     #   options_for_select([ "VISA", "MasterCard", "Discover" ], ["VISA", "Discover"]) 
    93     #     <option selected="selected">VISA</option>\n<option>MasterCard</option>\n<option selected="selected">Discover</option> 
    94     # 
    95     # NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag. 
     88    /** 
     89     *  Accepts a container (hash, array, enumerable, your type) and returns a string of option tags. Given a container 
     90     *  where the elements respond to first and last (such as a two-element array), the "lasts" serve as option values and 
     91     *  the "firsts" as option text. Hashes are turned into this form automatically, so the keys become "firsts" and values 
     92     *  become lasts. If +selected+ is specified, the matching "last" or element will get the selected option-tag.  +Selected+ 
     93     *  may also be an array of values to be selected when using a multiple select. 
     94     *  
     95     *  Examples (call, result): 
     96     *    options_for_select([["Dollar", "$"], ["Kroner", "DKK"]]) 
     97     *      <option value="$">Dollar</option>\n<option value="DKK">Kroner</option> 
     98     *  
     99     *    options_for_select([ "VISA", "MasterCard" ], "MasterCard") 
     100     *      <option>VISA</option>\n<option selected="selected">MasterCard</option> 
     101     *  
     102     *    options_for_select({ "Basic" => "$20", "Plus" => "$40" }, "$40") 
     103     *      <option value="$20">Basic</option>\n<option value="$40" selected="selected">Plus</option> 
     104     *  
     105     *    options_for_select([ "VISA", "MasterCard", "Discover" ], ["VISA", "Discover"]) 
     106     *      <option selected="selected">VISA</option>\n<option>MasterCard</option>\n<option selected="selected">Discover</option> 
     107     *  
     108     *  NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag. 
     109     */ 
    96110    function options_for_select($choices, $selected = null) { 
    97111        $options = array(); 
     
    113127    } 
    114128     
    115     # Returns a string of option tags that have been compiled by iterating over the +collection+ and assigning the 
    116     # the result of a call to the +value_method+ as the option value and the +text_method+ as the option text. 
    117     # If +selected_value+ is specified, the element returning a match on +value_method+ will get the selected option tag. 
    118     # 
    119     # Example (call, result). Imagine a loop iterating over each +person+ in <tt>@project.people</tt> to generate an input tag: 
    120     #   options_from_collection_for_select(@project.people, "id", "name") 
    121     #     <option value="#{person.id}">#{person.name}</option> 
    122     # 
    123     # NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag. 
     129    /** 
     130     * Returns a string of option tags that have been compiled by iterating over the +collection+ and assigning the 
     131     * the result of a call to the +value_method+ as the option value and the +text_method+ as the option text. 
     132     * If +selected_value+ is specified, the element returning a match on +value_method+ will get the selected option tag. 
     133     * 
     134     * Example (call, result). Imagine a loop iterating over each +person+ in <tt>@project.people</tt> to generate an input tag: 
     135     *   options_from_collection_for_select(@project.people, "id", "name") 
     136     *     <option value="#{person.id}">#{person.name}</option> 
     137     * 
     138     * NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag. 
     139     */ 
    124140    function options_from_collection_for_select($collection, $attribute_value, $attribute_text, $selected_value = null) { 
    125141        $options = array(); 
     
    134150    } 
    135151     
    136     # Returns a string of option tags for pretty much any country in the world. Supply a country name as +selected+ to 
    137     # have it marked as the selected option tag. You can also supply an array of countries as +priority_countries+, so 
    138     # that they will be listed above the rest of the (long) list. 
    139     # 
    140     # NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag. 
     152    /** 
     153     *  Returns a string of option tags for pretty much any country in the world. Supply a country name as +selected+ to 
     154     *  have it marked as the selected option tag. You can also supply an array of countries as +priority_countries+, so 
     155     *  that they will be listed above the rest of the (long) list. 
     156     * 
     157     *  NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag. 
     158     */ 
    141159    function country_options_for_select($selected = null, $priority_countries = array()) { 
    142160        $country_options = ""; 
     
    155173    } 
    156174     
     175    /** 
     176     * 
     177     */ 
    157178    function to_select_tag($choices, $options, $html_options) { 
    158179        $html_options = $this->add_default_name_and_id($html_options); 
     
    160181    } 
    161182     
     183    /** 
     184     * 
     185     */ 
    162186    function to_collection_select_tag($collection, $attribute_value, $attribute_text, $options, $html_options) { 
    163187        $html_options = $this->add_default_name_and_id($html_options); 
     
    165189    } 
    166190     
     191    /** 
     192     * 
     193     */ 
    167194    function to_country_select_tag($priority_countries, $options, $html_options) { 
    168195        $html_options = $this->add_default_name_and_id($html_options); 
     
    170197    } 
    171198 
     199    /** 
     200     * 
     201     */ 
    172202    private function add_options($option_tags, $options, $value = null) { 
    173203        if($options["include_blank"] == true) { 
     
    184214} 
    185215 
    186 ################################################################################################ 
    187 ## Avialble functions for use in views 
    188 ################################################################################################ 
    189 # Create a select tag and a series of contained option tags for the provided object and method. 
    190 # The option currently held by the object will be selected, provided that the object is available. 
    191 # See options_for_select for the required format of the choices parameter. 
    192 # 
    193 # Example with @post.person_id => 1: 
    194 #   select("post", "person_id", Person.find_all.collect {|p| [ p.name, p.id ] }, { :include_blank => true }) 
    195 # 
    196 # could become: 
    197 # 
    198 #   <select name="post[person_id"> 
    199 #     <option></option> 
    200 #     <option value="1" selected="selected">David</option> 
    201 #     <option value="2">Sam</option> 
    202 #     <option value="3">Tobias</option> 
    203 #   </select> 
    204 # 
    205 # This can be used to provide a functionault set of options in the standard way: before r}ering the create form, a 
    206 # new model instance is assigned the functionault options and bound to @model_name. Usually this model is not saved 
    207 # to the database. Instead, a second model object is created when the create request is received. 
    208 # This allows the user to submit a form page more than once with the expected results of creating multiple records. 
    209 # In addition, this allows a single partial to be used to generate form inputs for both edit and create forms. 
     216/** 
     217 * Avialble functions for use in views 
     218 * Create a select tag and a series of contained option tags for the provided object and method. 
     219 * The option currently held by the object will be selected, provided that the object is available. 
     220 * See options_for_select for the required format of the choices parameter. 
     221# 
     222 * Example with @post.person_id => 1: 
     223 *   select("post", "person_id", Person.find_all.collect {|p| [ p.name, p.id ] }, { :include_blank => true }) 
     224# 
     225 * could become: 
     226# 
     227 *   <select name="post[person_id"> 
     228 *     <option></option> 
     229 *     <option value="1" selected="selected">David</option> 
     230 *     <option value="2">Sam</option> 
     231 *     <option value="3">Tobias</option> 
     232 *   </select> 
     233# 
     234 * This can be used to provide a functionault set of options in the standard way: before r}ering the create form, a 
     235 * new model instance is assigned the functionault options and bound to @model_name. Usually this model is not saved 
     236 * to the database. Instead, a second model object is created when the create request is received. 
     237 * This allows the user to submit a form page more than once with the expected results of creating multiple records. 
     238 * In addition, this allows a single partial to be used to generate form inputs for both edit and create forms. 
     239 */ 
    210240function select($object_name, $attribute_name, $choices, $options = array(), $html_options = array()) { 
    211241    $form = new FormOptionsHelper($object_name, $attribute_name); 
     
    213243} 
    214244 
    215 # Return select and option tags for the given object and method using  
    216 # options_from_collection_for_select to generate the list of option tags. 
     245/** 
     246 * Return select and option tags for the given object and method using  
     247 * options_from_collection_for_select to generate the list of option tags. 
     248 */ 
    217249function collection_select($object_name, $attribute_name, $collection, $attribute_value, $attribute_text, $options = array(), $html_options = array()) { 
    218250    $form = new FormOptionsHelper($object_name, $attribute_name); 
     
    220252} 
    221253 
    222 # Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags. 
     254/** 
     255 * Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags. 
     256 */ 
    223257function country_select($object_name, $attribute_name, $priority_countries = null, $options = array(), $html_options = array()) { 
    224258    $form = new FormOptionsHelper($object_name, $attribute_name); 
  • trunk/trax/vendor/trax/action_view/helpers/form_tag_helper.php

    r132 r138  
    11<?php 
    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 the FormTagHelper 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 */ 
    2535class FormTagHelper extends Helpers { 
    2636 
    27  
     37    /** 
     38     * 
     39     */ 
    2840    private function convert_options($options = array()) { 
    2941        $arr = array('disabled', 'readonly', 'multiple'); 
     
    3446    } 
    3547 
     48    /** 
     49     * 
     50     */ 
    3651    private function boolean_attribute(&$options, $attribute) { 
    3752        if($options[$attribute]) { 
     
    4257    } 
    4358 
     59    /** 
     60     * 
     61     */ 
    4462    function form_tag($url_for_options = array(), $options = array(), $parameters_for_url = array()) { 
    4563        $html_options = array_merge(array("method" => "post"), $options); 
     
    5472    } 
    5573 
     74    /** 
     75     * 
     76     */ 
    5677    function start_form_tag() { 
    5778        $args = func_get_args(); 
     
    5980    } 
    6081 
     82    /** 
     83     * 
     84     */ 
    6185    function select_tag($name, $option_tags = null, $options = array()) { 
    6286        return $this->content_tag("select", $option_tags, array_merge(array("name" => $name, "id" => $name), $this->convert_options($options))); 
    6387    } 
    6488 
     89    /** 
     90     * 
     91     */ 
    6592    function text_field_tag($name, $value = null, $options = array()) { 
    6693        return $this->tag("input", array_merge(array("type" => "text", "name" => $name, "id" => $name, "value" => $value), $this->convert_options($options))); 
    6794    } 
    6895 
     96    /** 
     97     * 
     98     */ 
    6999    function hidden_field_tag($name, $value = null, $options = array()) { 
    70100        return $this->text_field_tag($name, $value, array_merge($options, array("type" => "hidden"))); 
    71101    } 
    72102 
     103    /** 
     104     * 
     105     */ 
    73106    function file_field_tag($name, $options = array()) { 
    74107        return $this->text_field_tag($name, null, array_merge($this->convert_options($options), array("type" => "file"))); 
    75108    } 
    76109 
     110    /** 
     111     * 
     112     */ 
    77113    function password_field_tag($name = "password", $value = null, $options = array()) { 
    78114        return $this->text_field_tag($name, $value, array_merge($this->convert_options($options), array("type" => "password"))); 
    79115    } 
    80116 
     117    /** 
     118     * 
     119     */ 
    81120    function text_area_tag($name, $content = null, $options = array()) { 
    82121        if ($options["size"]) { 
     
    90129    } 
    91130 
     131    /** 
     132     * 
     133     */ 
    92134    function check_box_tag($name, $value = "1", $checked = false, $options = array()) { 
    93135        $html_options = array_merge(array("type" => "checkbox", "name" => $name, "id" => $name, "value" => $value), $this->convert_options($options)); 
     
    96138    } 
    97139 
     140    /** 
     141     * 
     142     */ 
    98143    function radio_button_tag($name, $value, $checked = false, $options = array()) { 
    99144        $html_options = array_merge(array("type" => "radio", "name" => $name, "id" => $name, "value" => $value), $this->convert_options($options)); 
     
    102147    } 
    103148 
     149    /** 
     150     * 
     151     */ 
    104152    function submit_tag($value = "Save changes", $options = array()) { 
    105153        return $this->tag("input", array_merge(array("type" => "submit", "name" => "commit", "value" => $value), $this->convert_options($options))); 
    106154    } 
    107155 
     156    /** 
     157     * 
     158     */ 
    108159    function image_submit_tag($source, $options = array()) { 
    109160        return $this->tag("input", array_merge(array("type" => "image", "src" => image_path($source)), $this->convert_options($options))); 
     
    112163} 
    113164 
    114 ################################################################################################ 
    115 ## Avialble functions for use in views 
    116 ################################################################################################ 
     165/** 
     166 * Avialble functions for use in views 
     167 */ 
    117168function form_tag() { 
    118169    $form_tag_helper = new FormTagHelper(); 
     
    121172} 
    122173 
     174/** 
     175 * 
     176 */ 
    123177function start_form_tag() { 
    124178    $args = func_get_args(); 
     
    126180} 
    127181 
     182/** 
     183 * 
     184 */ 
    128185function end_form_tag() { 
    129186    return "</form>"; 
    130187} 
    131188 
     189/** 
     190 * 
     191 */ 
    132192function select_tag() { 
    133193    $form_tag_helper = new FormTagHelper(); 
     
    136196} 
    137197 
     198/** 
     199 * 
     200 */ 
    138201function text_field_tag() { 
    139202    $form_tag_helper = new FormTagHelper(); 
     
    142205} 
    143206 
     207/** 
     208 * 
     209 */ 
    144210function hidden_field_tag() { 
    145211    $form_tag_helper = new FormTagHelper(); 
     
    148214} 
    149215 
     216/** 
     217 * 
     218 */ 
    150219function file_field_tag() { 
    151220    $form_tag_helper = new FormTagHelper(); 
     
    154223} 
    155224 
     225/** 
     226 * 
     227 */ 
    156228function password_field_tag() { 
    157229    $form_tag_helper = new FormTagHelper(); 
     
    160232} 
    161233 
     234/** 
     235 * 
     236 */ 
    162237function text_area_tag() { 
    163238    $form_tag_helper = new FormTagHelper(); 
     
    166241} 
    167242 
     243/** 
     244 * 
     245 */ 
    168246function check_box_tag() { 
    169247    $form_tag_helper = new FormTagHelper(); 
     
    172250} 
    173251 
     252/** 
     253 * 
     254 */ 
    174255function radio_button_tag() { 
    175256    $form_tag_helper = new FormTagHelper(); 
     
    178259} 
    179260 
     261/** 
     262 * 
     263 */ 
    180264function submit_tag() { 
    181265    $form_tag_helper = new FormTagHelper(); 
     
    184268} 
    185269 
     270/** 
     271 * 
     272 */ 
    186273function image_submit_tag() { 
    187274    $form_tag_helper = new FormTagHelper(); 
  • trunk/trax/vendor/trax/action_view/helpers/url_helper.php

    r117 r138  
    11<?php 
    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. 
     2/** 
     3 *  File containing the UrlHelper 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 */ 
    2430 
     31/** 
     32 *  @todo Document this class 
     33 *  @package PHPonTrax 
     34 */ 
    2535class UrlHelper extends Helpers { 
    2636 
    27     # Creates a link tag of the given +name+ using an URL created by the set of +options+. 
    28     # It's also possible to pass a string instead of an options hash to 
    29     # get a link tag that just points without consideration. If null is passed as a name, the link itself will become the name. 
    30     # The $html_options have a special feature for creating javascript confirm alerts where if you pass ":confirm" => 'Are you sure?', 
    31     # the link will be guarded with a JS popup asking that question. If the user accepts, the link is processed, otherwise not. 
    32     # 
    33     # Example: 
    34     #   link_to("Delete this page", array(":action" => "delete", ":id" => $page->id), array(":confirm" => "Are you sure?")) 
     37    /** 
     38     * Creates a link tag of the given +name+ using an URL created by the set of +options+. 
     39     * It's also possible to pass a string instead of an options hash to 
     40     * get a link tag that just points without consideration. If null is passed as a name, the link itself will become the name. 
     41     * The $html_options have a special feature for creating javascript confirm alerts where if you pass ":confirm" => 'Are you sure?', 
     42     * the link will be guarded with a JS popup asking that question. If the user accepts, the link is processed, otherwise not. 
     43     * 
     44     * Example: 
     45     *   link_to("Delete this page", array(":action" => "delete", ":id" => $page->id), array(":confirm" => "Are you sure?")) 
     46     */ 
    3547    function link_to($name, $options = array(), $html_options = array()) { 
    3648        $html_options = $this->convert_confirm_option_to_javascript($html_options); 
     
    6274    } 
    6375 
     76    /** 
     77     *  @todo Document this method 
     78     */ 
    6479    function convert_confirm_option_to_javascript($html_options) { 
    6580        if($html_options['confirm']) { 
     
    7085    } 
    7186 
     87    /** 
     88     *  @todo Document this method 
     89     */ 
    7290    function convert_boolean_attributes(&$html_options, $bool_attrs) { 
    7391        foreach($bool_attrs as $x) { 
     
    8098    } 
    8199 
     100    /** 
     101     *  @todo Document this method 
     102     */ 
    82103    function button_to($name, $options = array(), $html_options = null) { 
    83104        $html_options = (!is_null($html_options) ? $html_options : array()); 
     
    97118    } 
    98119 
    99     # This tag is deprecated. Combine the link_to and AssetTagHelper::image_tag yourself instead, like: 
    100     #   link_to(image_tag("rss", :size => "30x45", :border => 0), "http://www.example.com") 
     120    /** 
     121     * This tag is deprecated. Combine the link_to and AssetTagHelper::image_tag yourself instead, like: 
     122     *   link_to(image_tag("rss", :size => "30x45", :border => 0), "http://www.example.com") 
     123     */ 
    101124    function link_image_to($src, $options = array(), $html_options = array(), $parameters_for_method_reference = array()) { 
    102125        $image_options = array("src" => (ereg("/", $src) ? $src : "/images/$src")); 
     
    131154} 
    132155 
    133 ################################################################################################ 
    134 ## Avialble functions for use in views 
    135 ################################################################################################ 
     156/** 
     157 *  Avialble functions for use in views 
     158 *  @todo Document this function 
     159 */ 
    136160function link_to($name, $options = array(), $html_options = array()) { 
    137161    $url_helper = new UrlHelper(); 
  • trunk/trax/vendor/trax/active_record.php

    r136 r138  
    11<?php 
    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 the ActiveRecord class 
     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 *  Load the {@link http://pear.php.net/manual/en/package.pear.php PEAR base class} 
     33 */ 
    2534require_once('PEAR.php'); 
     35 
     36/** 
     37 *  Load the {@link http://pear.php.net/manual/en/package.database.db.php PEAR DB package} 
     38 */ 
    2639require_once('DB.php'); 
    2740 
     41/** 
     42 *  Base class for the ActiveRecord design pattern 
     43 * 
     44 *  <p>Each subclass of this class is associated with a database table 
     45 *  in the Model section of the Model-View-Controller architecture. 
     46 *  By convention, the name of each subclass is the CamelCase singular 
     47 *  form of the table name, which is in the lower_case_underscore 
     48 *  plural notation.  For example,  
     49 *  a table named "order_details" would be associated with a subclass 
     50 *  of ActiveRecord named "OrderDetail", and a table named "people" 
     51 *  would be associated with subclass "Person".</p> 
     52 * 
     53 *  <p>For a discussion of the ActiveRecord design pattern, see 
     54 *  "Patterns of Enterprise  
     55 *  Application Architecture" by Martin Fowler, pp. 160-164.</p> 
     56 * 
     57 *  <p>Unit tester: {@link ActiveRecordTest}</p> 
     58 * 
     59 *  @package PHPonTrax 
     60 */ 
    2861class ActiveRecord { 
    2962 
    30     static private $db = null; # Reference to Pear db object 
     63    /** 
     64     *  Reference to the object returned by PEAR DB::Connect() 
     65     * 
     66     *  @var object DB 
     67     *  <b>FIXME: static should be after private</b> 
     68     */ 
     69    static private $db = null; 
     70 
     71    /** 
     72     *  <b>FIXME: dead code?  Never referenced in ActiveRecord</b><br> 
     73     *  <b>FIXME: static should be after protected</b><br> 
     74     *  <b>FIXME: static variables $rows_per_page, $page, $offset are 
     75     *  not declared.  Declaring them would provide a good place to 
     76     *  document them.  On the other hand, if the intent is to give 
     77     *  the user the ability to page through a result set, these 
     78     *  variables need to go in $_SESSION.</b> 
     79     */ 
    3180    static protected $inflector = null; # object to do class inflection 
     81 
     82    /** 
     83     *  Description of a row in the associated table in the database 
     84     * 
     85     *  <p>Retrieved from the RDBMS by {@link set_content_columns()}. 
     86     *  See {@link  
     87     *  http://pear.php.net/manual/en/package.database.db.db-common.tableinfo.php 
     88     *  DB_common::tableInfo()} for the format.  <b>NOTE:</b> Some 
     89     *  RDBMS's don't return all values.</p> 
     90     * 
     91     *  <p>An additional element 'human_name' is added to each column 
     92     *  by {@link set_content_columns()}.  The actual value contained 
     93     *  in each column is stored in an object variable with the name 
     94     *  given by the 'name' element of the column description for each 
     95     *  column.</p> 
     96     * 
     97     *  <p><b>NOTE:</b>The information from the database about which 
     98     *  columns are primary keys is <b>not used</b>.  Instead, the 
     99     *  primary keys in the table are listed in {@$primary_keys}, 
     100     *  which is maintained independently.</p> 
     101     *  @var string[] 
     102     *  @see $primary_keys 
     103     *  @see quoted_attributes() 
     104     *  @see __set() 
     105     */ 
    32106    public $content_columns = null; # info about each column in the table 
    33     public $table_name = null; # if you want to override table name set this in your model 
    34     public $database_name = null; # if you want to override database name set this in your model 
     107 
     108    /** 
     109     *  Table name 
     110     * 
     111     *  Name of the table in the database associated with the subclass. 
     112     *  Normally set to the pluralized lower case underscore form of 
     113     *  the class name by the constructor.  May be overridden. 
     114     *  @var string 
     115     */ 
     116    public $table_name = null; 
     117 
     118    /** 
     119     *  Database name override 
     120     * 
     121     *  Name of the database to use, if you are not using the value 
     122     *  read from file config/database.ini 
     123     *  @var string 
     124     */ 
     125    public $database_name = null; 
     126 
     127    /** 
     128     *  Mode to use when fetching data from database 
     129     * 
     130     *  See {@link 
     131     *  http://pear.php.net/manual/en/package.database.db.db-common.setfetchmode.php 
     132     *  the relevant PEAR DB class documentation} 
     133     *  @var integer 
     134     */ 
    35135    public $fetch_mode = DB_FETCHMODE_ASSOC; 
     136 
     137    /** 
     138     *  Force reconnect to database 
     139     * 
     140     *  @var boolean 
     141     */ 
    36142    public $force_reconnect = false; # should we force a connection everytime 
    37143    public $index_on = "id"; # find_all returns an array of objects each object index is off of this field 
    38144 
    39145    # Table associations 
     146    /** 
     147     *  @todo Document this API 
     148     *  @var string[] 
     149     */ 
    40150    protected $has_many = null; 
     151 
     152    /** 
     153     *  @todo Document this API 
     154     *  @var string[] 
     155     */ 
    41156    protected $has_one = null; 
     157 
     158    /** 
     159     *  @todo Document this API 
     160     *  @var string[] 
     161     */ 
    42162    protected $has_and_belongs_to_many = null; 
     163 
     164    /** 
     165     *  @todo Document this API 
     166     *  @var string[] 
     167     */ 
    43168    protected $belongs_to = null; 
     169 
     170    /** 
     171     *  @todo Document this API 
     172     *  @var string[] 
     173     */ 
    44174    protected $habtm_attributes = null; 
    45175    protected $save_associations = array(); 
    46176    public $auto_save_associations = true; # where or not to auto save defined associations if set 
    47177 
    48     protected $new_record = true;  # whether or not to create a new record or just update 
     178    /** 
     179     *  Whether this object represents a new record 
     180     * 
     181     *  true => This object was created without reading a row from the 
     182     *          database, so use SQL 'INSERT' to put it in the database. 
     183     *  false => This object was a row read from the database, so use 
     184     *           SQL 'UPDATE' to update database with new values. 
     185     *  @var boolean 
     186     */ 
     187    protected $new_record = true; 
     188 
     189    /** 
     190     *  Names of automatic update timestamp columns 
     191     * 
     192     *  When a row containing one of these columns is updated and 
     193     *  {@link $auto_timestamps} is true, update the contents of the 
     194     *  timestamp columns with the current date and time. 
     195     *  @see $auto_timestamps 
     196     *  @see $auto_create_timestamps 
     197     *  @var string[] 
     198     */ 
    49199    protected $auto_update_timestamps = array("updated_at","updated_on"); 
     200 
     201    /** 
     202     *  Names of automatic create timestamp columns 
     203     * 
     204     *  When a row containing one of these columns is created and 
     205     *  {@link $auto_timestamps} is true, store the current date and 
     206     *  time in the timestamp columns. 
     207     *  @see $auto_timestamps 
     208     *  @see $auto_update_timestamps 
     209     *  @var string[] 
     210     */ 
    50211    protected $auto_create_timestamps = array("created_at","created_on"); 
     212