function getBids() { $bids = new MyCollection(); $q = "select b.id, u.username, b.amount, b.date from bids as b, users as u where b.mechanic_id = u.id and b.appointment_id = {$this->id} order by b.date;"; $result = @mysql_query($q); if (@mysql_num_rows($result) > 0) { while ($bid = @mysql_fetch_object($result)) { $bids->add($bid); } } else { return null; } return $bids; }
function getCurrentJobs() { $jobs = new MyCollection(); $q = "select a.id, s.name, a.start_time, a.end_time, a.help_status from appointments as a, services as s where a.service_id=s.id and customer_id='{$this->id}' and a.start_time>=CURDATE() order by a.start_time;"; $result = @mysql_query($q); $i = 0; while ($job = @mysql_fetch_object($result)) { $i++; $jobs->add($job); } if ($i == 0) { return null; } else { return $jobs; } }
function getAvailableResources($type) { require_once './modules/mysql_connect.php'; $resources = new MyCollection(); // check all the resources for this time and find out how many of each are being used $q = "select d.id, d.name, d.price, d.total, count(a.id) as used from resource_descriptions as d left join resources_used as u on d.id=u.description_id left join appointments as a on a.id=u.apt_id and ('{$this->startDate}'>=start_time and '{$this->startDate}'<end_time or '{$this->endDate}'>start_time and '{$this->endDate}'<=end_time) where d.type='{$type}' group by d.id;"; $result = @mysql_query($q); $i = 0; while ($availableResource = @mysql_fetch_assoc($result)) { // if the number being used at this time exceeds the total number of that resource, don't add it if ($availableResource['used'] < $availableResource['total']) { $i++; $usedResource = new UsedResource($availableResource['id'], $availableResource['name'], $availableResource['price'], $availableResource['total'], $availableResource['used']); $resources->add($usedResource); } } if ($i == 0) { return null; } else { return $resources; } }
function getWinningBids() { require_once './modules/mysql_connect.php'; $bids = new MyCollection(); // check all the resources for this time and find out how many of each are being used $q = "select s.name, a.start_time, a.end_time, b.amount from bids as b, appointments as a, services as s where b.appointment_id=a.id and a.service_id=s.id and bid_status='S' and a.start_time>CURDATE() and b.mechanic_id={$this->id};"; $result = @mysql_query($q); $i = 0; while ($bid = @mysql_fetch_object($result)) { $i++; $bids->add($bid); } if ($i == 0) { return null; } else { return $bids; } }
include './modules/wrappers/header.php'; require_once './modules/mysql_connect.php'; $mechanics = new MyCollection(); $q = "select * from users where user_type='M';"; $result = @mysql_query($q); $i = 0; while ($mechanic = @mysql_fetch_object($result)) { $i++; // select a count of all appointments this mechanic has been accepted for that have already passed // (we are assuming he actually showed up to these appointments and hence has gained experience from it) $q = "select count(*) as count from bids as b, appointments as a where b.appointment_id = a.id and b.bid_status='S' and b.mechanic_id={$mechanic->id} and a.end_time<NOW();"; $expResult = @mysql_query($q); while ($exp = @mysql_fetch_object($expResult)) { $mechanic->exp = $exp->count; } $mechanics->add($mechanic); } if ($i == 0) { $mechanics = null; } ?> <div class="infoBox"> <h2>Mechanics</h2> <p><strong>List of available mechanics for hire:</strong></p> <?php if ($mechanics != null) { ?> <table class="result_table" border="1px"><tr><th>First Name</th><th>Last Name</th><th>Experience Rating</th></tr> <?php foreach ($mechanics as $mechanic) { echo "<tr><td>" . $mechanic->first_name . "</td><td>" . $mechanic->last_name . "</td><td>" . $mechanic->exp . "</td></tr>";
echo "next: {$var}\n"; return $var; } public function valid() { $var = $this->current() !== false; echo "valid: {$var}\n"; return $var; } } class MyCollection implements IteratorAggregate { private $items = array(); private $count = 0; // Required definition of interface IteratorAggregate public function getIterator() { return new MyIterator($this->items); } public function add($value) { $this->items[$this->count++] = $value; } } $coll = new MyCollection(); $coll->add('value 1'); $coll->add('value 2'); $coll->add('value 3'); foreach ($coll as $key => $val) { echo "key/value: [{$key} -> {$val}]\n\n"; }