本文整理汇总了PHP中ElggEntity::getGUID方法的典型用法代码示例。如果您正苦于以下问题:PHP ElggEntity::getGUID方法的具体用法?PHP ElggEntity::getGUID怎么用?PHP ElggEntity::getGUID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ElggEntity
的用法示例。
在下文中一共展示了ElggEntity::getGUID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createRandomAnnotations
/**
* Creates random annotations on $entity
*
* @param \ElggEntity $entity
* @param int $max
*/
protected function createRandomAnnotations($entity, $max = 1)
{
$annotations = array();
for ($i = 0; $i < $max; $i++) {
$name = 'test_annotation_name_' . rand();
$value = rand();
$id = create_annotation($entity->getGUID(), $name, $value, 'integer', $entity->getGUID());
$annotations[] = elgg_get_annotation_from_id($id);
}
return $annotations;
}
示例2: afterEntityUpdate
/**
* After an entity is done with ->save() check if we need to enqueue it
*
* @param string $event the name of the event
* @param string $type the type of the event
* @param \ElggEntity $entity supplied param
*
* @return void
*/
public static function afterEntityUpdate($event, $type, $entity)
{
if (!$entity instanceof \ElggEntity) {
// not an entity, since we listen to 'all'
return;
}
if (!isset($entity->tags)) {
// no tags
return;
}
if (!self::validateEntity($entity->getGUID())) {
return;
}
self::enqueueEntity($entity->getGUID());
}
示例3: pages_register_navigation_tree
/**
* Register the navigation menu
*
* @param ElggEntity $container Container entity for the pages
*/
function pages_register_navigation_tree($container)
{
if (!$container) {
return;
}
$top_pages = elgg_get_entities(array('type' => 'object', 'subtype' => 'page_top', 'container_guid' => $container->getGUID(), 'limit' => 0));
if (!$top_pages) {
return;
}
foreach ($top_pages as $page) {
elgg_register_menu_item('pages_nav', array('name' => $page->getGUID(), 'text' => $page->title, 'href' => $page->getURL()));
$stack = array();
array_push($stack, $page);
while (count($stack) > 0) {
$parent = array_pop($stack);
$children = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'page', 'metadata_name' => 'parent_guid', 'metadata_value' => $parent->getGUID(), 'limit' => 0));
if ($children) {
foreach ($children as $child) {
elgg_register_menu_item('pages_nav', array('name' => $child->getGUID(), 'text' => $child->title, 'href' => $child->getURL(), 'parent_name' => $parent->getGUID()));
array_push($stack, $child);
}
}
}
}
}
示例4: pages_get_navigation_tree
/**
* Produce the navigation tree
*
* @param ElggEntity $container Container entity for the pages
*
* @return array
*/
function pages_get_navigation_tree($container)
{
if (!$container) {
return;
}
$top_pages = elgg_get_entities(array('type' => 'object', 'subtype' => 'page_top', 'container_guid' => $container->getGUID(), 'limit' => 0));
if (!$top_pages) {
return;
}
/* @var ElggObject[] $top_pages */
$tree = array();
$depths = array();
foreach ($top_pages as $page) {
$tree[] = array('guid' => $page->getGUID(), 'title' => $page->title, 'url' => $page->getURL(), 'depth' => 0);
$depths[$page->guid] = 0;
$stack = array();
array_push($stack, $page);
while (count($stack) > 0) {
$parent = array_pop($stack);
$children = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'page', 'metadata_name' => 'parent_guid', 'metadata_value' => $parent->getGUID(), 'limit' => 0));
if ($children) {
foreach ($children as $child) {
$tree[] = array('guid' => $child->getGUID(), 'title' => $child->title, 'url' => $child->getURL(), 'parent_guid' => $parent->getGUID(), 'depth' => $depths[$parent->guid] + 1);
$depths[$child->guid] = $depths[$parent->guid] + 1;
array_push($stack, $child);
}
}
}
}
return $tree;
}
示例5: removeAdmin
/**
* listen to the remove admin event to unset the toggle admin flag
*
* @param string $event the event
* @param string $type the type of the event
* @param ElggEntity $entity the affected entity
*
* @return void
*/
public static function removeAdmin($event, $type, $entity)
{
if (!$entity instanceof \ElggUser) {
return;
}
elgg_unset_plugin_user_setting('switched_admin', $entity->getGUID(), 'admin_tools');
}
示例6: testElggEntityRecursiveDisableAndEnable
public function testElggEntityRecursiveDisableAndEnable()
{
global $CONFIG;
$obj1 = new \ElggObject();
$obj1->container_guid = $this->entity->getGUID();
$obj1->save();
$obj2 = new \ElggObject();
$obj2->container_guid = $this->entity->getGUID();
$obj2->save();
// disable $obj2 before disabling the container
$this->assertTrue($obj2->disable());
// disable entities container by $this->entity
$this->assertTrue($this->entity->disable());
$entity = get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid = '{$obj1->guid}'");
$this->assertIdentical($entity->enabled, 'no');
// enable entities that were disabled with the container (but not $obj2)
$this->assertTrue($this->entity->enable());
$entity = get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid = '{$obj1->guid}'");
$this->assertIdentical($entity->enabled, 'yes');
$entity = get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid = '{$obj2->guid}'");
$this->assertIdentical($entity->enabled, 'no');
// cleanup
$this->assertTrue($obj2->enable());
$this->assertTrue($obj2->delete());
$this->assertTrue($obj1->delete());
}
示例7: testSimpleGetters
public function testSimpleGetters()
{
$this->obj->type = 'foo';
$this->obj->subtype = 'subtype';
$this->obj->owner_guid = 77;
$this->obj->access_id = 2;
$this->obj->time_created = 123456789;
$this->assertEquals($this->obj->getGUID(), $this->obj->guid);
$this->assertEquals($this->obj->getType(), $this->obj->type);
// Note: before save() subtype returns string, int after
// see https://github.com/Elgg/Elgg/issues/5920#issuecomment-25246298
$this->assertEquals($this->obj->getSubtype(), $this->obj->subtype);
$this->assertEquals($this->obj->getOwnerGUID(), $this->obj->owner_guid);
$this->assertEquals($this->obj->getAccessID(), $this->obj->access_id);
$this->assertEquals($this->obj->getTimeCreated(), $this->obj->time_created);
$this->assertEquals($this->obj->getTimeUpdated(), $this->obj->time_updated);
}
示例8: toGUID
/**
* Get guids from an entity attribute
*
* @param ElggEntity|int $entity Entity or GUID
* @return int
*/
protected function toGUID($entity = null)
{
if ($entity instanceof ElggEntity) {
return (int) $entity->getGUID();
} else {
if ($this->exists($entity)) {
return (int) $entity;
}
}
return false;
}
示例9: testSimpleGetters
/**
* @requires PHP 5.3.2
*/
public function testSimpleGetters()
{
$this->obj->type = 'foo';
$this->obj->subtype = 'subtype';
$this->obj->owner_guid = 77;
$this->obj->access_id = 2;
$this->obj->time_created = 123456789;
$this->assertEquals($this->obj->getGUID(), $this->obj->guid);
$this->assertEquals($this->obj->getType(), $this->obj->type);
$this->assertEquals($this->obj->getSubtype(), $this->obj->subtype);
$this->assertEquals($this->obj->getOwnerGUID(), $this->obj->owner_guid);
$this->assertEquals($this->obj->getAccessID(), $this->obj->access_id);
$this->assertEquals($this->obj->getTimeCreated(), $this->obj->time_created);
$this->assertEquals($this->obj->getTimeUpdated(), $this->obj->time_updated);
}
示例10: __construct
/**
* Create a notification event
*
* @param \ElggData $object The object of the event (\ElggEntity)
* @param string $action The name of the action (default: create)
* @param \ElggEntity $actor The entity that caused the event (default: logged in user)
*
* @throws \InvalidArgumentException
*/
public function __construct(\ElggData $object, $action, \ElggEntity $actor = null)
{
if (elgg_instanceof($object)) {
$this->object_type = $object->getType();
$this->object_subtype = $object->getSubtype();
$this->object_id = $object->getGUID();
} else {
$this->object_type = $object->getType();
$this->object_subtype = $object->getSubtype();
$this->object_id = $object->id;
}
if ($actor == null) {
$this->actor_guid = _elgg_services()->session->getLoggedInUserGuid();
} else {
$this->actor_guid = $actor->getGUID();
}
$this->action = $action;
}
示例11: subsite_manager_move_entity_to_site
/**
* Move an entity to a new site (can anly be call by subsite_manager_move_group_to_site())
*
* @param ElggEntity $entity the entity to move
* @param ElggSite $target_site the target site
* @param array $access_conversion array with group and site access levels
*
* @access private
*
* @return bool
*/
function subsite_manager_move_entity_to_site(ElggEntity $entity, ElggSite $target_site, array $access_conversion)
{
static $newentity_cache;
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
if (!isset($backtrace[1])) {
return false;
}
$function = elgg_extract("function", $backtrace[1]);
if (empty($function) || !in_array($function, array("subsite_manager_move_group_to_site", "subsite_manager_move_entity_to_site"))) {
// because this is a dangerous function only allow it to be called the correct way
return false;
}
if (empty($entity) || !$entity instanceof ElggEntity) {
return false;
}
if (empty($target_site) || !elgg_instanceof($target_site, "site")) {
return false;
}
if ($entity->site_guid == $target_site->getGUID()) {
return false;
}
// check for access conversion rules
if (empty($access_conversion) || !is_array($access_conversion)) {
return false;
}
$group_acl = (int) elgg_extract("group_acl", $access_conversion);
if (empty($group_acl)) {
return false;
}
$old_site_acl = (int) elgg_extract("site_acl", $access_conversion);
$affected_access = array(ACCESS_PUBLIC, ACCESS_LOGGED_IN);
if (!empty($old_site_acl)) {
$affected_access[] = $old_site_acl;
}
// ignore access and show hidden entities
$ia = elgg_set_ignore_access(true);
$hidden = access_get_show_hidden_status();
access_show_hidden_entities(true);
// first move sub entities (eg blogs in group, event registrations, etc)
$options = array("type" => "object", "container_guid" => $entity->getGUID(), "limit" => false);
$batch = new ElggBatch("elgg_get_entities", $options);
$batch->setIncrementOffset(false);
foreach ($batch as $sub_entity) {
if (!subsite_manager_move_entity_to_site($sub_entity, $target_site, $access_conversion)) {
elgg_set_ignore_access($ia);
access_show_hidden_entities($hidden);
return false;
}
}
// also move owned (sub) entities
$options = array("type" => "object", "owner_guid" => $entity->getGUID(), "wheres" => array("(e.guid <> {$entity->getGUID()})"), "limit" => false);
$batch = new ElggBatch("elgg_get_entities", $options);
$batch->setIncrementOffset(false);
foreach ($batch as $sub_entity) {
if (!subsite_manager_move_entity_to_site($sub_entity, $target_site, $access_conversion)) {
elgg_set_ignore_access($ia);
access_show_hidden_entities($hidden);
return false;
}
}
$dbprefix = elgg_get_config("dbprefix");
// move access collections
$query = "UPDATE {$dbprefix}access_collections";
$query .= " SET site_guid = {$target_site->getGUID()}";
$query .= " WHERE owner_guid = {$entity->getGUID()}";
try {
update_data($query);
} catch (Exception $e) {
elgg_log("Subsite manager move entity({$entity->getGUID()}) access collections: " . $e->getMessage(), "ERROR");
elgg_set_ignore_access($ia);
access_show_hidden_entities($hidden);
return false;
}
// move annotations
$query = "UPDATE {$dbprefix}annotations";
$query .= " SET site_guid = {$target_site->getGUID()}";
$query .= " WHERE entity_guid = {$entity->getGUID()}";
try {
update_data($query);
} catch (Exception $e) {
elgg_log("Subsite manager move entity({$entity->getGUID()}) annotations: " . $e->getMessage(), "ERROR");
elgg_set_ignore_access($ia);
access_show_hidden_entities($hidden);
return false;
}
// change annotation access
$query = "UPDATE {$dbprefix}annotations";
$query .= " SET access_id = {$group_acl}";
$query .= " WHERE entity_guid = {$entity->getGUID()}";
//.........这里部分代码省略.........
示例12: pages_tools_flush_tree_html_cache
/**
* Clears tree html cache
*
* @param ElggEntity $entity the root entity to flush the cache for
*
* @return void
*/
function pages_tools_flush_tree_html_cache(ElggEntity $entity)
{
if (!$entity instanceof ElggEntity) {
return;
}
$locator = new Elgg_EntityDirLocator($entity->getGUID());
$cache_dir = elgg_get_data_path() . $locator->getPath() . 'tree_cache/';
$dh = opendir($cache_dir);
if (empty($dh)) {
return;
}
while (($filename = readdir($dh)) !== false) {
// make sure we have a file
if (!is_file($cache_dir . $filename)) {
continue;
}
unlink($cache_dir . $filename);
}
}
示例13: file_url_override
/**
* Populates the ->getUrl() method for file objects
*
* @param ElggEntity $entity File entity
* @return string File URL
*/
function file_url_override($entity)
{
$title = $entity->title;
$title = elgg_get_friendly_title($title);
return "file/view/" . $entity->getGUID() . "/" . $title;
}
示例14: elgg_count_comments
/**
* Count the number of comments attached to an entity
*
* @param ElggEntity $entity
* @return int Number of comments
*/
function elgg_count_comments($entity)
{
if ($commentno = trigger_plugin_hook('comments:count', $entity->getType(), array('entity' => $entity), false)) {
return $commentno;
} else {
return count_annotations($entity->getGUID(), "", "", "generic_comment");
}
}
示例15: has_access_to_entity
/**
* Can a user access an entity.
*
* @warning If a logged in user doesn't have access to an entity, the
* core engine will not load that entity.
*
* @tip This is mostly useful for checking if a user other than the logged in
* user has access to an entity that is currently loaded.
*
* @todo This function would be much more useful if we could pass the guid of the
* entity to test access for. We need to be able to tell whether the entity exists
* and whether the user has access to the entity.
*
* @param ElggEntity $entity The entity to check access for.
* @param ElggUser $user Optionally user to check access for. Defaults to
* logged in user (which is a useless default).
*
* @return bool
* @link http://docs.elgg.org/Access
*/
function has_access_to_entity($entity, $user = null)
{
global $CONFIG;
if (!isset($user)) {
$access_bit = get_access_sql_suffix("e");
} else {
$access_bit = get_access_sql_suffix("e", $user->getGUID());
}
$query = "SELECT guid from {$CONFIG->dbprefix}entities e WHERE e.guid = " . $entity->getGUID();
// Add access controls
$query .= " AND " . $access_bit;
if (get_data($query)) {
return true;
} else {
return false;
}
}