select_list("id", "name"); return array_merge(array(self::NONE => t("Nobody")), $options); } /** * Returns the hidden_item model related to the given item. * * There is an attempt to fetch the model from the database through the model * cache. If it fails, a new unsaved model is created. * * @param Item_Model $item the item * @return Hidden_Item_Model the related hidden_item model */ static function get_hidden_item_model(Item_Model $item) { try { $model = model_cache::get("item", $id); } catch (Exception $e) { $model = ORM::factory("hidden_item"); $model->item_id = $item->id; $model->validate(); } return $model; } /** * Returns whether the given item can be hidden. * * @param Item_Model $item the item * @return bool */ static function can_be_hidden(Item_Model $item) { if (empty($item)) { return false; } if ($item->type == "album") { return false; } return true; } /** * Returns whether the given item is hidden. * * @param Item_Model $item the item * @return bool */ static function is_hidden(Item_Model $item) { $model = self::get_hidden_item_model($item); return $model->loaded(); } /** * Hides the given item. * * @param Item_Model $item the item to hide */ static function hide(Item_Model $item) { if (self::is_hidden($item)) { return; } $hidden_item = self::get_hidden_item_model($item); $hidden_item->save(); } /** * Allows the given item to be displayed again. * * @param Item_Model $item the item to display */ static function show(Item_Model $item) { if (!self::is_hidden($item)) { return; } $hidden_item = self::get_hidden_item_model($item); $hidden_item->delete(); } /** * Returns whether the active user can view hidden items. * * @return bool */ static function can_view_hidden_items() { if (identity::active_user()->admin) { return true; } $authorized_group = module::get_var("hide", "access_permissions"); if (in_array($authorized_group, identity::group_ids_for_active_user())) { return true; } return false; } /** * Returns whether the active user can hide any items. * * @return bool */ static function can_hide() { if (identity::active_user()->admin) { return true; } return false; } }