1 | <?php |
||
13 | abstract class AliasModel extends UrlModel implements NamedModel |
||
14 | { |
||
15 | /** |
||
16 | * The name of the object |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $name; |
||
20 | |||
21 | /** |
||
22 | * A unique URL-friendly identifier for the object |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $alias; |
||
26 | |||
27 | /** |
||
28 | * Get the name of the object |
||
29 | * @return string |
||
30 | */ |
||
31 | 39 | public function getName() |
|
35 | |||
36 | /** |
||
37 | * Get the name of the team, safe for use in your HTML |
||
38 | * |
||
39 | * @return string The name of the team |
||
40 | */ |
||
41 | 1 | public function getEscapedName() |
|
49 | |||
50 | /** |
||
51 | * Change the object's name |
||
52 | * |
||
53 | * @return self |
||
54 | */ |
||
55 | public function setName($name) |
||
62 | |||
63 | /** |
||
64 | * Get an object's alias |
||
65 | * @return string|int The alias (or ID if the alias doesn't exist) |
||
66 | */ |
||
67 | 5 | public function getAlias() |
|
75 | |||
76 | /** |
||
77 | * Set a model's alias |
||
78 | * @param string $alias The new alias |
||
79 | * @return void |
||
80 | */ |
||
81 | public function setAlias($alias) |
||
85 | |||
86 | /** |
||
87 | * Reset a model's alias based on its name |
||
88 | * @return self |
||
89 | */ |
||
90 | 38 | public function resetAlias() |
|
96 | |||
97 | /** |
||
98 | * {@inheritdoc} |
||
99 | */ |
||
100 | 1 | public function getURL($action = 'show', $absolute = false, $params = array()) |
|
116 | |||
117 | /** |
||
118 | * Gets an entity from the supplied alias |
||
119 | * @param string $alias The object's alias |
||
120 | * @return AliasModel |
||
121 | */ |
||
122 | 3 | public static function fetchFromAlias($alias) |
|
126 | |||
127 | /** |
||
128 | * {@inheritdoc} |
||
129 | * @return AliasModel |
||
130 | */ |
||
131 | 3 | public static function fetchFromSlug($slug) |
|
141 | |||
142 | /** |
||
143 | * Generate a URL-friendly unique alias for an object name |
||
144 | * |
||
145 | * @param string $name The original object name |
||
146 | * @param int|null $id The ID of the object, if it's being edited and not created |
||
147 | * @return string|null The generated alias, or Null if we couldn't make one |
||
148 | */ |
||
149 | 39 | public static function generateAlias($name, $id = null) |
|
177 | |||
178 | /** |
||
179 | * Make sure that the generated alias provided is unique |
||
180 | * |
||
181 | * @param string $alias The alias |
||
182 | * @param int $id The ID of the object, if it's being edited and not created |
||
183 | * @return string An alias that is guaranteed to be unique |
||
184 | */ |
||
185 | 39 | private static function getUniqueAlias($alias, $id = 0) |
|
210 | |||
211 | /** |
||
212 | * Get a list of aliases that should not be given to objects |
||
213 | * |
||
214 | * For example, you want to prevent teams from getting the "new" alias. |
||
215 | * Otherwise, the team's link would be http://example.com/bzion/teams/new, |
||
216 | * and the user would go to the team creation page instead of the team's page. |
||
217 | * Disallowed aliases will have a number appended, so the URL would be |
||
218 | * http://example.com/bzion/teams/new2 |
||
219 | * |
||
220 | * @return string[] |
||
221 | */ |
||
222 | 39 | protected static function getDisallowedAliases() |
|
226 | } |
||
227 |