Changeset 214 for trunk/trax/vendor/trax

Show
Ignore:
Timestamp:
05/31/06 21:33:29 (6 years ago)
Author:
john
Message:

fixed paging syntax in find_all

Location:
trunk/trax/vendor/trax
Files:
2 modified

Legend:

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

    r213 r214  
    619619    }     
    620620     
    621     function pagination_range_text($object_name_or_object, $showing_text = "Showing", $showing_type = "items") { 
     621    function pagination_range_text($object_name_or_object, $range_text = "Showing", $range_type = "items") { 
    622622        if(is_object($object_name_or_object)) { 
    623623            $object = $object_name_or_object; 
     
    635635        } 
    636636         
    637         return "{$showing_text} {$start} - {$end} of {$object->pagination_count} {$showing_type}.";                      
     637        return "{$range_text} {$start} - {$end} of {$object->pagination_count} {$range_type}.";                      
    638638    } 
    639639     
  • trunk/trax/vendor/trax/active_record.php

    r213 r214  
    564564 
    565565            if(@array_key_exists("order", $parameters)) 
    566                 $orderings = $parameters['order']; 
     566                $order = $parameters['order']; 
    567567            elseif($parameters[1] != "") 
    568                 $orderings = $parameters[1]; 
     568                $order = $parameters[1]; 
    569569 
    570570            if(@array_key_exists("limit", $parameters)) 
     
    606606        # Set up the SQL segments 
    607607        $conditions = "{$join_table}.{$this_foreign_key}=".intval($this->id); 
    608         $orderings = null; 
     608        $order = null; 
    609609        $limit = null; 
    610610        $joins .= "LEFT JOIN {$join_table} ON {$other_table_name}.id = {$other_foreign_key}"; 
    611611 
    612612        # Get the list of other_class_name objects 
    613         return $object->find_all($conditions, $orderings, $limit, $joins); 
     613        return $object->find_all($conditions, $order, $limit, $joins); 
    614614    } 
    615615 
     
    633633 
    634634            if(@array_key_exists("order", $parameters)) 
    635                 $orderings = $parameters['order']; 
     635                $order = $parameters['order']; 
    636636            elseif($parameters[1] != "") 
    637                 $orderings = $parameters[1]; 
     637                $order = $parameters[1]; 
    638638 
    639639            if(@array_key_exists("limit", $parameters)) 
     
    684684 
    685685        # Get the list of other_class_name objects 
    686         return $other_class_object->find_all($conditions, $orderings, $limit, $joins); 
     686        return $other_class_object->find_all($conditions, $order, $limit, $joins); 
    687687    } 
    688688 
     
    723723         
    724724        # Get the list of other_class_name objects 
    725         $result = $other_class_object->find_first($conditions, $orderings); 
     725        $result = $other_class_object->find_first($conditions, $order); 
    726726        # There should only be one result, an object, if so return it 
    727727        if(is_object($result)) { 
     
    769769         
    770770        # Get the list of other_class_name objects 
    771         $result = $other_class_object->find_first($conditions, $orderings); 
     771        $result = $other_class_object->find_first($conditions, $order); 
    772772        # There should only be one result, an object, if so return it 
    773773        if(is_object($result)) { 
     
    998998                        $method_params .= implode("_",$field)."='".$parameters[$param_cnt++]."'"; 
    999999                        if($parameters[$param_cnt]) { 
    1000                             $orderings = $parameters[$param_cnt]; 
     1000                            $order = $parameters[$param_cnt]; 
    10011001                        } 
    10021002                    } 
     
    10061006 
    10071007            if($find_all) { 
    1008                 return $this->find_all($method_params, $orderings); 
     1008                return $this->find_all($method_params, $order); 
    10091009            } else { 
    1010                 return $this->find_first($method_params, $orderings); 
     1010                return $this->find_first($method_params, $order); 
    10111011            } 
    10121012        } 
     
    10181018     *  If no rows match, an empty array is returned. 
    10191019     *  @param string  SQL to use in the query.  If 
    1020      *    $conditions contains "SELECT", then $orderings, $limit and 
     1020     *    $conditions contains "SELECT", then $order, $limit and 
    10211021     *    $joins are ignored and the query is completely specified by 
    10221022     *    $conditions.  If $conditions is omitted or does not contain 
     
    10271027     *  @param string  Argument to "ORDER BY" in query. 
    10281028     *    If specified, the query will include 
    1029      *    "ORDER BY $orderings". If omitted, no ordering will be 
     1029     *    "ORDER BY $order". If omitted, no ordering will be 
    10301030     *    applied.   
    10311031     *  @param integer[] Page, rows per page??? 
     
    10451045     *  @throws {@link ActiveRecordError} 
    10461046     */ 
    1047     function find_all($conditions = null, $orderings = null, 
     1047    function find_all($conditions = null, $order = null, 
    10481048                      $limit = null, $joins = null) { 
    10491049        //error_log("find_all(".(is_null($conditions)?'null':$conditions) 
    1050         //          .', ' . (is_null($orderings)?'null':$orderings) 
     1050        //          .', ' . (is_null($order)?'null':$order) 
    10511051        //          .', ' . (is_null($limit)?'null':var_export($limit,true)) 
    10521052        //          .', ' . (is_null($joins)?'null':$joins).')'); 
     
    10631063            # named parameters. 
    10641064            if(is_array($conditions)) { 
    1065                 extract($conditions);   
     1065                if(@array_key_exists("per_page", $conditions) && !is_numeric($conditions['per_page'])) { 
     1066                    extract($conditions);  
     1067                    $per_page = 0;    
     1068                } else { 
     1069                    extract($conditions);      
     1070                } 
     1071                # If conditions wasn't in the array set it to null 
    10661072                if(is_array($conditions)) { 
    10671073                    $conditions = null;     
     
    10811087 
    10821088            # If ordering specified, include it 
    1083             if(!is_null($orderings)) { 
    1084                 $sql .= "ORDER BY $orderings "; 
    1085             } 
    1086  
    1087             # If limit specified, divide into pages 
    1088             if(!is_null($limit) || !is_null($offset) || !is_null($per_page)) { 
    1089  
    1090                 # Is output to be generated in pages? 
    1091                 if(is_array($limit)) {     
    1092                     # Yes, get next page number and rows per page from argument 
    1093                     list($this->page, $this->rows_per_page) = $limit; 
    1094                 } else { 
     1089            if(!is_null($order)) { 
     1090                $sql .= "ORDER BY $order "; 
     1091            } 
     1092 
     1093            # Is output to be generated in pages? 
     1094            if(is_numeric($limit) || is_numeric($offset) || is_numeric($per_page)) { 
     1095 
     1096                if(is_numeric($limit)) {     
    10951097                    $this->rows_per_page = $limit;         
    10961098                } 
    1097                 if(!is_null($per_page)) { 
     1099                if(is_numeric($per_page)) { 
    10981100                    $this->rows_per_page = $per_page;             
    10991101                } 
     
    11161118                # $sql .= "LIMIT $offset, $this->rows_per_page"; 
    11171119         
    1118                 # Send query to database 
    1119                 # Set number of total pages in result set  
    1120                 # without the LIMIT   
     1120                # Set number of total pages in result set   
    11211121                if($count = $this->count_all("*", $conditions, $joins)) { 
    11221122                    $this->pagination_count = $count; 
     
    11291129        } 
    11301130 
    1131         # echo "ActiveRecord::find_all() - sql: $sql\n<br>"; 
     1131        echo "ActiveRecord::find_all() - sql: $sql\n<br>"; 
    11321132        # echo "query: $sql\n"; 
    11331133        if($this->is_error($rs = $this->query($sql))) { 
     
    11691169     *    select based on some column other than "id", you must pass a 
    11701170     *    string argument ready to insert in the SQL SELECT. 
    1171      *  @param string $orderings Argument to "ORDER BY" in query. 
     1171     *  @param string $order Argument to "ORDER BY" in query. 
    11721172     *    If specified, the query will include "ORDER BY 
    1173      *    $orderings". If omitted, no ordering will be applied. 
     1173     *    $order". If omitted, no ordering will be applied. 
    11741174     *  @param integer[] $limit Page, rows per page??? 
    11751175     *  @param string $joins ??? 
     
    11881188     *  @throws {@link ActiveRecordError} 
    11891189     */ 
    1190     function find($id, $orderings = null, $limit = null, $joins = null) { 
     1190    function find($id, $order = null, $limit = null, $joins = null) { 
    11911191        if(is_array($id)) { 
    11921192            $conditions = "id IN(".implode(",",$id).")"; 
     
    11981198 
    11991199        if(is_array($id)) { 
    1200             return $this->find_all($conditions, $orderings, $limit, $joins); 
    1201         } else { 
    1202             return $this->find_first($conditions, $orderings, $limit, $joins); 
     1200            return $this->find_all($conditions, $order, $limit, $joins); 
     1201        } else { 
     1202            return $this->find_first($conditions, $order, $limit, $joins); 
    12031203        } 
    12041204    } 
     
    12091209     *  If no rows match, null is returned. 
    12101210     *  @param string $conditions SQL to use in the query.  If 
    1211      *    $conditions contains "SELECT", then $orderings, $limit and 
     1211     *    $conditions contains "SELECT", then $order, $limit and 
    12121212     *    $joins are ignored and the query is completely specified by 
    12131213     *    $conditions.  If $conditions is omitted or does not contain 
     
    12161216     *    include "WHERE $conditions".  If $conditions is null, the 
    12171217     *    entire table is returned. 
    1218      *  @param string $orderings Argument to "ORDER BY" in query. 
     1218     *  @param string $order Argument to "ORDER BY" in query. 
    12191219     *    If specified, the query will include 
    1220      *    "ORDER BY $orderings". If omitted, no ordering will be 
     1220     *    "ORDER BY $order". If omitted, no ordering will be 
    12211221     *    applied.   
    12221222     *  FIXME This parameter doesn't seem to make sense 
     
    12291229     *  @throws {@link ActiveRecordError} 
    12301230     */ 
    1231     function find_first($conditions, $orderings = null, $limit = null, $joins = null) { 
    1232         $result = $this->find_all($conditions, $orderings, $limit, $joins); 
     1231    function find_first($conditions, $order = null, $limit = null, $joins = null) { 
     1232        $result = $this->find_all($conditions, $order, $limit, $joins); 
    12331233        return @current($result); 
    12341234    }