<?php

class SodklasMod extends DbMod{
  
	function SodklasMod($ArrMsSp){
		parent::__construct($ArrMsSp);
		return true;
	}
	
	function GetFromDb($VarSqlName = 'SqlAll', $VarSqlGet = 'GetAll', $VarWhere = '', $VarOrder = '', $VarLimit = ''){
    $ArrSqlArray['SqlBuildTree']['select'] = 'a.KODES, a.SNAMES_'. $this->ArrMsSp->Sp_Lang .' AS SNAMES, a.ZES, a.NUS, count(*) AS ZesCount';
    $ArrSqlArray['SqlBuildTree']['from'] = $this->VarTableSodklas .' AS a';
    $ArrSqlArray['SqlBuildTree']['leftjoin'] = $this->VarTableSodklas ." b on b.ZES like (CONCAT(a.ZES, '.%'))";
    //$ArrSqlArray['SqlAll']['where'] = 'a.RBSIGNWORK_ID = b.RBSIGNWORK_ID AND a.RBFIRM_ID = c.RBFIRM_ID AND a.RBPRODUCE_ID = d.RBPRODUCE_ID';
    $ArrSqlArray['SqlBuildTree']['where'] = 'a.ZES != ""';
    if('' != $VarWhere){
      $ArrSqlArray['SqlBuildTree']['where'] .= ' AND '. $VarWhere;
    }
    $ArrSqlArray['SqlBuildTree']['group'] = 'a.ZES';
    if('' != $VarOrder){
      $ArrSqlArray['SqlBuildTree']['order'] = $VarOrder;
    }
    if('' != $VarLimit){
      $ArrSqlArray['SqlBuildTree']['limit'] = $VarLimit;
    }
    ///
    $ArrSqlArray['SqlRow']['select'] = 'a.KODES, a.SNAMES_'. $this->ArrMsSp->Sp_Lang .' AS SNAMES, a.ZES, a.NUS';
    $ArrSqlArray['SqlRow']['from'] = $this->VarTableSodklas .' AS a';
    //$ArrSqlArray['SqlAll']['where'] = 'a.RBSIGNWORK_ID = b.RBSIGNWORK_ID AND a.RBFIRM_ID = c.RBFIRM_ID AND a.RBPRODUCE_ID = d.RBPRODUCE_ID';
    if('' != $VarWhere){
      $ArrSqlArray['SqlRow']['where'] = $VarWhere;
    }
    ///
//    $ArrSqlArray['SqlCount']['select'] = 'count(*) AS vartotal';
//    $ArrSqlArray['SqlCount']['from'] = $this->VarTableSodklas .' AS a';
//    if('' != $VarWhere){
//      $ArrSqlArray['SqlCount']['where'] .= ' AND ' .$VarWhere;
//    }
    ///
    $ArrResult = $this->DbGet($ArrSqlArray[$VarSqlName], $VarSqlGet);
  	return $ArrResult;
	}
}
?>