<?php

/**
* @version 2.6.0
* @package Joomla 1.5
* @subpackage DT Register
* @copyright Copyright (C) 2006 DTH Development
* @copyright contact dthdev@dthdevelopment.com
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/

 class JomsocialFields extends JTable {

  var $id=null;

  var $fieldcode=null;

  var $published = null;
  
  var $ordering = 0 ;
  
  var $name = 0 ;

  function __construct( &$db ) {

    $this->db = $db ;

    parent::__construct( '#__community_fields', 'id', $db );

  }
}

 class JomsocialModel extends JModel{
     
	 var $_data;
	 var $_fields ;
     
	 function JomsocialModelJomsocial(){
	    $this->_fields = new JomsocialFields($this->_db);
		
	 }
	 
	 function jomsocialInstall(){
	    
		$query = "Describe  #__community_fields" ;
		$this->_db->setQuery($query);
		$this->_db->query();
		$this->_db->getErrorMsg();
		return (bool)(!$this->_db->getErrorNum());
			
	 }
	 
	 function getFields(){
	 
		if(!$this->jomsocialInstall()){
		   return array();
		}
	  $query = "Select * from #__community_fields where published=1 and type <> 'group' order by ordering " ;
		
		$this->_db->setQuery($query);
		return $this->_db->loadObjectList();
	 }
	 
	 function getFieldsOption(){
	  $fields = $this->getFields();
		$list = array();
		$list[]=JHTML::_('select.option',"", "Select Field");
		foreach($fields as $field){
		   
		   $list[]=JHTML::_('select.option',$field->id, $field->name);
		   
		}
		
		return $list ;
	 }

 }
?>