[RESOLU] Ajouter condition pour afficher 3 bordure d'image différente

Petit nouveau ! | 2 Messages

07 sept. 2013, 19:14

Bonsoir, je dispose d'un module php (widget worpdress) afin de gérer le recrutement pour notre guilde sur le jeu World of warcraft. Le soucis c'est qu'il n'affiche que l'image en clair quand on n'a besoin de cette classe et en grisé quand l'on ne la recherche pas. Une infobulle s'affiche pour monter la priorité du recrutement ( aucune, bas, moyen ou haut ) mais cela n'est pas assez tape a l’œil. Je voudrais savoir s'il était possible d'ajouter une fonction qui permet d'ajouter un border (rouge pour haut, jaune pour moyen et vert pour bas) sur l'image (image de classe a droite) qui est afficher. Une photo étant plus parlante je vous montre ce que je voudrais :) (Fait sur photoshop)

Original :
Image

Modifier :
Image

A savoir que le module et gérer par une partie Admin sur wordpress.
Image

Voila, je vous met a disposition le code du widget
- Un dossier images avec deux dossier ( Class, skills)
- widget.php
<?php
/*
Plugin Name: Simple WoW Recruitment DE
Plugin URI: http://www.frostproof.de/
Description: Simple World of Warcraft recruitment widget
Author: -Danio-
Version: 1.0.3
Author URI: http://www.frostproof.de/
*/

/*  This Plugin is a german translation and extension to Pandaria class.
	Original coding by:
	Copyright 2010-2011 tumichnix (email: tumichnix at screennetz.de)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

class SimpleWowRecruitment extends WP_Widget {

    /**
     * URL to plugin images
     */
    private $urlImages;

    /**
     * wow class
     */
    private $class = array(
        'dk' => array('sang ', 'givre ', 'impie '),
        'druide' => array('equilibre ', 'gardien ', 'farouche ', 'restauration '),
        'chasseur' => array('survie ', 'précision ', 'maitrise des bêtes '),
        'mage' => array('arcane ', 'feu ', 'givre '),
        'paladin' => array('sacré ', 'protection ', 'vindicte '),
        'prêtre' => array('discipline', 'sacré', 'ombre'),
        'voleur' => array('assassinat ', 'combat ', 'finesse '),
        'chaman' => array('elementaire ', 'amélioration ', 'restauration '),
        'démoniste' => array('affliction ', 'demonologie ', 'destruction '),
        'guerrier' => array('protection ', 'fureur ', 'armes '),
		'moine' => array('tisse-brume ', 'maître-brasseur ', 'maître-vent ')
    );

    /**
     * search options
     */
    private $searchOptions = array(
        0 => 'Aucune',
        1 => 'Bas',
        2 => 'Moyen',
        3 => 'Haut'
    );
	
	/**
	 * constructor
	 * @return void
	 */
	public function __construct() {
		$this->urlImages = WP_PLUGIN_URL.'/simple-wow-recruitment-de/images';
		parent::__construct('SimpleWowRecruitment', 'WoW-Recruitment', array('description' => 'Simple WoW Recruitment Widget'));
	}
	
	/**
	 * form
	 * @param array $instance 
	 * @return void
	 */
    public function form($instance) {
		$title = ($instance) ? esc_attr($instance['title']) : 'Recrutement';
        echo 'Titel:<br />';
        echo '<input type="text" class="widefat" id="'.$this->get_field_id('title').'" name="'.$this->get_field_name('title').'" value="'.$title.'" />';
        echo '<br /><br />';
		echo '<ul style="list-style-type: none">';
		foreach ($this->class as $class => $skills) {
            echo '<li><img src="'.$this->urlImages.'/class/'.$class.'.png" style="vertical-align: middle" /> <b>'.ucfirst($class).'</b>';
            echo '<ul style="margin-top: 10px; list-style-type: none">';
            foreach ($skills as $skill) {
				$key = $class.'-'.$skill;
                echo '<li style="padding-left: 30px"><img src="'.$this->urlImages.'/skills/'.$class.'_'.$skill.'.png" title="'.$this->formatSkill($skill).'" style="vertical-align: middle" />';
                echo '<select name="'.$this->get_field_name($key).'" id="'.$this->get_field_id($key).'" style="margin-left: 10px; width: 150px">';
                foreach ($this->searchOptions as $searchKey => $searchVal) {
                    echo '<option value="'.$searchKey.'" '.((array_key_exists($key, $instance) && $instance[$key] == $searchKey) ? 'selected="selected"' : '').'>'.$searchVal.'</option>';
                }
                echo '</select>';
                echo '</li>';
            }
            echo '</ul></li>';
        }
        echo '</ul>';
    }
	
	/**
	 * save
	 * @param array $new_instance
	 * @param array $old_instance
	 * @return array 
	 */
	public function update($newInstance, $oldInstance) {	
		$instance = $newInstance;
		$instance['title'] = strip_tags($newInstance['title']);		
		return $instance;
	}

	/**
	 *
	 * @param type $args
	 * @param type $instance 
	 */
    public function widget($args, $instance) {
		echo '<div class="widget-sb cf">';
		echo '<div class="">';
        echo '<div id="'.$args['widget_id'].'" class="widget-sb-title"><h3>'.$instance['title'].'</h3>';
		echo '</div>';
        echo '<div style="padding: 5px;"><table width="100%" border="0">';
        foreach ($this->class as $class => $skills) {
			echo '<tr height="22"><td><img src="'.$this->urlImages.'/class/'.$class.'.png" / style="vertical-align:middle;"> <span class="'.$class.'">'.ucfirst($class).'</span></td>';
			echo '<td width="99" style="text-align: right">';		
			foreach ($skills as $skill) {
				$key = $class.'-'.$skill;
				if (array_key_exists($key, $instance)) {
					if ($instance[$key] > 0) {
						echo '<img src="'.$this->urlImages.'/skills/'.$class.'_'.$skill.'.png" title="'.$this->formatSkill($skill).': '.$this->searchOptions[$instance[$key]].'"  style="vertical-align:middle;"/> ';
					} else {
						echo '<img src="'.$this->urlImages.'/skills/'.$class.'_'.$skill.'.png" title="'.$this->formatSkill($skill).': '.$this->searchOptions[$instance[$key]].'"  style="vertical-align:middle; filter:alpha(opacity=15); -moz-opacity: 0.15; opacity: 0.15;"/> ';
					}
				}
			}
			echo '</td></tr>';
        }
        echo '</table></div></div>';
		echo '</div>';
    }

    /**
     * format skillname
     * @param string $skill
     * @return string
     */
    private function formatSkill($skill) {

        return ucfirst(str_replace('_', ' ', $skill));
    }
}
add_action('widgets_init', create_function('', 'return register_widget("SimpleWowRecruitment");'));
?>
Si vous avez des question n'hésitez pas :) Bonne soirée

Petit nouveau ! | 2 Messages

09 sept. 2013, 00:07

Bon finalement j'ai résolue mon soucis avec un ami.. je vous donne la solution au cas ou cela pourrait servir à quelqu'un :
    public function widget($args, $instance) {
		echo '<div class="widget-sb cf">';
		echo '<div class="">';
        echo '<div id="'.$args['widget_id'].'" class="widget-sb-title"><h3>'.$instance['title'].'</h3>';
		echo '</div>';
        echo '<div style="padding: 5px;"><table width="100%" border="0">';
        foreach ($this->class as $class => $skills) {
			echo '<tr height="22"><td><img src="'.$this->urlImages.'/class/'.$class.'.png" / style="vertical-align:middle;"> <span class="'.$class.'">'.ucfirst($class).'</span></td>';
			echo '<td width="140" style="text-align: right">';		
			foreach ($skills as $skill) {
				$key = $class.'-'.$skill;
				if (array_key_exists($key, $instance)) {
                                        if ($instance[$key] == 0) {
                                                echo '<img src="'.$this->urlImages.'/skills/'.$class.'_'.$skill.'.png" title="'.$this->formatSkill($skill).': '.$this->searchOptions[$instance[$key]].'"  style="vertical-align:middle; border-style:solid; border-width:1px;  border-color:#241a18; filter:alpha(opacity=15); -moz-opacity: 0.15; opacity: 0.15;"/> ';
                                        } 
                                        elseif ($instance[$key] == 1)
                                        {
                                        echo '<img src="'.$this->urlImages.'/skills/'.$class.'_'.$skill.'.png" title="'.$this->formatSkill($skill).': '.$this->searchOptions[$instance[$key]].'"  style="vertical-align:middle;  border-style:solid; border-width:1px; border-color:red; "/> ';
                                        }
                                         elseif ($instance[$key] == 2)
                                        {
                                        echo '<img src="'.$this->urlImages.'/skills/'.$class.'_'.$skill.'.png" title="'.$this->formatSkill($skill).': '.$this->searchOptions[$instance[$key]].'"  style="vertical-align:middle;  border-style:solid; border-width:1px; border-color:yellow; "/> ';
                                        }
                                        elseif ($instance[$key] == 3)
                                        {
                                        echo '<img src="'.$this->urlImages.'/skills/'.$class.'_'.$skill.'.png" title="'.$this->formatSkill($skill).': '.$this->searchOptions[$instance[$key]].'"  style="vertical-align:middle;  border-style:solid; border-width:1px; border-color:green;  "/> ';
                                        }
                                        else
                                        {
                                        }
                                    }
                                }
			echo '</td></tr>';
        }
        echo '</table></div></div>';
		echo '</div>';
    }