• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IF $class = ($value->status == "done") HOW?

#1
Guys, I would like to use this to show three different colors on my gantt chart:

Code:
$class = ($value->status == "done") ? "#336699" : "";

Currently I have one color, that shows done tasks
Is this possible to use something like:


Code:
if $class = ($value->status == "open") ? "#536699" : "";
if $class = ($value->status == "in_progress") ? "#796699" : "";
if $class = ($value->status == "done") ? "#336699" : "";

But of course above code doesn't work. Can You please help me to create some "if" listing for that?
Reply

#2
https://davidwalsh.name/php-shorthand-if...-operators
Reply

#3
I would propose another way. Make the following helper function, PHP:

Code:
function get_task_status_class($status) {

    $status = strtolower(str_replace('_', '-', $status));

    if (!in_array($status, array(
        'open',
        'in-progress',
        'done'
    ))) {

        return '';
    }

    return $status;
}

It is to be used within the views, for example:

Code:
<span class="task-name <?php echo get_task_status_class($status); ?>"><?php echo html_escape($task_name); ?></span>

And add to your CSS:

Code:
.task-name.open {
    color: #536699;
}

.task-name.in-progress {
    color: #796699;
}

.task-name.done {
    color: #336699;
}
Reply

#4
You can use the switch conditional statement:

PHP Code:
switch ($value->status) {
  case 
"open":
     
$class "#536699";
     break;
  case 
"in_progress" :
     
$class "#796699";
     break;
   case 
"done" :
     
$class "#336699";
     break;
   default : 
      
//do nothing

Reply

#5
Hello,

Why not that :
$class = ($value->status == 'open') ? "#536699" : (($value->status == 'in_progress') ? "#796699" : (($value->status == 'done') ? "#336699" : ""));

Matt.
Reply

#6
This will also work.

PHP Code:
if($value->status === "open")
 
 {
 
   $class "#536699" 
  
}
elseif(
$value->status === "in_progress")
 
 {
 
   $class "#796699";
 
 }
else
 
 {
 
   $class "#336699";
 
 

I think that @ivantcholakov suggestion of using a CSS file instead of hardcoded color values is a very good idea. Not that I set a good example of that here  Angel
Reply

#7
@Fraps900, what's your feedback on the suggestions we gave you?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.