public static function saveList($students, $listID = null)
 {
     // Get the list
     if ($listID) {
         $list = BarbaraListTable::getInstance()->findOneById($listID);
         // Check if the students array has changed
         $change = false;
         if (count($list->Students) != count($students)) {
             $change = true;
         } else {
             foreach ($list->Students as $student) {
                 if (array_search($student->name, $students) === false) {
                     $change = true;
                     break;
                 }
             }
         }
         if (!$change) {
             return $list;
         }
         $list->Students->delete();
         $list->save();
     } else {
         $list = new BarbaraList();
         $list->save();
     }
     // Save each student in the database
     foreach ($students as $studentName) {
         if (!$studentName) {
             continue;
         }
         $student = new BarbaraStudent();
         $student->name = $studentName;
         $student->list_id = $list->id;
         $student->save();
     }
     // Save the list
     $list->save();
     return $list;
 }
 public function executeSave(sfWebRequest $request)
 {
     $this->form = new ClassListForm();
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter('list'));
         if ($this->form->isValid()) {
             // Save list
             $list = BarbaraList::saveList($this->form->students, $this->form->getValue('list'));
             return $this->redirect('list_print', $list);
         } else {
             return $this->executeIndex($request);
         }
     }
 }