I've got a Simple piece of php code combined with some html.
What i want to do is as follow:
I've got a php class defining some properties in my code. Class - Statuses
Variables of "Statuses" - Circle, size, color.
I want to link an svg element that gives the size and and radius of the circle and then the color as well.
I've got a function that when it is met, an if statement will then need to display the class circle with a size and color depending on the condition that is met.
Here is the class:
<?php
class Statuses
{
var $circle;
var $size;
var $color;
public function print_condition()
{
echo $this->circle;
echo $this->size;
echo $this->color;
}
public function condition($circle, $size, $color)
{
$this->circle = $circle;
$this->size = $size;
$this->color = $color;
}
}
$daily = new Statuses;
$daily->condition("height=\"300\" width=\"300\"", "cx=\"150\" cy=\"150\" r=\"100\"", "stroke=\"black\" stroke-width=\"3\" fill=\"green\"");
$daily->print_condition();
Here is the function:
<?php
function funcName()
{
if (condition) {
echo "I want to echo the 'daily' variable here";
} else {
echo "I want to echo the 'none' variable here";
}
}
and Here is the svg elements:
<div id="circles">
<svg id="green" height="300" width="300">
<circle cx="150" cy="150" r="100" stroke="black" stroke-width="3" fill="green" />
</svg>
<br>
<svg id="orange" height="300" width="300">
<circle cx="150" cy="150" r="100" stroke="black" stroke-width="3" fill="orange" />
</svg>
<br>
<svg id="red" height="300" width="300">
<circle cx="150" cy="150" r="100" stroke="black" stroke-width="3" fill="red" />
</svg>
</div>
I'm not sure how to get the svg element to display properly in the variable and i'm not sure how to invoke the variable in my function either.
Your advice is greatly appreciated.
Your naming convention makes it very difficult to understand your intentions, although I believe the following is what you need. Essentially you're trying to hard to cut corners.
Each "statuses" has a set of variables that make is a circle as defined in your svg. Just edit your class to include these as such and rename your variables.
<?php
class myCircle
{
$name;
$height;
$width;
$cx;
$cy;
$r;
$stroke;
$stroke-width;
$fill;
private function _print()
{
echo "<svg id='$this->name' height='$this->height' width='$this->width'>
<circle cx='$this->cx' cy='$this->cy' r='$this->r' stroke='$this->stroke' stroke-width='$this->stroke-width' fill='$this->fill' />
</svg>";
}
private function _set($name, $height, $width, $cx, $cy, $r, $stroke, $stroke-width, $fill)
{
$this->name = $name;
$this->height = $height;
$this->width = $width;
$this->cx = $cx;
$this->cy = $cy;
$this->r = $r;
$this->stroke = $stroke;
$this->stroke-width = $stroke-width;
$this->fill = $fill;
}
}
End of Class.
You've omitted what exactly your $condition is, so I've not included it in my answer. But to fulfil that and then use your class, you simply have to do the following :
(either have your myCircle class on the same php page, or include it, and then)
<div id="circles">
<?php if($condition){
$daily = new myCircle;
$daily->_set("testCircle", "300", "300", "150", "150", "100", "black", 3, "green");
$daily->_print();
}else{
// Nothing?
} ?>
<div>
Or for your three circles :
<?php
$circles = array("green", "orange" "red");
?>
<div id="circles">
<?php
if($condition){
for($i = 0; $i < count($circles); $i++){
$daily = new myCircle;
$daily->_set($circles[$i], "300", "300", "150", "150", "100", "black", 3, $circles[$i]);
$daily->_print();
}
} else{
// Do nothing
}
?>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With