I have a CakePHP-based application in development which acts as a user management tool in a Moodle-powered university and connects to Moodle's database.
Therefore the models we will have are: Users
, Groups
(Used as academic years, such as 2nd of Law Courses
(Used as unique subjects, such as "3rd IT's Database Management II")
This application is to be used only by an administrator, who will add new users and update existing ones as needed each year. Having the list of groups already populated, the administrator should browse to /users/add/, input the user details and then when clicking "Save" instead of returning to a list of students, he should be asked to select which group to enrol the student in (For example, first year of Architecture, 3rd year of Medicine...), which in turn will add him to corresponding HABTM tables of both Groups
and Courses
(Still haven't tried to edit Moodle's DB directly). However as I don't fully get this whole MVC thing I'm not sure of where to begin with as I don't seem to find the right examples and docs.
When editing the user, I think I would put some buttons to make tasks such as enroling the user in the next year subjects easier and faster, but that's stuff I'll worry about later when the basic functionality is working.
Below are some of my files, they are pretty basic.
Users/add.ctp
<h1>Add User</h1>
<?php
echo $this->Form->create('User');
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->input('name');
echo $this->Form->input('surname');
echo $this->Form->input('email');
echo $this->Form->input('role'); // Student or Teacher
echo $this->Form->end('Save User');
?>
Part of UsersController.php
public function add() {
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('Your user has been saved.'));
return $this->redirect(array('action' => 'index')); <!-- There would be a link to the enrolment page here? -->
}
$this->Session->setFlash(__('Unable to add your user.'));
}
}
I don't really know how to link the Users
model with the Group
one so adding a user is followed by adding subjects to it by selecting a year