Commit c1bc7042 by Damien Moulard

add local group to prestataires

parent b6fb99b5
......@@ -167,6 +167,7 @@ class WosmPL_Admin {
//TODO use of wp_verify_nonce
$wosmpl_latlon = $_POST['wosmpl_latlon'];
$wosmpl_geo_cat = $_POST['wosmpl_geo_cat'];
$wosmpl_local_group = $_POST['wosmpl_local_group'];
$wosmpl_presta_type = $_POST['wosmpl_presta_type'];
$wosmpl_post_addr = $_POST['wosmpl_post_addr'];
$wosmpl_partner_pict = $_POST['wosmpl_partner_pict'];
......@@ -184,6 +185,10 @@ class WosmPL_Admin {
$errors[] = 'Invalid category type';
}
if ($wosmpl_local_group && !is_numeric($wosmpl_local_group)) {
$errors[] = 'Invalid local group';
}
if (preg_match('/[^0-9 \, \.]+/', $wosmpl_latlon)) {
$errors[] = 'Invalid caracter in latlon string';
}
......@@ -207,6 +212,7 @@ class WosmPL_Admin {
$received_options = [
'wosmpl_latlon' => $wosmpl_latlon,
'wosmpl_geo_cat' => $wosmpl_geo_cat,
'wosmpl_local_group' => $wosmpl_local_group,
'wosmpl_presta_type' => $wosmpl_presta_type,
'wosmpl_post_addr' => $wosmpl_post_addr,
'wosmpl_partner_pict' => $wosmpl_partner_pict,
......@@ -223,15 +229,12 @@ class WosmPL_Admin {
if (count($errors) == 0) {
$metadata = get_post_meta( $post_id);
if (isset($metadata['wosmpl_latlon'])) {
foreach ($received_options as $key => $val){
update_post_meta( $post_id, $key, $val);
}
} else {
foreach ($received_options as $key => $val){
add_post_meta( $post_id, $key, $val);
foreach ($received_options as $key => $val) {
if (isset($metadata[$key])) {
update_post_meta( $post_id, $key, $val );
} else {
add_post_meta( $post_id, $key, $val );
}
}
} else {
......@@ -264,7 +267,7 @@ class WosmPL_Admin {
}
public function wosmpl_register_type(){
public function wosmpl_register_type() {
$args = array(
'label' => 'Partenaires',
'public' => true,
......@@ -274,7 +277,7 @@ class WosmPL_Admin {
'rewrite' => array('slug' => 'partenaires'),
'query_var' => true,
'menu_position'=> 5,
'has_archive' => TRUE,
'has_archive' => true,
//'menu_icon' => 'dashicons-video-alt',
'supports' => array(
'title',
......@@ -292,13 +295,14 @@ class WosmPL_Admin {
}
public function wosmpl_partner_template($single_template) {
global $post;
global $post;
if ($post->post_type == 'wosmpl_partners') {
$single_template = plugin_dir_path( dirname( __FILE__ ) ) . 'includes/templates/wosmpl-partner-template.php';
}
return $single_template;
}
if ($post->post_type == 'wosmpl_partners') {
$single_template = plugin_dir_path( dirname( __FILE__ ) ) . 'includes/templates/wosmpl-partner-template.php';
}
return $single_template;
}
}
......
......@@ -4,6 +4,8 @@ function wosmpl_geodata_box_html($post)
$wosmpl_latlon = get_post_meta($post->ID, 'wosmpl_latlon', true);
$s_cat = get_post_meta($post->ID, 'wosmpl_geo_cat', true);
$geo_cats = get_option('wosmpl_geo_cats', []);
$s_group = get_post_meta($post->ID, 'wosmpl_local_group', true);
$local_groups = get_option('wosmpl_local_groups', []);
$presta_type = get_post_meta($post->ID, 'wosmpl_presta_type', true);
$wosmpl_post_addr = get_post_meta($post->ID, 'wosmpl_post_addr', true);
......@@ -21,15 +23,26 @@ function wosmpl_geodata_box_html($post)
</div>
<?php if(count($geo_cats)>0) : ?>
<div>
<label for="wosmpl_geo_cat">Cat.</label>
<select name="wosmpl_geo_cat" class="postbox">
<option value="0" <?php selected($s_cat, '0'); ?>>Select cat.</option>
<?php
foreach ($geo_cats as $cat) {
echo '<option value="'.$cat['id'].'" '.selected($s_cat,$cat['id']).'>'.$cat['name'].'</option>';
}
?>
</select>
<label for="wosmpl_geo_cat">Cat.</label>
<select name="wosmpl_geo_cat" class="postbox">
<option value="0" <?php selected($s_cat, '0'); ?>>-- Select cat.</option>
<?php
foreach ($geo_cats as $cat) {
echo '<option value="'.$cat['id'].'" '.selected($s_cat, $cat['id']).'>'.$cat['name'].'</option>';
}
?>
</select>
</div>
<div>
<label for="wosmpl_local_group">Groupe local</label>
<select name="wosmpl_local_group" class="postbox">
<option value="0" <?php selected($s_group, '0'); ?>>-- Choix d'un groupe</option>
<?php
foreach ($local_groups as $group) {
echo '<option value="'.$group['id'].'" '.selected($s_group, $group['id']).'>'.$group['name'].'</option>';
}
?>
</select>
</div>
<div id="wosmpl_presta_type">
<label for="wosmpl_presta_type">Presta. type</label>
......
......@@ -28,5 +28,20 @@ if (is_null($geo_cats)) {
add_option('wosmpl_geo_cats', $geo_cats);
}
$local_groups = get_option('wosmpl_local_groups', NULL);
if (is_null($local_groups)) {
$local_groups = [
['id'=>1, 'name'=>"Montpellier Métropole"],
['id'=>2, 'name'=>"Bassin de Thau"],
['id'=>3, 'name'=>"Grand Pic Saint Loup-Vallée de l'Hérault"],
['id'=>4, 'name'=>"Pays de l'Or et de Lunel"],
['id'=>5, 'name'=>"Hérault Béziers Méditerranée"],
['id'=>6, 'name'=>"Lodèvois Larzac Clermontais"],
['id'=>7, 'name'=>"Grand Orb-Haut Languedoc-Minervois-Caroux"],
['id'=>8, 'name'=>"Avants Monts-Sud Hérault-La Domitienne"]
];
add_option('wosmpl_local_groups', $local_groups);
}
add_option('wosmpl_cat_icon_path', '/wp-content/plugins/wosmpl/public/css/images/');
add_option('wosmpl_cat_icon_name_prefix','wosmpl-marker-icon');
\ No newline at end of file
......@@ -143,7 +143,6 @@ function wosmpl_get_categories_ul($ul_class='sub-menu wosmpl-cat',$with_map_link
* Get loc geocat correspondance
* Will not more be needed in future version (dynamically retrieve cat data from kohinos)
*/
function get_local_geocat_id_correspondance ($kohinos_rubrique_slug) {
$id = 21;
switch ($kohinos_rubrique_slug) {
......@@ -215,6 +214,43 @@ function get_local_geocat_id_correspondance ($kohinos_rubrique_slug) {
return $id;
}
/*
* Get local group correspondance with local data
* TODO: more dynamic data correspondance
*/
function get_local_group_id_correspondance($kohinos_group_slug) {
// Default is first group
$id = 1;
switch ($kohinos_group_slug) {
case 'montpellier-metropole':
$id = 1;
break;
case 'bassin-de-thau':
$id = 2;
break;
case 'grand-pic-saint-loup-vallee-de-lherault':
$id = 3;
break;
case 'pays-de-lor-et-de-lunel':
$id = 4;
break;
case 'herault-beziers-mediterranee':
$id = 5;
break;
case 'lodevois-larzac-clermontais':
$id = 6;
break;
case 'grand-orb-haut-languedoc-minervois-caroux':
$id = 7;
break;
case 'avants-monts-sud-herault-la-domitienne':
$id = 8;
break;
}
return $id;
}
/**
* Programmaticaly insert (or update if kohinos_id found) a "partenaire" content
* Missing equivalents : wosmpl_partner_specialty, wosmpl_partner_challenge
......@@ -238,6 +274,7 @@ function wosmpl_insert_or_update_partner ($data) {
$defaultMetaAtCreation = [
'wosmpl_geo_cat' => '',
'wosmpl_local_group' => '',
'wosmpl_presta_type' => '',
'wosmpl_partner_challenge' => '',
'wosmpl_partner_specialty' => '',
......@@ -281,7 +318,10 @@ function wosmpl_insert_or_update_partner ($data) {
if (!empty($data['rubriques'])) {
//let's retrieve the last one (TODO : manage multi rubriques for a single partner)
$rub = array_pop($data['rubriques']);
$args['meta_input']['wosmpl_geo_cat'] = get_local_geocat_id_correspondance ($rub['slug']);
$args['meta_input']['wosmpl_geo_cat'] = get_local_geocat_id_correspondance($rub['slug']);
}
if (isset($data['groupe'])) {
$args['meta_input']['wosmpl_local_group'] = get_local_group_id_correspondance($data['groupe']['slug']);
}
if (!empty($data['metier'])) {
$args['meta_input']['wosmpl_presta_type'] = $data['metier'];
......@@ -318,13 +358,19 @@ function wosmpl_insert_or_update_partner ($data) {
}
if (is_numeric($pid)) {
$args['ID'] = $pid;
$post_id = wp_update_post($args);
if ($post_id) {
foreach ($args['meta_input'] as $key => $val) {
update_post_meta($post_id, $key, $val);
}
}
$args['ID'] = $pid;
$post_id = wp_update_post($args);
if ($post_id) {
$existing_metadata = get_post_meta( $post_id );
foreach ($args['meta_input'] as $key => $val) {
if (isset($existing_metadata[$key])) {
update_post_meta( $post_id, $key, $val );
} else {
add_post_meta( $post_id, $key, $val );
}
}
}
} else {
$args['meta_input'] += $defaultMetaAtCreation;
$post_id = wp_insert_post($args);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment