在 Piwik 中创建子表

发布于 2024-08-31 12:45:00 字数 2748 浏览 4 评论 0原文

我是 piwik 的新手。请帮助我解决我的问题。

问题:我必须创建 4 级子表。目前我最多可以创建第二级,我的意思是每行一个子表的表。 基本上,如果我单击表行,我应该获得子表。如果我再次单击子表行,它应该显示内部子表。 我需要创建表->子表->子表->子表。

我的代码:

function getpageViewsLevel1($idSite, $date, $period)
        {

         $query = "select * from....";

                $result = Piwik_FetchAll($query, array($idSite, $dateStart, $dateEnd));

                // convert this array to a DataTable object
                $dataTable = new Piwik_DataTable();

                //Add subtable to each result
                foreach ($result as $arr){
                        $piwik_row = new Piwik_DataTable_Row;
                        $piwik_row->setColumns($arr);
                        $subDataTable = new Piwik_DataTable();
                        $piwik_row->addSubTable($subDataTable);
                        $dataTable->addRow($piwik_row);
                }
                return $dataTable;
        }

function getpageViewsLevel2($idSite, $date, $period, $idSubtable)
        {

                // Find selected parent row and retrieve data

                $dataTable_old = $this->getpageViewsLevel1($idSite, $date, $period);
                $row_old = new Piwik_DataTable_Row;
                $row_old=$dataTable_old->getRowFromIdSubDataTable($idSubtable+1);

                $tmp=$row_old->getColumns();
                //Using $actionName in DB Query
                $actionName=$tmp['pageTitle'].'%';

                //db query
                $query = "select * ....";

                $result = Piwik_FetchAll($query, array($idSite, $dateStart, $dateEnd, $actionName));

                // convert this array to a DataTable object
                //$dataTable = new Piwik_DataTable();
                foreach ($result as $arr){
                        $piwik_row = new Piwik_DataTable_Row;
                        $piwik_row->setColumns($arr);
                    $subDataTable = new Piwik_DataTable();
                        $piwik_row->addSubTable($subDataTable);
                        $dataTable->addRow($piwik_row);
                }
                return $dataTable;
        }

直到这里工作正常。对于第三级,我无法应用相同的逻辑,因为我没有第二级表 ID。

function getpageViewsLevel3($idSite, $date, $period, $idSubtable)
        {

                // Find selected parent row and retrieve data

                $dataTable_old = $this->getpageViewsLevel2($idSite, $date, $period, ___???????????????);

请帮助我如何处理此问题。请告诉我是否还有其他解决方案可以解决此问题。 不过,如果我传递一些像“1”这样的数字进行测试,

$dataTable_old = $this->getpageViewsLevel2($idSite, $date, $period, 1);----->this is not working.

我需要在数据库查询中使用父行信息。

预先感谢您的帮助。

I am new to piwik.Please help me in my issue.

Issue: I have to create 4 levesl of subtables.Currently I can able to create upto 2nd level,I mean table with one subtable per row.
Basically If I click on a table row I shoud get the subtable.If I click on subtable row again it should show inner subtable.
I need to create Table->subtable->subtable->subtable.

My code :

function getpageViewsLevel1($idSite, $date, $period)
        {

         $query = "select * from....";

                $result = Piwik_FetchAll($query, array($idSite, $dateStart, $dateEnd));

                // convert this array to a DataTable object
                $dataTable = new Piwik_DataTable();

                //Add subtable to each result
                foreach ($result as $arr){
                        $piwik_row = new Piwik_DataTable_Row;
                        $piwik_row->setColumns($arr);
                        $subDataTable = new Piwik_DataTable();
                        $piwik_row->addSubTable($subDataTable);
                        $dataTable->addRow($piwik_row);
                }
                return $dataTable;
        }

function getpageViewsLevel2($idSite, $date, $period, $idSubtable)
        {

                // Find selected parent row and retrieve data

                $dataTable_old = $this->getpageViewsLevel1($idSite, $date, $period);
                $row_old = new Piwik_DataTable_Row;
                $row_old=$dataTable_old->getRowFromIdSubDataTable($idSubtable+1);

                $tmp=$row_old->getColumns();
                //Using $actionName in DB Query
                $actionName=$tmp['pageTitle'].'%';

                //db query
                $query = "select * ....";

                $result = Piwik_FetchAll($query, array($idSite, $dateStart, $dateEnd, $actionName));

                // convert this array to a DataTable object
                //$dataTable = new Piwik_DataTable();
                foreach ($result as $arr){
                        $piwik_row = new Piwik_DataTable_Row;
                        $piwik_row->setColumns($arr);
                    $subDataTable = new Piwik_DataTable();
                        $piwik_row->addSubTable($subDataTable);
                        $dataTable->addRow($piwik_row);
                }
                return $dataTable;
        }

Till here works fine.For the 3rd level,I am not able to apply the same logic as I dont have the 2ng level table ID.

function getpageViewsLevel3($idSite, $date, $period, $idSubtable)
        {

                // Find selected parent row and retrieve data

                $dataTable_old = $this->getpageViewsLevel2($idSite, $date, $period, ___???????????????);

Please help me how can I proceed with this issue.Please let me know is there any other solution to do this.
Though if I pass some number like '1' for testing,

$dataTable_old = $this->getpageViewsLevel2($idSite, $date, $period, 1);----->this is not working.

I need to use parent row info in my DB query.

Thanks in advance for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文