本文整理汇总了PHP中model_cache类的典型用法代码示例。如果您正苦于以下问题:PHP model_cache类的具体用法?PHP model_cache怎么用?PHP model_cache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了model_cache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: activate
static function activate() {
// Update the root item. This is a quick hack because the search module is activated as part
// of the official install, so this way we don't start off with a "your index is out of date"
// banner.
search::update(model_cache::get("item", 1));
search::check_index();
}
示例2: current
/**
* Cache the result row
*/
public function current()
{
$row = parent::current();
if (is_object($row)) {
model_cache::set($row);
}
return $row;
}
示例3: lookup_by_name
/**
* Look up a group by name.
* @param integer $id the group name
* @return Group_Model the group object, or null if the name was invalid.
*/
static function lookup_by_name($name)
{
$group = model_cache::get("group", $name, "name");
if ($group->loaded) {
return $group;
}
return null;
}
示例4: unstar
/**
* Allows the given item to be displayed again.
*
* @param int $id the item id
*/
public function unstar($id)
{
$item = model_cache::get("item", $id);
$msg = t("Un-starred <b>%title</b> item", array("title" => html::purify($item->title)));
$this->_check_star_permissions($item);
star::unstar($item);
message::success($msg);
json::reply(array("result" => "success", "reload" => 1));
}
示例5: show
/**
* Allows the given item to be displayed again.
*
* @param int $id the item id
*/
public function show($id)
{
$item = model_cache::get("item", $id);
$msg = t("Displayed <b>%title</b> item", array("title" => html::purify($item->title)));
$this->_check_hide_permissions($item);
hide::show($item);
message::success($msg);
json::reply(array("result" => "success", "reload" => 1));
}
示例6: get_hidden_item_model
/**
* 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;
}
示例7: remove_album_cover
static function remove_album_cover($album)
{
access::required("edit", $album);
@unlink($album->thumb_path());
model_cache::clear("item", $album->album_cover_item_id);
$album->album_cover_item_id = null;
$album->thumb_width = 0;
$album->thumb_height = 0;
$album->thumb_dirty = 1;
$album->save();
graphics::generate($album);
}
示例8: _lookup_by_field
/**
* Search the groups by the field and value.
* @param string $field_name column to look up the user by
* @param string $value value to match
* @return Group_Definition the group object, or null if the name was invalid.
*/
private static function _lookup_by_field($field_name, $value)
{
try {
$user = model_cache::get("group", $value, $field_name);
if ($user->loaded()) {
return $user;
}
} catch (Exception $e) {
if (strpos($e->getMessage(), "MISSING_MODEL") === false) {
throw $e;
}
}
return null;
}
示例9: site
static function site($uri, $protocol = false)
{
if (($pos = strpos($uri, "?")) !== false) {
list($uri, $query) = explode("?", $uri, 2);
$query = "?{$query}";
} else {
$query = "";
}
$parts = explode("/", $uri, 3);
if ($parts[0] == "albums" || $parts[0] == "photos") {
$uri = model_cache::get("item", $parts[1])->relative_path();
}
return parent::site($uri . $query, $protocol);
}
示例10: restore
public function restore($id)
{
// Allow the user to restore the original photo.
// Make sure the current user has suficient access to view and edit the item.
$item = ORM::factory("item", $id);
access::required("view", $item);
access::required("edit", $item);
// Figure out where the original was stashed at.
$original_image = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $item->file_path());
// Make sure the current item is a photo and that an original exists.
if ($item->is_photo() && file_exists($original_image)) {
// Delete the modified version of the photo.
@unlink($item->file_path());
// Copy the original image back over, display an error message if the copy fails.
if (@rename($original_image, $item->file_path())) {
// Re-generate the items resize and thumbnail.
$item_data = model_cache::get("item", $id);
$item_data->resize_dirty = 1;
$item_data->thumb_dirty = 1;
$item_data->save();
graphics::generate($item_data);
// If the item is the thumbnail for the parent album,
// fix the parent's thumbnail as well.
$parent = $item_data->parent();
if ($parent->album_cover_item_id == $item_data->id) {
copy($item_data->thumb_path(), $parent->thumb_path());
$parent->thumb_width = $item_data->thumb_width;
$parent->thumb_height = $item_data->thumb_height;
$parent->save();
}
// Display a success message and redirect to the items page.
message::success(t("Your original image has been restored."));
url::redirect($item->url());
} else {
// Display an error message if the copy failed.
message::error(t("Image restore failed!"));
url::redirect($item->url());
}
} else {
// Display an error message if there is not an original photo.
message::error(t("Image restore failed!"));
url::redirect($item->url());
}
}
示例11: save
public function save($source_id)
{
access::verify_csrf();
$source = ORM::factory("item", $source_id);
$target = ORM::factory("item", Input::instance()->post("target_id"));
access::required("view", $source);
access::required("view", $target);
access::required("edit", $target);
model_cache::clear();
$target->album_cover_item_id = $source->is_album() ? $source->album_cover_item_id : $source->id;
$target->thumb_dirty = 1;
$target->save();
graphics::generate($target);
$grand_parent = $target->parent();
if ($grand_parent && access::can("edit", $grand_parent) && $grand_parent->album_cover_item_id == null) {
item::make_album_cover($target);
}
$msg = t("Made <b>%title</b> album's cover for <b>%album</b>", array("title" => html::purify($source->title), "album" => html::purify($target->title)));
message::success($msg);
json::reply(array("result" => "success"));
}
示例12: get
/**
* Load the corresponding Module_Model
* @param string $module_name
*/
static function get($module_name)
{
return model_cache::get("module", $module_name, "name");
}
示例13: form_edit
public function form_edit($id)
{
$item = model_cache::get("item", $id);
access::required("view", $item);
access::required("edit", $item);
switch ($item->type) {
case "album":
return print album::get_edit_form($item);
case "photo":
return print photo::get_edit_form($item);
case "movie":
return print movie::get_edit_form($item);
}
}
示例14: _add_columns
/**
* Internal method to add Permission/Group columns
*
* @param Group_Model $group
* @param string $perm_name
* @return void
*/
private static function _add_columns($perm_name, $group)
{
$db = Database::instance();
$field = "{$perm_name}_{$group->id}";
$cache_table = $perm_name == "view" ? "items" : "access_caches";
$db->query("ALTER TABLE {{$cache_table}} ADD `{$field}` SMALLINT NOT NULL DEFAULT 0");
$db->query("ALTER TABLE {access_intents} ADD `{$field}` BOOLEAN DEFAULT NULL");
$db->update("access_intents", array($field => 0), array("item_id" => 1));
model_cache::clear();
ORM::factory("access_intent")->clear_cache();
}
示例15: _add_columns
/**
* Internal method to add Permission/Group columns
*
* @param Group_Model $group
* @param string $perm_name
* @return void
*/
private static function _add_columns($perm_name, $group)
{
$db = Database::instance();
$field = "{$perm_name}_{$group->id}";
$cache_table = $perm_name == "view" ? "items" : "access_caches";
$not_null = $cache_table == "items" ? "" : "NOT NULL";
$db->query("ALTER TABLE {{$cache_table}} ADD `{$field}` BINARY {$not_null} DEFAULT FALSE");
$db->query("ALTER TABLE {access_intents} ADD `{$field}` BINARY DEFAULT NULL");
$db->update("access_intents", array($field => self::DENY), array("item_id" => 1));
model_cache::clear();
ORM::factory("access_intent")->clear_cache();
}