Osclass forums

Development => Plugins => Topic started by: cameastwood on September 26, 2014, 09:34:08 pm

Title: Real Estate Attributes
Post by: cameastwood on September 26, 2014, 09:34:08 pm
Hello, I edited the script for the real estate attributes plugin, and I like it much better now. I thought I'd share it with you guys. Replace your item_edit.php file's content with this:

<h2><?php _e('Realestate attributes', 'realestate_attributes'); ?></h2>
<div class="box">
    <div class="row">
        <?php
            if( Session::newInstance()->_getForm('pre_property_type') != '' ) {
                $detail['e_type'] = Session::newInstance()->_getForm('pre_property_type');
            }
        ?>
        <label for="property_type"><?php _e('Type', 'realestate_attributes'); ?></label>
        <select name="property_type" id="property_type">
            <option value="FOR SALE" <?php if(@$detail['e_type'] == 'FOR SALE') { echo "selected"; } ?>><?php _e('For sale', 'realestate_attributes'); ?></option>
            <option value="FOR RENT" <?php if(@$detail['e_type'] == 'FOR RENT') { echo "selected"; } ?>><?php _e('For rent', 'realestate_attributes'); ?></option>
        </select>
    </div>
    <div class="row">
        <?php
            if( Session::newInstance()->_getForm('pre_numRooms') != '' ) {
                $detail['i_num_rooms'] = Session::newInstance()->_getForm('pre_numRooms');
            }
        ?>
        <label for="numRooms"><?php _e('Bedrooms', 'realestate_attributes'); ?></label>
        <select name="numRooms" id="numRooms">
        <?php foreach(range(1, 10) as $n) { ?>
            <option value="<?php echo $n; ?>" <?php if($n == @$detail['i_num_rooms']) { echo "selected"; } ?>><?php echo $n; ?></option>
        <?php } ?>
        </select>
    </div>
    <div class="row">
        <?php
            if( Session::newInstance()->_getForm('pre_numBathrooms') != '' ) {
                $detail['i_num_bathrooms'] = Session::newInstance()->_getForm('pre_numBathrooms');
            }
        ?>
        <label for="numBathrooms"><?php _e('Bathrooms', 'realestate_attributes'); ?></label>
        <select name="numBathrooms" id="numBathrooms">
        <?php foreach(range(1, 10) as $n) { ?>
            <option value="<?php echo $n; ?>" <?php if($n==@$detail['i_num_bathrooms']) { echo "selected"; } ?>><?php echo $n; ?></option>
        <?php } ?>
        </select>
    </div>
    <div class="row">
        <?php
            if( Session::newInstance()->_getForm('pre_squareMeters') != '' ) {
                $detail['s_square_meters'] = Session::newInstance()->_getForm('pre_squareMeters');
            }
        ?>
        <label for="squareMeters"><?php _e('Floor Area (Sq. Ft.)', 'realestate_attributes'); ?></label>
        <input type="text" name="squareMeters" id="squareMeters" value="<?php echo @$detail['s_square_meters']; ?>" size="4" maxlength="4" />
    </div>
    <div class="row">
        <?php
            if( Session::newInstance()->_getForm('pre_year') != '' ) {
                $detail['i_year'] = Session::newInstance()->_getForm('pre_year');
            }
        ?>
        <label for="year"><?php _e('Construction Year', 'realestate_attributes'); ?></label>
        <input type="text" name="year" id="year" value="<?php echo @$detail['i_year'];?>" size="4" maxlength="4" />
    </div>
    <div class="row">
        <?php
            if( Session::newInstance()->_getForm('pre_numGarages') != '' ) {
                $detail['i_num_garages'] = Session::newInstance()->_getForm('pre_numGarages');
            }
        ?>
        <label for="numGarages"><?php _e('Garage', 'realestate_attributes'); ?></label>
        <select name="numGarages" id="numGarages">
            <?php foreach(range(0, 5) as $n) { ?>
            <option value="<?php echo $n; ?>" <?php if($n==@$detail['i_num_garages']) { echo "selected"; } ?>><?php echo $n; ?></option>
            <?php } ?>
        </select>
    </div>
    <div class="row">
        <?php
            if( Session::newInstance()->_getForm('pre_condition') != '' ) {
                $detail['s_condition'] = Session::newInstance()->_getForm('pre_condition');
            }
        ?>
        <label for="condition"><?php _e('Condition', 'realestate_attributes'); ?></label>
        <input type="text" name="condition" id="condition" value="<?php echo @$detail['s_condition']; ?>" />
    </div>
    <div class="row">
        </h2><?php _e('Other Characteristics', 'realestate_attributes'); ?></h2>
        <ul class="checkbox-list">
            <?php
                if( Session::newInstance()->_getForm('pre_heating') != '' ) {
                    $detail['b_heating'] = Session::newInstance()->_getForm('pre_heating');
                }
            ?>
            <li>
                <input style="width: 20px;" type="checkbox" name="heating" id="heating" value="1" <?php if(@$detail['b_heating'] == 1) { echo 'checked="yes"'; } ?>/> <label style="float:none;" for="heating"><?php _e('View', 'realestate_attributes'); ?></label>
            </li>
            <?php
                if( Session::newInstance()->_getForm('pre_airCondition') != '' ) {
                    $detail['b_air_condition'] = Session::newInstance()->_getForm('pre_airCondition');
                }
            ?>
            <li>
                <input style="width: 20px;" type="checkbox" name="airCondition" id="airCondition" value="1" <?php if(@$detail['b_air_condition'] == 1) { echo 'checked="yes"'; } ?>/> <label style="float:none;" for="airCondition"><?php _e('Air Conditioning', 'realestate_attributes'); ?></label>
            </li>
            <?php
                if( Session::newInstance()->_getForm('pre_elevator') != '' ) {
                    $detail['b_elevator'] = Session::newInstance()->_getForm('pre_elevator');
                }
            ?>
            <li>
                <input style="width: 20px;" type="checkbox" name="elevator" id="elevator" value="1" <?php if(@$detail['b_elevator'] == 1) { echo 'checked="yes"'; } ?>/> <label style="float:none;" for="elevator"><?php _e('Fireplace', 'realestate_attributes'); ?></label>
            </li>
            <?php
                if( Session::newInstance()->_getForm('pre_terrace') != '' ) {
                    $detail['b_terrace'] = Session::newInstance()->_getForm('pre_terrace');
                }
            ?>
            <li>
                <input style="width: 20px;" type="checkbox" name="terrace" id="terrace" value="1" <?php if(@$detail['b_terrace'] == 1) { echo 'checked="yes"'; } ?>/> <label style="float:none;" for="terrace"><?php _e('Crawlspace', 'realestate_attributes'); ?></label>
            </li>
            <?php
                if( Session::newInstance()->_getForm('pre_parking') != '' ) {
                    $detail['b_parking'] = Session::newInstance()->_getForm('pre_parking');
                }
            ?>
            <li>
                <input style="width: 20px;" type="checkbox" name="parking" id="parking" value="1" <?php if(@$detail['b_parking'] == 1) { echo 'checked="yes"'; } ?>/> <label style="float:none;" for="parking"><?php _e('Appliances', 'realestate_attributes'); ?></label>
            </li>
            <?php
                if( Session::newInstance()->_getForm('pre_furnished') != '' ) {
                    $detail['b_furnished'] = Session::newInstance()->_getForm('pre_furnished');
                }
            ?>
            <li>
                <input style="width: 20px;" type="checkbox" name="furnished" id="furnished" value="1" <?php if(@$detail['b_furnished'] == 1) { echo 'checked="yes"'; } ?>/> <label style="float:none;" for="furnished"><?php _e('Furnished', 'realestate_attributes'); ?></label>
            </li>
            <?php
                if( Session::newInstance()->_getForm('pre_new') != '' ) {
                    $detail['b_new'] = Session::newInstance()->_getForm('pre_new');
                }
            ?>
            <li>
                <input style="width: 20px;" type="checkbox" name="new" id="new" value="1" <?php if(@$detail['b_new'] == 1) { echo 'checked="yes"'; } ?>/> <label style="float:none;" for="new"><?php _e('Window Coverings', 'realestate_attributes'); ?></label>
            </li>
            <?php
                if( Session::newInstance()->_getForm('pre_by_owner') != '' ) {
                    $detail['b_by_owner'] = Session::newInstance()->_getForm('pre_by_owner');
                }
            ?>
            <li>
                <input style="width: 20px;" type="checkbox" name="by_owner" id="by_owner" value="1" <?php if(@$detail['b_by_owner'] == 1) { echo 'checked="yes"'; } ?>/> <label style="float:none;" for="by_owner"><?php _e('Strata', 'realestate_attributes'); ?></label>
            </li>
        </ul>
        <div class="clear"></div>
    </div>
    <?php $locales = osc_get_locales();
    if(count($locales)==1) { ?>

    <div class="row">
        <?php
            if( Session::newInstance()->_getForm('pre_'.$locales[0]['pk_c_code'].'zone') != '' ) {
                $detail['locale'][$locales[0]['pk_c_code']]['s_zone'] = Session::newInstance()->_getForm('pre_'.$locales[0]['pk_c_code'].'zone');
            }
        ?>
        <label for="zone"><?php _e('Amenities Nearby', 'realestate_attributes'); ?></label>
        <input type="text" name="<?php echo $locales[0]['pk_c_code']; ?>#zone" id="zone" value="<?php echo @$detail['locale'][$locales[0]['pk_c_code']]['s_zone']; ?>"/>
    </div>

    <?php } else { ?>

    <div class="tabber">
    <?php foreach($locales as $locale) {?>
        <div class="tabbertab">
            <h2><?php echo $locale['s_name']; ?></h2>
            <p>
                <?php
                    if( Session::newInstance()->_getForm('pre_'.$locale['pk_c_code'].'transport') != '' ) {
                        $detail['locale'][$locale['pk_c_code']]['s_transport'] = Session::newInstance()->_getForm('pre_'.$locale['pk_c_code'].'transport');
                    }
                ?>
                <label for="transport"><?php _e('Transport', 'realestate_attributes'); ?></label><br />
                <input type="text" name="<?php echo $locale['pk_c_code']; ?>#transport" id="transport" style="width: 100%;" value="<?php echo @$detail['locale'][$locale['pk_c_code']]['s_transport']; ?>" />
            </p>
            <p>
                <?php
                    if( Session::newInstance()->_getForm('pre_'.$locale['pk_c_code'].'zone') != '' ) {
                        $detail['locale'][$locale['pk_c_code']]['s_zone'] = Session::newInstance()->_getForm('pre_'.$locale['pk_c_code'].'zone');
                    }
                ?>
                <label for="zone"><?php _e('Zone', 'realestate_attributes'); ?></label><br />
                <input type="text" name="<?php echo $locale['pk_c_code']; ?>#zone" id="zone" style="width: 100%;" value="<?php echo @$detail['locale'][$locale['pk_c_code']]['s_zone']; ?>"/>
            </p>
        </div>
    <?php }
    ?>
    </div>

    <?php } ?>
</div>
<script type="text/javascript">
        if(typeof tabberAutomatic == 'function') {
            tabberAutomatic();
        }
        if(typeof themeUiHook == 'function') {
            themeUiHook();
        }
</script>

Also, replace your helper.php file's content with this:

<?php
function get_realestate_attributes(){
    $locale = osc_current_user_locale();
    $return = array('attributes','other_attributes');
    $detail = ModelRealEstate::newInstance()->getAttributes( osc_item_id() );
    $keys = array_keys($detail) ;
    if(count($keys) == 1 && $keys[0] == 'locale' && is_null($detail[0]['locale']) ){
        // nothing to do
        return false;
    }
    if(@$detail['e_type'] != "") {
        $typeText = array(
            'FOR SALE' => __('For sale', 'realestate_attributes'),
            'FOR RENT' => __('For rent', 'realestate_attributes')
        );
        $return['attributes']['type'] = array(
                 'label' =>__('Type', 'realestate_attributes')
                ,'value' => @$typeText[$detail['e_type']]
            );
    }
    if(@$detail['locale'][$locale]['s_name'] != "") {
        $return['attributes']['property_type'] = array(
                 'label' =>__('Building Type', 'realestate_attributes')
                ,'value' => @$detail['locale'][$locale]['s_name']
            );

    }
    if(@$detail['i_num_rooms'] != "") {
        $return['attributes']['rooms'] = array(
                 'label' =>__('Bedrooms', 'realestate_attributes')
                ,'value' => @$detail['i_num_rooms']
            );
    }
    if(@$detail['i_num_bathrooms'] != "") {
        $return['attributes']['bathrooms'] = array(
                 'label' =>__('Bathrooms', 'realestate_attributes')
                ,'value' => @$detail['i_num_bathrooms']
            );
    }
    if(@$detail['s_square_meters'] != "") {
        $return['attributes']['square_meters'] = array(
                 'label' =>__('Floor Area (Sq. Ft.)', 'realestate_attributes')
                ,'value' => @$detail['s_square_meters']
            );
    }
    if(@$detail['i_year'] != "") {
        $return['attributes']['year'] = array(
                 'label' =>__('Construction Year', 'realestate_attributes')
                ,'value' => @$detail['i_year']
            );
    }
    if(@$detail['s_condition'] != "") {
        $return['attributes']['year'] = array(
                 'label' =>__('Condition', 'realestate_attributes')
                ,'value' => @$detail['s_condition']
            );
    }
    if(@@$detail['locale'][$locale]['s_zone'] != "") {
        $return['attributes']['year'] = array(
                 'label' =>__('Amenities Nearby', 'realestate_attributes')
                ,'value' => @@$detail['locale'][$locale]['s_zone']
            );
    }
    //other attributes
    if(@$detail['b_heating']) {
        $return['other_attributes']['b_heating'] = array(
                     'label' =>__('View', 'realestate_attributes')
                    ,'value' => true
                );
    }
    if(@$detail['b_air_condition']) {
        $return['other_attributes']['b_air_condition'] = array(
                         'label' =>__('Air Conditioning', 'realestate_attributes')
                        ,'value' => true
                    );
    }
    if(@$detail['b_elevator']) {
        $return['other_attributes']['b_elevator'] = array(
                         'label' =>__('Fireplace', 'realestate_attributes')
                        ,'value' => true
                    );
    }
    if(@$detail['b_terrace']) {
        $return['other_attributes']['b_terrace'] = array(
                         'label' =>__('Crawlspace', 'realestate_attributes')
                        ,'value' => true
                    );
    }
    if(@$detail['b_parking']) {
        $return['other_attributes']['b_parking'] = array(
                         'label' =>__('Appliances', 'realestate_attributes')
                        ,'value' => true
                    );
    }
    if(@$detail['b_furnished']) {
        $return['other_attributes']['b_furnished'] = array(
                         'label' =>__('Furnished', 'realestate_attributes')
                        ,'value' => true
                    );
    }
    if(@$detail['b_new']) {
        $return['other_attributes']['b_new'] = array(
                         'label' =>__('Window Coverings', 'realestate_attributes')
                        ,'value' => true
                    );
    }
    if(@$detail['b_by_owner']) {
        $return['other_attributes']['b_by_owner'] = array(
                         'label' =>__('Strata', 'realestate_attributes')
                        ,'value' => true
                    );
    }
    return $return;
}
function table_realestate_attributes(){
    $detail = get_realestate_attributes();
    if($detail['attributes']){
    ?>
    <h3><?php _e('Details', 'realestate_attributes') ; ?></h3>
    <div class="table-attributes">
        <table>
        <?php
            foreach($detail['attributes'] as $item){
                echo '<tr><td class="row-title">'.$item['label'].'</td><td>'.$item['value'].'</td></tr>';
            }
        ?>
        </table>
    </div>
    <?php
    }
}
function table_realestate_other_attributes(){
    $detail = get_realestate_attributes();
    if(isset($detail['other_attributes']) && is_array($detail['other_attributes'])){
    ?>
    <h4><?php _e('Other characteristics', 'realestate_attributes'); ?></h4>
    <ul class="list-other-attributes">
    <?php
        foreach($detail['other_attributes'] as $item){
            echo '<li><img src="'.osc_plugin_url(__FILE__).'img/tick.png"/>'.$item['label'].'</li>';
        }
    ?>
    </ul>
    <?php
    }
}
function realestate_attributes(){
    echo '<div class="realestate-details">';
    table_realestate_attributes();
    table_realestate_other_attributes();   
    echo '<div class="clear"></div></div>';
}
?>

Along with changing these files, change your realestate sub categories from Houses/Apartments for sale, and Houses/Apartments for rent, to Houses For Sale/Rent and Apartments For Sale/Rent.

Let me know if this helps anybody. :)
Title: Re: Real Estate Attributes
Post by: HORTENSIA on July 27, 2018, 02:36:59 pm
How can I give style to what appears on my item .
Title: Re: Real Estate Attributes
Post by: HORTENSIA on July 27, 2018, 10:54:52 pm
anybody
Title: Re: Real Estate Attributes
Post by: HORTENSIA on July 30, 2018, 03:37:48 pm
DONE