| 
									
										
										
										
											2015-07-13 03:01:42 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-11 02:31:09 +08:00
										 |  |  | namespace BookStack; | 
					
						
							| 
									
										
										
										
											2015-07-13 03:01:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-16 21:51:45 +08:00
										 |  |  | class Book extends Entity | 
					
						
							| 
									
										
										
										
											2015-07-13 03:01:42 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     protected $fillable = ['name', 'description']; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function getUrl() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return '/books/' . $this->slug; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function getEditUrl() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->getUrl() . '/edit'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 04:31:15 +08:00
										 |  |  |     public function pages() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-09-11 02:31:09 +08:00
										 |  |  |         return $this->hasMany('BookStack\Page'); | 
					
						
							| 
									
										
										
										
											2015-07-13 04:31:15 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-28 03:17:08 +08:00
										 |  |  |     public function chapters() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-09-11 02:31:09 +08:00
										 |  |  |         return $this->hasMany('BookStack\Chapter'); | 
					
						
							| 
									
										
										
										
											2015-07-28 03:17:08 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-01 03:11:44 +08:00
										 |  |  |     public function getExcerpt($length = 100) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return strlen($this->description) > $length ? substr($this->description, 0, $length-3) . '...' : $this->description; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 03:01:42 +08:00
										 |  |  | } |