19 protected static $primary_attr_names = array(
36 protected static $integer_attr_names = array(
54 protected static $null_attr_names = array(
64 protected $secondary_attr_names = array();
84 public $requires_access_control =
true;
89 public $primary_loader =
'get_entity_as_row';
94 public $secondary_loader =
'';
99 public $full_loader =
'';
104 protected $additional_select_values = array();
116 throw new \InvalidArgumentException(
'$class must be a class name.');
120 if (!is_string($required_type)) {
121 throw new \InvalidArgumentException(
'$requiredType must be a system entity type.');
123 $this->required_type = $required_type;
125 $this->initialized_attributes = $initialized_attrs;
126 $all_attr_names = array_keys($initialized_attrs);
127 $this->secondary_attr_names = array_diff($all_attr_names, self::$primary_attr_names);
137 return array_diff(self::$primary_attr_names, array_keys(
$row)) !== array();
147 return array_diff($this->secondary_attr_names, array_keys(
$row)) !== array();
158 if (
$row[
'type'] !== $this->required_type) {
160 throw new \InvalidClassException($msg);
170 return $this->additional_select_values;
187 if (!is_array(
$row) && !(
$row instanceof \stdClass)) {
192 if (empty(
$row[
'guid'])) {
193 throw new \InvalidArgumentException(
'$row must be or contain a GUID');
196 $was_missing_primaries = $this->isMissingPrimaries(
$row);
197 $was_missing_secondaries = $this->isMissingSecondaries(
$row);
200 if (($was_missing_primaries || $was_missing_secondaries) && is_callable($this->full_loader)) {
201 $fetched = (array) call_user_func($this->full_loader,
$row[
'guid']);
206 $this->checkType(
$row);
208 if ($was_missing_primaries) {
209 if (!is_callable($this->primary_loader)) {
210 throw new \LogicException(
'Primary attribute loader must be callable');
212 if ($this->requires_access_control) {
213 $fetched = (array) call_user_func($this->primary_loader,
$row[
'guid']);
216 $fetched = (array) call_user_func($this->primary_loader,
$row[
'guid']);
227 $this->checkType(
$row);
229 if ($was_missing_secondaries) {
230 if (!is_callable($this->secondary_loader)) {
231 throw new \LogicException(
'Secondary attribute loader must be callable');
233 $fetched = (array) call_user_func($this->secondary_loader,
$row[
'guid']);
235 throw new \IncompleteEntityException(
"Secondary loader failed to return row for {$row['guid']}");
241 $row = $this->filterAddedColumns(
$row);
243 $row[
'subtype'] = (int)
$row[
'subtype'];
246 foreach (self::$null_attr_names as
$key) {
256 foreach (self::$integer_attr_names as $key) {
257 if (isset(
$row[$key])) {
272 $acceptable_attrs = self::$primary_attr_names;
273 array_splice($acceptable_attrs, count($acceptable_attrs), 0, $this->secondary_attr_names);
274 $acceptable_attrs = array_combine($acceptable_attrs, $acceptable_attrs);
277 if (!isset($acceptable_attrs[
$key])) {
278 $this->additional_select_values[
$key] = $val;
getAdditionalSelectValues()
Get values selected from the database that are not attributes.
checkType($row)
Check that the type is correct.
if(isset($vars['id'])) $class
elgg_set_ignore_access($ignore=true)
Set if Elgg's access system should be ignored.
__construct($class, $required_type, array $initialized_attrs)
Constructor.
getRequiredAttributes($row)
Get all required attributes for the entity, validating any that are passed in.
filterAddedColumns($row)
Filter non-attribute keys into $this->additional_select_values.
isMissingPrimaries($row)
Get primary attributes missing that are missing.
isMissingSecondaries($row)
Get secondary attributes that are missing.