post_type == "societe") {
$element = new stdClass();
//traitement des données
$element->id = $pid;
$element->titre = $p->post_title;
$logo = get_field('logo_soc', $pid);
$element->logo_id = $logo["ID"];
//var_dump(get_field('logo_soc',$pid));
list($element->logo) = wp_get_attachment_image_src($element->logo_id, 'logo_societe_offre');
list($element->logo_single_offre) = wp_get_attachment_image_src($element->logo_id, 'logo_societe_offre_single');
list($element->logo_partage_fb) = wp_get_attachment_image_src($element->logo_id, 'logo_image_partage_fb');
$element->titre = $p->post_title;
$element->infos = get_field('infos_soc', $pid);
$element->responsable = get_field('responsable_soc', $pid);
$element->activites = get_field('activites_soc', $pid);
$element->departement = get_field('departement_soc', $pid);
$element->effectifs = get_field('effectifs_soc', $pid);
$element->contact = get_field('contact_soc', $pid);
$element->url = get_field('url_soc', $pid);
$element->infos_sup = get_field('infos_sup_soc', $pid);
$terms = wp_get_post_terms($pid, 'type-activite');
$element->filtre_activite = isset($terms[0]) ? $terms[0] : null;
$terms = wp_get_post_terms($pid, 'filieres');
$filiere_societe = isset($terms[0]) ? $terms[0] : null;
$element->filiere_societe = isset($filiere_societe->name) ? $filiere_societe->name : '';
$element->gmap = array(
'active' => 1,
'titre' => $p->post_title,
'description' => "",
'addresse' => get_field('infos_soc', $pid),
'latitude' => get_field('latitude', $pid),
'longitude' => get_field('longitude', $pid)
);
//stocker dans le tableau statique
self::$_elements[$pid] = $element;
}
}
public static function get_all_societe_to_js()
{
$societes = self::get_all_societe_by_adress();
$key = 0;
$option = '';
foreach ($societes as $value) {
$tag = array();
$societe = self::getById($value[0]);
if (isset($societe->filtre_activite->term_id)) {
switch ($societe->filtre_activite->term_id) {
case AMONT:
$tag[] = 'blue';
$option = 'this.pinOn.bluePin';
break;
case TRAITEUR:
$tag[] = 'orange';
$option = 'this.pinOn.orgPin';
break;
case VOLAILLE:
$tag[] = 'red';
$option = 'this.pinOn.redPin';
break;
case INTERNATIONAL:
$tag[] = 'purple';
$option = 'this.pinOn.purplePin';
break;
case PLATEFORME:
$tag[] = 'green';
$option = 'this.pinOn.greenPin';
break;
case PLATEFORME_86:
$tag[] = 'yellow';
$option = 'this.pinOn.yellowPin';
break;
case PLATEFORME_87:
$tag[] = 'brown';
$option = 'this.pinOn.yellowPin';
break;
case PLATEFORME_88:
$tag[] = 'pink';
$option = 'this.pinOn.yellowPin';
break;
case PLATEFORME_89:
$tag[] = 'gray';
$option = 'this.pinOn.yellowPin';
break;
case PLATEFORME_90:
$tag[] = 'beige';
$option = 'this.pinOn.yellowPin';
break;
case PLATEFORME_91:
$tag[] = 'emerald';
$option = 'this.pinOn.yellowPin';
break;
case PLATEFORME_92:
$tag[] = 'coral';
$option = 'this.pinOn.yellowPin';
break;
}
}
$results[$key] = array(
//'address' => $societe->gmap['addresse'],
'lat' => $societe->gmap['latitude'],
'lng' => $societe->gmap['longitude'],
'tag' => $tag,
'id' => $societe->id,
'data' => array(
'multitag' => 0,
'name' => '',
'society' => $societe->titre,
'responsable' => $societe->responsable,
'activity' => $societe->activites,
'effective' => $societe->effectifs . ' salariés',
'address1' => str_replace("\n", "
", strip_tags($societe->infos)),
'contact' => str_replace("\n", "
", strip_tags($societe->contact)),
'imgLogo' => $societe->logo,
'filiere' => (($societe->filiere_societe) ? $societe->filiere_societe : " "),
'idsociete' => $value,
),
'options' => array(
'icon' => $option,
)
);
$key++;
}
return json_encode($results);
}
/**
* fonction qui retourne une liste filtrée
*
*/
public static function getBy($tax = null, $order_by = 'date')
{
$args = array(
'post_type' => 'societe',
'post_status' => 'publish',
'numberposts' => -1,
'offset' => 0,
'order' => ($order_by == 'title') ? 'ASC' : 'DESC',
'orderby' => $order_by,
'fields' => 'ids'
);
if (!is_null($tax)) {
$args['tax_query'][] = array(
'taxonomy' => 'type-activite',
'field' => 'id',
'terms' => $tax
);
}
$elements = get_posts($args);
$elts = array();
foreach ($elements as $id) {
$elt = self::getById(intval($id));
$elts[] = $elt;
}
return $elts;
}
/*
* trouver s'il existe une valeur d'un array dans un array
*/
public static function in_array_r($needle, $haystack, $strict = false)
{
foreach ($haystack as $item) {
if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && self::in_array_r($needle, $item, $strict))) {
return true;
}
}
return false;
}
/*
* trouver les ID et de même adresse
*/
public static function get_all_societe_by_adress()
{
$societes = self::getBy();
$societe_variable = array();
$id_array = array();
foreach ($societes as $societe) {
$adresse = get_field('latitude', $societe->id);
if (self::in_array_r($adresse, $societe_variable)) {
$id_array[$adresse][] = $societe->id;
} else {
$id_array[$adresse][] = $societe->id;
}
array_push($societe_variable, $adresse);
}
return $id_array;
}
/*
* items societe
*/
public static function get_societe_items($societe, $position)
{
ob_start();
?>