/** * */ public function refine(&$pa_destination_data, $pa_group, $pa_item, $pa_source_data, $pa_options = null) { global $g_ui_locale_id; $o_log = isset($pa_options['log']) && is_object($pa_options['log']) ? $pa_options['log'] : null; $o_trans = isset($pa_options['transaction']) && $pa_options['transaction'] instanceof Transaction ? $pa_options['transaction'] : null; $va_group_dest = explode(".", $pa_group['destination']); $vs_terminal = array_pop($va_group_dest); $pm_value = trim($pa_source_data[$pa_item['source']]); // tour name if (is_array($pm_value)) { $va_tours = $pm_value; // for input formats that support repeating values } else { $va_tours = array($pm_value); } foreach ($va_tours as $pm_value) { if (!$pm_value) { if ($o_log) { $o_log->logWarn(_t('[tourMakerRefinery] No value set for tour')); } return null; } // Does tour already exist? if ($vn_tour_id = caGetTourID($pm_value)) { return $vn_tour_id; } // Set tour_type $vs_type = null; if ($vs_type_opt = $pa_item['settings']['tourMaker_tourType']) { $vs_type = BaseRefinery::parsePlaceholder($vs_type_opt, $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')); } if ((is_null($vs_type) || !$vs_type) && ($vs_type_opt = $pa_item['settings']['tourMaker_tourTypeDefault'])) { $vs_type = BaseRefinery::parsePlaceholder($vs_type_opt, $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')); } if ((!isset($vs_type) || !$vs_type) && $o_log) { $o_log->logWarn(_t('[tourMakerRefinery] No tour type is set for tour %1', $pm_value)); } // Create tour $t_tour = new ca_tours(); $t_tour->setMode(ACCESS_WRITE); if ($o_trans) { $t_tour->setTransaction($o_trans); } $t_tour->set('type_id', $vs_type); if (is_array($pa_item['settings']['tourMaker_attributes'])) { foreach ($pa_item['settings']['tourMaker_attributes'] as $vs_fld => $vs_val) { if (is_array($vs_val)) { continue; } if ($t_tour->hasField($vs_fld)) { $t_tour->set($vs_fld, BaseRefinery::parsePlaceholder($vs_val, $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' '))); unset($pa_item['settings']['tourMaker_attributes'][$vs_fld]); } } } if (!$t_tour->insert()) { if ($o_log) { $o_log->logError(_t('[tourMakerRefinery] Could not create tour %1: %2', $pm_value, join("; ", $t_tour->getErrors()))); } return null; } $t_tour->addLabel(array('name' => $pm_value), $g_ui_locale_id, null, true); if ($t_tour->numErrors() > 0) { if ($o_log) { $o_log->logError(_t('[tourMakerRefinery] Could not add label for tour %1: %2', $pm_value, join("; ", $t_tour->getErrors()))); } } if (is_array($pa_item['settings']['tourMaker_attributes'])) { foreach ($pa_item['settings']['tourMaker_attributes'] as $vs_element => $va_attr) { if (!is_array($va_attr)) { $va_attr = array($vs_element => BaseRefinery::parsePlaceholder($va_attr, $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')), 'locale_id' => $g_ui_locale_id); } else { foreach ($va_attrs as $vs_k => $vs_v) { $va_attr[$vs_k] = BaseRefinery::parsePlaceholder($vs_v, $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')); } $va_attr['locale_id'] = $g_ui_locale_id; } $t_tour->addAttribute($va_attr, $vs_element); } if (!$t_tour->update()) { if ($o_log) { $o_log->logError(_t('[tourMakerRefinery] Could not save data for tour %1: %2', $pm_value, join("; ", $t_tour->getErrors()))); } } } } // return id return $t_tour->getPrimaryKey(); }
/** * */ public function refine(&$pa_destination_data, $pa_group, $pa_item, $pa_source_data, $pa_options = null) { $this->opb_returns_multiple_values = true; $o_log = isset($pa_options['log']) && is_object($pa_options['log']) ? $pa_options['log'] : null; $va_group_dest = explode(".", $pa_group['destination']); $vs_terminal = array_pop($va_group_dest); $vs_dest_table = $va_group_dest[0]; $pm_value = $pa_source_data[$pa_item['source']]; if (is_array($pm_value)) { $va_tour_stops = $pm_value; // for input formats that support repeating values } else { if ($vs_delimiter = $pa_item['settings']['tourStopSplitter_delimiter']) { $va_tour_stops = explode($vs_delimiter, $pm_value); } else { $va_tour_stops = array($pm_value); } } $va_vals = array(); $vn_c = 0; foreach ($va_tour_stops as $vn_i => $vs_tour_stop) { if (!($vs_tour_stop = trim($vs_tour_stop))) { continue; } if (in_array($vs_terminal, array('name_singular', 'name_plural'))) { $this->opb_returns_multiple_values = false; return $vs_tour_stop; } if (in_array($vs_terminal, array('preferred_labels', 'nonpreferred_labels'))) { return array(0 => array('name_singular' => $vs_tour_stop, 'name_plural' => $vs_tour_stop)); } // Set label $va_val = array('preferred_labels' => array('name_singular' => $vs_tour_stop, 'name_plural' => $vs_tour_stop)); // Set relationship type if ($vs_rel_type_opt = $pa_item['settings']['tourStopSplitter_relationshipType']) { $va_val['_relationship_type'] = BaseRefinery::parsePlaceholder($vs_rel_type_opt, $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')); } if ((!isset($va_val['_relationship_type']) || !$va_val['_relationship_type']) && ($vs_rel_type_opt = $pa_item['settings']['tourStopSplitter_relationshipTypeDefault'])) { $va_val['_relationship_type'] = BaseRefinery::parsePlaceholder($vs_rel_type_opt, $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')); } if ((!isset($va_val['_relationship_type']) || !$va_val['_relationship_type']) && $o_log) { $o_log->logWarn(_t('[tourStopSplitterRefinery] No relationship type is set for tour stop %1', $vs_tour_stop)); } // Set tour_stop_type if ($vs_type_opt = $pa_item['settings']['tourStopSplitter_tourStopType']) { $va_val['_type'] = BaseRefinery::parsePlaceholder($vs_type_opt, $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')); } if ((!isset($va_val['_type']) || !$va_val['_type']) && ($vs_type_opt = $pa_item['settings']['tourStopSplitter_tourStopTypeDefault'])) { $va_val['_type'] = BaseRefinery::parsePlaceholder($vs_type_opt, $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')); } if ((!isset($va_val['_type']) || !$va_val['_type']) && $o_log) { $o_log->logWarn(_t('[tourStopSplitterRefinery] No collection type is set for tour stop %1', $vs_tour_stop)); } // Set tour $vn_tour_id = null; if ($vs_tour = $pa_item['settings']['tourStopSplitter_tour']) { $vn_tour_id = caGetTourID($vs_tour); } if (!$vn_tour_id) { // No tour = bail! if ($o_log) { $o_log->logWarn(_t('[tourStopSplitterRefinery] Could not find tour %1 to relate stop stops to.', $vs_tour_stop)); } return array(); } $va_val['tour_id'] = $vn_tour_id; // Set stop parents if ($va_parents = $pa_item['settings']['tourStopSplitter_parents']) { $va_val['parent_id'] = $va_val['_parent_id'] = caProcessRefineryParents('tourStopSplitterRefinery', 'ca_tour_stops', $va_parents, $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'log' => $o_log)); } // Set attributes if (is_array($va_attr_vals = caProcessRefineryAttributes($pa_item['settings']['tourStopSplitter_attributes'], $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'log' => $o_log)))) { $va_val = array_merge($va_val, $va_attr_vals); } if (!$va_val['_parent_id']) { if ($o_log) { $o_log->logError(_t('[tourStopSplitterRefinery] No parent found for %1', $vs_tour_stop)); } return array(); } $va_vals[] = $va_val; $vn_c++; } return $va_vals; }
/** * Override set() to do idno lookups on tours * */ public function set($pa_fields, $pm_value = "", $pa_options = null) { if (!is_array($pa_fields)) { $pa_fields = array($pa_fields => $pm_value); } foreach ($pa_fields as $vs_fld => $vs_val) { if ($vs_fld == 'tour_id' && preg_match("![^\\d]+!", $vs_val)) { if ($vn_tour_id = caGetTourID($vs_val)) { $pa_fields[$vs_fld] = $vn_tour_id; } } } return parent::set($pa_fields, null, $pa_options); }
/** * Fetch stop_id for stop with specified idno in tour * * @param string $ps_tour_code Tour code * @param string $ps_idno idno of stop to return stop_id for * @return int item_id of list item or null if no matching item was found */ function caGetTourStopID($ps_tour_code, $ps_idno) { $vn_tour_id = caGetTourID($ps_tour_code); $t_stop = new ca_tour_stops(); return $t_stop->load(array('tour_id' => $vn_tour_id, 'idno' => $ps_idno)); }