Skip to content

Instantly share code, notes, and snippets.

@markupboy
Created October 31, 2011 15:47
Show Gist options
  • Select an option

  • Save markupboy/1327799 to your computer and use it in GitHub Desktop.

Select an option

Save markupboy/1327799 to your computer and use it in GitHub Desktop.
Property Info
<?php
// TODO: REFACTOR CRAZY ASS QUERIES
$plugin_info = array(
'pi_name' => 'Property Info',
'pi_version' => '1.0',
'pi_author' => 'Blake Walters',
'pi_description' => 'Returns general info about a property',
'pi_usage' => Property_info::usage()
);
class Property_info {
var $return_data;
private function query_property_info($id, $cat_id) {
global $DB;
return $DB->query("SELECT exp_categories.cat_name FROM exp_relationships
LEFT JOIN exp_category_posts
ON exp_category_posts.entry_id = exp_relationships.rel_parent_id
LEFT JOIN exp_categories
ON exp_category_posts.cat_id = exp_categories.cat_id
WHERE exp_relationships.rel_child_id = $id
AND exp_categories.group_id = $cat_id
GROUP BY exp_categories.cat_name;"
);
}
private function get_property_info($id, $cat_id) {
$query = $this->query_property_info($id, $cat_id);
$results = array();
if ($query->num_rows > 0) {
foreach($query->result as $info) {
$results[] = intval($info['cat_name']);
}
sort($results);
} else {
$results[] = "0";
}
return $results;
}
function Property_info($str = '') {
global $TMPL, $FNS, $DB;
$id = $TMPL->fetch_param('id');
$tagdata = $TMPL->tagdata;
$bedrooms = $this->get_property_info($id, 18);
$bathrooms = $this->get_property_info($id, 19);
foreach ($TMPL->var_single as $key => $val) {
switch ($val) {
case 'beds_low':
$tagdata = $TMPL->swap_var_single($val, $bedrooms[0] == 0 ? "Studio" : $bedrooms[0], $tagdata);
break;
case 'beds_high':
$tagdata = $TMPL->swap_var_single($val, end($bedrooms), $tagdata);
break;
case 'baths_low':
$tagdata = $TMPL->swap_var_single($val, $bathrooms[0], $tagdata);
break;
case 'baths_high':
$tagdata = $TMPL->swap_var_single($val, end($bathrooms), $tagdata);
break;
}
}
$this->return_data = $tagdata;
}
function vaultware_data() {
global $TMPL;
$id = $TMPL->fetch_param('id');
return "vaultware stuff " ;
}
/* END */
// ----------------------------------------
// Plugin Usage
// ----------------------------------------
// This function describes how the plugin is used.
// Make sure and use output buffering
function usage()
{
ob_start();
?>
<?php
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
/* END */
}
// END CLASS
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment