0

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 Groupsand 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 Groupone so adding a user is followed by adding subjects to it by selecting a year

tereško
  • 58,060
  • 25
  • 98
  • 150
fernandopcg
  • 514
  • 6
  • 20
  • Just define the relation between User and Group on User model which is called Model association...After association of model, Cakephp will do his magic... For more information read documentation.. – Fazal Rasel Apr 24 '14 at 18:54

2 Answers2

0

Wow, okay, you have your work cut out for you.

Start here. Read this entire page (Actually do it): http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html

Next Go here and once again actually read the whole thing: http://book.cakephp.org/2.0/en/models/saving-your-data.html

Finally, go here and read all of this: http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html

There is no way I could do a better job of explaining MVC and how you need to link your data than is already out there on the web, but I use the three pages I sent you to almost daily to do my work. You'll need to grind through all of them, but once you do you will understand what you need to do to solve your question. Good Luck, and its only about 30 pages total, so nothing too crazy.

usumoio
  • 3,500
  • 6
  • 31
  • 57
0

I believe this functionality is already available in Moodle as cohorts.

Users can be grouped into a cohort :

http://docs.moodle.org/26/en/Cohorts

Then enrolled on a course automatically by using the cohort sync enrolment plugin :

http://docs.moodle.org/26/en/Cohort_sync

Russell England
  • 9,436
  • 1
  • 27
  • 41