<?php

/**

* @version		1.1

* @package		DJ Classifieds

* @subpackage	DJ Classifieds Component

* @copyright	Copyright (C) 2010 Blue Constant Media LTD, All rights reserved.

* @license		http://www.gnu.org/licenses GNU/GPL

* @autor url    http://design-joomla.eu

* @autor email  contact@design-joomla.eu

* @Developer    Lukasz Ciastek - lukasz.ciastek@design-joomla.eu

* 

* 

* DJ Classifieds is free software: you can redistribute it and/or modify

* it under the terms of the GNU General Public License as published by

* the Free Software Foundation, either version 3 of the License, or

* (at your option) any later version.

*

* DJ Classifieds is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.

*

* You should have received a copy of the GNU General Public License

* along with DJ Classifieds. If not, see <http://www.gnu.org/licenses/>.

* 

*/



class Options{

var $id;



function __construct(){

$id=null;

}

	

}





class TreeHelper{

var $parent_id;

var $id;

var $name;

var $childs = Array();

var $level;



function __construct(){

$parent_id=null;

$id=null;

$name=null;

$childs[]=null;

$elem[]=null;

$level=0;

}





public function getList(& $lists,& $lists_const,& $option=Array(),& $sprawdzone=Array()){



	$liczba = count($lists_const);

	$list->level = 0;

			$op= new Options;

			$op->id=$lists;

			$option[]=$op;

			

			

				   for($i=0; $i<$liczba;$i++ ){

					if($lists_const[$i]->parent_id==$lists){		

						$child=new TreeHelper();

						$child->id=$lists_const[$i]->id;

						$child->parent_id=$lists_const[$i]->parent_id;

						$child->level=$list->level+1;						

						$new_name=$lists_const[$i]->name;

							for($lev=0;$lev<$child->level;$lev++){

								$new_name="&nbsp;&nbsp;&nbsp;".$new_name;

							}

						$child->name=$new_name;



						

						$this->childs[]=$child;

						$this->getSortList($this->childs,$lists_const,$option,$sprawdzone);			

					}

				}	

				$result = Array();

				foreach($option as $opt)

				{

					$result[]=$opt->id;

				}

			

	

	return($result);		

}















public function getSortList(& $lists,& $lists_const,& $option=Array(),& $sprawdzone=Array()){



	$liczba = count($lists_const);

	foreach($lists as $list){



				$flaga=0;

				for($l=0;$l<count($sprawdzone);$l++){

					if($sprawdzone[$l]==$list->id){

						$flaga=1;

					}

				}

			

			if($flaga==0){

			$sprawdzone[]=$list->id;

			

			$this->parent_id = $list->parent_id;

			$this->id = $list->id;

			$this->name = $list->name;

			$op= new Options;

			$op->id=$this->id;

			$option[]=$op;

			

				$this->childs=Array();		

				   for($i=0; $i<$liczba;$i++ ){

					if($lists_const[$i]->parent_id==$list->id){		

						$child=new TreeHelper();

						$child->id=$lists_const[$i]->id;

						$child->parent_id=$lists_const[$i]->parent_id;

						$child->level=$list->level+1;

						$new_name=$lists_const[$i]->name;

							for($lev=0;$lev<$child->level;$lev++){

								$new_name="&nbsp;&nbsp;&nbsp;".$new_name;

							}

						$child->name=$new_name;



						

						$this->childs[]=$child;

						$this->getSortList($this->childs,$lists_const,$option,$sprawdzone);

					

					}

				}	

				

			}

	}

	return($option);		

}









}



?>



