/**
 * Returns metadata.  Accepts all elgg_get_entities() options for entity
 * restraints.
 *
 * @see elgg_get_entities
 *
 * @warning 1.7's find_metadata() didn't support limits and returned all metadata.
 *          This function defaults to a limit of 25. There is probably not a reason
 *          for you to return all metadata unless you're exporting an entity,
 *          have other restraints in place, or are doing something horribly
 *          wrong in your code.
 *
 * @param array $options Array in format:
 *
 * metadata_names               => null|ARR metadata names
 * metadata_values              => null|ARR metadata values
 * metadata_ids                 => null|ARR metadata ids
 * metadata_case_sensitive      => BOOL Overall Case sensitive
 * metadata_owner_guids         => null|ARR guids for metadata owners
 * metadata_created_time_lower  => INT Lower limit for created time.
 * metadata_created_time_upper  => INT Upper limit for created time.
 * metadata_calculation         => STR Perform the MySQL function on the metadata values returned.
 *                                   The "metadata_calculation" option causes this function to
 *                                   return the result of performing a mathematical calculation on
 *                                   all metadata that match the query instead of returning
 *                                   ElggMetadata objects.
 *
 * @return ElggMetadata[]|mixed
 * @since 1.8.0
 */
function elgg_get_metadata(array $options = array())
{
    // @todo remove support for count shortcut - see #4393
    // support shortcut of 'count' => true for 'metadata_calculation' => 'count'
    if (isset($options['count']) && $options['count']) {
        $options['metadata_calculation'] = 'count';
        unset($options['count']);
    }
    $options['metastring_type'] = 'metadata';
    return _elgg_get_metastring_based_objects($options);
}
示例#2
0
/**
 * Returns annotations.  Accepts all elgg_get_entities() options for entity
 * restraints.
 *
 * @see elgg_get_entities
 *
 * @param array $options Array in format:
 *
 * annotation_names              => null|ARR Annotation names
 * annotation_values             => null|ARR Annotation values
 * annotation_ids                => null|ARR annotation ids
 * annotation_case_sensitive     => BOOL Overall Case sensitive
 * annotation_owner_guids        => null|ARR guids for annotation owners
 * annotation_created_time_lower => INT Lower limit for created time.
 * annotation_created_time_upper => INT Upper limit for created time.
 * annotation_calculation        => STR Perform the MySQL function on the annotation values returned.
 *                                   Do not confuse this "annotation_calculation" option with the
 *                                   "calculation" option to elgg_get_entities_from_annotation_calculation().
 *                                   The "annotation_calculation" option causes this function to
 *                                   return the result of performing a mathematical calculation on
 *                                   all annotations that match the query instead of \ElggAnnotation
 *                                   objects.
 *                                   See the docs for elgg_get_entities_from_annotation_calculation()
 *                                   for the proper use of the "calculation" option.
 *
 *
 * @return \ElggAnnotation[]|mixed
 * @since 1.8.0
 */
function elgg_get_annotations(array $options = array())
{
    // @todo remove support for count shortcut - see #4393
    if (isset($options['__egefac']) && $options['__egefac']) {
        unset($options['__egefac']);
    } else {
        // support shortcut of 'count' => true for 'annotation_calculation' => 'count'
        if (isset($options['count']) && $options['count']) {
            $options['annotation_calculation'] = 'count';
            unset($options['count']);
        }
    }
    $options['metastring_type'] = 'annotations';
    return _elgg_get_metastring_based_objects($options);
}
示例#3
0
/**
 * Returns a singular metastring-based object by its ID.
 *
 * @param int    $id   The metastring-based object's ID
 * @param string $type The type: annotation or metadata
 * @return \ElggExtender
 * @access private
 */
function _elgg_get_metastring_based_object_from_id($id, $type)
{
    $id = (int) $id;
    if (!$id) {
        return false;
    }
    $options = array('metastring_type' => $type, 'metastring_id' => $id);
    $obj = _elgg_get_metastring_based_objects($options);
    if ($obj && count($obj) == 1) {
        return $obj[0];
    }
    return false;
}
示例#4
0
 /**
  * Returns annotations.  Accepts all elgg_get_entities() options for entity
  * restraints.
  *
  * @see elgg_get_entities
  *
  * @param array $options Array in format:
  *
  * annotation_names              => null|ARR Annotation names
  * annotation_values             => null|ARR Annotation values
  * annotation_ids                => null|ARR annotation ids
  * annotation_case_sensitive     => BOOL Overall Case sensitive
  * annotation_owner_guids        => null|ARR guids for annotation owners
  * annotation_created_time_lower => INT Lower limit for created time.
  * annotation_created_time_upper => INT Upper limit for created time.
  * annotation_calculation        => STR Perform the MySQL function on the annotation values returned.
  *                                   Do not confuse this "annotation_calculation" option with the
  *                                   "calculation" option to elgg_get_entities_from_annotation_calculation().
  *                                   The "annotation_calculation" option causes this function to
  *                                   return the result of performing a mathematical calculation on
  *                                   all annotations that match the query instead of \ElggAnnotation
  *                                   objects.
  *                                   See the docs for elgg_get_entities_from_annotation_calculation()
  *                                   for the proper use of the "calculation" option.
  *
  *
  * @return \ElggAnnotation[]|mixed
  */
 function find(array $options = array())
 {
     // support shortcut of 'count' => true for 'annotation_calculation' => 'count'
     if (isset($options['count']) && $options['count']) {
         $options['annotation_calculation'] = 'count';
         unset($options['count']);
     }
     $options['metastring_type'] = 'annotations';
     return _elgg_get_metastring_based_objects($options);
 }
 public function testGetMetastringBasedObjectWithDisabledAnnotation()
 {
     $name = 'test_annotation_name' . rand();
     $value = 'test_annotation_value' . rand();
     $id = create_annotation($this->object->guid, $name, $value);
     $annotation = elgg_get_annotation_from_id($id);
     $this->assertTrue($annotation->disable());
     $test = _elgg_get_metastring_based_objects(array('metastring_type' => 'annotations', 'guid' => $this->object->guid));
     $this->assertEqual(array(), $test);
     $prev = access_get_show_hidden_status();
     access_show_hidden_entities(true);
     $this->assertTrue(_elgg_delete_metastring_based_object_by_id($id, 'annotation'));
     access_show_hidden_entities($prev);
 }