Load items for the given model.

@param  StorableInterface|null $item Optional model.
@return StorableInterface[]
551447
public function loadItems(StorableInterface $item = null)
    {
        if ($item !== null) {
            $this->setModel($item);
        }

        $query = $this->sqlLoad();
        return $this->loadItemsFromQuery($query, [], $item);
    }
136182
public function importItem(Item $item)
    {
        foreach ($this->data as $templateData) {
            foreach ($item->getData() as $itemData) {
                if ($itemData->getName() === $templateData->getName()) {
                    $templateData->setName($itemData->getName());
                    $templateData->setValue($itemData->getValue());
                    $templateData->setPrompt($itemData->getPrompt());
                }
            }
        }

        return $this;
    }
274782
public function get($item)
    {
        $data = $this->getData();

        return empty($data->$item) ? null : $data->$item;
    }
1137675
protected function _serializeToArray($item)
    {
        $result = array();

        if (is($item, 'AnDomainBehaviorSerializable')) {
            $result = $item->toSerializableArray();
        } else {
            $result = (array) $item;
        }

        return $result;
    }
1069133
public function addItem($item)
    {
        if (!isset($this->_items)) {
            $this->_items = [];
        }
        if (!is_array($item)) {
            $item = [];
        }
        if (!isset($item['class'])) {
            $item['class'] = $this->itemClass;
        }
        $item = Yii::createObject($item);
        $this->_items[$item->id] = $item;

        return $item;
    }
432632
protected function findOrCreateItem(array $item)
    {
        $entity = null;
        // If the table was not truncated to begin with, find current entity
        // first
        if (false === $this->truncate) {
            if (!empty($this->lookupFields)) {
                $lookupConditions = array();
                foreach ($this->lookupFields as $fieldName) {
                    $lookupConditions[$fieldName] = $item[$fieldName];
                }
                $entity = $this->entityRepository->findOneBy(
                    $lookupConditions
                );
            } else {
                $entity = $this->entityRepository->find(current($item));
            }
        }

        if (!$entity) {
            return $this->getNewInstance();
        }

        return $entity;
    }
759019
private function getContainerParameters($item)
    {
        $matches = array();
        if (preg_match('/^%([^%]+)%$/', $item, $matches)) {
            if ($this->hasParameter($matches[1])) {
                return $this->getParameter($matches[1]);
            }
        }

        if (preg_match_all('/%([^%]+)%/', $item, $matches, PREG_PATTERN_ORDER)) {
            foreach ($matches[1] as $expr) {
                if ($this->hasParameter($expr)) {
                    $item = str_replace('%'.$expr.'%', $this->getParameter($expr), $item);
                }
            }
        }

        return $item;
    }
100963
public function load($collection = null)
    {

        $items = array();

        $list = DB::table($this->table);

        if ($collection !== null) {
            $list = $list->where('key', 'LIKE', $collection . '%');
        }

        $list = $list->pluck('value', 'key');


        // convert dotted list back to multidimensional array
        foreach ($list as $key => $value) {
            $value = json_decode($value);
            array_set($items, $key, $value);
        }

        return $items;
    }
80111
protected function loadAssociationObjectsToObject(array $item, $object)
    {
        foreach ($this->objectMetadata->getAssociationMappings() as $associationMapping) {

            $value = null;
            if (isset($item[$associationMapping['fieldName']]) && !is_object($item[$associationMapping['fieldName']])) {
                $value = $this->objectManager->getReference($associationMapping['targetEntity'], $item[$associationMapping['fieldName']]);
            }

            if (null === $value) {
                continue;
            }

            $setter = 'set' . ucfirst($associationMapping['fieldName']);
            $this->setValue($object, $value, $setter);
        }
    }
538483
protected function formatItem(string $type, $item): array
    {
        $formattedItem = [];

        if ('route' === $type) {
            return [
            'item_name' => $item,
            ];
        }

        $model = $item['model'];
        $formattedItem['item_name'] = $model;
        if (is_object($model)) {
            $formattedItem['item'] = $model;
            $formattedItem['item_name'] = get_class($model);
        }
        if ('field' === $type) {
            $formattedItem['item_name'] .= ":{$item['field']}";
        }

        return $formattedItem;
    }
1357663
public function parse(array $item): array
    {
        $section = Craft::$app->sections->getSectionByHandle($item['sectionHandle']);

        $item['sectionId'] = $section->id;

        $sectionEntryTypes = $section->getEntryTypes();
        if ($section->type === 'single') {
            $item['id'] = $sectionEntryTypes[0]->id;
            $item['name'] = $sectionEntryTypes[0]->name;
            $item['handle'] = $sectionEntryTypes[0]->handle;
        } else {
            foreach ($sectionEntryTypes as $sectionEntryType) {
                if ($sectionEntryType->handle === $item['handle']) {
                    $item['id'] = $sectionEntryType->id;
                }
            }
        }

        $entryType = isset($item['id']) ? Craft::$app->sections->getEntryTypeById((int) $item['id']) : new EntryType();
        $entryType->sectionId = $section->id;
        $entryType->name = $item['name'];
        $entryType->handle = $item['handle'];
        $entryType->hasTitleField = $item['hasTitleField'];
        if ((bool) $item['hasTitleField']) {
            $entryType->titleLabel = $item['titleLabel'];
        } else {
            $entryType->titleFormat = $item['titleFormat'];
        }

        $fieldLayout = $this->createFieldLayout($item, Entry::class);

        $item['fieldLayout'] = $fieldLayout;

        $entryType->setFieldLayout($fieldLayout);

        return [$entryType, null];
    }
775638
public function updateItem(StorableInterface $item, array $properties = null)
    {
        if ($item !== null) {
            $this->setModel($item);
        }
        $model  = $this->model();
        $table  = $this->table();
        $struct = array_keys($this->tableStructure());
        $fields = $this->getModelFields($model, $properties);

        $updates = [];
        $binds   = [];
        $types   = [];
        foreach ($fields as $field) {
            $key = $field->ident();
            if (in_array($key, $struct)) {
                if ($key !== $model->key()) {
                    $param = ':'.$key;
                    $updates[] = '`'.$key.'` = '.$param;
                }
                $binds[$key] = $field->val();
                $types[$key] = $field->sqlPdoType();
            } else {
                $this->logger->debug(
                    sprintf('Field "%s" not in table structure', $key)
                );
            }
        }
        if (empty($updates)) {
            $this->logger->warning(
                'Could not update items. No valid fields were set / available in database table.',
                [
                    'properties' => $properties,
                    'structure'  => $struct
                ]
            );
            return false;
        }

        $binds[$model->key()] = $model->id();
        $types[$model->key()] = PDO::PARAM_STR;

        $query = '
            UPDATE
                `'.$table.'`
            SET
                '.implode(", \n\t", $updates).'
            WHERE
                `'.$model->key().'`=:'.$model->key().'';

        $driver = $this->db()->getAttribute(PDO::ATTR_DRIVER_NAME);
        if ($driver == self::MYSQL_DRIVER_NAME) {
            $query .= "\n".'LIMIT 1';
        }

        $result = $this->dbQuery($query, $binds, $types);

        if ($result === false) {
            return false;
        } else {
            return true;
        }
    }
227074
public function setItem(Item $item = null)
    {
        if ($this->item !== $item) {
            // romove link on this item for old item
            if ($this->item instanceof Item) {
                $tmp = $this->item;
                $this->item = null;
                $tmp->removeSource($this);
            }
            $this->item = $item;
            // add link on this item
            if ($item instanceof Item) {
                $this->item->addSource($this);
            }
        }

        return $this;
    }
367292
public function indexOf($collection=null, $item=null) {
    list($collection, $item) = self::_wrapArgs(func_get_args(), 2);
    
    $collection = self::_collection($collection);
    
    $key = array_search($item, $collection, true);
    return self::_wrap((is_bool($key)) ? -1 : $key);
  }
587031
private function getRelationships(Item $item)
    {
        if ($include_params = $this->resource->getIncludeParams()) {
            $item->setIncludeParams($include_params);

            return $item->getIncluded();
        }

        return [];
    }
181554
protected function findOrCreateItem(array $item)
    {
        $object = null;
        // If the table was not truncated to begin with, find current object
        // first
        if (!$this->truncate) {
            if (!empty($this->lookupFields)) {
                $lookupConditions = array();
                foreach ($this->lookupFields as $fieldName) {
                    $lookupConditions[$fieldName] = $item[$fieldName];
                }

                $object = call_user_func($this->lookupMethod, $lookupConditions);
            } else {
                $object = $this->objectRepository->find(current($item));
            }
        }

        if (!$object) {
            return $this->getNewInstance();
        }

        return $object;
    }
339912
public function findByStockItem(
        StockItemInterface $item,
        ?BatchInterface $batch = null
    ): array {
        return array_filter(
            $this->findAll(),
            function ($su) use ($item) {
                return $su->getStockItem() == $item;
            }
        );
    }