/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Monitor the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Printers::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function getInfo() { /* Items allocated*/ $commodity['consumable'] = Consumable::model()->findAll(); $commodity['monitor'] = Monitor::model()->findAll(); $commodity['printers'] = Printers::model()->findAll(); $commodity['devices'] = Devices::model()->findAll(); $dup = $commodity; /* Items available on Loan*/ $availableOnLoan = 0; $thresholdItems = 0; $content = ''; foreach ($commodity as $key => $commo) { foreach ($commo as $item) { if ($item['available_on_loan'] == 1 || $item['available_on_loan'] == 'Yes') { ++$availableOnLoan; } if ($key == 'consumable') { $commodity = Commodity::model()->findByAttributes(array('name' => $key)); $allocates = Allocate::model()->findAllByAttributes(array('commodity_id' => $commodity['id'], 'cons_id' => $item['id'])); if (count($allocates) < $item['threshold']) { ++$thresholdItems; } } } } /** Allocated and unallocated **/ $countAllocated = 0; $countUnAllocated = 0; $commodity = $dup; $unAllocated = Allocate::model()->findAllByAttributes(array('date_out' => NULL)); $allocated = Allocate::model()->findAll('date_out IS NOT NULL'); $countAllocated += count($allocated); $countUnAllocated += count($unAllocated); $content .= '<b style="color:red">' . $availableOnLoan . '</b> item available on loan<br/>'; $content .= '<b style="color:red">' . $thresholdItems . '</b> item below threshold<br/>'; $content .= '<b style="color:red">' . $countAllocated . '</b> item allocated<br/>'; $content .= '<b style="color:red">' . $countUnAllocated . '</b> item unallocated<br/>'; /* Items below threshold*/ return $content; }