Refill item field from source.

@param Item $item
@param string $field

@return Item
7035
public function refill(Item $item, $field)
    {
        $url = $this->getSourceForFill($item);
        if (!$url || !preg_match(Filler::REG_ITEM_ID, $url, $match)) {
            return $item;
        }

        // get data
        $body = $this->browser->get('anime', ['aid' => $match['id']]);

        switch ($field) {
            case self::FIELD_DATE_END:
                $item->setDateEnd(new \DateTime($body->filter('enddate')->text()));
                break;
            case self::FIELD_DATE_PREMIERE:
                $item->setDatePremiere(new \DateTime($body->filter('startdate')->text()));
                break;
            case self::FIELD_EPISODES:
                $this->filler->setEpisodes($item, $body);
                break;
            case self::FIELD_EPISODES_NUMBER:
                $item->setEpisodesNumber($body->filter('episodecount')->text());
                break;
            case self::FIELD_GENRES:
                $new_item = $this->filler->setGenres(new Item(), $body);
                foreach ($new_item->getGenres() as $new_genre) {
                    $item->addGenre($new_genre);
                }
                break;
            case self::FIELD_NAMES:
                $new_item = $this->filler->setNames(new Item(), $body);
                // set main name in top of names list
                $new_names = $new_item->getNames()->toArray();
                array_unshift($new_names, (new Name())->setName($new_item->getName()));
                foreach ($new_names as $new_name) {
                    $item->addName($new_name);
                }
                break;
            case self::FIELD_SOURCES:
                if ($url = $body->filter('url')->text()) {
                    $item->addSource((new Source())->setUrl($url));
                }
                break;
            case self::FIELD_SUMMARY:
                $item->setSummary($this->cleaner->clean($body->filter('description')->text()));
                break;
        }

        return $item;
    }
440935
protected function setItemSupplier($item, $product)
    {
        // get products supplier
        if ($product->getSupplier()) {
            $item->setSupplier($product->getSupplier());
            $item->setSupplierName($product->getSupplier()->getName());
        } else {
            $item->setSupplier(null);
            $item->setSupplierName('');
        }
    }
1346090
protected function getForm($field, Item $item_origin, Item $item_fill)
    {
        switch ($field) {
            case RefillerInterface::FIELD_DATE_END:
                $form = new DateEndForm();
                $data = ['date_end' => $item_fill->getDateEnd()];
                break;
            case RefillerInterface::FIELD_DATE_PREMIERE:
                $form = new DatePremiereForm();
                $data = ['date_premiere' => $item_fill->getDatePremiere()];
                break;
            case RefillerInterface::FIELD_DURATION:
                $form = new DurationForm();
                $data = ['duration' => $item_fill->getDuration()];
                break;
            case RefillerInterface::FIELD_EPISODES:
                $form = new EpisodesForm();
                $data = ['episodes' => $item_fill->getEpisodes()];
                break;
            case RefillerInterface::FIELD_EPISODES_NUMBER:
                $form = new EpisodesNumberForm();
                $data = ['episodes_number' => $item_fill->getEpisodesNumber()];
                break;
            case RefillerInterface::FIELD_FILE_INFO:
                $form = new FileInfoForm();
                $data = ['file_info' => $item_fill->getFileInfo()];
                break;
            case RefillerInterface::FIELD_GENRES:
                $form = $this->get('anime_db.form.type.refill.gengres');
                $data = ['genres' => $item_fill->getGenres()];
                break;
            case RefillerInterface::FIELD_IMAGES:
                $form = new ImagesForm();
                $data = ['images' => $item_fill->getImages()];
                break;
            case RefillerInterface::FIELD_COUNTRY:
                $form = $this->get('anime_db.form.type.refill.country');
                $data = ['country' => $item_fill->getCountry()];
                break;
            case RefillerInterface::FIELD_NAMES:
                $form = new NamesForm();
                $data = ['names' => $item_fill->getNames()];
                break;
            case RefillerInterface::FIELD_SOURCES:
                $form = new SourcesForm();
                $data = ['sources' => $item_fill->getSources()];
                break;
            case RefillerInterface::FIELD_SUMMARY:
                $form = new SummaryForm();
                $data = ['summary' => $item_fill->getSummary()];
                break;
            case RefillerInterface::FIELD_TRANSLATE:
                $form = new TranslateForm();
                $data = ['translate' => $item_fill->getTranslate()];
                break;
            case RefillerInterface::FIELD_STUDIO:
                $form = $this->get('anime_db.form.type.refill.studio');
                $data = ['studio' => $item_fill->getStudio()];
                break;
            default:
                throw $this->createNotFoundException('Field \''.$field.'\' is not supported');
        }
        // search new source link
        /* @var $sources_origin Source[] */
        $sources_origin = array_reverse($item_origin->getSources()->toArray());
        /* @var $sources_fill Source[] */
        $sources_fill = array_reverse($item_fill->getSources()->toArray());
        foreach ($sources_fill as $source_fill) {
            // sources is already added
            foreach ($sources_origin as $source_origin) {
                if ($source_fill->getUrl() == $source_origin->getUrl()) {
                    continue 2;
                }
            }
            $data['source'] = $source_fill->getUrl();
            break;
        }

        return $this->createForm($form, $data);
    }
1199085
public function setItem(Item $item)
    {
        if ($this->item !== $item) {
            $this->item = $item->addGenre($this);
        }

        return $this;
    }
919408
public function search(Item $item, $field)
    {
        // can refill from source. not need search
        if ($url = $this->getSourceForFill($item)) {
            return [
                new ItemRefiller(
                    $item->getName(),
                    ['url' => $url],
                    $url,
                    $item->getCover(),
                    $item->getSummary()
                ),
            ];
        }

        // get name for search
        if (!($name = $item->getName())) {
            foreach ($item->getNames() as $name) {
                if ($name) {
                    break;
                }
            }
        }

        $result = [];
        // do search
        if ($name) {
            $result = $this->search->search(['name' => $name]);
            /* @var $item \AnimeDb\Bundle\CatalogBundle\Plugin\Fill\Search\Item */
            foreach ($result as $key => $item) {
                parse_str(parse_url($item->getLink(), PHP_URL_QUERY), $query);
                $link = array_values($query)[0]['url'];
                $result[$key] = new ItemRefiller(
                    $item->getName(),
                    ['url' => $link],
                    $link,
                    $item->getImage(),
                    $item->getDescription()
                );
            }
        }

        return $result;
    }
909050
protected function fixPaths(Item $item)
    {
        $url = new Url($item->getSource());
        $item->setIntro($this->getFixedText($item->getIntro(), $url->getFullHost()));
        $item->setContent($this->getFixedText($item->getContent(), $url->getFullHost()));

        return $item;
    }
631957
protected function getItemTotal($item)
    {
        return $item->getRowTotal() - $item->getDiscountAmount() + $item->getTaxAmount() + $item->getWeeeTaxAppliedRowAmount();
    }
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;
    }
517776
public function insertItem($item,$position=0){
		$itemO=$this->beforeAddItem($item);
		 $start = array_slice($this->items, 0, $position);
		 $end = array_slice($this->items, $position);
		 $start[] = $item;
		 $this->items=array_merge($start, $end);
		 return $itemO;
	}
1129519
public function get($item)
    {
        $key = $this->getItemKey($item);

        if (null !== $key) {
            if (isset($this->items[$key])) {
                $item = $this->items[$key];
            } else {
                $this->items[$key] = $item;
            }
        }

        return $item;
    }
166058
public function addAt(Item $item, $position = null)
    {
        if (0 === $position) {
            array_unshift($this->items, $item);
        } else if (null === $position) {
            $this->items[] = $item;
        } else if (count($this->items) <= $position) {
            $this->items[] = $item;
        } else {
            array_splice($this->items, $position, 0, [$item]);
        }

        $this->isUpdated = true;

        return $this;
    }
179584
public function addItem(Item $item)
    {
        if (!$this->items->contains($item)) {
            $this->items->add($item);
            $item->setCountry($this);
        }

        return $this;
    }
844895
public function push($item)
    {
        if (!is_array($item)) {
            $this->items = array_merge($this->items, [$item]);
            return $this;
        }
        $this->items = array_merge($this->items, $item);
        return $this;
    }
969098
protected function convertItem($item)
    {
        foreach ($item as $key => $value) {
            if (!isset($this->converters[$key])) {
                continue;
            }

            foreach ($this->converters[$key] as $converter) {
                $item[$key] = call_user_func($converter, $item[$key]);
            }
        }

        return $item;
    }
1256520
public function fillAction(Item $item)
    {
        // do fill
        $this->get('anime_db.item_folder_filler.filler_folder')->fillFolder($item);

        return $this->render('AnimeDbItemFolderFillerBundle:Filler:fill.html.twig', [
            'item' => $item
        ]);
    }
1177604
private function mapStashStorageItems($item, $key)
    {
        if ( is_array($item) ) {
            foreach ( $item as $currentKey => $currentValue ) {
                $item[$currentKey] = $this->{__FUNCTION__}($currentValue, $currentKey);
            }

            return $item;
        }

        return $this->sanitizeStashStorageItem($item, $key);
    }
966024
public function itemCreate(Item $item)
    {
        $response = $this->getGuzzleClient()
            ->post(
                '/items',
                array_merge($this->setQuery(), $this->setBody($item))
            );

        return $this->serializer->deserialize(
            $response->getBody()->getContents(),
            Item::class,
            'json'
        );
    }