13/02/2013 1:26pm

PHP | Problem -


class SchoolClass extends DataObject {


static $db = array (
'Name' => 'Varchar',
'RegistrationCode' => 'Varchar'
);

static $has_one = array (
'School' => 'School'
);

static $has_many = array (
'Students' => 'Member',
'Uploads' => 'Attachment',
'Tasks' => 'Task'
);


...

public function StudentsWithTeacher() {
$teachers = Member::get()->filter(array(
'Groups.Permissions.Code:exactmatch' => 'TEACHER_ADMIN',
'SchoolID' => $this->SchoolID
));
return $this->Students()->addMany($teachers);
}


2 Comments 2 Solutions

13/02/2013 1:42pm

PHP | Solution - Anonymous

public function StudentsWithTeacher() {

$teachers = Member::get()->filter(array(
'Groups.Permissions.Code:exactmatch' => 'TEACHER_ADMIN',
'SchoolID' => $this->SchoolID

));

$students = new ArrayList($this->Students());
$teachers = new ArrayList($teachers);

return $students->merge($teachers);

}

13/02/2013 1:33pm

PHP | Solution - Anonymous

                                foreach($schoolClass->StudentsWithTeacher() as $student) {
$message = new Message;
$message->Title = $messageTemplate->Title;
$message->Body = $messageTemplate->Body;
$message->StudentID = $student->ID;
$message->FromStudent = false;
$message->TaskID = $task->ID;
$message->write();
// Attachments
foreach($messageTemplate->Attachments() as $attachment) {
$attachment->Messages()->add($message);
}
}

Post Comment