<?php
class page_livestock extends Page {
function init(){
parent::init();
$m = $this->add('Model_Livestock_Types');
$tabs = $this->add('Tabs');
foreach ($m as $r) { //Loop thru livestock types and create a tab with CRUD for each
$name = $r['name'];
$id = $r['id'];
$tm = $this->setModel("Livestock_$name")->addCondition('type_id', $id);
$tf = "setTab$name";
$tm['type_id'] = $id;
$tab = $tabs->addTab("$name");
if (method_exists(__CLASS__, $tf)) {
$this->$tf($tab, $tm); //some livestock need special form handling or CRUD fields, manage them with their own method
} else {
$this->setTab($tab, $tm); //if not use a default method
}
}
}
private function setTabPigs(&$t, $tm) {
$fields['grid'] = array('name','tag_no','sex','dob','dod');
$fields['edit'] = array('name','tag_no','sex','dob','dod','comments');
$c = $this->add('CRUD')->setModel($tm,$fields['edit'],$fields['grid']);
$t->add($c);
if ($f = $c->form) {
$f->addField('text','sire');
}
}
private function setTabSheep(&$t, $tm) {
$fields['grid'] = array('name','race','tag_no','sex','dob','dod');
$fields['edit'] = array('name','race','tag_no','sex','dob','dod','comments');
$t->add('CRUD')->setModel($tm,$fields['edit'],$fields['grid']);
}
private function setTab(&$t, $tm) {
$t->add('CRUD')->setModel($tm);
}
}