NOW() and joined_date < NOW())"; }else{ $depts = $this->getChildCompanyStuctures($request['department']); $query = "where department in (".implode(",",$depts).") and (((termination_date = '0001-01-01 00:00:00' or termination_date = '0000-00-00 00:00:00') and joined_date < NOW()) or (termination_date > NOW() and joined_date < NOW()))"; } return array($query, $params); } public function getChildCompanyStuctures($companyStructId){ $childIds = array(); $childIds[] = $companyStructId; $nodeIdsAtLastLevel = $childIds; $count = 0; do{ $count++; $companyStructTemp = new CompanyStructure(); if(empty($nodeIdsAtLastLevel) || empty($childIds)){ break; } $idQuery = "parent in (".implode(",",$nodeIdsAtLastLevel).") and id not in(".implode(",",$childIds).")"; LogManager::getInstance()->debug($idQuery); $list = $companyStructTemp->Find($idQuery, array()); if(!$list){ LogManager::getInstance()->debug($companyStructTemp->ErrorMsg()); } $nodeIdsAtLastLevel = array(); foreach($list as $item){ $childIds[] = $item->id; $nodeIdsAtLastLevel[] = $item->id; } }while(count($list) > 0 && $count < 10); return $childIds; } }