@@ 71-108 (lines=38) @@ | ||
68 | * @throws IOException If cannot load remaining data from db |
|
69 | * @throws InvalidParameterException If not passed a db result |
|
70 | */ |
|
71 | public function __construct($row = null) { |
|
72 | $this->initializeAttributes(); |
|
73 | ||
74 | // compatibility for 1.7 api. |
|
75 | $this->initialise_attributes(false); |
|
76 | ||
77 | if (!empty($row)) { |
|
78 | // Is $row is a DB entity table row |
|
79 | if ($row instanceof \stdClass) { |
|
80 | // Load the rest |
|
81 | if (!$this->load($row)) { |
|
82 | $msg = "Failed to load new " . get_class() . " for GUID:" . $row->guid; |
|
83 | throw new \IOException($msg); |
|
84 | } |
|
85 | } else if ($row instanceof \ElggSite) { |
|
86 | // $row is an \ElggSite so this is a copy constructor |
|
87 | elgg_deprecated_notice('This type of usage of the \ElggSite constructor was deprecated. Please use the clone method.', 1.7); |
|
88 | foreach ($row->attributes as $key => $value) { |
|
89 | $this->attributes[$key] = $value; |
|
90 | } |
|
91 | } else if (strpos($row, "http") !== false) { |
|
92 | // url so retrieve by url |
|
93 | elgg_deprecated_notice("Passing URL to constructor is deprecated. Use get_site_by_url()", 1.9); |
|
94 | $row = get_site_by_url($row); |
|
95 | foreach ($row->attributes as $key => $value) { |
|
96 | $this->attributes[$key] = $value; |
|
97 | } |
|
98 | } else if (is_numeric($row)) { |
|
99 | // $row is a GUID so load |
|
100 | elgg_deprecated_notice('Passing a GUID to constructor is deprecated. Use get_entity()', 1.9); |
|
101 | if (!$this->load($row)) { |
|
102 | throw new \IOException("Failed to load new " . get_class() . " from GUID:" . $row); |
|
103 | } |
|
104 | } else { |
|
105 | throw new \InvalidParameterException("Unrecognized value passed to constuctor."); |
|
106 | } |
|
107 | } |
|
108 | } |
|
109 | ||
110 | /** |
|
111 | * Loads the full \ElggSite when given a guid. |
@@ 72-111 (lines=40) @@ | ||
69 | * |
|
70 | * @throws IOException|InvalidParameterException if there was a problem creating the user. |
|
71 | */ |
|
72 | public function __construct($row = null) { |
|
73 | $this->initializeAttributes(); |
|
74 | ||
75 | // compatibility for 1.7 api. |
|
76 | $this->initialise_attributes(false); |
|
77 | ||
78 | if (!empty($row)) { |
|
79 | // Is $row is a DB entity row |
|
80 | if ($row instanceof \stdClass) { |
|
81 | // Load the rest |
|
82 | if (!$this->load($row)) { |
|
83 | $msg = "Failed to load new " . get_class() . " for GUID:" . $row->guid; |
|
84 | throw new \IOException($msg); |
|
85 | } |
|
86 | } else if (is_string($row)) { |
|
87 | // $row is a username |
|
88 | elgg_deprecated_notice('Passing a username to constructor is deprecated. Use get_user_by_username()', 1.9); |
|
89 | $user = get_user_by_username($row); |
|
90 | if ($user) { |
|
91 | foreach ($user->attributes as $key => $value) { |
|
92 | $this->attributes[$key] = $value; |
|
93 | } |
|
94 | } |
|
95 | } else if ($row instanceof \ElggUser) { |
|
96 | // $row is an \ElggUser so this is a copy constructor |
|
97 | elgg_deprecated_notice('This type of usage of the \ElggUser constructor was deprecated. Please use the clone method.', 1.7); |
|
98 | foreach ($row->attributes as $key => $value) { |
|
99 | $this->attributes[$key] = $value; |
|
100 | } |
|
101 | } else if (is_numeric($row)) { |
|
102 | // $row is a GUID so load entity |
|
103 | elgg_deprecated_notice('Passing a GUID to constructor is deprecated. Use get_entity()', 1.9); |
|
104 | if (!$this->load($row)) { |
|
105 | throw new \IOException("Failed to load new " . get_class() . " from GUID:" . $row); |
|
106 | } |
|
107 | } else { |
|
108 | throw new \InvalidParameterException("Unrecognized value passed to constuctor."); |
|
109 | } |
|
110 | } |
|
111 | } |
|
112 | ||
113 | /** |
|
114 | * Load the \ElggUser data from the database |