dynamic grid view responding to hierarchical filter

Hello,

I am looking for advice on how to approach a need in my app.

My best way to try to explain my need would be ‘dynamic grid view based on hierarchical filter’ ?????

I am quite new to YII.Spent 2 weeks reading docs and succeeded in creating a core app with a sqlite relation database. Giix and Yii allow for amazing results !

To the point:

I have the following scheme (for an inventory system, this is a simplified model)




Object		Room		Level		Building

------		-------		-----		--------

id	    /	id	     /	id	      /	id

name	  /	room	   /	level	     /	building

Room_id	/	Level_id /	Building_id /	



an object can be in only one room. a room can host many objects.

0-to-Many relations all the way in fact.

I succeed in having basic views and manage the whole thing quite well.

I need to go further, and I want to design a VIEW where I can select the building, then the Level, then the Room, and know at every level how many objects are in the defined location. for example I wish to obtain something like

  1. a dynamic menu:



- Building1 (9)			(meaning 9 objects in buildingA)

- Building2 (7)

- - Level1 (5)

- - Level2 (2)

- - - Room1 (3)



  1. and on the right of the page, a cGridView (or else) with Objects data reflecting the selection on the left menu.

I am not asking for someone to do my work,

I am just a little lost on how to achieve this.

I read a lot about tree views, but here I don’t have a “tree-type” database.

Any help on the best way to approach this is very welcome.

thank you for your time trying to help me.

best regards

Olivier.

Hi again,

I’ve been working on the menu data part.

I can display a tree-like menu with the good information from the database

in my Object Controller




    public function actionObjectsByLocation() {

                $data = array();

                $buildings=Building::model()->findAll(array('order'=>'building desc'));

                foreach ($buildings as $building) // for each building we search for levels, rooms, and objects

                    {

                    $nObjectsByBuilding = 0;

                    $levels=Level::model()->findAll(array('condition'=>'Building_id = '.$building->id, "order"=>"level desc"));

                    foreach ($levels as $level)

                            {

                            $nObjectsByLevel=0;

                            $rooms=Room::model()->findAll(array('condition'=>'Level_id = '.$level->id, "order"=>"room desc"));

                            foreach ($rooms as $room)

                                {

                                	$nObjectsByRoom=0;

                                	$objects=Object::model()->findAll(array('condition'=>'Room_id = '.$room->id, "order"=>"title desc"));

                                	foreach ($objects as $object)

                                    	{

                                    		array_push($data,' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '.$object->title);

                                    		$nObjectsByRoom++;

                                    		$nObjectsByLevel++;

                                    		$nObjectsByBuilding++;

                                    	}

                                	array_push($data,' - - - - - - - - - - - - - - - - - - - - '.$room->room.' ('.$nObjectsByRoom.' objects in this room)');

                                	

                                }

                        	array_push($data,' - - - - - - - - - - '.$level->level.' ('.$nObjectsByLevel.' objects in this level)');

							

                            }

                    array_push($data,$building->building.' ('.$nObjectsByBuilding.' objects in this building)');

                    }

        $dataReverse = array_reverse($data); // to count easily i made everything backwards and now we reverse the data array to display properly

		$this->render('objectsByLocation', array('data' => $dataReverse,));

	}



and a simple view objectsByLocation.php




<?php 

    foreach($data as $result)

        {

           echo $result.'<br>';

    }



Still I am wondering how to properly display the OBJECT data depending on the location I choose on the left menu, which would act as a filter.

Thxs for your time.

Olivier.