$newsCategory = NewsCategory::fetchFromParameters($_POST);
    if (!$newsCategory->save()) {
        $logger->LogError("Error saving news category.");
        foreach ($newsCategory->errors as $error) {
            $logger->LogError($error);
            $errors[] = $error;
        }
    } else {
        $message = "Values were updated successfully!";
    }
} else {
    if (isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) {
        $logger->LogInfo("Page was called for edit of id: " . $_REQUEST['id']);
        $id = intval($_REQUEST['id']);
        $logger->LogDebug("Numeric id is: {$id}");
        $newsCategory = NewsCategory::fetchFromDb($id);
        if ($newsCategory == null) {
            $logger->LogError("Invalid request. No news category with id: {$id} exists.");
            $errors[] = "Invalid request. No news category with id: {$id} exists.";
        }
    }
}
$defaultLanguage = Language::fetchDefaultLangauge();
?>
</td>
</tr>

<tr>
  <td valign="top">
  	<?php 
if (sizeof($errors) > 0) {
Exemplo n.º 2
0
 public function isValid()
 {
     $this->errors = array();
     if ($this->categoryId == 0) {
         $this->errors[] = "Category must be set";
     }
     if ($this->title->areAnyValuesEmpty()) {
         $this->errors[] = "Title cannot be empty";
     }
     if ($this->contents->areAnyValuesEmpty()) {
         $this->errors[] = "Contents cannot be empty";
     }
     if (strlen(trim($this->posterName)) == 0) {
         $this->errors[] = "Poster name cannot be empty";
     }
     if ($this->id == 0 && strlen(trim($this->imageSmall)) == 0) {
         $this->errors[] = "Small image name cannot be empty";
     }
     if ($this->id == 0 && strlen(trim($this->imageMedium)) == 0) {
         $this->errors[] = "Medium image name cannot be empty";
     }
     if ($this->id == 0 && strlen(trim($this->imageLarge)) == 0) {
         $this->errors[] = "Large image name cannot be empty";
     }
     if (strlen(trim($this->posterName)) == 0) {
         $this->errors[] = "Poster name cannot be empty";
     }
     if (sizeof($this->errors) == 0) {
         $newsCategory = NewsCategory::fetchFromDb($this->categoryId);
         if ($newsCategory == null) {
             $this->errors[] = "Invalid category";
         }
     }
     return sizeof($this->errors) == 0;
 }