ldc-groupe/content/themes/ldc/societe.class.php
Vincent BRIDIER 134507db43 - Backup DEV
- Add DotEnv
- Fix Bato
- Etc..
2020-05-04 15:59:02 +02:00

283 lines
No EOL
9.3 KiB
PHP

<?php
class CSociete {
private static $_elements;
public function __construct() {
}
/**
* fonction qui prend les informations son Id.
*
* @param type $pid
*/
public static function getById($pid) {
$pid = intval($pid);
//On essaye de charger l'element
if(!isset(self::$_elements[$pid])) {
self::_load($pid);
}
//Si on a pas réussi à chargé l'article (pas publiée?)
if(!isset(self::$_elements[$pid])) {
return FALSE;
}
return self::$_elements[$pid];
}
/**
* fonction qui charge toutes les informations dans le variable statique $_elements.
*
* @param type $pid
*/
private static function _load($pid) {
$pid = intval($pid);
$p = get_post($pid);
if($p->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", "<br />", strip_tags($societe->infos)),
'contact' => str_replace("\n", "<br />", strip_tags($societe->contact)),
'imgLogo' => $societe->logo,
'filiere' => (($societe->filiere_societe)? $societe->filiere_societe:"&nbsp;"),
'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();
?>
<div class="implantation-control clearfix">
<a data-societe="<?php echo $position; ?>" href="javascript:;" title="" class="prev-control"></a>
<a data-societe="<?php echo ($position + 1); ?>" href="javascript:;" title="" class="next-control"></a>
</div>
<div class="address-wrapper">
<div class="navigation-societe">1/2</div>
<a href="#" title="" class="close">
<img src="<?php echo get_template_directory_uri(); ?>/images/design/close_map.png" alt="">
</a>
<h2><?php echo (($societe->filiere_societe)? $societe->filiere_societe:"&nbsp;");?></h2>
<div class="adress clearfix" >
<img src="<?php echo $societe->logo;?>" alt="" class="implantation-img"/>
<div class="description">
<h2>Société : <?php echo $societe->titre;?></h2>
<div class="detail-societe clearfix">
<p class="societe-adress">
<span><?php echo __("Adresse", 'ldc');?> : </span><br>
<span class="address"><?php echo str_replace("\n", "<br />", strip_tags($societe->infos));?></span>
</p>
<p>
<span><?php echo __("Responsable", 'ldc');?> : </span><span class="responsable"><?php echo $societe->responsable;?></span>
</p>
<p>
<span><?php echo __("Activités", 'ldc');?> : </span><span class="activity"><?php echo $societe->activites;?></span>
</p>
<p>
<span><?php echo __("Effectifs", 'ldc');?> : </span><span class="effective"><?php echo $societe->effectifs . ' salariés';?></span>
</p>
</div>
<p class="contact-societe">
<span class="contact"><?php echo str_replace("\n", "<br />", strip_tags($societe->contact));?></span>
</p>
</div>
</div>
</div>
<?php
$contents = ob_get_contents();
ob_clean();
echo $contents;
}
}
?>