[쿼리문]
<query id="getSubjectExtra" action="select"> <tables> <table name="documents" alias="doc" /> <table name="document_extra_vars" alias="dev_startdate" type="left join"> <conditions> <condition operation="equal" column="doc.document_srl" default="dev_startdate.document_srl" /> <condition operation="equal" column="dev_startdate.eid" default="startdate" pipe="and" /> </conditions> </table> <table name="document_extra_vars" alias="dev_enddate" type="left join"> <conditions> <condition operation="equal" column="doc.document_srl" default="dev_enddate.document_srl" /> <condition operation="equal" column="dev_enddate.eid" default="enddate" pipe="and" /> </conditions> </table> <table name="document_extra_vars" alias="dev_manager" type="left join"> <conditions> <condition operation="equal" column="doc.document_srl" default="dev_manager.document_srl" /> <condition operation="equal" column="dev_manager.eid" default="manager" pipe="and" /> </conditions> </table> <table name="document_extra_vars" alias="dev_year" type="left join"> <conditions> <condition operation="equal" column="doc.document_srl" default="dev_year.document_srl" /> <condition operation="equal" column="dev_year.eid" default="year" pipe="and" /> </conditions> </table> <table name="document_extra_vars" alias="dev_address" type="left join"> <conditions> <condition operation="equal" column="doc.document_srl" default="dev_address.document_srl" /> <condition operation="equal" column="dev_address.eid" default="addresslist" pipe="and" /> </conditions> </table> <table name="document_extra_vars" alias="dev_category" type="left join"> <conditions> <condition operation="equal" column="doc.document_srl" default="dev_category.document_srl" /> <condition operation="equal" column="dev_category.eid" default="category" pipe="and" /> </conditions> </table> </tables> <columns> <column name="doc.module_srl" /> <column name="doc.document_srl" /> <column name="doc.title" /> <column name="dev_year.value" alias="year" /> <column name="dev_address.value" alias="address" /> <column name="dev_startdate.value" alias="startdate" /> <column name="dev_enddate.value" alias="enddate" /> <column name="dev_manager.value" alias="manager" /> <column name="dev_category.value" alias="category" /> </columns> <conditions> <condition operation="equal" column="doc.module_srl" var="module_srl" filter="number" notnull="notnull" /> <condition operation="like" column="dev_address.value" var="address" pipe="and" /> <condition operation="like" column="dev_year.value" var="year" pipe="and" /> <condition operation="like" column="dev_startdate.value" var="startdate" pipe="or" /> <condition operation="like" column="dev_enddate.value" var="enddate" pipe="or" /> <condition operation="like" column="dev_manager.value" var="manager" pipe="or" /> <condition operation="like" column="dev_category.value" var="category" pipe="or" /> </conditions> <navigation> <index var="sort_index" default="startdate" order="desc" /> <list_count var="list_count" default="20" /> <page_count var="page_count" default="10" /> <page var="page" default="1" /> </navigation> </query>
[설명]
지난번에 올린 게시물에서는 모든 확장변수를 한큐에 검색하는 것이었고, 이 쿼리문은
여러개의 확장변수를 각각 검색 가능한 쿼리문입니다.
[준비물]
1. 쿼리문.xml
2. 게시판 확장변수 설정
3. 기본 게시판 리스트와는 별개로 동작되는 list 파일
3번의 경우 검색폼부터 리스트까지 별도로 작업해야합니다.
3. 기본 게시판 리스트와 별개로 동작되는 리스트파일
1) 리스트 부분
<block> {@ $obj = new stdClass(); $obj->module_srl = $module_info->module_srl; $obj->year = isset($_GET['year']) ? $_GET['year'] : NULL; $obj->address = isset($_GET['addresslist']) ? $_GET['addresslist'] : NUll; $obj->page = Context::get('page'); $obj->page_navigation = Context::get('page_navigation'); $obj->total_count = Context::get('total_count'); $obj->total_page = Context::get('total_page'); $query_path = $module_info->module."/skins/".$module_info->skin; // 쿼리경로 $document_list = executeQueryArray($query_path.'.getSubjectExtra',$obj); // 쿼리문 } </block> <section class="cd-timeline js-cd-timeline"> <div class="container max-width-lg cd-timeline__container"> <div class="cd-timeline__block today" cond="!$mod=='search'"> <div>오늘</div> <p>{date("Y.m.d")}</p> </div> <!--@foreach($document_list->data as $no => $document)--> {@ $document = getModel('document')->getDocument($document->document_srl); $document_cover = (new TimelineItem)->getCoverContent($document->document_srl); } <div class="cd-timeline__block <!--@if($document->getExtraEidValue('startdate')=='20180101')-->start<!--@end-->" > <div class="cd-timeline__img cd-timeline__img--picture"> {@ $category = implode('', $document->getExtraEidValue('category')); switch($category): case '지역 문제 해결과 지원': $category = 'cat1'; break; case '협력 및 네트워킹': $category = 'cat2'; break; case '교육과 역량강화': $category = 'cat3'; break; case '프로젝트 관리와 지원': $category = 'cat4'; break; case '조사/분석': $category = 'cat5'; break; case '정보제공과 홍보': $category = 'cat6'; break; case '조직운영 및 관리': $category = 'cat7'; break; endswitch; } <img src="img/ico-{$category}.png" alt="Picture"> </div> <div class="cd-timeline__content text-component"> <h2>{$document->getTitle()}</h2> <p class="color-contrast-medium"> <ul> <li> {@ if($document->getExtraEidValue('startdate')): $startdate = date("Y.m.d", strtotime($document->getExtraEidValue('startdate'))); else: $startdate = ''; endif; $enddate = date("Y.m.d", strtotime($document->getExtraEidValue('enddate'))); } {$startdate} - {$enddate} </li> <li> {@ $town = explode('|',$document->getExtraEidValue('addresslist')) } <block loop="$town=>$val"> {@ $val = explode(' ',$val); } <div>{$val[0]}({$val[1]})</div> </block> <block cond="0">{$town[0]}({$town[1]})</block> </li> </ul> </p> <div class="flex justify-between items-center"> <span class="cd-timeline__date"> {$startdate} </span> <a href="{getUrl('document_srl',$document->document_srl,'type','timeline')}" class="btn btn--subtle">자세히 보기</a> </div> </div> </div> <!--@endforeach--> </div> </section>
2) 검색 부분
<form name="ap_extra_search " action="{getUrl()}" method="get" class="ap_extra_search timeline" style="width: 90rem"> <!--<input type="hidden" name="act" value="">--> <input type="hidden" name="mod" value="search"> <!--<input type="hidden" name="error_return_url" value="{getUrl('','mid',$mid,'type','timeline')}" /> <input type="hidden" name="success_return_url" value="{getUrl('','mid',$mid,'type','timeline')}" />--> <input type="hidden" name="type" value="timeline"> <input type="hidden" name="vid" value="{$vid}"> <input type="hidden" name="mid" value="{$mid}"> <input type="hidden" name="year" value="{$year}"> <input type="hidden" name="category" value="{$category}"> <input type="hidden" name="addresslist" value="{$addresslist}" id="addresslist"> <div class="form-body"> <div class="exsearch-content" style="width: 90%"> <div class="input-group"> <select name="addressRegion" id="addressRegion1"> <option>읍면 선택</option> <option value="장수읍" selected|cond="$_GET['addressRegion']=='장수읍'">장수읍</option> <option value="산서면" selected|cond="$_GET['addressRegion']=='산서면'">산서면</option> <option value="번암면" selected|cond="$_GET['addressRegion']=='번암면'">번암면</option> <option value="장계면" selected|cond="$_GET['addressRegion']=='장계면'">장계면</option> <option value="천천면" selected|cond="$_GET['addressRegion']=='천천면'">천천면</option> <option value="계남면" selected|cond="$_GET['addressRegion']=='계남면'">계남면</option> <option value="계북면" selected|cond="$_GET['addressRegion']=='계북면'">계북면</option> </select> </div> <div class="input-group"> <select name="addressDo" id="addressDo1"> <option value="">전체</option> </select> </div> <div class="input-group"> <select name="addressSiGunGu" id="addressSiGunGu1"> <option value="">전체</option> </select> </div> <div class="input-group"> <select name="year"> <option value="">추진년도</option> <!--@for($i = date('Y'); $i >= 2018; $i--)--> <option value="{$i}" <!--@if($_GET['year']==$i)-->selected<!--@end-->>{$i}</option> <!--@end--> </select> <label>추친년도</label> </div> <div class="input-group"> <input type="text" class="text rx_ev_text itx" name="extra_vars3" value="" placeholder="지역구"> <label>지역구</label> </div> <div class="input-group" style="display: flex;align-items: center;gap: 4px;"> <input type="checkbox" class="text rx_ev_text itx" id="use_town" name="use_town" value="" style="width: auto" checked|cond="!$addresslist"> <label for="use_town" style="display:inline;font-size:1em;"> 해당없음 </label> </div> <div class="input-group"> <div class="exsearch-footer"> <input type="submit" value="검색"> <input type="button" name='reset' value="검색초기화" onclick="location.href='{getUrl('','mid',$mid)}'" cond="$mod=='search'"/> </div> </div> </div> </div> <div class="cat-wrap"> <ul> <li data-category="지역 문제 해결과 지원"> <input type="checkbox" value="지역 문제 해결과 지원" name="category" style="display:none" checked /> <span class="category">지역 문제 해결과 지원</span><br> <span class="cnt"> {$oDocument->getExtraEidValue('category2')} </span> </li> <li data-category="협력 및 네트워킹"> <input type="checkbox" value="협력 및 네트워킹" name="category" style="display:none" checked /> <span class="category">협력 및 네트워킹</span><br><span class="cnt">(0)</span> </li> <li data-category="교육과 역량강화"> <input type="checkbox" value="교육과 역량강화" name="category" style="display:none" checked /> <span class="category">교육과 역량강화</span><br><span class="cnt">(0)</span> </li> <li data-category="프로젝트 관리와 지원"> <input type="checkbox" value="프로젝트 관리와 지원" name="category" style="display:none" checked /> <span class="category">프로젝트 관리와 지원</span><br><span class="cnt">(0)</span> </li> <li data-category="조사/분석"> <input type="checkbox" value="조사/분석" name="category" style="display:none" checked /> <span class="category">조사/분석</span><br><span class="cnt">(0)</span> </li> <li data-category="정보제공과 홍보"> <input type="checkbox" value="정보제공과 홍보" name="categories" style="display:none" checked /> <span class="category">정보제공과 홍보</span><br><span class="cnt">(0)</span> </li> <li data-category="조직운영 및 관리"> <input type="checkbox" value="조직운영 및 관리" name="category" style="display:none" checked /> <span class="category">조직운영 및 관리</span><br><span class="cnt">(0)</span> </li> </ul> </div> </form>
3) 자바스크립트 부분
<script> $(function() { $("li[data-category]").click(function(){ $(this).find("input[type=checkbox]").prop("checked", !$(this).find("input[type=checkbox]").prop("checked")); }); //마을목록 데이터 $.ajax({ url: '/modules/board/skins/jslocal_timeline/func/townlist.php', dataType: 'json', async: false }).done(function(e) { window.town = e; }); <!--@if(!$addressRegion)--> // $("#addressRegion1").html("<option value=\"\">읍면선택</option>"); // // Object.keys(window.town).forEach(function(e) { // $(`<option value="${e}">${e}</option>`).appendTo("#addressRegion1"); // }); <!--@end--> $("#addressDo1").html("<option value=\"\">리선택</option>"); $("#addressSiGunGu1").html("<option value=\"\">마을선택</option>"); $("#addressRegion1").change(function(ev) { $("#addressDo1").html("<option value=\"\">리선택</option>"); $("#addressSiGunGu1").html("<option value=\"\">마을선택</option>"); if ($(this).val() != '') { Object.keys(window.town[$(this).val()]).forEach(function(e) { $(`<option value="${e}">${e}</option>`).appendTo("#addressDo1"); }); } }); $("#addressDo1").change(function(ev) { $("#addressSiGunGu1").html("<option value=\"\">마을선택</option>"); if ($("#addressRegion1").val() != '' && $(this).val() != '') { window.town[$("#addressRegion1").val()][$(this).val()].forEach(function(e) { $(`<option value="${e}">${e}</option>`).appendTo("#addressSiGunGu1"); }) } }); // $c = $(".cd-timeline__container"); // $i = get_data(); // $c.html(""); $("li[data-category] span.cnt").text("(0)").data("cnt", 0); // function get_el(e) { // return ` // <div class="cd-timeline__block"> // <div class="cd-timeline__img cd-timeline__img--picture"> // <img src="img/cd-icon-picture.svg" alt="Picture"> // </div> // // <div class="cd-timeline__content text-component"> // <h2><a href="/{$mid}/${e.document_srl}?type=timeline">${e.title}</a></h2> // <p class="color-contrast-medium"></p> // </div> // </div> // `; // } // $($i).each(function(i,e) { // var t = e.regdate.toString().match(/^(\d\d\d\d)(\d\d)(\d\d)/); // $(get_el(e)).appendTo($c); // $("li[data-category='" + e.category + "'] span.cnt").data("cnt", $("li[data-category='" + e.category + "'] span.cnt").data("cnt") +1); // $("li[data-category='" + e.category + "'] span.cnt").text("(" + $("li[data-category='" + e.category + "'] span.cnt").data("cnt") + ")"); // }); // $("[name='ap_extra_search'] input[type='submit']").click(function(e) { // e.preventDefault(); // $c = $(".cd-timeline__container"); // $i = get_data(); // $c.html(""); // $("li[data-category] span.cnt").text("(0)").data("cnt", 0); // $($i).each(function(i,e) { // var t = e.regdate.toString().match(/^(\d\d\d\d)(\d\d)(\d\d)/); // console.log(t); // $(get_el(e)).appendTo($c); // $("li[data-category='" + e.category + "'] span.cnt").data("cnt", $("li[data-category='" + e.category + "'] span.cnt").data("cnt") +1); // $("li[data-category='" + e.category + "'] span.cnt").text("(" + $("li[data-category='" + e.category + "'] span.cnt").data("cnt") + ")"); // }); // }); }) </script> <script> document.addEventListener('DOMContentLoaded', function() { // 각 셀렉트 요소에 대한 이벤트 리스너 추가 var addressRegionSelect = document.getElementById('addressRegion1'); var addressDoSelect = document.getElementById('addressDo1'); var addressSiGunGuSelect = document.getElementById('addressSiGunGu1'); var addressInput = document.querySelector('input[name="addresslist"]'); addressRegionSelect.addEventListener('change', updateAddressValue); addressDoSelect.addEventListener('change', updateAddressValue); addressSiGunGuSelect.addEventListener('change', updateAddressValue); // 체크박스에 대한 이벤트 리스너 추가 var useTownCheckbox = document.getElementById('use_town'); useTownCheckbox.addEventListener('change', function() { if (useTownCheckbox.checked) { // 해당없음 체크하면 셀렉트 값과 input[name='address'] 초기화 // addressRegionSelect.value = '읍면 선택'; // addressRegionSelect.text = '읍면 선택'; // addressDoSelect.value = '전체'; // addressSiGunGuSelect.value = '전체'; // addressInput.value = ''; // var option = document.createElement('option'); // option.text = '읍면 선택'; // option.value = ''; // 빈 값으로 설정할 경우 선택되었을 때 value가 빈 문자열이 됩니다. // addressRegionSelect.add(option, 0); // 첫 번째 위치에 추가 // addressDoSelect.options[1].selected = true; // break; addressRegionSelect.selectedIndex = 0; addressDoSelect.selectedIndex = 0; addressSiGunGuSelect.selectedIndex = 0; } }); // 주소 값 업데이트 함수 function updateAddressValue() { useTownCheckbox.checked = false; var regionValue = addressRegionSelect.value; var doValue = ' ' + addressDoSelect.value; var siGunGuValue = ' ' + addressSiGunGuSelect.value; var address = regionValue + doValue + siGunGuValue; // 선택된 값이 '읍면 선택', '전체' 등이 아니면 input[name='address']에 업데이트 if (regionValue !== '읍면 선택' && doValue !== '리 선택' && siGunGuValue !== '마을 선택') { addressInput.value = address.trimRight(); } else { // 선택된 값이 '읍면 선택', '전체' 등이면 input[name='address'] 초기화 addressInput.value = ''; } } }); // 해당없음 체크시 동작하는 스크립트 // Wait for the DOM to be ready document.addEventListener("DOMContentLoaded", function() { // Get the checkbox and text field elements var checkbox = document.getElementById("use_town"); var addresslistField = document.getElementById("addresslist"); // Add an event listener to the checkbox checkbox.addEventListener("change", function() { // If the checkbox is checked, clear the text field; otherwise, set its original value if (checkbox.checked) { addresslistField.value = ""; } else { // You may set the original value here if needed } }); }); </script>