/** * Get the values for the specified fields, for the stated catalogue entry. * * @param ?ID_TEXT The catalogue name we are getting an entry in (NULL: lookup) * @param mixed The ID of the entry we are getting OR the row * @param ?array A list of fields that we are limiting ourselves to (NULL: get ALL fields) * @param ?array The database rows for the fields for this catalogue (NULL: find them) * @param boolean Whether to order the fields in their natural database order * @param ID_TEXT The view type we're doing * @set PAGE SEARCH CATEGORY * @return array A list of maps (each field for the entry gets a map), where each map contains 'effective_value' (the value for the field). Some maps get additional fields (effective_value_nontrans, effective_value_pure), depending on the field type */ function get_catalogue_entry_field_values($catalogue_name, $entry_id, $only_fields = NULL, $fields = NULL, $natural_order = false, $view_type = 'PAGE') { global $CAT_FIELDS_CACHE; if (is_null($fields)) { if (isset($CAT_FIELDS_CACHE[$catalogue_name]) && !$natural_order) { $fields = $CAT_FIELDS_CACHE[$catalogue_name]; } else { if (is_null($catalogue_name)) { $catalogue_name = $GLOBALS['SITE_DB']->query_value('catalogue_entries', 'c_name', array('id' => $entry_id)); } $fields = $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('*'), array('c_name' => $catalogue_name), 'ORDER BY ' . ($natural_order ? 'id' : 'cf_order')); } } if (!$natural_order) { $CAT_FIELDS_CACHE[$catalogue_name] = $fields; } require_code('fields'); // Work out an ID filter for what fields to show $only_field_ids = mixed(); if (get_value('catalogue_limit_cat_field_load__' . $catalogue_name) === '1') { $only_field_ids = array(); foreach ($fields as $i => $field) { $field_id = $field['id']; if (!is_null($only_fields) && !in_array($i, $only_fields)) { continue; } if ($field['cf_defines_order'] == 0) { if ($view_type == 'CATEGORY' && $field['cf_put_in_category'] == 0) { continue; } if ($view_type == 'SEARCH' && $field['cf_put_in_search'] == 0) { continue; } } $only_field_ids[] = $field_id; } } foreach ($fields as $i => $field) { $field_id = $field['id']; if (!is_null($only_fields) && !in_array($i, $only_fields)) { continue; } $ob = get_fields_hook($field['cf_type']); list($raw_type, , $type) = $ob->get_field_value_row_bits($field); if (is_null($raw_type)) { $raw_type = $field['cf_type']; } switch ($raw_type) { case 'short_trans': $fields[$i]['effective_value_nontrans'] = _get_catalogue_entry_field($field_id, $entry_id, 'short_trans', $only_field_ids); if (is_null($fields[$i]['effective_value_nontrans'])) { $fields[$i]['effective_value'] = do_lang_tempcode('INTERNAL_ERROR'); $fields[$i]['effective_value_pure'] = do_lang('INTERNAL_ERROR'); break; } $fields[$i]['effective_value'] = get_translated_tempcode(intval($fields[$i]['effective_value_nontrans'])); $fields[$i]['effective_value_pure'] = get_translated_text(intval($fields[$i]['effective_value_nontrans'])); break; case 'long_trans': $fields[$i]['effective_value_nontrans'] = _get_catalogue_entry_field($field_id, $entry_id, 'long_trans', $only_field_ids); if (is_null($fields[$i]['effective_value_nontrans'])) { $fields[$i]['effective_value'] = do_lang_tempcode('INTERNAL_ERROR'); $fields[$i]['effective_value_pure'] = do_lang('INTERNAL_ERROR'); break; } $fields[$i]['effective_value'] = get_translated_tempcode(intval($fields[$i]['effective_value_nontrans'])); $fields[$i]['effective_value_pure'] = get_translated_text(intval($fields[$i]['effective_value_nontrans'])); break; case 'long_text': $fields[$i]['effective_value_pure'] = _get_catalogue_entry_field($field_id, $entry_id, 'long', $only_field_ids); $fields[$i]['effective_value'] = $fields[$i]['effective_value_pure']; if (is_null($fields[$i]['effective_value'])) { $fields[$i]['effective_value'] = do_lang_tempcode('INTERNAL_ERROR'); $fields[$i]['effective_value_pure'] = do_lang('INTERNAL_ERROR'); break; } break; case 'short_text': $fields[$i]['effective_value_pure'] = _get_catalogue_entry_field($field_id, $entry_id, 'short', $only_field_ids); $fields[$i]['effective_value'] = $fields[$i]['effective_value_pure']; if (is_null($fields[$i]['effective_value'])) { $fields[$i]['effective_value'] = do_lang_tempcode('NA_EM'); $fields[$i]['effective_value_pure'] = do_lang('NA'); break; } break; case 'long_unescaped': $fields[$i]['effective_value'] = _get_catalogue_entry_field($field_id, $entry_id, 'long', $only_field_ids); if (is_null($fields[$i]['effective_value'])) { $fields[$i]['effective_value'] = do_lang_tempcode('NA_EM'); $fields[$i]['effective_value_pure'] = do_lang('NA'); break; } break; case 'short_unescaped': case 'float_unescaped': case 'integer_unescaped': $fields[$i]['effective_value'] = _get_catalogue_entry_field($field_id, $entry_id, $type, $only_field_ids); if (is_null($fields[$i]['effective_value'])) { $fields[$i]['effective_value'] = do_lang_tempcode('NA_EM'); $fields[$i]['effective_value_pure'] = do_lang('NA'); break; } break; default: warn_exit(do_lang_tempcode('INTERNAL_ERROR')); } } return $fields; }
/** * Save custom fields to a content item. * * @param ID_TEXT Award hook codename * @param ID_TEXT Content entry ID */ function save_form_custom_fields($content_type, $id) { if (fractional_edit()) { return; } $existing = get_bound_content_entry($content_type, $id); require_code('catalogues'); // Get field values $fields = $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('*'), array('c_name' => '_' . $content_type), 'ORDER BY cf_order'); $map = array(); require_code('fields'); foreach ($fields as $field) { $ob = get_fields_hook($field['cf_type']); list(, , $storage_type) = $ob->get_field_value_row_bits($field); $value = $ob->inputted_to_field_value(!is_null($existing), $field, 'uploads/catalogues', is_null($existing) ? NULL : _get_catalogue_entry_field($field['id'], $existing, $storage_type)); $map[$field['id']] = $value; } $first_cat = $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'MIN(id)', array('c_name' => '_' . $content_type)); require_code('catalogues2'); if (!is_null($existing)) { actual_edit_catalogue_entry($existing, $first_cat, 1, '', 0, 0, 0, $map); } else { $catalogue_entry_id = actual_add_catalogue_entry($first_cat, 1, '', 0, 0, 0, $map); $GLOBALS['SITE_DB']->query_insert('catalogue_entry_linkage', array('catalogue_entry_id' => $catalogue_entry_id, 'content_type' => $content_type, 'content_id' => $id)); } }
/** * Get a entry-id=>value map of what a submitted catalogue entry form has set * * @param ID_TEXT The name of the catalogue that was used * @param ?AUTO_LINK ID of entry being edited (NULL: not being edited) * @return array The map */ function get_set_field_map($catalogue_name, $editing_id = NULL) { // Get field values $fields = $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('*'), array('c_name' => $catalogue_name), 'ORDER BY cf_order'); $map = array(); require_code('fields'); require_code('catalogues'); foreach ($fields as $field) { $object = get_fields_hook($field['cf_type']); list(, , $storage_type) = $object->get_field_value_row_bits($field); $value = $object->inputted_to_field_value(!is_null($editing_id), $field, 'uploads/catalogues', is_null($editing_id) ? NULL : _get_catalogue_entry_field($field['id'], $editing_id, $storage_type)); $map[$field['id']] = $value; } return $map; }
/** * Delete a catalogue entry. * * @param AUTO_LINK The ID of the entry to delete */ function actual_delete_catalogue_entry($id) { $old_category_id = $GLOBALS['SITE_DB']->query_value('catalogue_entries', 'cc_id', array('id' => $id)); $catalogue_name = $GLOBALS['SITE_DB']->query_value('catalogue_entries', 'c_name', array('id' => $id)); require_code('fields'); require_code('catalogues'); $fields = $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('*'), array('c_name' => $catalogue_name)); $title = NULL; foreach ($fields as $field) { $object = get_fields_hook($field['cf_type']); list(, , $storage_type) = $object->get_field_value_row_bits($field); $value = _get_catalogue_entry_field($field['id'], $id, $storage_type); if (method_exists($object, 'cleanup')) { $object->cleanup($value); } if (is_null($title)) { if ($storage_type == 'long_trans' || $storage_type == 'short_trans') { $title = get_translated_text(intval($value)); } else { $title = $value; } } } $lang1 = $GLOBALS['SITE_DB']->query_select('catalogue_efv_long_trans', array('cv_value'), array('ce_id' => $id)); $lang2 = $GLOBALS['SITE_DB']->query_select('catalogue_efv_short_trans', array('cv_value'), array('ce_id' => $id)); $lang = array_merge($lang1, $lang2); foreach ($lang as $lang_to_delete) { if (true) { require_code('attachments2'); require_code('attachments3'); delete_lang_comcode_attachments($lang_to_delete['cv_value'], 'catalogue_entry', strval($id)); } else { delete_lang($lang_to_delete['cv_value']); } } $GLOBALS['SITE_DB']->query_delete('catalogue_efv_long_trans', array('ce_id' => $id)); $GLOBALS['SITE_DB']->query_delete('catalogue_efv_short_trans', array('ce_id' => $id)); $GLOBALS['SITE_DB']->query_delete('catalogue_efv_long', array('ce_id' => $id)); $GLOBALS['SITE_DB']->query_delete('catalogue_efv_short', array('ce_id' => $id)); $GLOBALS['SITE_DB']->query_delete('catalogue_efv_float', array('ce_id' => $id)); $GLOBALS['SITE_DB']->query_delete('catalogue_efv_integer', array('ce_id' => $id)); $GLOBALS['SITE_DB']->query_delete('catalogue_entries', array('id' => $id), '', 1); $GLOBALS['SITE_DB']->query_delete('trackbacks', array('trackback_for_type' => 'catalogues', 'trackback_for_id' => $id)); $GLOBALS['SITE_DB']->query_delete('rating', array('rating_for_type' => 'catalogues', 'rating_for_id' => $id)); require_code('seo2'); seo_meta_erase_storage('catalogue_entry', strval($id)); calculate_category_child_count_cache($old_category_id); decache('main_recent_cc_entries'); decache('main_cc_embed'); if ($catalogue_name[0] != '_') { log_it('DELETE_CATALOGUE_ENTRY', strval($id), $title); } }