We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34109
    • 119 Posts
    I'm building a bookings system using MIGXDB. The system takes bookings for 8 minute slots during the day, so when a booking is added I need the user to first select a date, then based on that date have all the available time slots displayed in a select list. Is this possible with MIGXDB?

    Thanks!

    Chris
      Studio Republic
      http://www.studiorepublic.com
      0845 226 3205
      @christodhunter
      • 4172
      • 5,888 Posts
      there are several ways.

      I think the simplest would be to have listbox-TVs for year/month/day/available time slots build with the dynamicdropdown-TVs
      https://github.com/Bruno17/dddx

      With dddx you can define parent/child - listbox - TVs, which are depending on each other.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 34109
        • 119 Posts
        Thanks Bruno - I'll take a look at dddx
          Studio Republic
          http://www.studiorepublic.com
          0845 226 3205
          @christodhunter
          • 34109
          • 119 Posts
          Thanks Bruno - I'll take a look at dddx
            Studio Republic
            http://www.studiorepublic.com
            0845 226 3205
            @christodhunter
            • 4172
            • 5,888 Posts
            found I've created exactly something like that some time ago for a court-reservation-system
            Could try to package my configuration together.
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 34109
              • 119 Posts
              That would be awesome Bruno - thank you! Looking at dddx I'm not sure it would do what I need it to. The second TV would need to be populated with all the times not already booked, rather than pulling in rows from the database.
                Studio Republic
                http://www.studiorepublic.com
                0845 226 3205
                @christodhunter
                • 4172
                • 5,888 Posts
                yeah, exactly like mine. There is a special processor which collects the available times (not allready booked) for the combo.
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 34109
                  • 119 Posts
                  Ah ok - looked more into dddx and the examples and it looks perfect. You're a star, Bruno!
                    Studio Republic
                    http://www.studiorepublic.com
                    0845 226 3205
                    @christodhunter
                    • 4172
                    • 5,888 Posts
                    create 4 dddx - TVs

                    1.
                    name: reservation_year
                    dddx Group: reservation

                    2.
                    Parent Dropdown: select-> reservation_year
                    name: reservation_month
                    dddx Group: reservation

                    3.
                    Parent Dropdown: select-> reservation_month
                    name: reservation_day
                    dddx Group: reservation

                    4.
                    Parent Dropdown: select-> reservation_day
                    name: reservation_slot
                    dddx Group: reservation

                    and 4 processors

                    core/components/dddx/processors/mgr/reservation/getoptions.reservation_year.php

                    <?php
                    
                    $tv = $modx->getObject('modTemplateVar', array('name' => $scriptProperties['tvname']));
                    $inputProperties = $tv->get('input_properties');
                    
                    $firstText = $modx->getOption('firstText', $inputProperties, '-- choose one --');
                    
                    $startjahr = strftime('%Y');
                    //$ruletype = $modx->getOption('reservation_ruletype', $scriptProperties, 0);
                    $startmonat = 1;
                    $options = array();
                    $options[] = array('id' => '', 'name' => $firstText);
                    
                    for ($i = $startjahr; $i <= $startjahr + 1; $i++) {
                        $option['id'] = $i;
                        $option['name'] = $i;
                        $options[] = $option;
                    }
                    
                    $count = count($options);
                    
                    return $this->outputArray($options, $count);
                    
                    


                    core/components/dddx/processors/mgr/reservation/getoptions.reservation_month.php

                    <?php
                    
                    $tv = $modx->getObject('modTemplateVar', array('name' => $scriptProperties['tvname']));
                    $inputProperties = $tv->get('input_properties');
                    
                    $firstText = $modx->getOption('firstText', $inputProperties, '-- choose one --');
                    
                    $year = $modx->getOption('reservation_jahr', $scriptProperties, strftime('%Y'));
                    $startmonat = 1;
                    $options = array();
                    $options[] = array('id' => '', 'name' => $firstText);
                    if (!empty($year)) {
                        $days_in_month = date('t', strtotime($year . '-' . $month . '-01'));
                        $starttag = 1;
                        for ($i = $startmonat; $i <= 12; $i++) {
                            $option['id'] = $i;
                            $option['name'] = $i;
                            $options[] = $option;
                        }
                    }
                    $count = count($options);
                    
                    return $this->outputArray($options, $count);
                    
                    


                    core/components/dddx/processors/mgr/reservation/getoptions.reservation_day.php

                    <?php
                    
                    $tv = $modx->getObject('modTemplateVar', array('name' => $scriptProperties['tvname']));
                    $inputProperties = $tv->get('input_properties');
                    
                    $firstText = $modx->getOption('firstText', $inputProperties, '-- choose one --');
                    
                    $year = $modx->getOption('reservation_jahr', $scriptProperties, strftime('%Y'));
                    $month = $modx->getOption('reservation_monat', $scriptProperties, 0);
                    
                    $options = array();
                    $options[] = array('id' => '', 'name' => $firstText);
                    if (!empty($month)) {
                        $days_in_month = date('t', strtotime($year . '-' . $month . '-01'));
                        $starttag = 1;
                    
                        for ($i = $starttag; $i <= $days_in_month; $i++) {
                            $option['id'] = $i;
                            $option['name'] = $i;
                            $options[] = $option;
                        }
                    }
                    
                    
                    $count = count($options);
                    
                    return $this->outputArray($options, $count);
                    


                    core/components/dddx/processors/mgr/reservation/getoptions.reservation_slot.php

                    here with some demo-content, you will need to modify it to your needs.

                    <?php
                    
                    $year = $modx->getOption('reservation_jahr', $scriptProperties, 0);
                    $month = $modx->getOption('reservation_monat', $scriptProperties, 0);
                    $day = $modx->getOption('reservation_tag', $scriptProperties, 0);
                    //$court_id = $modx->getOption('reservation_platz',$scriptProperties,0);
                    //$ruletype = $modx->getOption('reservation_ruletype',$scriptProperties,0);
                    $reservation_id = $modx->getOption('object_id', $scriptProperties, 0);
                    
                    
                    $tv = $modx->getObject('modTemplateVar', array('name' => $scriptProperties['tvname']));
                    $inputProperties = $tv->get('input_properties');
                    
                    $firstText = $modx->getOption('firstText', $inputProperties, '-- choose one --');
                    
                    /*
                    $classname = $modx->getOption('classname', $inputProperties, '');
                    $packageName = $modx->getOption('packagename', $inputProperties, '');
                    
                    if (!empty($packageName)) {
                    $packagepath = $modx->getOption('core_path') . 'components/' . $packageName . '/';
                    $modelpath = $packagepath . 'model/';
                    
                    $modx->addPackage($packageName, $modelpath, $prefix);
                    }
                    */
                    
                    
                    $options = array();
                    $options[] = array('id' => '', 'name' => $firstText);
                    $reservables = array();
                    if (!empty($court_id) && !empty($day) && !empty($month) && !empty($year)) {
                    
                        $date = strtotime($year . '-' . $month . '-' . $day);
                    
                    
                        if ($court = $modx->getObject('crCourt', $court_id)) {
                            $reservables = $court->generateReservableArray($date, $ruletype);
                    
                            foreach ($reservables as $reservable) {
                                if (isset($reservable['reservation_id']) && $reservable['reservation_id'] != $reservation_id) {
                                    //Stunde ist durch andere Reservation belegt
                                } else {
                                    $option['id'] = $reservable['hour'];
                                    $option['name'] = $reservable['hour'];
                                    $options[] = $option;
                                }
                    
                    
                            }
                    
                        }
                    }
                    //some demo-reservables
                    $reservables = '
                        [
                        {"hour":"8:00",
                        "reservation_id":"10"},
                        {"hour":"8:30",
                        "reservation_id":"11"},
                        {"hour":"9:00"},
                        {"hour":"9:30",
                        "reservation_id":"12"},
                        {"hour":"10:00",
                        "reservation_id":"13"},
                        {"hour":"10:30"},
                        {"hour":"11:00"},
                        {"hour":"11:30"},
                        {"hour":"12:00",
                        "reservation_id":"14"},
                        {"hour":"12:30"},
                        {"hour":"13:00"},
                        {"hour":"13:30"},
                        {"hour":"14:00"},
                        {"hour":"14:30"},
                        {"hour":"15:00"}
                        ]';
                    
                    $reservables = $modx->fromJson($reservables);
                    
                    
                    foreach ($reservables as $reservable) {
                        if (isset($reservable['reservation_id']) && $reservable['reservation_id'] != $reservation_id) {
                            //Stunde ist durch andere Reservation belegt
                        } else {
                            $option['id'] = $reservable['hour'];
                            $option['name'] = $reservable['hour'];
                            $options[] = $option;
                        }
                    
                    
                    }
                    
                    $count = count($options);
                    
                    return $this->outputArray($options, $count);
                    
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                      • 34109
                      • 119 Posts
                      Fantastic - thank you Bruno!!
                        Studio Republic
                        http://www.studiorepublic.com
                        0845 226 3205
                        @christodhunter