Passed
Push — master ( c0a3a7...3b84a4 )
by Jeroen
58:51
created

ElggBlog::initializeAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 3
cp 0
crap 2
1
<?php
2
/**
3
 * Extended class to override the time_created
4
 *
5
 * @property string $status      The published status of the blog post (published, draft)
6
 * @property string $comments_on Whether commenting is allowed (Off, On)
7
 * @property string $excerpt     An excerpt of the blog post used when displaying the post
8
 * @property string $new_post    Whether this is an auto-save (not fully saved) ("1" = yes, "" = no)
9
 */
10
class ElggBlog extends ElggObject {
11
12
	/**
13
	 * {@inheritDoc}
14
	 */
15
	protected function initializeAttributes() {
16
		parent::initializeAttributes();
17
18
		$this->attributes['subtype'] = "blog";
19
	}
20
21
	/**
22
	 * Can a user comment on this blog?
23
	 *
24
	 * @see ElggObject::canComment()
25
	 *
26
	 * @param int  $user_guid User guid (default is logged in user)
27
	 * @param bool $default   Default permission
28
	 *
29
	 * @return bool
30
	 *
31
	 * @since 1.8.0
32
	 */
33
	public function canComment($user_guid = 0, $default = null) {
34
		$result = parent::canComment($user_guid, $default);
35
		if ($result == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
36
			return $result;
37
		}
38
39
		if ($this->comments_on === 'Off' || $this->status !== 'published') {
40
			return false;
41
		}
42
		
43
		return true;
44
	}
45
46
	/**
47
	 * Get the excerpt for this blog post
48
	 *
49
	 * @param int $length Length of the excerpt (optional)
50
	 * @return string
51
	 * @since 1.9.0
52
	 */
53
	public function getExcerpt($length = 250) {
54
		if ($this->excerpt) {
55
			return $this->excerpt;
56
		} else {
57
			return elgg_get_excerpt($this->description, $length);
58
		}
59
	}
60
61
}
62