/** * Check if requested page is a static page * * @param string $hook name of the hook * @param string $type type of the hook * @param array $return_value return value * @param array $params hook parameters * * @return array */ public static function routeAll($hook, $type, $return_value, $params) { if (!is_array($return_value)) { // someone else already routed this page return; } /** * $return_value contains: * $return_value['identifier'] => requested handler * $return_value['segments'] => url parts ($page) */ $identifier = elgg_extract('identifier', $return_value); if (empty($identifier)) { return; } $handlers = _elgg_services()->router->getPageHandlers(); if (elgg_extract($identifier, $handlers)) { return; } $ia = elgg_set_ignore_access(true); $entities = elgg_get_entities_from_metadata(['type' => 'object', 'subtype' => \StaticPage::SUBTYPE, 'limit' => 1, 'metadata_name_value_pairs' => ['friendly_title' => $identifier], 'metadata_case_sensitive' => false]); elgg_set_ignore_access($ia); if (empty($entities)) { return; } $entity = $entities[0]; if (!has_access_to_entity($entity) && !$entity->canEdit()) { return; } $return_value['segments'] = ['view', $entity->getGUID()]; $return_value['identifier'] = 'static'; return $return_value; }
private function getFolders($parent, $limit = 100, $offset = 0, $count = false) { $dbprefix = elgg_get_config("dbprefix"); $options = array('type' => 'object', 'subtype' => 'folder', 'limit' => $limit, 'offset' => $offset); if (!$count) { $options['joins'] = "JOIN {$dbprefix}objects_entity oe ON e.guid = oe.guid"; $options['order_by'] = 'oe.title ASC'; } else { $options['count'] = true; } if ($parent) { if ($parent instanceof ElggUser | $parent instanceof ElggGroup) { $options['container_guid'] = $parent->guid; $options['metadata_name_value_pairs'] = array(array('name' => 'parent_guid', 'value' => 0)); } else { $options['container_guid'] = $parent->container_guid; $options['metadata_name_value_pairs'] = array(array('name' => 'parent_guid', 'value' => $parent->guid)); } return elgg_get_entities_from_metadata($options); } else { if (!$count) { return array(); } else { return 0; } } }
/** * @SWG\Get( * path="/api/groups/{guid}/events", * security={{"oauth2": {"all"}}}, * tags={"events"}, * summary="Find events in a specific group.", * description="Find the most recent events from a specific group.", * produces={"application/json"}, * @SWG\Parameter( * name="guid", * in="path", * description="The guid of the specific group", * required=true, * type="integer", * @SWG\Items(type="integer") * ), * @SWG\Parameter( * name="offset", * in="query", * description="Offset the results by", * default=0, * required=false, * type="integer", * @SWG\Items(type="integer") * ), * @SWG\Parameter( * name="limit", * in="query", * description="Limit the results by", * default=20, * required=false, * type="integer", * @SWG\Items(type="integer") * ), * @SWG\Response( * response=200, * description="Succesful operation.", * @SWG\Schema( * type="array", * @SWG\Items(ref="#/definitions/Event") * ), * ), * @SWG\Response( * response="404", * description="Could not find the requested event.", * ) * ) */ public function getGroup($request, $response, $args) { $currentUser = elgg_get_logged_in_user_entity(); $guid = (int) $args['guid']; $group = get_entity($guid); if (!$group | !$group instanceof \ElggGroup) { return $response->withStatus(404); } $params = $request->getQueryParams(); $limit = (int) $params['limit']; $offset = (int) $params['offset']; if (!$limit | $limit < 0 | $limit > 50) { $limit = 20; } $dbprefix = elgg_get_config("dbprefix"); $options = array('type' => 'object', 'subtype' => 'event', 'offset' => $offset, 'limit' => $limit, 'container_guid' => $group->guid, 'metadata_name_value_pairs' => array(array('name' => 'start_day', 'operand' => '>=', 'value' => mktime(0, 0, 1))), 'order_by_metadata' => array('name' => 'start_day', 'direction' => 'ASC', 'as' => 'integer')); $entities = array(); foreach (elgg_get_entities_from_metadata($options) as $entity) { $entities[] = $this->parseEvent($entity); } $options['count'] = true; $total = elgg_get_entities_from_metadata($options); $response = $response->withHeader('Content-type', 'application/json'); return $response->write(json_encode(array('total' => $total, 'entities' => $entities), JSON_PRETTY_PRINT)); }
/** * Returns an entity template * * @param string $template_name Template name * @param string $language Language * @return Template|false */ function notifications_editor_get_template_entity($template_name, $language = 'en') { $templates = elgg_get_entities_from_metadata(array('types' => 'object', 'subtypes' => Template::SUBTYPE, 'metadata_name_value_pairs' => array(array('name' => 'template', 'value' => $template_name), array('name' => 'language', 'value' => $language)), 'limit' => 1)); if ($templates) { return $templates[0]; } $template_parts = explode(':', $template_name); array_unshift($template_parts, 'notifications'); $template_folder = implode('/', $template_parts); $template = new Template(); $template->subject = elgg_view("{$template_folder}/subject.{$language}.html"); if (!$template->subject && $language != 'en') { $template->subject = elgg_view("{$template_folder}/subject.en.html"); } $template->summary = elgg_view("{$template_folder}/summary.{$language}.html"); if (!$template->summary && $language != 'en') { $template->summary = elgg_view("{$template_folder}/summary.en.html"); } $template->body = elgg_view("{$template_folder}/body.{$language}.html"); if (!$template->body && $language != 'en') { $template->body = elgg_view("{$template_folder}/body.en.html"); } $template->template_folder = $template_folder; $template->template = $template_name; $template->language = $language; return $template; }
function batch_delete_images() { // delete $log = elgg_get_config('mfp_log'); $log_time = elgg_get_config('mfp_logtime'); $options = array('type' => 'object', 'subtype' => 'image', 'metadata_name_value_pairs' => array('name' => 'mfp_delete_check', 'value' => $log_time), 'limit' => 0); $images = new ElggBatch('elgg_get_entities_from_metadata', $options); $images->setIncrementOffset(false); $total = elgg_get_entities_from_metadata(array_merge($options, array('count' => true))); file_put_contents($log, "Starting deletion of {$total} images" . "\n", FILE_APPEND); $i = 0; $count = 0; foreach ($images as $image) { $count++; if ($image->delete()) { $i++; } if ($count == 1 || !($count % 25)) { $time = date('m/d/Y g:i:s a'); $j = $count - $i; $message = "Deleted {$i}, skipped {$j}, of {$total} images as of {$time}"; file_put_contents($log, $message . "\n", FILE_APPEND); } } $message = '<div class="done">Completed: Deleted ' . $i . ', skipped ' . $j . ', of ' . $total . '</div>'; file_put_contents($log, $message . "\n", FILE_APPEND); }
/** * Web service to retrieve list of groups * * @param string $username Username * @param string $limit Number of users to return * @param string $offset Indexing offset, if any * * @return array */ function group_get_groups($context, $username, $limit, $offset) { if (!$username) { $user = get_loggedin_user(); } else { $user = get_user_by_username($username); } if ($context == "all") { $groups = elgg_get_entities(array('types' => 'group', 'limit' => $limit, 'full_view' => FALSE)); } if ($context == "mine" || $context == "user") { $groups = $user->getGroups(); } if ($context == "owned") { $groups = elgg_get_entities(array('types' => 'group', 'owner_guid' => $user->guid, 'limit' => $limit, 'full_view' => FALSE)); } if ($context == "featured") { $groups = elgg_get_entities_from_metadata(array('metadata_name' => 'featured_group', 'metadata_value' => 'yes', 'types' => 'group', 'limit' => 10)); } if ($groups) { foreach ($groups as $single) { $group['guid'] = $single->guid; $group['name'] = $single->name; $group['members'] = count($single->getMembers($limit = 0)); $group['avatar_url'] = get_entity_icon_url($single, 'small'); $return[] = $group; } } else { $msg = elgg_echo('groups:none'); throw new InvalidParameterException($msg); } return $return; }
function hflts_page_handler($page) { if (elgg_extract(0, $page) === 'collective') { $content = elgg_view('hflts/collective', array('nAlternativas' => $page[1], 'nCriterios' => $page[2], 'nExpertos' => $page[3], 'G' => $page[4], 'import_file' => $page[5], 'weight_file' => $page[6])); $params = array('title' => 'DM con datos de samples/set_' . $page[5] . '.csv (' . $page[6] . ')', 'content' => $content, 'filter' => ''); $body = elgg_view_layout('content', $params); echo elgg_view_page('hflts', $body); return true; } set_input('username', $page[0]); //necesario $user = elgg_get_page_owner_entity(); // ej strem $guid = elgg_get_page_owner_guid(); // id de strem //aqui es donde tengo que filtrar por guid como en https://elgg.org/discussion/view/2268999/doubt-in-elgg-get-entities-from-metadata $valorations = elgg_get_entities_from_metadata(['type' => 'object', 'subtype' => 'evaluation_content', 'metadata_name_value_pairs' => array('name' => 'user_guid', 'value' => $guid), 'limit' => $vars['entity']->num_display, 'pagination' => false, 'order_by_metadata' => ['name' => 'state', 'direction' => 'ASC', 'as' => 'text']]); if (!$valorations) { $valorations = '<p class="mtm">' . elgg_echo('evaluationcontent:none') . '</p>'; } $content = elgg_view('hflts/driver', array('valorations' => $valorations)); $params = array('title' => 'Valoraciones de ' . $user->name, 'content' => $content, 'filter' => ''); $body = elgg_view_layout('content', $params); echo elgg_view_page('hflts', $body); }
/** * Reorders todo to new position * * @param int $offset new position * * @return void */ public function moveToPosition($offset) { $current_order = $this->order; $options = array('type' => 'object', 'subtype' => $this::SUBTYPE, 'container_guid' => $this->container_guid, 'order_by_metadata' => array('name' => 'order', 'direction' => 'ASC', 'as' => 'integer'), 'limit' => false); $entities = elgg_get_entities_from_metadata($options); if (empty($entities)) { // nothing to do return; } $current_pos_entity = elgg_extract($offset, $entities); if (!$current_pos_entity) { return; } $new_order = $current_pos_entity->order; $forward = false; if ($current_order < $new_order) { $forward = true; } $this->order = $new_order; foreach ($entities as $entity) { if ($entity->guid == $this->guid) { continue; } if ($forward) { if ($entity->order <= $new_order) { $entity->order--; } } else { if ($entity->order >= $new_order) { $entity->order++; } } } }
/** * 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; }
function get_likerating_byannotation($annotation_guid, $limit = 50) { $subtypeArray = array('like_rate'); $options = array('metadata_name' => "annotation_guid", 'metadata_value' => $annotation_guid, 'type' => 'object', 'subtypes' => $subtypeArray, 'limit' => $limit, 'offset' => $offset); $list_object = elgg_get_entities_from_metadata($options); return $list_object; }
/** * ban user if sending too many messages * * @param string $event * @param string $type * @param ElggObject $object * @return bool */ function community_spam_messages_throttle($event, $type, $object) { if ($object->getSubtype() !== 'messages') { return; } if (community_spam_is_new_user()) { $msg_limit = elgg_get_plugin_setting('new_user_msg_limit', 'community_spam_tools'); } else { $msg_limit = elgg_get_plugin_setting('msg_limit', 'community_spam_tools'); } if (!$msg_limit) { return; } // two message objects created per message but after they are saved, // both are set to private so we only have access to one later on $msg_limit = $msg_limit + 1; $params = array('type' => 'object', 'subtype' => 'messages', 'created_time_lower' => time() - 5 * 60, 'metadata_names' => 'fromId', 'metadata_values' => elgg_get_logged_in_user_guid(), 'count' => true); $num_msgs = elgg_get_entities_from_metadata($params); if ($num_msgs > $msg_limit) { $spammer = elgg_get_logged_in_user_entity(); $spammer->annotate('banned', 1); // this integrates with ban plugin $spammer->ban("Sent {$num_msgs} in 5 minutes"); return false; } }
function pages_draw_child($childentity, $path) { $child = "\n\t\t{\n"; $child .= "\t\t\t\"text\": \"<a href=\\\"{$childentity->getURL()}\\\">" . addslashes($childentity->title) . "</a>\"\n"; $extras = ""; $haschild = elgg_get_entities_from_metadata(array('metadata_name' => 'parent_guid', 'metadata_value' => $childentity->guid, 'limit' => 9999)); if ($haschild) { if (in_array($childentity->guid, $path)) { $extras .= "\t\t\t,\"expanded\": true"; $extras .= "\t\t\t,\"children\": [\n"; $childstring = ""; foreach ($haschild as $subchild) { $childstringtemp = pages_draw_child($subchild, $path); if (!empty($childstringtemp)) { if (!empty($childstring)) { $childstring .= ", "; } $childstring .= $childstringtemp; } } $extras .= $childstring . "\n\t\t\t]\n"; } else { $extras .= ",\t\t\t\"id\": \"{$childentity->getGUID()}\",\n\t\t\t\"hasChildren\": true\n"; } } $child .= $extras . "\t\t}"; return $child; }
public function testElggGetEntitiesFromMetadata() { global $CONFIG, $METASTRINGS_CACHE, $METASTRINGS_DEADNAME_CACHE; $METASTRINGS_CACHE = $METASTRINGS_DEADNAME_CACHE = array(); $this->object->title = 'Meta Unit Test'; $this->object->save(); $this->create_metastring('metaUnitTest'); $this->create_metastring('tested'); // create_metadata returns id of metadata on success $this->assertTrue(create_metadata($this->object->guid, 'metaUnitTest', 'tested')); // check value with improper case $options = array('metadata_names' => 'metaUnitTest', 'metadata_values' => 'Tested', 'limit' => 10, 'metadata_case_sensitive' => TRUE); $this->assertFalse(elgg_get_entities_from_metadata($options)); // compare forced case with ignored case $options = array('metadata_names' => 'metaUnitTest', 'metadata_values' => 'tested', 'limit' => 10, 'metadata_case_sensitive' => TRUE); $case_true = elgg_get_entities_from_metadata($options); $this->assertIsA($case_true, 'array'); $options = array('metadata_names' => 'metaUnitTest', 'metadata_values' => 'Tested', 'limit' => 10, 'metadata_case_sensitive' => FALSE); $case_false = elgg_get_entities_from_metadata($options); $this->assertIsA($case_false, 'array'); $this->assertIdentical($case_true, $case_false); // check deprecated get_entities_from_metadata() function $deprecated = get_entities_from_metadata('metaUnitTest', 'tested', '', '', 0, 10, 0, '', 0, FALSE, TRUE); $this->assertIdentical($deprecated, $case_true); // check entity list //$this->dump(list_entities_from_metadata('metaUnitTest', 'Tested', '', '', 0, 10, TRUE, TRUE, TRUE, FALSE)); // clean up $this->delete_metastrings(); $this->object->delete(); }
function pleiofile_add_folder_to_zip(ZipArchive &$zip_archive, ElggObject $folder, $folder_path = "") { if (!empty($zip_archive) && !empty($folder) && elgg_instanceof($folder, "object", "folder")) { $folder_title = elgg_get_friendly_title($folder->title); $zip_archive->addEmptyDir($folder_path . $folder_title); $folder_path .= $folder_title . DIRECTORY_SEPARATOR; $file_options = array("type" => "object", "subtype" => "file", "limit" => false, "relationship" => "folder_of", "relationship_guid" => $folder->getGUID()); // add files from this folder to the zip if ($files = elgg_get_entities_from_relationship($file_options)) { foreach ($files as $file) { // check if the file exists if ($zip_archive->statName($folder_path . $file->originalfilename) === false) { // doesn't exist, so add $zip_archive->addFile($file->getFilenameOnFilestore(), $folder_path . sanitize_file_name($file->originalfilename)); } else { // file name exists, so create a new one $ext_pos = strrpos($file->originalfilename, "."); $file_name = substr($file->originalfilename, 0, $ext_pos) . "_" . $file->getGUID() . substr($file->originalfilename, $ext_pos); $zip_archive->addFile($file->getFilenameOnFilestore(), $folder_path . sanitize_file_name($file_name)); } } } // check if there are subfolders $folder_options = array("type" => "object", "subtype" => "folder", "limit" => false, "metadata_name_value_pairs" => array("parent_guid" => $folder->getGUID())); if ($sub_folders = elgg_get_entities_from_metadata($folder_options)) { foreach ($sub_folders as $sub_folder) { pleiofile_add_folder_to_zip($zip_archive, $sub_folder, $folder_path); } } } }
function file_tools_object_handler_delete($event, $type, $object) { static $delete_files; if (!empty($object) && elgg_instanceof($object, "object", FILE_TOOLS_SUBTYPE)) { // find subfolders $options = array("type" => "object", "subtype" => FILE_TOOLS_SUBTYPE, "container_guid" => $object->getContainerGUID(), "limit" => false, "metadata_name_value_pairs" => array("name" => "parent_guid", "value" => $object->getGUID()), "wheres" => array("(e.guid <> " . $object->getGUID() . ")")); if ($subfolders = elgg_get_entities_from_metadata($options)) { // delete subfolders foreach ($subfolders as $subfolder) { $subfolder->delete(); } } // fill the static, to delete files in a folder if (!isset($delete_files)) { $delete_files = false; if (get_input("files") == "yes") { $delete_files = true; } } // should we remove files? if ($delete_files) { // find file in this folder $options = array("type" => "object", "subtype" => "file", "container_guid" => $object->getContainerGUID(), "limit" => false, "relationship" => FILE_TOOLS_RELATIONSHIP, "relationship_guid" => $object->getGUID()); if ($files = elgg_get_entities_from_relationship($options)) { // delete files in folder foreach ($files as $file) { $file->delete(); } } } } }
/** * The cron hook will take care of sending all the scheduled newsletters * * @param string $hook name of the hook * @param string $type type of the hook * @param string $returnvalue returnvalue of the hook * @param array $params params of the hook * * @return void */ function newsletter_cron_handler($hook, $type, $returnvalue, $params) { if (!empty($params) && is_array($params)) { $cron_ts = elgg_extract("time", $params, time()); // check for time drift if (date("i", $cron_ts) >= 30) { // example of the time: 14:59:56 // which should be the hourly cron for 15:00:00 $cron_ts = $cron_ts + 30 * 60; } // make the timestamp to an hour $newsletter_ts = mktime(date("H", $cron_ts), 0, 0, date("n", $cron_ts), date("j", $cron_ts), date("Y", $cron_ts)); $options = array("type" => "object", "subtype'" => Newsletter::SUBTYPE, "limit" => false, "metadata_name_value_pairs" => array("name" => "scheduled", "value" => $newsletter_ts)); // ignore access $ia = elgg_set_ignore_access(true); $newsletters = elgg_get_entities_from_metadata($options); // retore access elgg_set_ignore_access($ia); if (!empty($newsletters)) { foreach ($newsletters as $newsletter) { newsletter_start_commandline_sending($newsletter); } } } }
/** * Clean unvalidated users cron hook */ function clean_unvalidate($vars) { $days_till_first_reminder = elgg_get_plugin_setting("validation_reminder_first_message") * 1; $days_till_second_reminder = elgg_get_plugin_setting("validation_reminder_second_message") * 1; $days_till_removal = elgg_get_plugin_setting("validation_reminder_remove") * 1; $proviousAccessShowHiddenEntities = access_show_hidden_entities(true); $proviousIgnoreAccess = elgg_set_ignore_access(true); $dbprefix = elgg_get_config('dbprefix'); // @var $users ElggUser[] $users = elgg_get_entities_from_metadata(['type' => 'user', 'limit' => false, 'metadata_name_value_pair' => array(array('name' => 'validated', 'value' => false))]); foreach ($users as $user) { $validate_reminder_start_date = $user->time_created; if (time() - $validate_reminder_start_date >= $days_till_removal * 24 * 60 * 60) { $user->delete(); echo 'Account deleted'; } else { if (time() - $validate_reminder_start_date >= $days_till_second_reminder * 24 * 60 * 60 && time() - $validate_reminder_start_date <= ($days_till_second_reminder + 1) * 24 * 60 * 60) { send_validation_reminder_mail($user, $days_till_removal, $days_till_second_reminder); echo 'Send second reminder send'; } else { if (time() - $validate_reminder_start_date >= $days_till_first_reminder * 24 * 60 * 60 && time() - $validate_reminder_start_date <= ($days_till_first_reminder + 1) * 24 * 60 * 60) { send_validation_reminder_mail($user, $days_till_removal, $days_till_first_reminder); echo 'Send first reminder send'; } else { echo 'Waiting for validation'; } } } echo ' for user: '******'<br>'; } elgg_set_ignore_access($proviousIgnoreAccess); access_show_hidden_entities($proviousAccessShowHiddenEntities); }
/** * 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); } } } } }
/** * Handle /wizard * * @param array $page url elements * * @return bool */ function wizard_page_handler($page) { $include_file = false; $pages_base = elgg_get_plugins_path() . 'wizard/pages/'; switch ($page[0]) { case 'view': if (!empty($page[1]) && is_numeric($page[1])) { set_input('guid', $page[1]); $include_file = "{$pages_base}view.php"; } break; default: // try to find a wizard if (!empty($page[0])) { $options = array('type' => 'object', 'subtype' => Wizard::SUBTYPE, 'limit' => 1, 'metadata_name_value_pairs' => array('friendly_title' => $page[0])); $entities = elgg_get_entities_from_metadata($options); if (!empty($entities)) { set_input('guid', $entities[0]->getGUID()); $include_file = "{$pages_base}view.php"; } } break; } if (!empty($include_file)) { include $include_file; return true; } return false; }
/** * returns an array to be used in elgg_get_* functions * * @param int $assignee the guid of the assigned user * @param int $group_filter optional group filter * * @return array */ function todos_get_open_assigned_item_options($assignee = 0, $group_filter = 0) { $assignee = sanitise_int($assignee, false); $group_filter = sanitise_int($group_filter, false); $options = array('type' => 'object', 'subtype' => TodoItem::SUBTYPE, 'limit' => false, 'metadata_name_value_pairs' => array(array('name' => 'order', 'value' => 0, 'operand' => '>')), 'full_view' => false, 'item_class' => 'todos-list-item', 'list_class' => 'todos-list mtl', 'pagination' => false); if (!empty($assignee)) { // assiged to specific person $options['metadata_name_value_pairs'][] = array('name' => 'assignee', 'value' => $assignee); $options['show_assignee'] = false; } else { // just assigned $options['metadata_name_value_pairs'][] = array('name' => 'assignee', 'value' => 0, 'operand' => '>'); } if (!empty($group_filter) && $assignee !== $group_filter) { $group_lists = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => TodoList::SUBTYPE, 'container_guid' => $group_filter, 'limit' => false, 'callback' => false, 'metadata_name_value_pairs' => array('active' => true))); if (!empty($group_lists)) { $guids = array(); foreach ($group_lists as $row) { $guids[] = (int) $row->guid; } $options['wheres'] = array('e.container_guid IN (' . implode(',', $guids) . ')'); } } return $options; }
/** * This method is called when a users points are updated. * We check to see what the users current balance is and * assign the appropriate badge. */ function badges_userpoints($hook, $type, $return, $params) { if ($params['entity']->badges_locked) { return true; } $points = $params['entity']->userpoints_points; $badge = get_entity($params['entity']->badges_badge); $options = array('type' => 'object', 'subtype' => 'badge', 'limit' => false, 'order_by_metadata' => array('name' => 'badges_userpoints', 'direction' => DESC, 'as' => integer)); $options['metadata_name_value_pairs'] = array(array('name' => 'badges_userpoints', 'value' => $points, 'operand' => '<=')); $entities = elgg_get_entities_from_metadata($options); if ((int) elgg_get_plugin_setting('lock_high', 'elggx_badges')) { if ($badge->badges_userpoints > $entities[0]->badges_userpoints) { return true; } } if ($badge->guid != $entities[0]->guid) { $params['entity']->badges_badge = $entities[0]->guid; if (!elgg_trigger_plugin_hook('badges:update', 'object', array('entity' => $user), true)) { $params['entity']->badges_badge = $badge->guid; return false; } // Announce it on the river $user_guid = $params['entity']->getGUID(); elgg_delete_river(array("view" => 'river/object/badge/assign', "subject_guid" => $user_guid, "object_guid" => $user_guid)); elgg_delete_river(array("view" => 'river/object/badge/award', "subject_guid" => $user_guid, "object_guid" => $user_guid)); elgg_create_river_item(array('view' => 'river/object/badge/award', 'action_type' => 'award', 'subject_guid' => $user_guid, 'object_guid' => $user_guid)); } return true; }
function rijkshuisstijl_get_news_leader() { $leader = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'news', 'metadata_name_value_pairs' => array(array('name' => 'featuredPhotoTime', 'operand' => '!=', 'value' => 'null')), 'limit' => 1)); if (count($leader) == 1) { return $leader[0]; } return null; }
/** @override */ public function getEntities(array $options = array()) { if (empty($options)) { // Experimental API return new EntitiesQuery($this); } else { return \elgg_get_entities_from_metadata($options); } }
/** * Get the steps * * @param bool $count get the count of the steps * * @return false|WizardStep[]|int */ public function getSteps($count = false) { $count = (bool) $count; $options = ['type' => 'object', 'subtype' => WizardStep::SUBTYPE, 'limit' => false, 'container_guid' => $this->getGUID(), 'order_by_metadata' => ['name' => 'order', 'as' => 'integer', 'direction' => 'ASC']]; if ($count) { $options['count'] = true; } return elgg_get_entities_from_metadata($options); }
/** * This function attempts to retrieve a previously imported entity via its UUID. * * @param string $uuid A unique ID * * @return mixed */ function get_entity_from_uuid($uuid) { $uuid = sanitise_string($uuid); $options = array('metadata_name' => 'import_uuid', 'metadata_value' => $uuid); $entities = elgg_get_entities_from_metadata($options); if ($entities) { return $entities[0]; } return false; }
/** * Validates if is list is complete and marks as complete */ public function validateListCompleteness() { $options = array('type' => 'object', 'subtype' => TodoItem::SUBTYPE, 'count' => true, 'container_guid' => $this->guid, 'metadata_names' => array('order')); $incomplete_children_count = elgg_get_entities_from_metadata($options); if ($this->isActive() && $incomplete_children_count === 0) { $this->markAsInactive(); } elseif (!$this->isActive() && $incomplete_children_count > 0) { $this->markAsActive(); } }
/** * Get the answer that was marked as the correct answer. * * @return fasle|ElggAnswer */ public function getMarkedAnswer() { $result = false; $options = ['type' => 'object', 'subtype' => ElggAnswer::SUBTYPE, 'limit' => 1, 'container_guid' => $this->getGUID(), 'metadata_name_value_pairs' => array('name' => 'correct_answer', 'value' => true)]; $answers = elgg_get_entities_from_metadata($options); if (!empty($answers)) { $result = $answers[0]; } return $result; }
function hj_framework_get_entities_from_metadata_by_priority($type = 'object', $subtype = null, $owner_guid = NULL, $container_guid = null, $metadata_name_value_pairs = null, $limit = 0, $offset = 0, $count = false) { if (is_array($metadata_name_value_pairs)) { $db_prefix = elgg_get_config('dbprefix'); $entities = elgg_get_entities_from_metadata(array('type' => $type, 'subtype' => $subtype, 'owner_guid' => $owner_guid, 'container_guid' => $container_guid, 'metadata_name_value_pairs' => $metadata_name_value_pairs, 'limit' => $limit, 'offset' => $offset, 'count' => $count, 'joins' => array("JOIN {$db_prefix}metadata as mt on e.guid = mt.entity_guid\n JOIN {$db_prefix}metastrings as msn on mt.name_id = msn.id\n JOIN {$db_prefix}metastrings as msv on mt.value_id = msv.id"), 'wheres' => array("((msn.string = 'priority'))"), 'order_by' => "CAST(msv.string AS SIGNED) ASC")); } else { $entities = hj_framework_get_entities_by_priority(array('type' => $type, 'subtype' => $subtype, 'owner_guid' => $owner_guid, 'container_guid' => $container_guid, 'limit' => $limit)); } return $entities; }
function expozeum_cron($hook, $entity_type, $returnvalue, $params) { $time = time() - 7 * 24 * 60 * 60; $options = array('type' => 'object', 'subtype' => 'hjalbumimage', 'metadata_name_value_pairs' => array('name' => 'expozeum', 'value' => true), 'limit' => 0, 'wheres' => array('e.access_id != ' . ACCESS_PUBLIC)); $illegals = elgg_get_entities_from_metadata($options); foreach ($illegals as $illegal) { unset($illegal->expozeum); } echo elgg_echo('expozeum:clean:done'); }
/** * Assemblies function library * * @package Lorea * @subpackage Assemblies * * Copyright 2012-2013 Lorea Faeries <*****@*****.**> * * This file is part of the Assemblies plugin for Elgg. * * Assemblies is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * Assemblies is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/>. */ function assemblies_get_next_assembly($group) { $options = array('types' => 'object', 'subtypes' => 'assembly', 'limit' => 1, 'container_guid' => $group->guid, 'metadata_name_value_pairs' => array(array('name' => 'date', 'value' => time(), 'operand' => '>=')), 'order_by_metadata' => array('name' => 'date', 'direction' => 'ASC')); $assemblies = elgg_get_entities_from_metadata($options); if (count($assemblies)) { return $assemblies[0]; } else { return false; } }