2
2
3
3
namespace BookStack \Entities \Models ;
4
4
5
- use BookStack \Sorting \SortRule ;
6
- use BookStack \Uploads \Image ;
7
- use Exception ;
8
5
use Illuminate \Database \Eloquent \Builder ;
9
6
use Illuminate \Database \Eloquent \Model ;
10
- use Illuminate \Database \Eloquent \Relations \BelongsTo ;
11
- use Illuminate \Database \Eloquent \Relations \HasOne ;
12
7
13
8
/**
14
- * @property int $entity_id
15
- * @property string $entity_type
16
- * @property string $description
17
- * @property string $description_html
9
+ * @property int $entity_id
10
+ * @property string $entity_type
11
+ * @property string $description
12
+ * @property string $description_html
18
13
* @property ?int $default_template_id
19
14
* @property ?int $image_id
20
15
* @property ?int $sort_rule_id
@@ -25,9 +20,6 @@ class EntityContainerContents extends Model
25
20
protected $ primaryKey = 'entity_id ' ;
26
21
public $ incrementing = false ;
27
22
28
- // TODO - Should put the entity methods and relations back onto the original models
29
- // if we're going back to mostly keeping to the models.
30
-
31
23
/**
32
24
* Override the default set keys for save query method to make it work with composite keys.
33
25
*/
@@ -40,7 +32,7 @@ public function setKeysForSaveQuery($query): Builder
40
32
}
41
33
42
34
/**
43
- * Override the default set keys for select query method to make it work with composite keys.
35
+ * Override the default set keys for a select query method to make it work with composite keys.
44
36
*/
45
37
protected function setKeysForSelectQuery ($ query ): Builder
46
38
{
@@ -49,66 +41,4 @@ protected function setKeysForSelectQuery($query): Builder
49
41
50
42
return $ query ;
51
43
}
52
-
53
- /**
54
- * Relation for the cover image for this entity.
55
- * @return HasOne<Image, $this>
56
- */
57
- public function cover (): HasOne
58
- {
59
- return $ this ->hasOne (Image::class, 'image_id ' );
60
- }
61
-
62
- public function getCover (): Image |null
63
- {
64
- return $ this ->cover ()->first ();
65
- }
66
-
67
- /**
68
- * Returns a shelf cover image URL, if cover not exists return default cover image.
69
- */
70
- public function getCoverUrl (int $ width = 440 , int $ height = 250 , string |null $ default = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== ' ): string |null
71
- {
72
- if (!$ this ->image_id ) {
73
- return $ default ;
74
- }
75
-
76
- try {
77
- return $ this ->getCover ()?->getThumb($ width , $ height , false ) ?? $ default ;
78
- } catch (Exception $ err ) {
79
- return $ default ;
80
- }
81
- }
82
-
83
- /**
84
- * Check if this data supports having a default template assigned.
85
- */
86
- public function supportsDefaultTemplate (): bool
87
- {
88
- return in_array ($ this ->entity_type , ['book ' , 'chapter ' ]);
89
- }
90
-
91
- /**
92
- * Check this data supports having a cover image assigned.
93
- */
94
- public function supportsCoverImage (): bool
95
- {
96
- return in_array ($ this ->entity_type , ['book ' , 'bookshelf ' ]);
97
- }
98
-
99
- /**
100
- * Get the Page used as a default template to be used for new items within this container.
101
- */
102
- public function defaultTemplate (): BelongsTo
103
- {
104
- return $ this ->belongsTo (Page::class, 'default_template_id ' );
105
- }
106
-
107
- /**
108
- * Get the sort rule assigned to this container, if existing.
109
- */
110
- public function sortRule (): BelongsTo
111
- {
112
- return $ this ->belongsTo (SortRule::class);
113
- }
114
44
}
0 commit comments