Reputation: 445
I've been braking my brain tryig to figure out how to model this, instead of going on low level php. So I have these models/tables:
Student (id,name). Program (id, name, startdate, enddate, firstpaymentDueDate, qtyOfPeriods, price).
I have to register the application of a student into a program that consist on several months. So I want to populete a table: paymentSchedule (id, student_id, dueDate, amount) Since one program can have upto 10 periods, I would need to add auto 10 records in the paymentSchedule for each student application. My question is if this can be modeled?
I would leter use the paymentSchedule to take records for payments and insert them into a transactions table.
Thanks for all your support, and thanks for developing such great toolkit!
Upvotes: 0
Views: 172
Reputation: 190
SHORT ANSWER: YES, you can model this in ATK4
You basically have all the tables perfectly set up.
To create a model, simply create a file Student.php and place it in your /lib/Model/ folder.
class Model_Student extends Model_Table {
public $entity_code = 'Student';
function init() {
parent::init();
$this->addField('name')->caption('Student Name');
}
}
You can do the same for your other tables:
Program (id, name, startdate, enddate, firstpaymentDueDate, qtyOfPeriods, price)
and
paymentSchedule (id, student_id, dueDate, amount)
To know more about models, i suggest you read the intro: http://agiletoolkit.org/learn/understand/model/intro
Processing a table, like paymentSchedule
is a different
story altogether. You need DSQL (Dynamic SQL) to do this.
Assuming your Program
table is in a model class named
Model_Program
. To retrieve an entry:
$m = $this->add('Model_Program');
$v = $m->dsql()
->field('qtyOfPeriods')
->field('price')
->where('id=',$programid) // specific program
->do_getOne();
$m = $this->add('Model_PaymentSched');
$r = $m->dsql()
->set('student_id',$studentid) // specific student
->set('amount',$v['price'])
->do_insert();
This will retrieve an entry for a particular program and then insert it in the payment schedule:
Upvotes: 2