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

Source for file htf_tag_table.phl

Documentation is available at htf_tag_table.phl

  1. <?php
  2. /**
  3.  * htf_tag_tableクラス
  4.  *
  5.  * htmlのtableタグ情報を保有・生成するクラス
  6.  *
  7.  * @package HtmlTemplateFramework
  8.  * @subpackage htmltagbase
  9.  * @access  public
  10.  * @author    Yamauchi Shogo <htf@as-prj.com>
  11.  * @version $Id: htf_tag_table.phl ,v 1.0 $
  12.  ***/
  13. require_once("htf_com_define.inc");        //共通定数
  14. require_once("htf_com_func.inc");        //共通関数
  15. require_once("htf_tag_element.phl");    //エレメントクラス
  16.  
  17. /**
  18.  * htmlのtableタグ情報を保有・生成するクラス
  19.  * 
  20.  * htmlのtableタグを保有し、保有している内容でhtmlのtableタグ記述を生成します。
  21.  *
  22.  * @access  public
  23.  * @author    Yamauchi Shogo <htf@as-prj.com>
  24.  ***/
  25.  class htf_tag_table extends htf_tag_element {
  26.  
  27.    /**
  28.     * 使用するtableタグ配下のエリアを指定する。指定値は、使用するエリアのコード値をサマリした値を設定する。エリアコード値は以下。
  29.     * 1:theadを使用<br>
  30.     * 2:tbodyを使用<br>
  31.     * 4:tfootを使用<br>
  32.     * 
  33.     * @access public
  34.     * @var int 
  35.     */
  36.     var $use_area;    //タグ出力するエリア指定(thead/tbody/tfoot)
  37.       /**
  38.     * theadタグのコンテンツ配列番号。生成時に設定される(更新不可)。
  39.     * 
  40.     * @access public
  41.     * @var int 
  42.     */
  43.     var $th_ix;        //theadのインデックス番号
  44.       /**
  45.     * tfootタグのコンテンツ配列番号。生成時に設定される(更新不可)。
  46.     * 
  47.     * @access public
  48.     * @var int 
  49.     */
  50.     var $tf_ix;        //tfootのインデックス番号
  51.       /**
  52.     * tbodyタグのコンテンツ配列番号。生成時に設定される(更新不可)。
  53.     * 
  54.     * @access public
  55.     * @var int 
  56.     */
  57.     var $tb_ix;        //tbodyのインデックス番号
  58.  
  59.     
  60.     /**
  61.      * コンストラクタ
  62.      *
  63.      * 引数の大文字小文字出力指定、エリアコードを参照し、htf_tag_tableを生成します。
  64.      * タグ出力エリアコードの指定値については、$use_area内容を参照。
  65.      *
  66.      * @access     public
  67.      * @param     int    $strelement_case  大文字・小文字出力(デフォルトは小文字出力)
  68.      * @param     int    $use_area_code    タグ出力エリアコード(THEAD/TBODY/TFOOTの使用・デフォルトはTBODYのみ)
  69.      * @return    void 
  70.      ***/
  71.     function htf_tag_table($strelement_case=HTF_CASE_LOWER,
  72.                            $use_area_code=HTF_TAG_TABLE_USE_TBODY{
  73.         //属性配列作成
  74.         $this->attributes = array();
  75.         
  76.         //要素内容配列作成
  77.         $this->contents = array();
  78.         //thead生成
  79.         $thead new htf_tag_element("thead"TRUE$strelement_case);
  80.         $this->th_ix = $this->add_content($thead1;
  81.         //tfoot生成
  82.         $tfoot new htf_tag_element("tfoot"TRUE$strelement_case);
  83.         $this->tf_ix = $this->add_content($tfoot1;
  84.         //tbody生成
  85.         $tbody new htf_tag_element("tbody"TRUE$strelement_case);
  86.         $this->tb_ix = $this->add_content($tbody1;
  87.  
  88.         //要素名の大文字・小文字設定
  89.         $this->case = $strelement_case;
  90.         //要素名設定
  91.         $this->name = "table";
  92.         //クローズタグの要・不要
  93.         $this->close_flg = TRUE;
  94.         //使用エリア(thead/tbody/tfoot)の設定
  95.         $this->use_area = $use_area_code;
  96.         
  97.         return;
  98.     }
  99.  
  100.     /**
  101.      * 指定エリア(thead/tbody/tfoot)に保持している行数を返します。
  102.      * 複数指定エリアの場合は合計行数を返します。
  103.      * タグ出力エリアコードの指定値については、$use_area内容を参照。
  104.      * 
  105.      * @access     public
  106.      * @param     int    $use_area_code    タグ出力エリアコード(THEAD/TBODY/TFOOT・デフォルトはTBODYのみ)
  107.      * @return    int    成功時:保持している行数 失敗時:-1
  108.      ***/
  109.     function rows($use_area_code=HTF_TAG_TABLE_USE_TBODY{
  110.         $retnum 0;
  111.         //THEAD
  112.         if ($this->judge_use_area($use_area_codeHTF_TAG_TABLE_USE_THEAD)) {
  113.             $thead $this->contents[$this->th_ix];
  114.             $retnum count($thead->contents);
  115.         }
  116.         //TBODY
  117.         if ($this->judge_use_area($use_area_codeHTF_TAG_TABLE_USE_TBODY)) {
  118.             $tbody $this->contents[$this->tb_ix];
  119.             $retnum += count($tbody->contents);
  120.         }
  121.         //TFOOT
  122.         if ($this->judge_use_area($use_area_codeHTF_TAG_TABLE_USE_TFOOT)) {
  123.             $tbody $this->contents[$this->tf_ix];
  124.             $retnum += count($tbody->contents);
  125.         }
  126.         return $retnum;
  127.     }
  128.  
  129.     /**
  130.      * 指定エリア(thead/tbody/tfoot)の指定行番号に保持しているカラム数を返します。
  131.      * エリアが複数指定の場合は最初に合致したエリアをサーチします。
  132.      * タグ出力エリアコードの指定値については、$use_area内容を参照。
  133.      *
  134.      * @access     public
  135.      * @param     int    $rownum           取得する行番号(未指定の場合は0)
  136.      * @param     int    $use_area_code    タグ出力エリアコード(THEAD/TBODY/TFOOT・デフォルトはTBODYのみ)
  137.      * @return    int    成功時:保持している行数 失敗時:-1
  138.      ***/
  139.     function columns($rownum=0$use_area_code=HTF_TAG_TABLE_USE_TBODY{
  140.         //THEADの場合
  141.         if ($this->judge_use_area($use_area_codeHTF_TAG_TABLE_USE_THEAD)) {
  142.             $thead $this->contents[$this->th_ix];
  143.             if ($this->check_rownum($rownum$thead->contents)) {
  144.                 return count($thead->contents[$rownum]->contents);
  145.             else {
  146.                 return -1;
  147.             }
  148.         }
  149.         //TBODYの場合
  150.         if ($this->judge_use_area($use_area_codeHTF_TAG_TABLE_USE_TBODY)) {
  151.             $tbody $this->contents[$this->tb_ix];
  152.             if ($this->check_rownum($rownum$tbody->contents)) {
  153.                 return count($tbody->contents[$rownum]->contents);
  154.             else {
  155.                 return -1;
  156.             }
  157.         }
  158.         //TFOOTの場合
  159.         if ($this->judge_use_area($use_area_codeHTF_TAG_TABLE_USE_TFOOT)) {
  160.             $tfoot $this->contents[$this->tf_ix];
  161.             if ($this->check_rownum($rownum$tfoot->contents)) {
  162.                 return count($tfoot->contents[$rownum]->contents);
  163.             else {
  164.                 return -1;
  165.             }
  166.         }
  167.         return -1;
  168.     }
  169.  
  170.     /**
  171.      * 引数のtrオブジェクトを、theadに追加します。
  172.      *
  173.      * @access     public
  174.      * @param     htf_tag_tr $tr        追加するtrタグオブジェクト
  175.      * @return    int    成功時:追加後のthead内要素数 失敗時:-1
  176.      ***/
  177.     function add_row_thead($tr{
  178.         //行オブジェクト追加
  179.         $ret $this->contents[$this->th_ix]->add_content($tr);
  180.         if ($ret == -1{
  181.             //行オブジェクト追加失敗
  182.             return -1;
  183.         }
  184.         //theadの要素内容数を返す
  185.         return count($this->contents[$this->th_ix]->contents);
  186.     }
  187.  
  188.     /**
  189.      * 引数のtrオブジェクトを、tbodyに追加します。
  190.      *
  191.      * @access     public
  192.      * @param     htf_tag_tr $tr        追加するtrタグオブジェクト
  193.      * @return    int    成功時:追加後のtbody内要素数 失敗時:-1
  194.      ***/
  195.     function add_row_tbody($tr{
  196.         //行オブジェクト追加
  197.         $ret $this->contents[$this->tb_ix]->add_content($tr);
  198.         if ($ret == -1{
  199.             //行オブジェクト追加失敗
  200.             return -1;
  201.         }
  202.         //tbodyの要素内容数を返す
  203.         return count($this->contents[$this->tb_ix]->contents);
  204.     }
  205.  
  206.     /**
  207.      * 引数のtrオブジェクトを、tfootに追加します。
  208.      *
  209.      * @access     public
  210.      * @param     htf_tag_tr $tr         追加するtrタグオブジェクト
  211.      * @return    int    成功時:追加後のtfoot要素数 失敗時:-1
  212.      ***/
  213.     function add_row_tfoot($tr{
  214.         //行オブジェクト追加
  215.         $ret $this->contents[$this->tf_ix]->add_content($tr);
  216.         if ($ret == -1{
  217.             //行オブジェクト追加失敗
  218.             return -1;
  219.         }
  220.         //tfootの要素内容数を返す
  221.         return count($this->contents[$this->tf_ix]->contents);
  222.     }
  223.  
  224.     /**
  225.      * thead内の指定番号行に、引数のタグオブジェクト(th/td)を追加します。
  226.      *
  227.      * @access     public
  228.      * @param     int              $rownum  設定するelementオブジェクトの配列番号
  229.      * @param     mixed            $thtd    追加するthまたはtdのタグオブジェクト
  230.      * @return    int              成功時:追加後のelement要素数 失敗時:-1
  231.      ***/
  232.     function add_column_thead($rownum$thtd{
  233.         //行番号チェック
  234.         if (!$this->check_rownum($rownum$this->contents[$this->th_ix]->contents)) {
  235.             return -1;
  236.         }
  237.         //カラム追加
  238.         $ret $this->contents[$this->th_ix]->contents[$rownum]->add_content($thtd);
  239.         if ($ret == -1{
  240.             return -1;
  241.         }
  242.         //指定行の要素内容数を返す
  243.         return count($this->contents[$this->th_ix]->contents[$rownum]->contents);
  244.     }
  245.  
  246.     /**
  247.      * tbody内の指定番号行に、引数のタグオブジェクト(th/td)を追加します。
  248.      *
  249.      * @access     public
  250.      * @param     int              $rownum  設定するelementオブジェクトの配列番号
  251.      * @param     mixed            $thtd    追加するthまたはtdのタグオブジェクト
  252.      * @return    int              成功時:追加後のelement要素数 失敗時:-1
  253.      ***/
  254.     function add_column_tbody($rownum$thtd{
  255.         //行番号チェック
  256.         if (!$this->check_rownum($rownum$this->contents[$this->tb_ix]->contents)) {
  257.             return -1;
  258.         }
  259.         //カラム追加
  260.         $ret $this->contents[$this->tb_ix]->contents[$rownum]->add_content($thtd);
  261.         if ($ret == -1{
  262.             return -1;
  263.         }
  264.         //指定行の要素内容数を返す
  265.         return count($this->contents[$this->tb_ix]->contents[$rownum]->contents);
  266.     }
  267.  
  268.     /**
  269.      * tfoot内の指定番号行に、引数のタグオブジェクト(th/td)を追加します。
  270.      *
  271.      * @access     public
  272.      * @param     int              $rownum  設定するelementオブジェクトの配列番号
  273.      * @param     mixed            $thtd    追加するthまたはtdタグオブジェクト
  274.      * @return    int              成功時:追加後のelement要素数 失敗時:-1
  275.      ***/
  276.     function add_column_tfoot($rownum$thtd{
  277.         //行番号チェック
  278.         if (!$this->check_rownum($rownum$this->contents[$this->tf_ix]->contents)) {
  279.             return -1;
  280.         }
  281.         //カラム追加
  282.         $ret $this->contents[$this->tf_ix]->contents[$rownum]->add_content($thtd);
  283.         if ($ret == -1{
  284.             return -1;
  285.         }
  286.         //指定行の要素内容数を返す
  287.         return count($this->contents[$this->tf_ix]->contents[$rownum]->contents);
  288.     }
  289.  
  290.     function get_htmltag({
  291.         
  292.         //開始タグ
  293.         $strret=htf_add_cr($this->get_starttag());
  294.         
  295.         //エリア判別してタグ取得
  296.         //THEAD
  297.         if ($this->judge_use_area($this->use_area,HTF_TAG_TABLE_USE_THEAD)) {
  298.             $strret.=$this->contents[$this->th_ix]->get_htmltag();
  299.         }
  300.         //TFOOT
  301.         if ($this->judge_use_area($this->use_area,HTF_TAG_TABLE_USE_TFOOT)) {
  302.             $strret.=$this->contents[$this->tf_ix]->get_htmltag();
  303.         }
  304.         //BODY
  305.         if ($this->judge_use_area($this->use_area,HTF_TAG_TABLE_USE_TBODY)) {
  306.             $strret.=$this->contents[$this->tb_ix]->get_htmltag();
  307.         }
  308.         
  309.         //終了タグ
  310.         $strret.=htf_add_cr($this->get_endtag());
  311.         
  312.         return $strret;
  313.     }
  314.  
  315.     function print_htmltag({
  316.         
  317.         //開始タグ
  318.         print(htf_add_cr($this->get_starttag()));
  319.         
  320.         //エリア判別してタグ取得
  321.         //THEAD
  322.         if ($this->judge_use_area($this->use_area,HTF_TAG_TABLE_USE_THEAD)) {
  323.             $this->contents[$this->th_ix]->print_htmltag();
  324.         }
  325.         //TFOOT
  326.         if ($this->judge_use_area($this->use_area,HTF_TAG_TABLE_USE_TFOOT)) {
  327.             $this->contents[$this->tf_ix]->print_htmltag();
  328.         }
  329.         //BODY
  330.         if ($this->judge_use_area($this->use_area,HTF_TAG_TABLE_USE_TBODY)) {
  331.             $this->contents[$this->tb_ix]->print_htmltag();
  332.         }
  333.         
  334.         //終了タグ
  335.         print(htf_add_cr($this->get_endtag()));
  336.         
  337.     }
  338.  
  339.     /**
  340.      * 作成するエリアを判別します。
  341.      *
  342.      * @access     private
  343.      * @param     int     $inttype      エリア指定
  344.      * @param     int     $intusetype   判別するエリア
  345.      * @return    bool    TRUE:使用する FALSE:使用しない
  346.      ***/
  347.     function judge_use_area($inttype$intusetype{
  348.         if (($inttype&$intusetype== $intusetype{
  349.             return TRUE;
  350.         else {
  351.             return FALSE;
  352.         }
  353.     }
  354.  
  355.     /**
  356.      * 指定行番号が正しいか・存在するかどうかチェックします。
  357.      *
  358.      * @access     private
  359.      * @param     int     $rownum       指定行番号
  360.      * @param     array   $arr          判別する配列
  361.      * @return    bool    TRUE:OK FALSE:NG
  362.      ***/
  363.     function check_rownum($rownum$arr{
  364.         //NULLや空文字はNG
  365.         if (!htf_is_existsval($rownum)) {
  366.             return FALSE;
  367.         }
  368.         //0以上件数-1以下であること
  369.         if <= $rownum && $rownum <= count($arr)-1{
  370.             return TRUE;
  371.         else {
  372.             return FALSE;
  373.         }
  374.     }
  375. }
  376.  
  377. ?>

Documentation generated on Tue, 19 Sep 2006 06:21:22 +0900 by phpDocumentor 1.3.0