Completed
Pull Request — gcconnex (#1585)
by
unknown
26:26 queued 10:13
created

thewire_image.php ➔ thewire_image_get_attachments()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 3
nop 1
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Procedural code for The Wire Image
4
 */
5
6
/**
7
 * Returns attachments for $post_guid
8
 *
9
 * @param int $post_guid The GUID of The Wire post to get image for.
10
 * @return TheWireImage|false
11
 */
12
function thewire_image_get_attachments($post_guid) {
13
	$post_guid = sanitise_int($post_guid);
14
	if (!$post_guid) {
15
		return false;
16
	}
17
18
	$attachments = elgg_get_entities_from_relationship(array(
19
		'relationship' => 'is_attachment',
20
		'relationship_guid' => $post_guid,
21
		'inverse_relationship' => true,
22
		'limit' => 1
23
	));
24
25
	if ($attachments) {
26
		return $attachments[0];
27
	}
28
29
	return false;
30
}