Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like ElggEntity often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ElggEntity, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
41 | abstract class ElggEntity extends \ElggData implements |
||
42 | Notable, // Calendar interface (deprecated 1.9) |
||
|
|||
43 | Locatable, // Geocoding interface |
||
44 | Importable // Allow import of data (deprecated 1.9) |
||
45 | { |
||
46 | |||
47 | /** |
||
48 | * If set, overrides the value of getURL() |
||
49 | */ |
||
50 | protected $url_override; |
||
51 | |||
52 | /** |
||
53 | * Icon override, overrides the value of getIcon(). |
||
54 | */ |
||
55 | protected $icon_override; |
||
56 | |||
57 | /** |
||
58 | * Holds metadata until entity is saved. Once the entity is saved, |
||
59 | * metadata are written immediately to the database. |
||
60 | */ |
||
61 | protected $temp_metadata = array(); |
||
62 | |||
63 | /** |
||
64 | * Holds annotations until entity is saved. Once the entity is saved, |
||
65 | * annotations are written immediately to the database. |
||
66 | */ |
||
67 | protected $temp_annotations = array(); |
||
68 | |||
69 | /** |
||
70 | * Holds private settings until entity is saved. Once the entity is saved, |
||
71 | * private settings are written immediately to the database. |
||
72 | */ |
||
73 | protected $temp_private_settings = array(); |
||
74 | |||
75 | /** |
||
76 | * Volatile data structure for this object, allows for storage of data |
||
77 | * in-memory that isn't sync'd back to the metadata table. |
||
78 | */ |
||
79 | protected $volatile = array(); |
||
80 | |||
81 | /** |
||
82 | * Tells how many tables are going to need to be searched in order to fully populate this object |
||
83 | * |
||
84 | * @var int |
||
85 | */ |
||
86 | protected $tables_split; |
||
87 | |||
88 | /** |
||
89 | * Tells how many tables describing object have been loaded thus far |
||
90 | * |
||
91 | * @var int |
||
92 | */ |
||
93 | protected $tables_loaded; |
||
94 | |||
95 | /** |
||
96 | * Initialize the attributes array. |
||
97 | * |
||
98 | * This is vital to distinguish between metadata and base parameters. |
||
99 | * |
||
100 | * @return void |
||
101 | */ |
||
102 | 32 | protected function initializeAttributes() { |
|
103 | 32 | parent::initializeAttributes(); |
|
104 | |||
105 | 32 | $this->attributes['guid'] = null; |
|
106 | 32 | $this->attributes['type'] = null; |
|
107 | 32 | $this->attributes['subtype'] = null; |
|
108 | |||
109 | 32 | $this->attributes['owner_guid'] = _elgg_services()->session->getLoggedInUserGuid(); |
|
110 | 32 | $this->attributes['container_guid'] = _elgg_services()->session->getLoggedInUserGuid(); |
|
111 | |||
112 | 32 | $this->attributes['site_guid'] = null; |
|
113 | 32 | $this->attributes['access_id'] = ACCESS_PRIVATE; |
|
114 | 32 | $this->attributes['time_updated'] = null; |
|
115 | 32 | $this->attributes['last_action'] = null; |
|
116 | 32 | $this->attributes['enabled'] = "yes"; |
|
117 | |||
118 | // There now follows a bit of a hack |
||
119 | /* Problem: To speed things up, some objects are split over several tables, |
||
120 | * this means that it requires n number of database reads to fully populate |
||
121 | * an entity. This causes problems for caching and create events |
||
122 | * since it is not possible to tell whether a subclassed entity is complete. |
||
123 | * |
||
124 | * Solution: We have two counters, one 'tables_split' which tells whatever is |
||
125 | * interested how many tables are going to need to be searched in order to fully |
||
126 | * populate this object, and 'tables_loaded' which is how many have been |
||
127 | * loaded thus far. |
||
128 | * |
||
129 | * If the two are the same then this object is complete. |
||
130 | * |
||
131 | * Use: isFullyLoaded() to check |
||
132 | */ |
||
133 | 32 | $this->tables_split = 1; |
|
134 | 32 | $this->tables_loaded = 0; |
|
135 | 32 | } |
|
136 | |||
137 | /** |
||
138 | * Clone an entity |
||
139 | * |
||
140 | * Resets the guid so that the entity can be saved as a distinct entity from |
||
141 | * the original. Creation time will be set when this new entity is saved. |
||
142 | * The owner and container guids come from the original entity. The clone |
||
143 | * method copies metadata but does not copy annotations or private settings. |
||
144 | * |
||
145 | * @note metadata will have its owner and access id set when the entity is saved |
||
146 | * and it will be the same as that of the entity. |
||
147 | * |
||
148 | * @return void |
||
149 | */ |
||
150 | public function __clone() { |
||
151 | $orig_entity = get_entity($this->guid); |
||
152 | if (!$orig_entity) { |
||
153 | _elgg_services()->logger->error("Failed to clone entity with GUID $this->guid"); |
||
154 | return; |
||
155 | } |
||
156 | |||
157 | $metadata_array = elgg_get_metadata(array( |
||
158 | 'guid' => $this->guid, |
||
159 | 'limit' => 0 |
||
160 | )); |
||
161 | |||
162 | $this->attributes['guid'] = ""; |
||
163 | |||
164 | $this->attributes['subtype'] = $orig_entity->getSubtype(); |
||
165 | |||
166 | // copy metadata over to new entity - slightly convoluted due to |
||
167 | // handling of metadata arrays |
||
168 | if (is_array($metadata_array)) { |
||
169 | // create list of metadata names |
||
170 | $metadata_names = array(); |
||
171 | foreach ($metadata_array as $metadata) { |
||
172 | $metadata_names[] = $metadata['name']; |
||
173 | } |
||
174 | // arrays are stored with multiple enties per name |
||
175 | $metadata_names = array_unique($metadata_names); |
||
176 | |||
177 | // move the metadata over |
||
178 | foreach ($metadata_names as $name) { |
||
179 | $this->__set($name, $orig_entity->$name); |
||
180 | } |
||
181 | } |
||
182 | } |
||
183 | |||
184 | /** |
||
185 | * Set an attribute or metadata value for this entity |
||
186 | * |
||
187 | * Anything that is not an attribute is saved as metadata. |
||
188 | * |
||
189 | * @warning Metadata set this way will inherit the entity's owner and |
||
190 | * access ID. If you want more control over metadata, use \ElggEntity::setMetadata() |
||
191 | * |
||
192 | * @param string $name Name of the attribute or metadata |
||
193 | * @param mixed $value The value to be set |
||
194 | * @return void |
||
195 | * @see \ElggEntity::setMetadata() |
||
196 | */ |
||
197 | 15 | public function __set($name, $value) { |
|
198 | 15 | if ($this->$name === $value) { |
|
199 | // quick return if value is not changing |
||
200 | return; |
||
201 | } |
||
202 | 15 | if (array_key_exists($name, $this->attributes)) { |
|
203 | // Certain properties should not be manually changed! |
||
204 | switch ($name) { |
||
205 | 13 | case 'guid': |
|
206 | 13 | case 'time_updated': |
|
207 | 13 | case 'last_action': |
|
208 | 1 | return; |
|
209 | break; |
||
210 | 12 | case 'access_id': |
|
211 | 12 | case 'owner_guid': |
|
212 | 12 | View Code Duplication | case 'container_guid': |
213 | 3 | if ($value !== null) { |
|
214 | 3 | $this->attributes[$name] = (int)$value; |
|
215 | 3 | } else { |
|
216 | $this->attributes[$name] = null; |
||
217 | } |
||
218 | 3 | break; |
|
219 | 10 | default: |
|
220 | 10 | $this->attributes[$name] = $value; |
|
221 | 10 | break; |
|
222 | 10 | } |
|
223 | 12 | } else { |
|
224 | 2 | $this->setMetadata($name, $value); |
|
225 | } |
||
226 | 14 | } |
|
227 | |||
228 | /** |
||
229 | * Sets the value of an attribute or metadata |
||
230 | * |
||
231 | * @param string $name Name |
||
232 | * @param mixed $value Value |
||
233 | * |
||
234 | * @return bool |
||
235 | * @deprecated 1.9 |
||
236 | */ |
||
237 | public function set($name, $value) { |
||
238 | elgg_deprecated_notice("Use -> instead of set()", 1.9); |
||
239 | $this->__set($name, $value); |
||
240 | |||
241 | return true; |
||
242 | } |
||
243 | |||
244 | /** |
||
245 | * Get an attribute or metadata value |
||
246 | * |
||
247 | * If the name matches an attribute, the attribute is returned. If metadata |
||
248 | * does not exist with that name, a null is returned. |
||
249 | * |
||
250 | * This only returns an array if there are multiple values for a particular |
||
251 | * $name key. |
||
252 | * |
||
253 | * @param string $name Name of the attribute or metadata |
||
254 | * @return mixed |
||
255 | */ |
||
256 | 28 | public function __get($name) { |
|
257 | 28 | if (array_key_exists($name, $this->attributes)) { |
|
258 | 28 | if ($name === 'subtype' && $this->attributes['guid']) { |
|
259 | // note: only show deprecation notice if user reads ->subtype after save/load |
||
260 | elgg_deprecated_notice("Use getSubtype()", 1.9); |
||
261 | } |
||
262 | 28 | return $this->attributes[$name]; |
|
263 | } |
||
264 | |||
265 | 3 | return $this->getMetadata($name); |
|
266 | } |
||
267 | |||
268 | /** |
||
269 | * Return the value of an attribute or metadata |
||
270 | * |
||
271 | * @param string $name Name |
||
272 | * @return mixed Returns the value of a given value, or null. |
||
273 | * @deprecated 1.9 |
||
274 | */ |
||
275 | public function get($name) { |
||
276 | elgg_deprecated_notice("Use -> instead of get()", 1.9); |
||
277 | return $this->__get($name); |
||
278 | } |
||
279 | |||
280 | /** |
||
281 | * Get the entity's display name |
||
282 | * |
||
283 | * @return string The title or name of this entity. |
||
284 | */ |
||
285 | abstract public function getDisplayName(); |
||
286 | |||
287 | /** |
||
288 | * Sets the title or name of this entity. |
||
289 | * |
||
290 | * @param string $displayName The title or name of this entity. |
||
291 | * @return void |
||
292 | */ |
||
293 | abstract public function setDisplayName($displayName); |
||
294 | |||
295 | /** |
||
296 | * Return the value of a piece of metadata. |
||
297 | * |
||
298 | * @param string $name Name |
||
299 | * |
||
300 | * @return mixed The value, or null if not found. |
||
301 | */ |
||
302 | 3 | public function getMetadata($name) { |
|
350 | |||
351 | /** |
||
352 | * Unset a property from metadata or attribute. |
||
353 | * |
||
354 | * @warning If you use this to unset an attribute, you must save the object! |
||
355 | * |
||
356 | * @param string $name The name of the attribute or metadata. |
||
357 | * |
||
358 | * @return void |
||
359 | * @todo some attributes should be set to null or other default values |
||
360 | */ |
||
361 | 1 | public function __unset($name) { |
|
368 | |||
369 | /** |
||
370 | * Set metadata on this entity. |
||
371 | * |
||
372 | * Plugin developers usually want to use the magic set method ($entity->name = 'value'). |
||
373 | * Use this method if you want to explicitly set the owner or access of the metadata. |
||
374 | * You cannot set the owner/access before the entity has been saved. |
||
375 | * |
||
376 | * @param string $name Name of the metadata |
||
377 | * @param mixed $value Value of the metadata (doesn't support assoc arrays) |
||
378 | * @param string $value_type 'text', 'integer', or '' for automatic detection |
||
379 | * @param bool $multiple Allow multiple values for a single name. |
||
380 | * Does not support associative arrays. |
||
381 | * @param int $owner_guid GUID of entity that owns the metadata. |
||
382 | * Default is owner of entity. |
||
383 | * @param int $access_id Who can read the metadata relative to the owner. |
||
384 | * Default is the access level of the entity. |
||
385 | * |
||
386 | * @return bool |
||
387 | * @throws InvalidArgumentException |
||
388 | */ |
||
389 | 2 | public function setMetadata($name, $value, $value_type = '', $multiple = false, $owner_guid = 0, $access_id = null) { |
|
457 | |||
458 | /** |
||
459 | * Deletes all metadata on this object (metadata.entity_guid = $this->guid). |
||
460 | * If you pass a name, only metadata matching that name will be deleted. |
||
461 | * |
||
462 | * @warning Calling this with no $name will clear all metadata on the entity. |
||
463 | * |
||
464 | * @param null|string $name The name of the metadata to remove. |
||
465 | * @return bool |
||
466 | * @since 1.8 |
||
467 | */ |
||
468 | public function deleteMetadata($name = null) { |
||
484 | |||
485 | /** |
||
486 | * Deletes all metadata owned by this object (metadata.owner_guid = $this->guid). |
||
487 | * If you pass a name, only metadata matching that name will be deleted. |
||
488 | * |
||
489 | * @param null|string $name The name of metadata to delete. |
||
490 | * @return bool |
||
491 | * @since 1.8 |
||
492 | */ |
||
493 | View Code Duplication | public function deleteOwnedMetadata($name = null) { |
|
509 | |||
510 | /** |
||
511 | * Remove metadata |
||
512 | * |
||
513 | * @warning Calling this with no or empty arguments will clear all metadata on the entity. |
||
514 | * |
||
515 | * @param string $name The name of the metadata to clear |
||
516 | * @return mixed bool |
||
517 | * @deprecated 1.8 Use deleteMetadata() |
||
518 | */ |
||
519 | public function clearMetadata($name = '') { |
||
523 | |||
524 | /** |
||
525 | * Disables metadata for this entity, optionally based on name. |
||
526 | * |
||
527 | * @param string $name An options name of metadata to disable. |
||
528 | * @return bool |
||
529 | * @since 1.8 |
||
530 | */ |
||
531 | View Code Duplication | public function disableMetadata($name = '') { |
|
542 | |||
543 | /** |
||
544 | * Enables metadata for this entity, optionally based on name. |
||
545 | * |
||
546 | * @warning Before calling this, you must use {@link access_show_hidden_entities()} |
||
547 | * |
||
548 | * @param string $name An options name of metadata to enable. |
||
549 | * @return bool |
||
550 | * @since 1.8 |
||
551 | */ |
||
552 | View Code Duplication | public function enableMetadata($name = '') { |
|
563 | |||
564 | /** |
||
565 | * Get a piece of volatile (non-persisted) data on this entity. |
||
566 | * |
||
567 | * @param string $name The name of the volatile data |
||
568 | * |
||
569 | * @return mixed The value or null if not found. |
||
570 | */ |
||
571 | public function getVolatileData($name) { |
||
582 | |||
583 | /** |
||
584 | * Set a piece of volatile (non-persisted) data on this entity |
||
585 | * |
||
586 | * @param string $name Name |
||
587 | * @param mixed $value Value |
||
588 | * |
||
589 | * @return void |
||
590 | */ |
||
591 | public function setVolatileData($name, $value) { |
||
598 | |||
599 | /** |
||
600 | * Remove all relationships to and from this entity. |
||
601 | * If you pass a relationship name, only relationships matching that name |
||
602 | * will be deleted. |
||
603 | * |
||
604 | * @warning Calling this with no $relationship will clear all relationships |
||
605 | * for this entity. |
||
606 | * |
||
607 | * @param null|string $relationship The name of the relationship to remove. |
||
608 | * @return bool |
||
609 | * @see \ElggEntity::addRelationship() |
||
610 | * @see \ElggEntity::removeRelationship() |
||
611 | */ |
||
612 | public function deleteRelationships($relationship = null) { |
||
617 | |||
618 | /** |
||
619 | * Remove all relationships to and from this entity. |
||
620 | * |
||
621 | * @return bool |
||
622 | * @see \ElggEntity::addRelationship() |
||
623 | * @see \ElggEntity::removeRelationship() |
||
624 | * @deprecated 1.8 Use \ElggEntity::deleteRelationships() |
||
625 | */ |
||
626 | public function clearRelationships() { |
||
630 | |||
631 | /** |
||
632 | * Add a relationship between this an another entity. |
||
633 | * |
||
634 | * @tip Read the relationship like "This entity is a $relationship of $guid_two." |
||
635 | * |
||
636 | * @param int $guid_two GUID of the target entity of the relationship. |
||
637 | * @param string $relationship The type of relationship. |
||
638 | * |
||
639 | * @return bool |
||
640 | * @see \ElggEntity::removeRelationship() |
||
641 | * @see \ElggEntity::deleteRelationships() |
||
642 | */ |
||
643 | public function addRelationship($guid_two, $relationship) { |
||
646 | |||
647 | /** |
||
648 | * Remove a relationship |
||
649 | * |
||
650 | * @param int $guid_two GUID of the target entity of the relationship. |
||
651 | * @param string $relationship The type of relationship. |
||
652 | * |
||
653 | * @return bool |
||
654 | * @see \ElggEntity::addRelationship() |
||
655 | * @see \ElggEntity::deleteRelationships() |
||
656 | */ |
||
657 | public function removeRelationship($guid_two, $relationship) { |
||
660 | |||
661 | /** |
||
662 | * Adds a private setting to this entity. |
||
663 | * |
||
664 | * Private settings are similar to metadata but will not |
||
665 | * be searched and there are fewer helper functions for them. |
||
666 | * |
||
667 | * @param string $name Name of private setting |
||
668 | * @param mixed $value Value of private setting |
||
669 | * |
||
670 | * @return bool |
||
671 | */ |
||
672 | 9 | public function setPrivateSetting($name, $value) { |
|
680 | |||
681 | /** |
||
682 | * Returns a private setting value |
||
683 | * |
||
684 | * @param string $name Name of the private setting |
||
685 | * |
||
686 | * @return mixed Null if the setting does not exist |
||
687 | */ |
||
688 | 3 | public function getPrivateSetting($name) { |
|
698 | |||
699 | /** |
||
700 | * Removes private setting |
||
701 | * |
||
702 | * @param string $name Name of the private setting |
||
703 | * |
||
704 | * @return bool |
||
705 | */ |
||
706 | public function removePrivateSetting($name) { |
||
709 | |||
710 | /** |
||
711 | * Deletes all annotations on this object (annotations.entity_guid = $this->guid). |
||
712 | * If you pass a name, only annotations matching that name will be deleted. |
||
713 | * |
||
714 | * @warning Calling this with no or empty arguments will clear all annotations on the entity. |
||
715 | * |
||
716 | * @param null|string $name The annotations name to remove. |
||
717 | * @return bool |
||
718 | * @since 1.8 |
||
719 | */ |
||
720 | View Code Duplication | public function deleteAnnotations($name = null) { |
|
731 | |||
732 | /** |
||
733 | * Deletes all annotations owned by this object (annotations.owner_guid = $this->guid). |
||
734 | * If you pass a name, only annotations matching that name will be deleted. |
||
735 | * |
||
736 | * @param null|string $name The name of annotations to delete. |
||
737 | * @return bool |
||
738 | * @since 1.8 |
||
739 | */ |
||
740 | View Code Duplication | public function deleteOwnedAnnotations($name = null) { |
|
756 | |||
757 | /** |
||
758 | * Disables annotations for this entity, optionally based on name. |
||
759 | * |
||
760 | * @param string $name An options name of annotations to disable. |
||
761 | * @return bool |
||
762 | * @since 1.8 |
||
763 | */ |
||
764 | View Code Duplication | public function disableAnnotations($name = '') { |
|
775 | |||
776 | /** |
||
777 | * Enables annotations for this entity, optionally based on name. |
||
778 | * |
||
779 | * @warning Before calling this, you must use {@link access_show_hidden_entities()} |
||
780 | * |
||
781 | * @param string $name An options name of annotations to enable. |
||
782 | * @return bool |
||
783 | * @since 1.8 |
||
784 | */ |
||
785 | View Code Duplication | public function enableAnnotations($name = '') { |
|
796 | |||
797 | /** |
||
798 | * Helper function to return annotation calculation results |
||
799 | * |
||
800 | * @param string $name The annotation name. |
||
801 | * @param string $calculation A valid MySQL function to run its values through |
||
802 | * @return mixed |
||
803 | */ |
||
804 | private function getAnnotationCalculation($name, $calculation) { |
||
814 | |||
815 | /** |
||
816 | * Adds an annotation to an entity. |
||
817 | * |
||
818 | * @warning By default, annotations are private. |
||
819 | * |
||
820 | * @warning Annotating an unsaved entity more than once with the same name |
||
821 | * will only save the last annotation. |
||
822 | * |
||
823 | * @param string $name Annotation name |
||
824 | * @param mixed $value Annotation value |
||
825 | * @param int $access_id Access ID |
||
826 | * @param int $owner_guid GUID of the annotation owner |
||
827 | * @param string $vartype The type of annotation value |
||
828 | * |
||
829 | * @return bool|int Returns int if an annotation is saved |
||
830 | */ |
||
831 | public function annotate($name, $value, $access_id = ACCESS_PRIVATE, $owner_guid = 0, $vartype = "") { |
||
839 | |||
840 | /** |
||
841 | * Gets an array of annotations. |
||
842 | * |
||
843 | * To retrieve annotations on an unsaved entity, pass array('name' => [annotation name]) |
||
844 | * as the options array. |
||
845 | * |
||
846 | * @param array $options Array of options for elgg_get_annotations() except guid. This |
||
847 | * may be passed a string annotation name, but this usage is deprecated. |
||
848 | * @param int $limit Limit (deprecated) |
||
849 | * @param int $offset Offset (deprecated) |
||
850 | * @param string $order Order by time: asc or desc (deprecated) |
||
851 | * |
||
852 | * @return array |
||
853 | * @see elgg_get_annotations() |
||
854 | */ |
||
855 | public function getAnnotations($options = array(), $limit = 50, $offset = 0, $order = "asc") { |
||
891 | |||
892 | /** |
||
893 | * Remove an annotation or all annotations for this entity. |
||
894 | * |
||
895 | * @warning Calling this method with no or an empty argument will remove |
||
896 | * all annotations on the entity. |
||
897 | * |
||
898 | * @param string $name Annotation name |
||
899 | * @return bool |
||
900 | * @deprecated 1.8 Use ->deleteAnnotations() |
||
901 | */ |
||
902 | public function clearAnnotations($name = "") { |
||
906 | |||
907 | /** |
||
908 | * Count annotations. |
||
909 | * |
||
910 | * @param string $name The type of annotation. |
||
911 | * |
||
912 | * @return int |
||
913 | */ |
||
914 | public function countAnnotations($name = "") { |
||
917 | |||
918 | /** |
||
919 | * Get the average of an integer type annotation. |
||
920 | * |
||
921 | * @param string $name Annotation name |
||
922 | * |
||
923 | * @return int |
||
924 | */ |
||
925 | public function getAnnotationsAvg($name) { |
||
928 | |||
929 | /** |
||
930 | * Get the sum of integer type annotations of a given name. |
||
931 | * |
||
932 | * @param string $name Annotation name |
||
933 | * |
||
934 | * @return int |
||
935 | */ |
||
936 | public function getAnnotationsSum($name) { |
||
939 | |||
940 | /** |
||
941 | * Get the minimum of integer type annotations of given name. |
||
942 | * |
||
943 | * @param string $name Annotation name |
||
944 | * |
||
945 | * @return int |
||
946 | */ |
||
947 | public function getAnnotationsMin($name) { |
||
950 | |||
951 | /** |
||
952 | * Get the maximum of integer type annotations of a given name. |
||
953 | * |
||
954 | * @param string $name Annotation name |
||
955 | * |
||
956 | * @return int |
||
957 | */ |
||
958 | public function getAnnotationsMax($name) { |
||
961 | |||
962 | /** |
||
963 | * Count the number of comments attached to this entity. |
||
964 | * |
||
965 | * @return int Number of comments |
||
966 | * @since 1.8.0 |
||
967 | */ |
||
968 | public function countComments() { |
||
984 | |||
985 | /** |
||
986 | * Gets an array of entities with a relationship to this entity. |
||
987 | * |
||
988 | * @param array $options Options array. See elgg_get_entities_from_relationship() |
||
989 | * for a list of options. 'relationship_guid' is set to |
||
990 | * this entity. |
||
991 | * @param bool $inverse Is this an inverse relationship? (deprecated) |
||
992 | * @param int $limit Number of elements to return (deprecated) |
||
993 | * @param int $offset Indexing offset (deprecated) |
||
994 | * |
||
995 | * @return array|false An array of entities or false on failure |
||
996 | * @see elgg_get_entities_from_relationship() |
||
997 | */ |
||
998 | public function getEntitiesFromRelationship($options = array(), $inverse = false, $limit = 50, $offset = 0) { |
||
1013 | |||
1014 | /** |
||
1015 | * Gets the number of entities from a specific relationship type |
||
1016 | * |
||
1017 | * @param string $relationship Relationship type (eg "friends") |
||
1018 | * @param bool $inverse_relationship Invert relationship |
||
1019 | * |
||
1020 | * @return int|false The number of entities or false on failure |
||
1021 | */ |
||
1022 | public function countEntitiesFromRelationship($relationship, $inverse_relationship = false) { |
||
1030 | |||
1031 | /** |
||
1032 | * Can a user edit this entity? |
||
1033 | * |
||
1034 | * @tip Can be overridden by registering for the permissions_check plugin hook. |
||
1035 | * |
||
1036 | * @param int $user_guid The user GUID, optionally (default: logged in user) |
||
1037 | * |
||
1038 | * @return bool Whether this entity is editable by the given user. |
||
1039 | * @see elgg_set_ignore_access() |
||
1040 | */ |
||
1041 | public function canEdit($user_guid = 0) { |
||
1073 | |||
1074 | /** |
||
1075 | * Can a user delete this entity? |
||
1076 | * |
||
1077 | * @tip Can be overridden by registering for the permissions_check:delete plugin hook. |
||
1078 | * |
||
1079 | * @param int $user_guid The user GUID, optionally (default: logged in user) |
||
1080 | * |
||
1081 | * @return bool Whether this entity is deletable by the given user. |
||
1082 | * @since 1.11 |
||
1083 | * @see elgg_set_ignore_access() |
||
1084 | */ |
||
1085 | public function canDelete($user_guid = 0) { |
||
1114 | |||
1115 | /** |
||
1116 | * Can a user edit metadata on this entity? |
||
1117 | * |
||
1118 | * If no specific metadata is passed, it returns whether the user can |
||
1119 | * edit any metadata on the entity. |
||
1120 | * |
||
1121 | * @tip Can be overridden by by registering for the permissions_check:metadata |
||
1122 | * plugin hook. |
||
1123 | * |
||
1124 | * @param \ElggMetadata $metadata The piece of metadata to specifically check or null for any metadata |
||
1125 | * @param int $user_guid The user GUID, optionally (default: logged in user) |
||
1126 | * |
||
1127 | * @return bool |
||
1128 | * @see elgg_set_ignore_access() |
||
1129 | */ |
||
1130 | public function canEditMetadata($metadata = null, $user_guid = 0) { |
||
1161 | |||
1162 | /** |
||
1163 | * Can a user add an entity to this container |
||
1164 | * |
||
1165 | * @param int $user_guid The GUID of the user creating the entity (0 for logged in user). |
||
1166 | * @param string $type The type of entity we're looking to write |
||
1167 | * @param string $subtype The subtype of the entity we're looking to write |
||
1168 | * |
||
1169 | * @return bool |
||
1170 | * @see elgg_set_ignore_access() |
||
1171 | */ |
||
1172 | public function canWriteToContainer($user_guid = 0, $type = 'all', $subtype = 'all') { |
||
1175 | |||
1176 | /** |
||
1177 | * Can a user comment on an entity? |
||
1178 | * |
||
1179 | * @tip Can be overridden by registering for the permissions_check:comment, |
||
1180 | * <entity type> plugin hook. |
||
1181 | * |
||
1182 | * @param int $user_guid User guid (default is logged in user) |
||
1183 | * |
||
1184 | * @return bool |
||
1185 | */ |
||
1186 | public function canComment($user_guid = 0) { |
||
1197 | |||
1198 | /** |
||
1199 | * Can a user annotate an entity? |
||
1200 | * |
||
1201 | * @tip Can be overridden by registering for the plugin hook [permissions_check:annotate:<name>, |
||
1202 | * <entity type>] or [permissions_check:annotate, <entity type>]. The hooks are called in that order. |
||
1203 | * |
||
1204 | * @tip If you want logged out users to annotate an object, do not call |
||
1205 | * canAnnotate(). It's easier than using the plugin hook. |
||
1206 | * |
||
1207 | * @param int $user_guid User guid (default is logged in user) |
||
1208 | * @param string $annotation_name The name of the annotation (default is unspecified) |
||
1209 | * |
||
1210 | * @return bool |
||
1211 | */ |
||
1212 | public function canAnnotate($user_guid = 0, $annotation_name = '') { |
||
1237 | |||
1238 | /** |
||
1239 | * Returns the access_id. |
||
1240 | * |
||
1241 | * @return int The access ID |
||
1242 | */ |
||
1243 | 1 | public function getAccessID() { |
|
1246 | |||
1247 | /** |
||
1248 | * Returns the guid. |
||
1249 | * |
||
1250 | * @return int|null GUID |
||
1251 | */ |
||
1252 | 8 | public function getGUID() { |
|
1255 | |||
1256 | /** |
||
1257 | * Returns the entity type |
||
1258 | * |
||
1259 | * @return string The entity type |
||
1260 | */ |
||
1261 | 7 | public function getType() { |
|
1264 | |||
1265 | /** |
||
1266 | * Get the entity subtype |
||
1267 | * |
||
1268 | * @return string The entity subtype |
||
1269 | */ |
||
1270 | 7 | public function getSubtype() { |
|
1277 | |||
1278 | /** |
||
1279 | * Get the guid of the entity's owner. |
||
1280 | * |
||
1281 | * @return int The owner GUID |
||
1282 | */ |
||
1283 | 2 | public function getOwnerGUID() { |
|
1286 | |||
1287 | /** |
||
1288 | * Return the guid of the entity's owner. |
||
1289 | * |
||
1290 | * @return int The owner GUID |
||
1291 | * @deprecated 1.8 Use getOwnerGUID() |
||
1292 | */ |
||
1293 | public function getOwner() { |
||
1297 | |||
1298 | /** |
||
1299 | * Gets the \ElggEntity that owns this entity. |
||
1300 | * |
||
1301 | * @return \ElggEntity The owning entity |
||
1302 | */ |
||
1303 | public function getOwnerEntity() { |
||
1306 | |||
1307 | /** |
||
1308 | * Set the container for this object. |
||
1309 | * |
||
1310 | * @param int $container_guid The ID of the container. |
||
1311 | * |
||
1312 | * @return bool |
||
1313 | */ |
||
1314 | public function setContainerGUID($container_guid) { |
||
1317 | |||
1318 | /** |
||
1319 | * Set the container for this object. |
||
1320 | * |
||
1321 | * @param int $container_guid The ID of the container. |
||
1322 | * |
||
1323 | * @return bool |
||
1324 | * @deprecated 1.8 use setContainerGUID() |
||
1325 | */ |
||
1326 | public function setContainer($container_guid) { |
||
1330 | |||
1331 | /** |
||
1332 | * Gets the container GUID for this entity. |
||
1333 | * |
||
1334 | * @return int |
||
1335 | */ |
||
1336 | 1 | public function getContainerGUID() { |
|
1339 | |||
1340 | /** |
||
1341 | * Gets the container GUID for this entity. |
||
1342 | * |
||
1343 | * @return int |
||
1344 | * @deprecated 1.8 Use getContainerGUID() |
||
1345 | */ |
||
1346 | public function getContainer() { |
||
1350 | |||
1351 | /** |
||
1352 | * Get the container entity for this object. |
||
1353 | * |
||
1354 | * @return \ElggEntity |
||
1355 | * @since 1.8.0 |
||
1356 | */ |
||
1357 | public function getContainerEntity() { |
||
1360 | |||
1361 | /** |
||
1362 | * Returns the UNIX epoch time that this entity was last updated |
||
1363 | * |
||
1364 | * @return int UNIX epoch time |
||
1365 | */ |
||
1366 | 2 | public function getTimeUpdated() { |
|
1369 | |||
1370 | /** |
||
1371 | * Gets the URL for this entity. |
||
1372 | * |
||
1373 | * Plugins can register for the 'entity:url', <type> plugin hook to |
||
1374 | * customize the url for an entity. |
||
1375 | * |
||
1376 | * @return string The URL of the entity |
||
1377 | */ |
||
1378 | 1 | public function getURL() { |
|
1379 | |||
1380 | 1 | $url = ""; |
|
1381 | |||
1382 | // @todo remove when elgg_register_entity_url_handler() has been removed |
||
1383 | 1 | if ($this->guid) { |
|
1384 | global $CONFIG; |
||
1385 | if (isset($CONFIG->entity_url_handler[$this->getType()][$this->getSubtype()])) { |
||
1386 | $function = $CONFIG->entity_url_handler[$this->getType()][$this->getSubtype()]; |
||
1387 | if (is_callable($function)) { |
||
1388 | $url = call_user_func($function, $this); |
||
1389 | } |
||
1390 | } elseif (isset($CONFIG->entity_url_handler[$this->getType()]['all'])) { |
||
1391 | $function = $CONFIG->entity_url_handler[$this->getType()]['all']; |
||
1392 | if (is_callable($function)) { |
||
1393 | $url = call_user_func($function, $this); |
||
1394 | } |
||
1395 | View Code Duplication | } elseif (isset($CONFIG->entity_url_handler['all']['all'])) { |
|
1396 | $function = $CONFIG->entity_url_handler['all']['all']; |
||
1397 | if (is_callable($function)) { |
||
1398 | $url = call_user_func($function, $this); |
||
1399 | } |
||
1400 | } |
||
1401 | |||
1402 | if ($url) { |
||
1403 | $url = elgg_normalize_url($url); |
||
1404 | } |
||
1405 | } |
||
1406 | |||
1407 | 1 | $type = $this->getType(); |
|
1408 | 1 | $params = array('entity' => $this); |
|
1409 | 1 | $url = _elgg_services()->hooks->trigger('entity:url', $type, $params, $url); |
|
1410 | |||
1411 | // @todo remove when \ElggEntity::setURL() has been removed |
||
1412 | 1 | if (!empty($this->url_override)) { |
|
1413 | $url = $this->url_override; |
||
1414 | } |
||
1415 | |||
1416 | 1 | return elgg_normalize_url($url); |
|
1417 | } |
||
1418 | |||
1419 | /** |
||
1420 | * Overrides the URL returned by getURL() |
||
1421 | * |
||
1422 | * @warning This override exists only for the life of the object. |
||
1423 | * |
||
1424 | * @param string $url The new item URL |
||
1425 | * |
||
1426 | * @return string The URL |
||
1427 | * @deprecated 1.9.0 See \ElggEntity::getURL() for details on the plugin hook |
||
1428 | */ |
||
1429 | public function setURL($url) { |
||
1434 | |||
1435 | /** |
||
1436 | * Get the URL for this entity's icon |
||
1437 | * |
||
1438 | * Plugins can register for the 'entity:icon:url', <type> plugin hook |
||
1439 | * to customize the icon for an entity. |
||
1440 | * |
||
1441 | * @param mixed $params A string defining the size of the icon (e.g. tiny, small, medium, large) |
||
1442 | * or an array of parameters including 'size' |
||
1443 | * @return string The URL |
||
1444 | * @since 1.8.0 |
||
1445 | */ |
||
1446 | public function getIconURL($params = array()) { |
||
1472 | |||
1473 | /** |
||
1474 | * Returns a URL for the entity's icon. |
||
1475 | * |
||
1476 | * @param string $size Either 'large', 'medium', 'small' or 'tiny' |
||
1477 | * |
||
1478 | * @return string The url or false if no url could be worked out. |
||
1479 | * @deprecated 1.8 Use getIconURL() |
||
1480 | */ |
||
1481 | public function getIcon($size = 'medium') { |
||
1485 | |||
1486 | /** |
||
1487 | * Set an icon override for an icon and size. |
||
1488 | * |
||
1489 | * @warning This override exists only for the life of the object. |
||
1490 | * |
||
1491 | * @param string $url The url of the icon. |
||
1492 | * @param string $size The size its for. |
||
1493 | * |
||
1494 | * @return bool |
||
1495 | * @deprecated 1.8 See getIconURL() for the plugin hook to use |
||
1496 | */ |
||
1497 | public function setIcon($url, $size = 'medium') { |
||
1510 | |||
1511 | /** |
||
1512 | * Add this entity to a site |
||
1513 | * |
||
1514 | * This creates a 'member_of_site' relationship. |
||
1515 | * |
||
1516 | * @param \ElggSite $site The site to add this entity to |
||
1517 | * |
||
1518 | * @return bool |
||
1519 | * @todo add \ElggSite type hint once we have removed addToSite() from \ElggUser |
||
1520 | * and \ElggObject |
||
1521 | */ |
||
1522 | public function addToSite($site) { |
||
1529 | |||
1530 | /** |
||
1531 | * Remove this entity from a site |
||
1532 | * |
||
1533 | * This deletes the 'member_of_site' relationship. |
||
1534 | * |
||
1535 | * @param \ElggSite $site The site to remove this entity from |
||
1536 | * |
||
1537 | * @return bool |
||
1538 | * @todo add \ElggSite type hint once we have removed addToSite() from \ElggUser |
||
1539 | */ |
||
1540 | public function removeFromSite($site) { |
||
1547 | |||
1548 | /** |
||
1549 | * Gets the sites this entity is a member of |
||
1550 | * |
||
1551 | * Site membership is determined by relationships and not site_guid. |
||
1552 | * |
||
1553 | * @param array $options Options array for elgg_get_entities_from_relationship() |
||
1554 | * Parameters set automatically by this method: |
||
1555 | * 'relationship', 'relationship_guid', 'inverse_relationship' |
||
1556 | * |
||
1557 | * @return array |
||
1558 | * @todo add type hint when \ElggUser and \ElggObject have been updates |
||
1559 | */ |
||
1560 | View Code Duplication | public function getSites($options = array()) { |
|
1570 | |||
1571 | /** |
||
1572 | * Tests to see whether the object has been fully loaded. |
||
1573 | * |
||
1574 | * @return bool |
||
1575 | */ |
||
1576 | public function isFullyLoaded() { |
||
1579 | |||
1580 | /** |
||
1581 | * Save an entity. |
||
1582 | * |
||
1583 | * @return bool|int |
||
1584 | * @throws InvalidParameterException |
||
1585 | * @throws IOException |
||
1586 | */ |
||
1587 | 1 | public function save() { |
|
1607 | |||
1608 | /** |
||
1609 | * Create a new entry in the entities table. |
||
1610 | * |
||
1611 | * Saves the base information in the entities table for the entity. Saving |
||
1612 | * the type-specific information is handled in the calling class method. |
||
1613 | * |
||
1614 | * @warning Entities must have an entry in both the entities table and their type table |
||
1615 | * or they will throw an exception when loaded. |
||
1616 | * |
||
1617 | * @return int The new entity's GUID |
||
1618 | * @throws InvalidParameterException If the entity's type has not been set. |
||
1619 | * @throws IOException If the new row fails to write to the DB. |
||
1620 | */ |
||
1621 | 1 | protected function create() { |
|
1622 | 1 | global $CONFIG; |
|
1623 | |||
1624 | // Using attribute array directly; get function does something special! |
||
1625 | 1 | $type = $this->getDatabase()->sanitizeString($this->attributes['type']); |
|
1626 | 1 | if ($type == "") { |
|
1627 | 1 | throw new \InvalidParameterException("Entity type must be set."); |
|
1628 | } |
||
1629 | |||
1630 | $subtype = $this->attributes['subtype']; |
||
1631 | $subtype_id = add_subtype($type, $subtype); |
||
1632 | $owner_guid = (int)$this->attributes['owner_guid']; |
||
1633 | $access_id = (int)$this->attributes['access_id']; |
||
1634 | $now = (string)time(); |
||
1635 | $time_created = isset($this->attributes['time_created']) ? (int)$this->attributes['time_created'] : $now; |
||
1636 | |||
1637 | $site_guid = $this->attributes['site_guid']; |
||
1638 | if ($site_guid == 0) { |
||
1639 | $site_guid = $CONFIG->site_guid; |
||
1640 | } |
||
1641 | $site_guid = (int)$site_guid; |
||
1642 | |||
1643 | $container_guid = $this->attributes['container_guid']; |
||
1644 | if ($container_guid == 0) { |
||
1645 | $container_guid = $owner_guid; |
||
1646 | $this->attributes['container_guid'] = $container_guid; |
||
1647 | } |
||
1648 | $container_guid = (int)$container_guid; |
||
1649 | |||
1650 | if ($access_id == ACCESS_DEFAULT) { |
||
1651 | throw new \InvalidParameterException('ACCESS_DEFAULT is not a valid access level. See its documentation in elgglib.h'); |
||
1652 | } |
||
1653 | |||
1654 | $owner = $this->getOwnerEntity(); |
||
1655 | if ($owner && !$owner->canWriteToContainer(0, $type, $subtype)) { |
||
1656 | return false; |
||
1657 | } |
||
1658 | |||
1659 | if ($owner_guid != $container_guid) { |
||
1660 | $container = $this->getContainerEntity(); |
||
1661 | if ($container && !$container->canWriteToContainer(0, $type, $subtype)) { |
||
1662 | return false; |
||
1663 | } |
||
1664 | } |
||
1665 | |||
1666 | if ( $type == "object" ){ |
||
1667 | if ( $subtype == "mission-posted" || $subtype == "mission" || $subtype == "bookmarks" || $subtype == "groupforumtopic" || $subtype == "event_calendar" || $subtype == "thewire" || $subtype == "blog" || $subtype == "file" ){ |
||
1668 | $duplicate_check = md5( sanitize_string($this->title).sanitize_string($this->description) ) . $owner_guid . get_input('__elgg_ts'); |
||
1669 | try{ |
||
1670 | $result = $this->getDatabase()->insertData("INSERT into {$CONFIG->dbprefix}entities |
||
1671 | (type, subtype, owner_guid, site_guid, container_guid, |
||
1672 | access_id, time_created, time_updated, last_action, enabled, duplicate_check) |
||
1673 | values |
||
1674 | ('$type', $subtype_id, $owner_guid, $site_guid, $container_guid, |
||
1675 | $access_id, $time_created, $now, $now, 'no', '$duplicate_check')"); |
||
1676 | } |
||
1677 | catch( DatabaseException $e ){ |
||
1678 | error_log("Duplication prevented: " . $e->getMessage()); |
||
1679 | return null; |
||
1680 | } |
||
1681 | } |
||
1682 | View Code Duplication | else{ |
|
1683 | $result = $this->getDatabase()->insertData("INSERT into {$CONFIG->dbprefix}entities |
||
1684 | (type, subtype, owner_guid, site_guid, container_guid, |
||
1685 | access_id, time_created, time_updated, last_action, enabled) |
||
1686 | values |
||
1687 | ('$type', $subtype_id, $owner_guid, $site_guid, $container_guid, |
||
1688 | $access_id, $time_created, $now, $now, 'no')"); |
||
1689 | } |
||
1690 | } |
||
1691 | View Code Duplication | else { |
|
1692 | $result = $this->getDatabase()->insertData("INSERT into {$CONFIG->dbprefix}entities |
||
1693 | (type, subtype, owner_guid, site_guid, container_guid, |
||
1694 | access_id, time_created, time_updated, last_action) |
||
1695 | values |
||
1696 | ('$type', $subtype_id, $owner_guid, $site_guid, $container_guid, |
||
1697 | $access_id, $time_created, $now, $now)"); |
||
1698 | } |
||
1699 | |||
1700 | if (!$result) { |
||
1701 | throw new \IOException("Unable to save new object's base entity information!"); |
||
1702 | } |
||
1703 | |||
1704 | // for BC with 1.8, ->subtype always returns ID, ->getSubtype() the string |
||
1705 | $this->attributes['subtype'] = (int)$subtype_id; |
||
1706 | $this->attributes['guid'] = (int)$result; |
||
1707 | $this->attributes['time_created'] = (int)$time_created; |
||
1708 | $this->attributes['time_updated'] = (int)$now; |
||
1709 | $this->attributes['last_action'] = (int)$now; |
||
1710 | $this->attributes['site_guid'] = (int)$site_guid; |
||
1711 | $this->attributes['container_guid'] = (int)$container_guid; |
||
1712 | |||
1713 | // Save any unsaved metadata |
||
1714 | if (sizeof($this->temp_metadata) > 0) { |
||
1715 | foreach ($this->temp_metadata as $name => $value) { |
||
1716 | $this->$name = $value; |
||
1717 | } |
||
1718 | |||
1719 | $this->temp_metadata = array(); |
||
1720 | } |
||
1721 | |||
1722 | // Save any unsaved annotations. |
||
1723 | if (sizeof($this->temp_annotations) > 0) { |
||
1724 | foreach ($this->temp_annotations as $name => $value) { |
||
1725 | $this->annotate($name, $value); |
||
1726 | } |
||
1727 | |||
1728 | $this->temp_annotations = array(); |
||
1729 | } |
||
1730 | |||
1731 | // Save any unsaved private settings. |
||
1732 | if (sizeof($this->temp_private_settings) > 0) { |
||
1733 | foreach ($this->temp_private_settings as $name => $value) { |
||
1734 | $this->setPrivateSetting($name, $value); |
||
1735 | } |
||
1736 | |||
1737 | $this->temp_private_settings = array(); |
||
1738 | } |
||
1739 | |||
1740 | _elgg_cache_entity($this); |
||
1741 | |||
1742 | return $result; |
||
1743 | } |
||
1744 | |||
1745 | /** |
||
1746 | * Update the entity in the database. |
||
1747 | * |
||
1748 | * @return bool Whether the update was successful. |
||
1749 | * |
||
1750 | * @throws InvalidParameterException |
||
1751 | */ |
||
1752 | protected function update() { |
||
1821 | |||
1822 | /** |
||
1823 | * Loads attributes from the entities table into the object. |
||
1824 | * |
||
1825 | * @param mixed $guid GUID of entity or \stdClass object from entities table |
||
1826 | * |
||
1827 | * @return bool |
||
1828 | */ |
||
1829 | protected function load($guid) { |
||
1869 | |||
1870 | /** |
||
1871 | * Stores non-attributes from the loading of the entity as volatile data |
||
1872 | * |
||
1873 | * @param array $data Key value array |
||
1874 | * @return void |
||
1875 | */ |
||
1876 | protected function loadAdditionalSelectValues(array $data) { |
||
1881 | |||
1882 | /** |
||
1883 | * Load new data from database into existing entity. Overwrites data but |
||
1884 | * does not change values not included in the latest data. |
||
1885 | * |
||
1886 | * @internal This is used when the same entity is selected twice during a |
||
1887 | * request in case different select clauses were used to load different data |
||
1888 | * into volatile data. |
||
1889 | * |
||
1890 | * @param \stdClass $row DB row with new entity data |
||
1891 | * @return bool |
||
1892 | * @access private |
||
1893 | */ |
||
1894 | public function refresh(\stdClass $row) { |
||
1900 | |||
1901 | /** |
||
1902 | * Disable this entity. |
||
1903 | * |
||
1904 | * Disabled entities are not returned by getter functions. |
||
1905 | * To enable an entity, use {@link \ElggEntity::enable()}. |
||
1906 | * |
||
1907 | * Recursively disabling an entity will disable all entities |
||
1908 | * owned or contained by the parent entity. |
||
1909 | * |
||
1910 | * You can ignore the disabled field by using {@link access_show_hidden_entities()}. |
||
1911 | * |
||
1912 | * @note Internal: Disabling an entity sets the 'enabled' column to 'no'. |
||
1913 | * |
||
1914 | * @param string $reason Optional reason |
||
1915 | * @param bool $recursive Recursively disable all contained entities? |
||
1916 | * |
||
1917 | * @return bool |
||
1918 | * @see \ElggEntity::enable() |
||
1919 | */ |
||
1920 | 1 | public function disable($reason = "", $recursive = true) { |
|
1999 | |||
2000 | /** |
||
2001 | * Enable the entity |
||
2002 | * |
||
2003 | * @warning Disabled entities can't be loaded unless |
||
2004 | * {@link access_show_hidden_entities(true)} has been called. |
||
2005 | * |
||
2006 | * @param bool $recursive Recursively enable all entities disabled with the entity? |
||
2007 | * @see access_show_hiden_entities() |
||
2008 | * @return bool |
||
2009 | */ |
||
2010 | public function enable($recursive = true) { |
||
2061 | |||
2062 | /** |
||
2063 | * Is this entity enabled? |
||
2064 | * |
||
2065 | * @return boolean Whether this entity is enabled. |
||
2066 | */ |
||
2067 | 1 | public function isEnabled() { |
|
2070 | |||
2071 | /** |
||
2072 | * Deletes the entity. |
||
2073 | * |
||
2074 | * Removes the entity and its metadata, annotations, relationships, |
||
2075 | * river entries, and private data. |
||
2076 | * |
||
2077 | * Optionally can remove entities contained and owned by this entity. |
||
2078 | * |
||
2079 | * @warning If deleting recursively, this bypasses ownership of items contained by |
||
2080 | * the entity. That means that if the container_guid = $this->guid, the item will |
||
2081 | * be deleted regardless of who owns it. |
||
2082 | * |
||
2083 | * @param bool $recursive If true (default) then all entities which are |
||
2084 | * owned or contained by $this will also be deleted. |
||
2085 | * |
||
2086 | * @return bool |
||
2087 | */ |
||
2088 | public function delete($recursive = true) { |
||
2194 | |||
2195 | /** |
||
2196 | * {@inheritdoc} |
||
2197 | */ |
||
2198 | 1 | public function toObject() { |
|
2204 | |||
2205 | /** |
||
2206 | * Prepare an object copy for toObject() |
||
2207 | * |
||
2208 | * @param \stdClass $object Object representation of the entity |
||
2209 | * @return \stdClass |
||
2210 | */ |
||
2211 | 1 | protected function prepareObject($object) { |
|
2224 | |||
2225 | /* |
||
2226 | * LOCATABLE INTERFACE |
||
2227 | */ |
||
2228 | |||
2229 | /** |
||
2230 | * Gets the 'location' metadata for the entity |
||
2231 | * |
||
2232 | * @return string The location |
||
2233 | */ |
||
2234 | public function getLocation() { |
||
2237 | |||
2238 | /** |
||
2239 | * Sets the 'location' metadata for the entity |
||
2240 | * |
||
2241 | * @param string $location String representation of the location |
||
2242 | * |
||
2243 | * @return void |
||
2244 | */ |
||
2245 | public function setLocation($location) { |
||
2248 | |||
2249 | /** |
||
2250 | * Set latitude and longitude metadata tags for a given entity. |
||
2251 | * |
||
2252 | * @param float $lat Latitude |
||
2253 | * @param float $long Longitude |
||
2254 | * |
||
2255 | * @return void |
||
2256 | * @todo Unimplemented |
||
2257 | */ |
||
2258 | 1 | public function setLatLong($lat, $long) { |
|
2262 | |||
2263 | /** |
||
2264 | * Return the entity's latitude. |
||
2265 | * |
||
2266 | * @return float |
||
2267 | * @todo Unimplemented |
||
2268 | */ |
||
2269 | 1 | public function getLatitude() { |
|
2272 | |||
2273 | /** |
||
2274 | * Return the entity's longitude |
||
2275 | * |
||
2276 | * @return float |
||
2277 | * @todo Unimplemented |
||
2278 | */ |
||
2279 | 1 | public function getLongitude() { |
|
2282 | |||
2283 | /* |
||
2284 | * NOTABLE INTERFACE |
||
2285 | */ |
||
2286 | |||
2287 | /** |
||
2288 | * Set the time and duration of an object |
||
2289 | * |
||
2290 | * @param int $hour If ommitted, now is assumed. |
||
2291 | * @param int $minute If ommitted, now is assumed. |
||
2292 | * @param int $second If ommitted, now is assumed. |
||
2293 | * @param int $day If ommitted, now is assumed. |
||
2294 | * @param int $month If ommitted, now is assumed. |
||
2295 | * @param int $year If ommitted, now is assumed. |
||
2296 | * @param int $duration Duration of event, remainder of the day is assumed. |
||
2297 | * |
||
2298 | * @return true |
||
2299 | * @deprecated 1.9 |
||
2300 | */ |
||
2301 | public function setCalendarTimeAndDuration($hour = null, $minute = null, $second = null, |
||
2316 | |||
2317 | /** |
||
2318 | * Returns the start timestamp. |
||
2319 | * |
||
2320 | * @return int |
||
2321 | * @deprecated 1.9 |
||
2322 | */ |
||
2323 | public function getCalendarStartTime() { |
||
2327 | |||
2328 | /** |
||
2329 | * Returns the end timestamp. |
||
2330 | * |
||
2331 | * @return int |
||
2332 | * @deprecated 1.9 |
||
2333 | */ |
||
2334 | public function getCalendarEndTime() { |
||
2338 | |||
2339 | /* |
||
2340 | * EXPORTABLE INTERFACE |
||
2341 | */ |
||
2342 | |||
2343 | /** |
||
2344 | * Returns an array of fields which can be exported. |
||
2345 | * |
||
2346 | * @return array |
||
2347 | * @deprecated 1.9 Use toObject() |
||
2348 | */ |
||
2349 | public function getExportableValues() { |
||
2362 | |||
2363 | /** |
||
2364 | * Export this class into an array of ODD Elements containing all necessary fields. |
||
2365 | * Override if you wish to return more information than can be found in |
||
2366 | * $this->attributes (shouldn't happen) |
||
2367 | * |
||
2368 | * @return array |
||
2369 | * @deprecated 1.9 |
||
2370 | */ |
||
2371 | public function export() { |
||
2448 | |||
2449 | /* |
||
2450 | * IMPORTABLE INTERFACE |
||
2451 | */ |
||
2452 | |||
2453 | /** |
||
2454 | * Import data from an parsed ODD xml data array. |
||
2455 | * |
||
2456 | * @param ODD $data XML data |
||
2457 | * |
||
2458 | * @return true |
||
2459 | * |
||
2460 | * @throws InvalidParameterException |
||
2461 | * @deprecated 1.9 Use toObject() |
||
2462 | */ |
||
2463 | public function import(ODD $data) { |
||
2482 | |||
2483 | /* |
||
2484 | * SYSTEM LOG INTERFACE |
||
2485 | */ |
||
2486 | |||
2487 | /** |
||
2488 | * Return an identification for the object for storage in the system log. |
||
2489 | * This id must be an integer. |
||
2490 | * |
||
2491 | * @return int |
||
2492 | */ |
||
2493 | public function getSystemLogID() { |
||
2496 | |||
2497 | /** |
||
2498 | * For a given ID, return the object associated with it. |
||
2499 | * This is used by the system log. It can be called on any Loggable object. |
||
2500 | * |
||
2501 | * @param int $id GUID. |
||
2502 | * @return int GUID |
||
2503 | */ |
||
2504 | public function getObjectFromID($id) { |
||
2507 | |||
2508 | /** |
||
2509 | * Returns tags for this entity. |
||
2510 | * |
||
2511 | * @warning Tags must be registered by {@link elgg_register_tag_metadata_name()}. |
||
2512 | * |
||
2513 | * @param array $tag_names Optionally restrict by tag metadata names. |
||
2514 | * |
||
2515 | * @return array |
||
2516 | */ |
||
2517 | public function getTags($tag_names = null) { |
||
2543 | |||
2544 | /** |
||
2545 | * Remove the membership of all access collections for this entity (if the entity is a user) |
||
2546 | * |
||
2547 | * @return bool |
||
2548 | * @since 1.11 |
||
2549 | */ |
||
2550 | public function deleteAccessCollectionMemberships() { |
||
2574 | |||
2575 | /** |
||
2576 | * Remove all access collections owned by this entity |
||
2577 | * |
||
2578 | * @return bool |
||
2579 | * @since 1.11 |
||
2580 | */ |
||
2581 | public function deleteOwnedAccessCollections() { |
||
2601 | } |
||
2602 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.