0

Hie guys, im seeking your help. An applicant applies for a place and the details are saved in the applicants table and is given a default status of waiting. The administrator accepts applicants form waiting to either accepted or denied. When a student is accepted his details should automatically be saved to the students table. Applicants table and students have 26 fields in common and the national id is common and unique in both tables but it is not a primary key in either table.

a) Is it possible to approve applicants to students and post their details to students details in this instance?

b) How do i link these two tables? Is it possible to link tables with a unique key that is not a primary key in cakephp?

c) How can i transfer the details from applicants details to students details?

For posting data from applicants details to students i have tried this in my controller but i am getting fatal error. I have only tried two fields for testing.

if($this->request->data['submit']=='Approve') {
    $this->ApplicantsDetail->StudentDetail->set(array(
        'reg_number' => $regnumber,
        'code'=>$code
    ));
}

For approving applicants to students i used the following code

if($this->request->data['submit']=='Approve') { 
    $code=$this->request->data['ApplicantsDetail']['code'];

    for($k=0;$k<sizeof($this->request->data['ApplicantsDetail']['id']);$k++){
        $id=$this->request->data['ApplicantsDetail']['id'];
        $newcode=$this->ApplicantsDetail->ProgrammeChoice->find('list', array(
            'fields'=>array('applicants_detail_id','choice','programme_code'),
            'conditions'=>array('ProgrammeChoice.programme_code'=>$code,'ProgrammeChoice.choice'=>1)
        ));
        $tau1 = array('ApplicantsDetail.statu_id' => '1');
    }
}   
tereško
  • 58,060
  • 25
  • 98
  • 150
alicemap
  • 43
  • 1
  • 10

1 Answers1

0

When admin approves the record, get the data of that record by id or code as you like -

$applicationData        = $this->ApplicantsDetail->findById($applicationId);

or

$applicationData        = $this->ApplicantsDetail->findByCode($applicationCode);

Then create an array as follows -

$studentData['StudentDetail'] = $applicationData['ApplicantsDetail'];

And then save the record in students table.

$this->StudentDetail->save($studentData);
Sitansu
  • 861
  • 2
  • 14
  • 24
  • Thank you Sitansu, but some of the fields in applicant are not in the student so the entire applicant's record is not being moved to the student but about 26 fields of 40 are the same – alicemap Jul 17 '12 at 13:15
  • You can unset those fields also if you want to add some extra fields you can add also. Like. unset($applicationData['ApplicantsDetail']['image']); . . before assigning to the new array. If you want to add extra fields you can add after assigning to the new array as - $studentData['StudentDetail'] = $applicationData['ApplicantsDetail']; $studentData['StudentDetail']['new_field'] = 'xyz'; – Sitansu Jul 18 '12 at 11:59