
Untitled
By: a guest on
May 2nd, 2012 | syntax:
None | size: 1.82 KB | hits: 16 | expires: Never
<?php
// Symfony Doctrine Transaction
if($this->form->isValid()) {
$conn = Doctrine_Manager::connection();
try {
$conn->beginTransaction();
$student_group = new StudentGroup();
$student_group->user_id = $user->getId();
$student_group->name = $this->form->getValue('group_name');
$student_group->save();
$last_insert_id = $student_group->getId();
$error = false;
foreach($request->getParameter('group[member_list]') as $member) {
// List members in detail table
if ($member == $teacher_email) {
$error = true;
$error_email = $member;
} else {
$student_group_members = new StudentGroup_Members();
$student_group_members->student_group_id = $last_insert_id;
$student_group_members->email = $member;
$student_group_members->save();
}
}
$conn->commit();
if ($error) $error = $I18N->__('<br />Error in adding %email% to the group. You are not allow to add yourself to the group.', array('%email%' => $error_email));
$this->getUser()->setFlash('good_notice', $I18N->__('Group added.') . $error);
$this->redirect('teacher/addgroup');
} catch (Exception $e) {
$conn->rollback();
$this->getUser()->setFlash('bad_notice', $I18N->__('Error in adding new group.'));
}
}
?>