/** * Load items from the database table and return them in the same type class that getAll() returns * * A selector string or Selectors may be provided so that this can be used as a find() by descending classes that don't load all items at once. * * @param WireArray $items * @param Selectors|string|null $selectors Selectors or a selector string to find, or NULL to load all. * @return WireArray Returns the same type as specified in the getAll() method. * */ protected function ___load(WireArray $items, $selectors = null) { $query = $this->getLoadQuery($selectors); $database = $this->wire('database'); $sql = $query->getQuery(); $stmt = $database->prepare($sql); $stmt->execute(); $lookupField = $this->getLookupField(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $item = $this->makeBlankItem(); $lookupValue = $row[$lookupField]; unset($row[$lookupField]); $item->addLookupItem($lookupValue, $row); foreach ($row as $field => $value) { $item->{$field} = $value; } if ($items->has($item)) { // LEFT JOIN is adding more elements of the same item, i.e. from lookup table // if the item is already present in $items, then use the existing one rather // and throw out the one we just created $item = $items->get($item); $item->addLookupItem($lookupValue, $row); } else { // add a new item $items->add($item); } } $stmt->closeCursor(); $items->setTrackChanges(true); return $items; }
/** * Load items from the database table and return them in the same type class that getAll() returns * A selector string or Selectors may be provided so that this can be used as a find() by descending classes that don't load all items at once. * * @param Selectors|string|null $selectors Selectors or a selector string to find, or NULL to load all. * @return WireArray Returns the same type as specified in the getAll() method. * */ protected function ___load(WireArray $items, $selectors = null) { $query = $this->getLoadQuery($selectors); $result = $this->getFuel('db')->query($query); while ($row = $result->fetch_assoc()) { $item = $this->makeBlankItem(); foreach ($row as $field => $value) { if ($field == 'data') { if ($value) { $value = $this->decodeData($value); } else { continue; } } $item->{$field} = $value; } $item->setTrackChanges(true); $items->add($item); } $result->free(); $items->setTrackChanges(true); return $items; }
/** * Load items from the database table and return them in the same type class that getAll() returns * A selector string or Selectors may be provided so that this can be used as a find() by descending classes that don't load all items at once. * * @param WireArray $items * @param Selectors|string|null $selectors Selectors or a selector string to find, or NULL to load all. * @return WireArray Returns the same type as specified in the getAll() method. * */ protected function ___load(WireArray $items, $selectors = null) { $database = $this->wire('database'); $sql = $this->getLoadQuery($selectors)->getQuery(); $query = $database->prepare($sql); $query->execute(); while ($row = $query->fetch(PDO::FETCH_ASSOC)) { $item = $this->makeBlankItem(); foreach ($row as $field => $value) { if ($field == 'data') { if ($value) { $value = $this->decodeData($value); } else { continue; } } $item->{$field} = $value; } $item->setTrackChanges(true); $items->add($item); } $query->closeCursor(); $items->setTrackChanges(true); return $items; }
/** * Load items from the database table and return them in the same type class that getAll() returns * A selector string or Selectors may be provided so that this can be used as a find() by descending classes that don't load all items at once. * * @param Selectors|string|null $selectors Selectors or a selector string to find, or NULL to load all. * @return WireArray Returns the same type as specified in the getAll() method. * */ protected function ___load(WireArray $items, $selectors = null) { $query = $this->getLoadQuery($selectors); $result = $this->fuel('db')->query($query); $lookupField = $this->getLookupField(); while ($row = $result->fetch_assoc()) { $item = $this->makeBlankItem(); $lookupValue = $row[$lookupField]; unset($row[$lookupField]); $item->addLookupItem($lookupValue, $row); foreach ($row as $field => $value) { $item->{$field} = $value; } if ($items->has($item)) { // LEFT JOIN is adding more elements of the same item, i.e. from lookup table // if the item is already present in $items, then use the existing one rather // and throw out the one we just created $item = $items->get($item); $item->addLookupItem($lookupValue, $row); } else { // add a new item $items->add($item); } } if ($result) { $result->free(); } $items->setTrackChanges(true); return $items; }
/** * Load items from the database table and return them in the same type class that getAll() returns * A selector string or Selectors may be provided so that this can be used as a find() by descending classes that don't load all items at once. * * @param Selectors|string|null $selectors Selectors or a selector string to find, or NULL to load all. * @return WireArray Returns the same type as specified in the getAll() method. * */ protected function ___load(WireArray $items, $selectors = null) { $query = $this->getLoadQuery($selectors); $result = $this->fuel('db')->query($query); $lookupField = $this->getLookupField(); while ($row = $result->fetch_assoc()) { $item = $this->makeBlankItem(); foreach ($row as $field => $value) { if ($field == $lookupField) { $item->addLookupItem($value); } else { $item->{$field} = $value; } } if ($items->has($item)) { // LEFT JOIN is adding more elements of the same item, i.e. from lookup table $items->get($item)->addLookupItem($row[$lookupField]); // $items->get($item)->setArray($row); } else { $items->add($item); } } if ($result) { $result->free(); } $items->setTrackChanges(true); return $items; }