Esempio n. 1
0
 public function create_children_departure($tsmart_departure_id)
 {
     $query = $this->_db->getQuery(true);
     $query->delete('#__tsmart_departure')->where('tsmart_departure_parent_id=' . (int) $tsmart_departure_id);
     $this->_db->setQuery($query);
     $ok = $this->_db->execute();
     if (!$ok) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     $table_departure = $this->getTable();
     $table_departure->load($tsmart_departure_id);
     $date_type = $table_departure->date_type;
     if ($date_type == 'day_select') {
         $days_seleted = explode(',', $table_departure->days_seleted);
     } else {
         $sale_period_from = $table_departure->sale_period_from;
         $sale_period_to = $table_departure->sale_period_to;
         $days_seleted = TSMUtility::dateRange($sale_period_from, $sale_period_to);
         $weekly = $table_departure->weekly;
         $weekly = explode(',', $weekly);
         foreach ($days_seleted as $key => $day) {
             $day_of_week = strtolower(date('D', strtotime($day)));
             if (!in_array($day_of_week, $weekly)) {
                 unset($days_seleted[$key]);
             }
         }
     }
     require_once JPATH_ROOT . '/administrator/components/com_tsmart/helpers/tsmdeparture.php';
     foreach ($days_seleted as $day) {
         $table_departure->departure_date = $day;
         $day = JFactory::getDate($day);
         $table_departure->tsmart_departure_id = 0;
         $table_departure->departure_code = tsmDeparture::get_format_departure_code($tsmart_departure_id, $day);
         $table_departure->tsmart_departure_parent_id = $tsmart_departure_id;
         $ok = $table_departure->store();
         if (!$ok) {
             $this->setError($table_departure->getErrors());
             return false;
         }
     }
     return true;
 }