<?php

class UsersPrefMod extends DbMod{
  var $VarTableUsersPrefTypes = array('integer', 'text', 'text', 'text');

	function UsersPrefMod($ArrMsSp){
		parent::__construct($ArrMsSp);
		return true;
	}

	function GetFromDb($VarSqlName = 'SqlAll', $VarSqlGet = 'GetAll', $VarWhere = '', $VarOrder = '', $VarLimit = '', $VarLeftjoinWhere = ''){
    /*** begin default values ***/
    $ArrSqlArray['SqlAll']['select'] = 'a.userspref_var, a.*, b.usersprefvalue_value';
    $ArrSqlArray['SqlAll']['from'] = $this->VarTableUsersPref .' AS a';
    $ArrSqlArray['SqlAll']['leftjoin'] = $this->VarTableUsersPrefValue .' AS b ON a.userspref_id = b.userspref_id';
    if('' != $VarLeftjoinWhere){
      $ArrSqlArray['SqlAll']['leftjoin'] .= ' AND '. $VarLeftjoinWhere;
    }
    if('' != $VarWhere){
      $ArrSqlArray['SqlAll']['where'] = $VarWhere;
    }
    if('' != $VarOrder){
      $ArrSqlArray['SqlAll']['order'] = $VarOrder;
    }
    if('' != $VarLimit){
      $ArrSqlArray['SqlAll']['limit'] = $VarLimit;
    }
    /*** end default values ***/
    ///
    $ArrSqlArray['SqlRow']['select'] = 'a.*';
    $ArrSqlArray['SqlRow']['from'] = $this->VarTableUsersPref .' AS a';
    $ArrSqlArray['SqlRow']['where'] = '';
    if('' != $VarWhere){
      $ArrSqlArray['SqlRow']['where'] = $VarWhere;
    }
    ///
    $ArrSqlArray['SqlCount']['select'] = 'count(*) AS vartotal';
    $ArrSqlArray['SqlCount']['from'] = $this->VarTableUsersPref .' AS a';
    if('' != $VarWhere){
      $ArrSqlArray['SqlCount']['where'] = $VarWhere;
    }
    $ArrResult = $this->DbGet($ArrSqlArray[$VarSqlName], $VarSqlGet);
  	return $ArrResult;
	}

  function GetPref($VarUsersId = ''){
    $ArrUsersPref = $this->GetFromDb('SqlAll', 'GetAssoc', '', '', '', "b.users_id = '". $VarUsersId ."'");
    foreach ($ArrUsersPref as $key => $value) {
      if(true === isset($value['usersprefvalue_value']) && '' != $value['usersprefvalue_value']){
        $ArrUsersPref[$key]['usersprefvalue_setvalue'] = $value['usersprefvalue_value'];
      }
      else{
        $ArrUsersPref[$key]['usersprefvalue_setvalue'] = $value['userspref_defaultvalue'];
      }
    }
    return $ArrUsersPref;
  }
}
?>