예제 #1
0
 /**
  * Process the form.  At this point we know that the user passes all the criteria in
  * userCanExecute().
  *
  * @param array $data
  *
  * @return Bool|Array
  */
 public function handleSubmission(array $data)
 {
     $fields = array();
     $unknownValues = array();
     $c = $this->getItemClass();
     // Yeah, this is needed in PHP 5.3 >_>
     foreach ($data as $name => $value) {
         $matches = array();
         if (preg_match('/item-(.+)/', $name, $matches)) {
             if ($matches[1] === 'id' && ($value === '' || $value === '0')) {
                 $value = null;
             }
             if ($c::canHasField($matches[1])) {
                 $fields[$matches[1]] = $value;
             } else {
                 $unknownValues[$matches[1]] = $value;
             }
         }
     }
     $keys = array_keys($fields);
     $fields = array_combine($keys, array_map(array($this, 'handleKnownField'), $keys, $fields));
     /* EPPageObject */
     $item = new $c($fields, is_null($fields['id']));
     foreach ($unknownValues as $name => $value) {
         $this->handleUnknownField($item, $name, $value);
     }
     $revAction = new EPRevisionAction();
     $revAction->setUser($this->getUser());
     $revAction->setComment('');
     // TODO
     $revAction->setMinor(false);
     // TODO
     $success = $item->revisionedSave($revAction);
     if ($success) {
         return true;
     } else {
         return array();
         // TODO
     }
 }