/**
  * This abstract function performs the processing of the user request.
  * @param User $user The requesting user. If the user is not null, then by convention
  * actions will assume the user is authenticated, otherwise not.
  * @throws Exception If an error was encountered while processing this request, an exception
  * will be thrown.
  * @return void
  */
 public function processRequest(User $user = NULL)
 {
     // if image id was specified, parse it, attempt to load an image data object using the id
     $imageId = RequestParser::parseRequestParam($_REQUEST, EditImageAction::GET_PARAM_IMAGE_ID, RequestParser::PARAM_FILTER_TYPE_INT);
     $imageData = NULL;
     if ($imageId != NULL) {
         $imageData = ImageData::loadImageDataById(DbConnectionUtil::getDbConnection(), $imageId);
     }
     // otherwise create a new image data object
     if ($imageData == NULL) {
         $imageData = new ImageData();
         $imageData->setSubmitterUserId($user->getId());
     }
     // set the fields in the image data object
     $author = NULL;
     if (isset($_POST['author'])) {
         $author = $_POST['author'];
     }
     if ($author != NULL) {
         $imageData->setAuthor($author);
     }
     $title = NULL;
     if (isset($_POST['title'])) {
         $title = $_POST['title'];
     }
     if ($title != NULL) {
         $imageData->setTitle($title);
     }
     $year = NULL;
     if (isset($_POST['year'])) {
         $year = $_POST['year'];
     }
     if ($year != NULL) {
         $imageData->setYear($year);
     }
     // update attributes list
     $attributeString = $_POST[EditImageAction::POST_PARAM_ATTRIBUTE_LIST];
     if (!empty($attributeString)) {
         $attributeStringList = explode(",", $attributeString);
     } else {
         $attributeStringList = array();
     }
     // add new attributes
     foreach ($attributeStringList as $attString) {
         if ($attString != "") {
             if (!$imageData->hasAttribute($attString)) {
                 $imageData->addAttributeByString($attString);
             }
         }
     }
     $dbConnection = DbConnectionUtil::getDbConnection();
     // remove deleted ones
     $attributeList = $imageData->getAttributeList();
     foreach ($attributeList as $attribute) {
         if (!in_array($attribute->getAttribute(), $attributeStringList)) {
             $imageData->removeAttributeBystring($attribute->getAttribute());
             $attribute->delete($dbConnection);
         }
     }
     // save the image data object
     $imageData->save($dbConnection);
     // if image data was uploaded, process the image uploads and save again
     if (!empty($_FILES[EditImageAction::POST_PARAM_THUMBNAIL]['name'])) {
         $thumbnailUri = $this->processImageUpload('image_data_thumbs', $imageData->getId(), EditImageAction::POST_PARAM_THUMBNAIL);
         $imageData->setThumbnailUri($thumbnailUri);
         $imageData->save($dbConnection);
     }
     if (!empty($_FILES[EditImageAction::POST_PARAM_FILE]['name'])) {
         $fileUri = $this->processImageUpload('image_data', $imageData->getId(), EditImageAction::POST_PARAM_FILE);
         $imageData->setContentUri($fileUri);
         $imageData->save($dbConnection);
     }
     // redirect the user to the image viewing page
     $getParamMap = array(ImageDetailsView::GET_PARAM_IMAGE_ID => $imageData->getId());
     $imageDetailsViewUrl = UrlFormatter::formatRoutingItemUrl('views/ImageDetailsView', $getParamMap);
     header("Location: {$imageDetailsViewUrl}");
 }
 /**
  * This is a private helper function for populating an ImageData obejct given
  * the specified DB result row.
  * @param int $imageId The DB id of the image being populated.
  * @param array $resultRow The DB query result row this function will consume data from.
  * @return ImageData A populated image data object.
  */
 private static function populateImageDataByDbResultRow(array $resultRow, PDO $dbConnection)
 {
     $imageData = new ImageData($resultRow['id']);
     $imageData->setContentUri($resultRow['content_uri']);
     $imageData->setSubmitterUserId($resultRow['submitter_user_id']);
     $imageData->setThumbnailUri($resultRow['thumbnail_uri']);
     $imageData->setAuthor($resultRow['author']);
     $imageData->setTitle($resultRow['title']);
     $imageData->setYear($resultRow['year']);
     $imageData->setAttributeList(ImageAttribute::loadImageAttributeListByImageDataId($dbConnection, $imageData->getId()));
     return $imageData;
 }