Plugin Directory

Changeset 1658007


Ignore:
Timestamp:
05/15/2017 07:57:28 PM (9 years ago)
Author:
robby.roboter
Message:

customization with a menu

Location:
redi-restaurant-reservation/branches/andrew
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • redi-restaurant-reservation/branches/andrew/css/restaurant.css

    r1600333 r1658007  
    278278
    279279
    280 .redi-restaurant-time-button {
     280.redi-restaurant-time-button, .redi-restaurant-duration-button {
    281281
    282282     float: left;
  • redi-restaurant-reservation/branches/andrew/js/restaurant.js

    r1623273 r1658007  
    1111jQuery(function () {
    1212   
    13     jQuery('#step1button').show();
    14    
     13    jQuery('#step1button').show();   
    1514    jQuery('.disabled').on('click', function (e) {
    1615        e.preventDefault();
     
    4544        jQuery('#redi-restaurant-startTime-alt').val(jQuery('#redi-restaurant-startHour').val() + ':' + jQuery('#redi-restaurant-startMinute').val()); // update time in hidden field
    4645    }
    47 
    48 
    4946
    5047    jQuery('#redi-restaurant-startHour').change(updateTime);
     
    6562            var month1 = jQuery('#redi-restaurant-startDate').datepicker('getDate').getMonth() + 1;
    6663            var year1 = jQuery('#redi-restaurant-startDate').datepicker('getDate').getFullYear();
    67             var fullDate = year1 + '-' + zeroFill(month1) + '-' + zeroFill(day1)
     64            var fullDate = year1 + '-' + zeroFill(month1) + '-' + zeroFill(day1);
    6865            if (timeshiftmode === 'byshifts') {
    6966                step1call(fullDate)
     
    194191            UserEmail: jQuery('#UserEmail').val(),
    195192            UserComments: jQuery('#UserComments').val(),
     193            Menu: jQuery('#menu').val(),
     194            duration: jQuery('#redi-restaurant-durationHidden').val(),
    196195            UserPhone: jQuery('#UserPhone').val(),
    197196            placeID: jQuery('#placeID').val(),
    198197            lang: locale,
    199             apikeyid: apikeyid
     198            apikeyid: apikeyid           
    200199        };
    201200        var field_1 = jQuery('#field_1');
     
    298297            startDateISO: jQuery('#redi-restaurant-startDateISO').val(),
    299298            persons: jQuery('#persons').val(),
     299            duration: jQuery('#redi-restaurant-durationHidden').val(),
    300300            lang: locale,
    301301            timeshiftmode: timeshiftmode,
     
    314314                if (response['alternativeTime'] !== undefined) {
    315315                    switch (response['alternativeTime']) {
    316                         case 1: //AlternativeTimeBlocks see class AlternativeTime::
     316                        case 1: //AlternativeTimeBlocks see class AlternativeTime:
    317317                            //pass thought
    318318                        case 2: //AlternativeTimeByShiftStartTime
     
    327327                                }
    328328                                if (response[res]['Available']) all_busy = false;
    329                             }
     329                            }                           
    330330                            display_all_busy(all_busy);
    331331                            break;
     
    399399                                display_all_busy(all_busy);
    400400                            }
     401
     402                            console.log(response);
     403                            jQuery('#menu').find('option').remove();
     404                            for(var menu in response['menus']){
     405                                jQuery('#menu').append(jQuery('<option>', { value : response['menus'][menu]['title'] }).text(response['menus'][menu]['title']));
     406                            }
    401407                            break;
    402408                    }
     
    493499            ID: jQuery('#redi-restaurant-cancelID').val(),
    494500            Email: jQuery('#redi-restaurant-cancelEmail').val(),
    495             Reason: jQuery('#redi-restaurant-cancelReason').val(),
     501            Reason: jQuery('#redi-restaurant-cancelReason').val(),           
    496502            lang: locale,
    497503            apikeyid: apikeyid
     
    540546        jQuery('#step2').show();
    541547    });
     548
     549    jQuery(document).on('click', '.redi-restaurant-duration-button', function(event){       
     550        event.preventDefault();
     551        jQuery('#redi-restaurant-durationHidden').val(jQuery(this).val());
     552
     553        var day1 = jQuery('#redi-restaurant-startDate').datepicker('getDate').getDate();
     554        var month1 = jQuery('#redi-restaurant-startDate').datepicker('getDate').getMonth() + 1;
     555        var year1 = jQuery('#redi-restaurant-startDate').datepicker('getDate').getFullYear();
     556        var fullDate = year1 + '-' + zeroFill(month1) + '-' + zeroFill(day1);       
     557        step1call(fullDate);
     558    });
    542559});
    543560
  • redi-restaurant-reservation/branches/andrew/redi-restaurant-reservation.php

    r1654604 r1658007  
    623623                }
    624624
    625                 $reservationTime = $this->getReservationTime();
     625                //$reservationTime = $this->getReservationTime();
    626626
    627627                $custom_fields_save_to = $this->GetOption( 'customfields_save_to' );
     
    10761076            }
    10771077
     1078            $durations = self::getDurations();
     1079            $defaultDuration = 0;
     1080            foreach($durations as $duration){
     1081                if(isset($duration['default'])){
     1082                    $defaultDuration = $duration['minutes'];
     1083                }
     1084            }
     1085            $menus = self::getMenus(date('d.m.Y'), date('l'));
    10781086            $hide_clock    = false;
    10791087            $persons       = (int) $this->GetOption( 'MinPersons' );
     
    10931101                            'startTime'    => '0:00',
    10941102                            'persons'      => $persons,
    1095                             'lang'         => get_locale()
     1103                            'lang'         => get_locale(),
     1104                            'duration'     => $defaultDuration
    10961105                        )
    10971106                    )
     
    11331142                $manual = true;
    11341143            }
     1144
    11351145            require_once( REDI_RESTAURANT_TEMPLATE . 'frontend.php' );
    11361146            $out = ob_get_contents();
     
    12971307
    12981308            // calculate end time
    1299             $endTimeInt = strtotime( '+' . $this->getReservationTime( $persons ) . 'minutes', $startTimeInt );
     1309            $endTimeInt = strtotime( '+' . $post['duration'] . 'minutes', $startTimeInt );
    13001310
    13011311            // format to ISO
     
    13321342
    13331343                    case AlternativeTime::AlternativeTimeByDay:
    1334                         $params['ReservationDuration'] = $this->getReservationTime( $persons );
     1344                        $params['ReservationDuration'] = $post['duration'];
    13351345                        $query                         = $this->redi->availabilityByDay( $categoryID, $params );
    13361346                        break;
     
    13621372            }
    13631373
    1364             if ( $timeshiftmode === 'byshifts' ) {
     1374            if ( $timeshiftmode === 'byshifts' ) {             
     1375            //  var_dump($menus);
     1376                $query['menus'] = self::getMenus(date('d.m.Y', $startTimeInt), date('l', $startTimeInt));
    13651377                $query['alternativeTime'] = $alternativeTime;
    13661378                switch ( $alternativeTime ) {
     
    13961408            }
    13971409
     1410           
    13981411            return $query;
    13991412        }
     
    14231436
    14241437                case 'step2':
    1425 
     1438echo 'step2';
    14261439                    $persons = (int) self::GetPost( 'persons' );
    14271440                    // convert to int
     
    14321445
    14331446                    // calculate end time
    1434                     $endTimeInt = strtotime( '+' . $this->getReservationTime( $persons ) . 'minutes', $startTimeInt );
     1447                    $endTimeInt = strtotime( '+' . $post['duration'] . 'minutes', $startTimeInt );
    14351448
    14361449                    // format to ISO
     
    14491462                    );
    14501463
    1451                     $params['ReservationDuration'] = $this->getReservationTime( $persons );
     1464                    //$params['ReservationDuration'] = $this->getReservationTime( $persons );
    14521465                    $query                         = $this->redi->query( $categoryID, $params );
    14531466
     
    14771490
    14781491                    // calculate end time
    1479                     $endTimeInt = strtotime( '+' . $this->getReservationTime( $persons ) . 'minutes', $startTimeInt );
     1492                    $endTimeInt = strtotime( '+' . self::GetPost('duration') . 'minutes', $startTimeInt );
    14801493
    14811494                    // format to ISO
     
    15031516                        $comment .= '<br/>';
    15041517                    }
    1505                     $comment .= mb_substr( self::GetPost( 'UserComments', '' ), 0, 250 );
     1518                    $comment .= mb_substr( self::GetPost( 'UserComments' ), 0, 250 );
     1519                    $comment .= '<br/>Menu: '.self::GetPost( 'Menu' );
    15061520
    15071521                    $params = array(
     
    16171631
    16181632        private function getReservationTime( $persons = 0 ) {
     1633            echo 'getReservationTime';
    16191634            $filename = plugin_dir_path( __FILE__ ) . 'reservationtime.json';
    16201635
     
    16651680            return str_replace( '_', '-', get_locale());
    16661681        }
     1682
     1683        private function getDurations()
     1684        {
     1685            $posts = get_posts(array(
     1686                    'numberposts' => -1,
     1687                    'post_status' => 'publish',
     1688                    'post_type' => 'duration',                   
     1689                    'order' => 'ASC',
     1690                    'orderby'   => 'meta_value_num', //or 'meta_value_num'
     1691                    'meta_query' => array(array('key' => 'minutes'))
     1692            ));
     1693            $durations = [];
     1694
     1695            foreach ($posts as $post) {
     1696                 $custom_fields = self::ArrayKeysLowercase(get_post_custom($post->ID));
     1697                        $duration = array (
     1698                          'title' => $post->post_title
     1699                          );
     1700                if (isset($custom_fields['minutes'])) {
     1701                    $duration['minutes'] = $custom_fields['minutes'][0];
     1702                }if (isset($custom_fields['default'])) {
     1703                    $duration['default'] = true;
     1704                }   
     1705                $durations[] = $duration;
     1706                 
     1707            }
     1708
     1709            return $durations;
     1710        }
     1711
     1712        private function getMenus($date, $dayofweek)
     1713        {
     1714            $posts = get_posts(array(
     1715                    'numberposts' => -1,
     1716                    'post_status' => 'publish',
     1717                    'post_type' => 'menu',
     1718                    'meta_query' => array(
     1719                        'relation' => 'OR',
     1720                        array(
     1721                            'relation' => 'AND',
     1722                            array(
     1723                                'key' => 'dayofweek',
     1724                                'value' => $dayofweek
     1725                            ),
     1726                        ),
     1727                        array(
     1728                            'relation' => 'AND',
     1729                            array(
     1730                                'key' => 'dayofweek',
     1731                                'compare' => 'NOT EXISTS'
     1732                            ),
     1733                        )
     1734                    )
     1735                )
     1736            );
     1737            $menus = [];
     1738
     1739            foreach ($posts as $post) {
     1740                $menus[] = array(
     1741                    'title' => $post->post_title,
     1742                );
     1743            }
     1744
     1745            return $menus;
     1746        }
     1747
     1748        public function ArrayKeysLowercase($array){
     1749            $return =[];
     1750            foreach ($array as $key=>$value){
     1751                $return[strtolower($key)] = $value;
     1752            }
     1753                return $return;
     1754        }
    16671755    }
    16681756}
  • redi-restaurant-reservation/branches/andrew/templates/frontend.php

    r1654604 r1658007  
    3939        <input id="redi-restaurant-startDateISO" type="hidden" value="<?php echo $startDateISO ?>" name="startDateISO"/>
    4040
    41 
    4241        <?php if(!$hide_clock):?>
    4342        <label for="redi-restaurant-startHour"><?php _e('Time', 'redi-restaurant-reservation')?>:<span class="redi_required"> *</span></label>
     
    6362        <?php endif;?>
    6463        <label for="persons">
    65         <?php _e('Persons', 'redi-restaurant-reservation')?>:<span class="redi_required"> *</span></label>
     64            <?php _e('Persons', 'redi-restaurant-reservation')?>:<span class="redi_required"> *</span>
     65        </label>
    6666        <select name="persons" id="persons" class="redi-reservation-select">
    6767            <?php for ($i = $minPersons; $i != $maxPersons+1; $i++): ?>
     
    7676            <?php endif ?>
    7777        </select>
    78         <?php if ( $timeshiftmode === 'byshifts' || $hidesteps): ?>
     78        <div>
     79            <label for="menu">
     80                <?php _e('Menu', 'redi-restaurant-reservation')?>:<span class="redi_required"> *</span>
     81            </label>
     82           
     83            <select name="menu" id="menu" class="redi-reservation-select">
     84                <?php foreach($menus as $menu):?>
     85                <option value="<?php echo $menu['title'] ?>"><?php echo $menu['title'] ?></option>
     86                <?php endforeach ?>
     87            </select>
     88            <label for="duration">
     89                <?php _e('Duration', 'redi-restaurant-reservation')?>:<span class="redi_required"> *</span>
     90            </label>
     91            <?php $defaultDuration = 0;?>
     92            <?php foreach($durations as $duration):?>
     93            <?php if(isset($duration['default'])) $defaultDuration = $duration['minutes'];?>
     94                <button class="redi-restaurant-duration-button button" value="<?php echo $duration['minutes'] ?>"><?php echo $duration['title'] ?></button>     
     95            <?php endforeach ?>
     96            <input type="hidden" id="redi-restaurant-durationHidden" value="<?php echo $defaultDuration ?> "/>
     97        </div>
     98        <br/><br/>
     99        <?php if ( $timeshiftmode === 'byshifts' || $hidesteps): ?>         
    79100            <div id="step1times">
    80101                <span id="step1buttons">
     
    113134        <?php endif /* normal */ ?>
    114135        <div id="large_groups_message" style="display: none;" class="redi-reservation-alert-info redi-reservation-alert"><?php echo $largeGroupsMessage?></div>
    115 
    116 
    117136        <div id="step1busy" <?php if(!$all_busy):?>style="display: none;"<?php endif; ?> class="redi-reservation-alert-error redi-reservation-alert">
    118137            <?php _e('Reservation is not available on selected day. Please select another day.', 'redi-restaurant-reservation');?>
     
    130149    </div>
    131150
    132 
    133     <div id="step2" <?php if ($timeshiftmode !=='byshifts' || $hidesteps): ?>style="display: none" <?php endif ?>>
    134 
     151    <div id="step2" <?php if ($timeshiftmode !=='byshifts' || $hidesteps): ?>style="display: none" <?php endif ?>> 
    135152        <?php if ( $timeshiftmode !=='byshifts' || $hidesteps ): ?>
    136153            <h2>
     
    158175                    <?php if ( isset( $available['Availability'] ) && is_array($available['Availability']) ): ?>
    159176                        <?php $all_busy = true; ?>
    160 
    161177                        <?php foreach ( $available['Availability'] as $button ): ?><button title="<?php echo $button['Reason']?>" <?php if(!$button['Available']):?>disabled="disabled"<?php endif?> class="redi-restaurant-time-button button" value="<?php echo $button['StartTimeISO'] ?>"><?php echo $button['StartTime'] ?></button><?php if($button['Available']) $all_busy = false; ?><?php endforeach; ?>
    162178
Note: See TracChangeset for help on using the changeset viewer.