コード例 #1
0
 /**
  * Process the form.  At this point we know that the user passes all the criteria in
  * userCanExecute(), and if the data array contains 'Username', etc, then Username
  * resets are allowed.
  *
  * @param array $data
  *
  * @return Bool|Array
  */
 public function onSubmit(array $data)
 {
     $fields = array();
     foreach ($data as $name => $value) {
         $matches = array();
         if (preg_match('/contest-(.+)/', $name, $matches)) {
             if ($matches[1] == 'end') {
                 $value = wfTimestamp(TS_MW, strtotime($value));
             }
             $fields[$matches[1]] = $value;
         }
     }
     // If no ID is set, this means it's a new contest, so set the ID to null for an insert.
     // However, the user can have hot the back button after creation of a new contest,
     // re-submitting the form. In this case, get the ID of the already existing item for an update.
     if (!array_key_exists('id', $fields) || $fields['id'] === '') {
         $contest = Contest::s()->selectRow('id', array('name' => $fields['name']));
         $fields['id'] = $contest === false ? null : $contest->getField('id');
     }
     $contest = new Contest($fields, is_null($fields['id']));
     $contest->setChallenges($this->getSubmittedChallenges());
     $success = $contest->writeAllToDB();
     $success = $this->removeDeletedChallenges($data['delete-challenges']) && $success;
     if ($success) {
         return true;
     } else {
         return array();
         // TODO
     }
 }