summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2010-01-26 00:23:45 -0800
committerBharat Mediratta <bharat@menalto.com>2010-01-26 00:23:45 -0800
commit5c68519d9233eabe98fce34fc00cdd4595f03ded (patch)
tree1e630271c71f999a333103270e0bf2baad58d30f
parent953c9283ad039adde0d131f2a0e563642d3dcbd1 (diff)
Specialize the album cover id check to allow the root album to have no
album cover.
-rw-r--r--modules/gallery/models/item.php16
1 files changed, 10 insertions, 6 deletions
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 4f5105b1..e4ff0bfb 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -717,7 +717,7 @@ class Item_Model extends ORM_MPTT {
public function validate($array=null) {
if (!$array) {
$this->rules = array(
- "album_cover_item_id" => array("callbacks" => array(array($this, "valid_item"))),
+ "album_cover_item_id" => array("callbacks" => array(array($this, "valid_album_cover"))),
"description" => array("rules" => array("length[0,65535]")),
"mime_type" => array("callbacks" => array(array($this, "valid_field"))),
"name" => array("rules" => array("length[0,255]", "required"),
@@ -848,14 +848,18 @@ class Item_Model extends ORM_MPTT {
}
/**
- * Make sure the field refers to a valid item by id, or is null.
+ * Make sure the album cover item id refers to a valid item, or is null.
*/
- public function valid_item(Validation $v, $field) {
- if ($this->$field && db::build()
+ public function valid_album_cover(Validation $v, $field) {
+ if ($this->id == 1) {
+ return;
+ }
+
+ if ($this->album_cover_item_id && db::build()
->from("items")
- ->where("id", "=", $this->$field)
+ ->where("id", "=", $this->album_cover_item_id)
->count_records() != 1) {
- $v->add_error($field, "invalid_item");
+ $v->add_error("album_cover_item_id", "invalid_item");
}
}