<?php

class ProgrammPrefMod extends DbMod{
  var $VarTableProgrammPrefTypes = array('integer', 'text', 'text', 'text');

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

	function GetFromDb($VarSqlName = 'SqlAll', $VarSqlGet = 'GetAll', $VarWhere = '', $VarOrder = '', $VarLimit = '', $VarLeftjoinWhere = ''){
    /*** begin default values ***/
    $ArrSqlArray['SqlAll']['select'] = 'a.programmpref_var, a.*, b.programmprefvalue_value';
    $ArrSqlArray['SqlAll']['from'] = $this->VarTableProgrammPref .' AS a';
    $ArrSqlArray['SqlAll']['leftjoin'] = $this->VarTableProgrammPrefValue .' AS b ON a.programmpref_id = b.programmpref_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->VarTableProgrammPref .' AS a';
    $ArrSqlArray['SqlRow']['where'] = '';
    if('' != $VarWhere){
      $ArrSqlArray['SqlRow']['where'] = $VarWhere;
    }
    ///
    $ArrSqlArray['SqlCount']['select'] = 'count(*) AS vartotal';
    $ArrSqlArray['SqlCount']['from'] = $this->VarTableProgrammPref .' AS a';
    if('' != $VarWhere){
      $ArrSqlArray['SqlCount']['where'] = $VarWhere;
    }
    ///
    $ArrResult = $this->DbGet($ArrSqlArray[$VarSqlName], $VarSqlGet);
  	return $ArrResult;
	}

  function GetPref($VarOrganizId = ''){
    if(true === is_numeric($VarOrganizId)){
      $ArrProgrammPref = $this->GetFromDb('SqlAll', 'GetAssoc', '', '', '', 'b.organiz_id = "'. $VarOrganizId .'"');
      foreach ($ArrProgrammPref as $key => $value) {
        if(true === isset($value['programmprefvalue_value']) && '' != $value['programmprefvalue_value']){
          $ArrProgrammPref[$key]['programmprefvalue_setvalue'] = $value['programmprefvalue_value'];
        }
        else{
          $ArrProgrammPref[$key]['programmprefvalue_setvalue'] = $value['programmpref_defaultvalue'];
        }
      }
      return $ArrProgrammPref;
    }
    else{
      return array('error' => $this->ArrMsSp->Sp_LangMessage['error']['ErrSettingWrong']);
    }
  }
}
?>