admin) { // Display items that are not in idcaches. $model->and_open()->join("albumpassword_idcaches", "items.id", "albumpassword_idcaches.item_id", "LEFT OUTER") ->and_where("albumpassword_idcaches.item_id", "IS", NULL); // ... Unless their password id corresponds with a valid password. $existing_password = ORM::factory("items_albumpassword")->where("password", "=", cookie::get("g3_albumpassword"))->find_all(); if (count($existing_password) > 0) { foreach ($existing_password as $one_password) { $model->or_where("albumpassword_idcaches.password_id", "=", $one_password->id); } } // Or the current user is the owner of the item. $model->or_where("items.owner_id", "=", identity::active_user()->id)->close(); } return $model; } }