flag_get_flagged_content() doesn't have a documented @return (!!!) but it looks like it just returns rows from the {flag_content} table.

For D7, we need something that can be passed direct to entity_load(), ie it should return an array of ids.

For that matter, given that you'd need to sniff the flag to get the entity type, we could have:

// Get ids:
$flag_name = 'foo';
$ids = flag_get_flagged_ids($flag_name);

// Get entities
$flag_name = 'foo';
$entities = flag_get_flagged_entities($flag_name);

Though I guess you'd still need to do a flag_get_flag($flag_name) yourself to know what the type of the entities you'd just got was...

Comments

joachim’s picture

We should also index the result by the entity ID. That's unique since we only ever retrieve one type of entity.

joachim’s picture

Issue tags: +Needs change record

Turns out this function is somewhat of a misnomer, as it outputs what looks more like flagging data than entities:

Array
(
[0] => stdClass Object
(
[flagging_id] => 5
[fid] => 1
[entity_type] => node
[entity_id] => 1
[uid] => 3
[sid] => 0
[timestamp] => 1343838053
)

[1] => stdClass Object
(
[flagging_id] => 8
[fid] => 1
[entity_type] => node
[entity_id] => 3
[uid] => 1
[sid] => 0
[timestamp] => 1344548217
)

[2] => stdClass Object
(
[flagging_id] => 4
[fid] => 1
[entity_type] => node
[entity_id] => 3
[uid] => 3
[sid] => 0
[timestamp] => 1343838052
)

)

Therefore what I think should change here is:

- rename to flag_get_flag_flagging_data() (not flaggings, as we return data rows from the table and not full entities.)
- change the key of the returned data to be useful. We can't make the returned array use the entityID as the key, as the same entity may occur multiple times (flagged by different users). So no good for entity_load(). But if you want flagged entities you probably want Views anyway.
- However, keying by flagging id is doable and possibly useful if you want to load the flagging entities.

joachim’s picture

Status: Active » Needs review
StatusFileSize
new679 bytes
joachim’s picture

Let's see what the testbot says, but this is an API function that isn't called by anything in Flag so should be ok :)

joachim’s picture

Change record text:

flag_get_flagged_content() has been renamed to flag_get_flag_flagging_data() to better reflect its returned data. In addition, the returned result set is now keyed by the flagging id.

joachim’s picture

Status: Needs review » Fixed

Issue #1704534 by joachim: Changed flag_get_flagged_content() to flag_get_flag_flagging_data() and key results by flagging id.

joachim’s picture

Automatically closed -- issue fixed for 2 weeks with no activity.