Пример #1
0
function showSearchForm($filterAttributes)
{
    //filterAttributes must have the following form:
    //example: $filterAttributes['1'] = [4, ['München']]
    //where '1' = ID of the filter (values 1-4), 4 = attribute-ID, ['München'] = List of selectable values
    $districts = Idp_Main::getAllDistricts();
    $selectedDistrict = -1;
    if (key_exists('district', $filterAttributes)) {
        $selectedDistrict = $filterAttributes['district'];
    }
    $keywords = "";
    if (key_exists('keywords', $filterAttributes)) {
        $keywords = $filterAttributes['keywords'];
    }
    $image_category = 0;
    if (key_exists('image_category', $filterAttributes)) {
        $image_category = $filterAttributes['image_category'];
    }
    $image_tags = [];
    if (key_exists('image_tags', $filterAttributes)) {
        $image_tags = Idp_Main::getImageTagsByIds($filterAttributes['image_tags']);
    }
    $favorites_of = -1;
    if (key_exists('favorites_of', $filterAttributes)) {
        $favorites_of = $filterAttributes['favorites_of'];
    }
    ?>
	<div id="searchForm">
		<form method="post" action=".">
			<h6><?php 
    echo __('Search for building attributes', 'idp-theme');
    ?>
</h6>
			<div class="row">
				<div class="col-md-6">
					<select id="district" name = "district" class="form-control input-sm">
						<option value="-1"><?php 
    echo __('All districts', 'idp-theme');
    ?>
</option>
						<?php 
    foreach ($districts as $district) {
        echo "<option ";
        if ($district['district_id'] == $selectedDistrict) {
            echo " selected ";
        }
        echo "value=\"{$district['district_id']}\">{$district['district_name']}</option>";
    }
    ?>
					</select>
				</div>
				<div class="col-md-6">
					<div class="input-group input-group-sm" style="width: 100%">
						<input id="keywords" name="keywords" type="text" value="<?php 
    echo $keywords;
    ?>
" class="form-control" placeholder="<?php 
    echo __('Keywords', 'idp-theme');
    ?>
...">
						<span class="input-group-btn">
							<button id="clearKeywordsButton" class="btn btn-default" type="button"><span class="glyphicon glyphicon-remove"></span></button>
						</span>
					</div>
				</div>
			</div>
			<br/>
			<script>
				$("#clearKeywordsButton").on("click", function(){
				$("#keywords").val('');			
				}).change();
			</script>
		
		
			<div class="row">
				<?php 
    $categories = Idp_Main::getAttributeCategories();
    for ($i = 1; $i <= 3; $i++) {
        ?>
					<div class="col-md-3">
						<div class="input-group input-group-sm" style="width: 100%">
							<select id="filter<?php 
        echo $i;
        ?>
" name="filter<?php 
        echo $i;
        ?>
" class="form-control">
								<option value = "-1" label="<?php 
        echo __('Choose attribute', 'idp-theme');
        ?>
...."><?php 
        echo __('Choose attribute', 'idp-theme');
        ?>
...</option>
								<?php 
        foreach ($categories as $category) {
            $attributes = Idp_Main::getAttributes($category->id);
            echo "<optgroup label=\"{$category->name}\">";
            foreach ($attributes as $attribute) {
                $selectableValues = Idp_Main::getAllSetValuesForAttribute($attribute->id);
                if (!empty($selectableValues) and $attribute->visible != 0) {
                    echo "<option ";
                    if (array_key_exists($i, $filterAttributes)) {
                        if ($attribute->id == $filterAttributes[$i][0]) {
                            echo " selected ";
                        } else {
                            for ($j = 1; $j <= 3; $j++) {
                                if ($i != $j and $attribute->id == $filterAttributes[$j][0]) {
                                    echo " disabled ";
                                }
                            }
                        }
                    }
                    echo "value = \"{$attribute->id}\" label=\"{$attribute->attribute}\">{$attribute->attribute}</option>";
                }
            }
            echo "</optgroup>";
        }
        ?>
							</select>	
							<span class="input-group-btn">
								<button id="clearFilter<?php 
        echo $i;
        ?>
" class="btn btn-default" type="button"><span class="glyphicon glyphicon-remove"></span></button>
							</span>							
						</div>
						
						<script>
						$("#clearFilter<?php 
        echo $i;
        ?>
").on("click", function(){
						$("#filter<?php 
        echo $i;
        ?>
").val(-1);	
						$("#filter<?php 
        echo $i;
        ?>
").trigger("change");
						});
						</script>
						
						<?php 
        $searchAttribute = -1;
        $selectedValues = [];
        if (array_key_exists($i, $filterAttributes)) {
            $searchAttribute = $filterAttributes[$i][0];
            $selectedValues = $filterAttributes[$i][1];
        }
        ?>
				
						<div id="valueSelect<?php 
        echo $i;
        ?>
">
							<?php 
        getSearchableValues($i, $searchAttribute, $selectedValues, false);
        ?>
						</div>
						<script>
							$("#filter<?php 
        echo $i;
        ?>
").on("change", function(){
										var ajaxurl = '<?php 
        echo admin_url('admin-ajax.php');
        ?>
';
										var data = {'action': 'getSearchableValues', 'index': <?php 
        echo $i;
        ?>
, 'searchAttribute': $(this).val(), 'selectedValues': <?php 
        echo json_encode($selectedValues);
        ?>
};
										jQuery.post(ajaxurl, data, function(response) {
											$('#valueSelect<?php 
        echo $i;
        ?>
').html(response);
										});	
							});
						</script>
					</div>
				<?php 
    }
    ?>
				
				<div class="col-md-3">
					<div class="input-group" style="width: 100%">
						<input id="decade" name="decade" type="checkbox" <?php 
    key_exists('decade', $filterAttributes) ? print 'checked' : (print '');
    ?>
 >
						<label for="decade"><?php 
    echo __('Built in decades', 'idp-theme');
    ?>
</label>
					</div>
					<div class="row">
						<div class="col-md-5">
							<?php 
    $decades = Idp_Main::getAllDecades();
    ?>
							<select id="decadeFrom" name="decadeFrom" class="form-control input-sm">
								<?php 
    if (key_exists('decadeFrom', $filterAttributes)) {
        $decadeFrom = $filterAttributes['decadeFrom'];
    } else {
        $decadeFrom = $decades[0]->decade;
    }
    foreach ($decades as $decade) {
        echo "<option ";
        if ($decade->decade == $decadeFrom) {
            echo "selected ";
        }
        echo "value=\"{$decade->decade}\" label=\"{$decade->decade}er\">{$decade->decade}er</option>";
    }
    ?>
							</select>
							</div>
							<div class="col-md-2">
							<?php 
    echo __('to', 'idp-theme');
    ?>
							</div>
							<div class="col-md-5">
							<select id="decadeTo" name="decadeTo" class="form-control input-sm">
								<?php 
    if (key_exists('decadeTo', $filterAttributes)) {
        $decadeTo = $filterAttributes['decadeTo'];
    } else {
        $decadeTo = end($decades)->decade;
    }
    foreach ($decades as $decade) {
        echo "<option ";
        if ($decade->decade == $decadeTo) {
            echo "selected ";
        }
        echo "value=\"{$decade->decade}\" label=\"{$decade->decade}er\">{$decade->decade}er</option>";
    }
    ?>
							</select>
						</div>
					</div>
				</div>
					
				<script>
					$('#decade').on("change", function(){
						if($(this).prop('checked')){
							$('#decadeFrom').prop("disabled", false);
							$('#decadeTo').prop("disabled", false);
						}
						else{
							$('#decadeFrom').prop("disabled", true);
							$('#decadeTo').prop("disabled", true);
						}
					}).change();
				</script>
					
			</div>

			<h6><?php 
    echo __('Image Search', 'idp-theme');
    ?>
</h6>
			<div class="row">
				<div class="col-md-6">
					<select name="image_category" id="image_category" class="form-control input-sm">
						<option value="0"><?php 
    echo __('All image categories', 'idp-theme');
    ?>
</option>
						<?php 
    $categories = Idp_Main::getImageCategories();
    foreach ($categories as $category) {
        $selected = "";
        if (!empty($image_category) && $category->id == $image_category) {
            $selected = "selected";
        }
        echo "<option {$selected} value=\"{$category->id}\">{$category->name}</option>";
    }
    ?>
					</select>
				</div>
				<div class="col-md-6">
				<div class="input-group input-group-sm">
					<span class="input-group-addon">
					<span class="glyphicon glyphicon-tags" aria-hidden="true" title="Nach Tags suchen"></span></span>
					<input name="image_tags" id="image_tags" type="text" class="form-control"/>
					</div>
					<a data-toggle="modal" href="#imageTagsModal"><?php 
    _e('Show all tags', 'idp-theme');
    ?>
</a>
				</div>
			</div>
			<br/>
			
			<script>			
			$('select[id^="filter"]').on("change", function() {
				var selectedValues = [];
				var sel = $('select[id^="filter"]');
				sel.each(function() {
					selectedValues.push(this.value);
				});
				sel.find('option').prop('disabled', false);
				sel.each(function() {
					if(jQuery.inArray( this.value, selectedValues ) > -1){
						sel.not(this).find('option[value=' + this.value + '][value!=-1]').prop('disabled', true);
					}
				});				
			});
			</script>
			<script>
				$(function(){
					<?php 
    foreach ($image_tags as $image_tag) {
        echo "\$('#image_tags').tagsinput('add', { value: {$image_tag->id}, text: '{$image_tag->name}' });";
    }
    ?>
				});
			</script>
			
			<?php 
    $usersWithFavorites = Idp_Main::getUsersWithFavorites();
    ?>
			<div class="row">
			<div class="col-md-6">
			<div class="input-group">
			  <span class="input-group-btn">
				<button class="btn btn-primary" type="submit"><?php 
    echo __('Search', 'idp-theme');
    ?>
</button>
			  </span>
			  <select name="favorites_of" id="favorites_of" class="form-control">
					<option value="-1"><?php 
    echo __('in all buildings', 'idp-theme');
    ?>
</option>
					<?php 
    foreach ($usersWithFavorites as $user_id => $user_name) {
        echo "<option ";
        if ($user_id == $favorites_of) {
            echo " selected ";
        }
        echo "value=\"{$user_id}\">" . __('in favorites of', 'idp-theme') . " {$user_name}</option>";
    }
    ?>
			  </select>
			</div>
			</div>
			</div>
		</form>
	</div>
	<br/>
	<?php 
}
		            </td>		            
		            <th class="manage-column column-col_value_name" scope="col"><?php 
echo __('Value', 'idp-plugin');
?>
</th>       
		    		<th class="manage-column column-col_value_attribute" scope="col"><?php 
echo __('Attribute', 'idp-plugin');
?>
</th>
		        </tr>
		    </tfoot>

		    <tbody class="searchable">
		    <?php 
$values = Idp_Main::getSelectableValues($attribute_id);
$categories = Idp_Main::getAttributeCategories();
$row_alternate = true;
foreach ($values as $value) {
    if ($row_alternate) {
        ?>
		    			<tr class=\"alternate\" valign=\"top\">
		    			<?php 
    } else {
        ?>
		    			<tr valign=\"top\">
		    			<?php 
    }
    ?>
			    		<th class="check-column" scope="row">
				        	<label class="screen-reader-text" for="cb-select-<?php 
    echo $value->id;
Пример #3
0
 /**
  * Return data for a single building.
  * The array should contain key => value pairs, so we can iterate through it (or pick certain pairs)
  *
  * 
  * @author Christopher Siewert
  * @return districts
  */
 public static function getBuildingBasicInfos($id)
 {
     global $wpdb;
     $building = array();
     $building = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}building WHERE id = %d", $id), ARRAY_A);
     $bounds = $wpdb->get_row($wpdb->prepare("SELECT d.id AS districtid, d.name AS districtname, b.coordinates AS coordinates FROM {$wpdb->prefix}bounds b, {$wpdb->prefix}district d WHERE b.id = %d AND b.district = d.id", $building['bounds']), ARRAY_A);
     $in = array("[[[", "lat", "\\", "lng", "\"", ":", "]]]");
     $out = array("[", "", "", "", "", "", "]");
     $building['bounds'] = str_replace($in, $out, $bounds['coordinates']);
     // remove unnecessary parts from the string
     $building['district']['id'] = $bounds['districtid'];
     $building['district']['name'] = $bounds['districtname'];
     $categories = Idp_Main::getAttributeCategories($id);
     foreach ($categories as $category) {
         $building['categories'][$category->id] = $category->name;
     }
     if (!isset($building['categories'])) {
         $building['categories'] = [];
     }
     return $building;
 }