Inserts a new item or a list of new items depending on the parent and the referenced item ID.

@param \stdClass $params Associative list of parameters
@return array Associative list with nodes and success value
181260
public function insertItems( \stdClass $params )
	{
		$this->checkParams( $params, array( 'items' ) );

		$manager = $this->getManager();

		$refId = ( isset( $params->refid ) ? $params->refid : null );
		$parentId = ( ( isset( $params->parentid ) && $params->parentid !== 'root' ) ? $params->parentid : null );
		$items = ( !is_array( $params->items ) ? array( $params->items ) : $params->items );

		foreach( $items as $entry )
		{
			$item = $manager->createItem();
			$item->fromArray( (array) $this->transformValues( $entry ) );
			$manager->insertItem( $item, $parentId, $refId );

			$entry->{'locale.site.id'} = $item->getId();
		}

		return array(
			'items' => ( !is_array( $params->items ) ? reset( $items ) : $items ),
			'success' => true,
		);
	}
613805
public static function create(array $params = [])
    {
        $headers = new static();
        foreach ($params as $key => $value) {
            $headers->set($key, $value);
        }
        return $headers;
    }
1080192
private static function getParamObject(array $params) {
        $obj              = new stdClass;
        $obj->paramData   = array();
        $obj->paramIsFile = array();
        foreach ($params as $key => $value) {
            if (strpos($key, '@') === 0) {
                $obj->paramData[substr($key, 1)]   = self::safeGetContents($key, $value);
                $obj->paramIsFile[substr($key, 1)] = true;
            } elseif (strpos($key, '#') === 0) {
                $obj->paramData[substr($key, 1)]   = $value;
                $obj->paramIsFile[substr($key, 1)] = true;
            } else {
                $obj->paramData[$key]   = $value;
                $obj->paramIsFile[$key] = false;
            }
        }
        return $obj;
    }
794357
public function uploadItem( \stdClass $params )
	{
		$this->checkParams( $params, array( 'site', 'domain' ) );
		$this->setLocale( $params->site );

		$context = $this->getContext();
		$manager = \Aimeos\MShop\Factory::createManager( $context, 'media' );
		$typeManager = \Aimeos\MShop\Factory::createManager( $context, 'media/type' );

		$item = $manager->createItem();
		$item->setTypeId( $typeManager->findItem( 'default', [], 'product' )->getId() );
		$item->setDomain( 'product' );
		$item->setStatus( 1 );

		$file = $this->getUploadedFile();

		\Aimeos\Controller\Common\Media\Factory::createController( $context )->add( $item, $file );
		$item = $manager->saveItem( $item );

		return (object) $item->toArray( true );
	}
1168313
public function searchItems( \stdClass $params )
	{
		$manager = $this->getManager();

		$total = 0;
		$search = $manager->createSearch();

		if( isset( $params->options->showall ) && $params->options->showall == false )
		{
			$localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager( $this->getContext() );

			$langids = [];
			foreach( $localeManager->searchItems( $localeManager->createSearch() ) as $item ) {
				$langids[] = $item->getLanguageId();
			}

			if( !empty( $langids ) ) {
				$search->setConditions( $search->compare( '==', 'locale.language.id', $langids ) );
			}
		}

		$search = $this->initCriteria( $search, $params );

		$sort = $search->getSortations();
		$sort[] = $search->sort( '+', 'locale.language.label' );
		$search->setSortations( $sort );

		$items = $this->getManager()->searchItems( $search, [], $total );

		return array(
			'items' => $this->toArray( $items ),
			'total' => $total,
			'success' => true,
		);
	}
94947
public static function addParameter($url, $params)
    {
        if (!$url) {
            return $url;
        }
        if ($params) {
            if (is_array($params)) {
                $newParams = [];
                foreach ($params as $key => $item) {
                    $newParams[] = $key . '=' . $item;
                }
                $params = join('&', $newParams);
            }
            return $url . (strstr($url, '?') ? '&' : '?') . $params;
        }
        return $url;
    }
646631
public function searchItems( stdClass $params )
	{
		$this->_checkParams( $params, array( 'site' ) );
		$this->_setLocale( $params->site );

		$total = 0;
		$search = $this->_initCriteria( $this->_getManager()->createSearch(), $params );

		if( isset( $params->domain ) && isset( $params->parentid ) )
		{
			$listManager = MShop_Factory::createManager( $this->_getContext(), $params->domain . '/list' );
			$criteria = $listManager->createSearch();

			$expr = array();
			$expr[] = $criteria->compare( '==', $params->domain . '.list.parentid', $params->parentid );
			$expr[] = $criteria->compare( '==', $params->domain . '.list.domain', 'price' );
			$criteria->setConditions( $criteria->combine( '&&', $expr ) );

			$result = $listManager->searchItems( $criteria );

			$ids = array();
			foreach( $result as $items ) {
				$ids[] = $items->getRefId();
			}

			$expr = array();
			$expr[] = $search->compare( '==', 'price.id', $ids );
			$expr[] = $search->getConditions();
			$search->setConditions( $search->combine( '&&', $expr ) );
		}

		$items = $this->_getManager()->searchItems( $search, array(), $total );

		return array(
			'items' => $this->_toArray( $items ),
			'total' => $total,
			'success' => true,
		);
	}
176310
public function addParams(array $params)
    {
        foreach ($params as $k => $v) {
            $this->addParam($k, $v);
        }
        return $this;
    }
791077
public function add($params) 
    {
        $response = $this->client->update(
            $this->uri,
            $params
        );

        return json_encode($response->getContent(), JSON_FORCE_OBJECT);
    }
783835
public function layoutItemsProcFunc(array &$params)
    {
        $this->init($params['row']['pid']);
        $layoutSelectItems = $this->layoutSetup->getLayoutSelectItems(
            isset($params['row']['colPos'][0]) ? $params['row']['colPos'][0] : $params['row']['colPos'],
            $params['row']['tx_gridelements_columns'],
            $params['row']['tx_gridelements_container'],
            $this->layoutSetup->getRealPid()
        );
        $params['items'] = ArrayUtility::keepItemsInArray($layoutSelectItems, $params['items'], true);
    }
506258
public function moveItems( \stdClass $params )
	{
		$this->checkParams( $params, array( 'site', 'items', 'oldparentid', 'newparentid' ) );
		$this->setLocale( $params->site );

		$manager = $this->getManager();

		$ids = [];
		$refId = ( isset( $params->refid ) ? $params->refid : null );
		$items = ( !is_array( $params->items ) ? array( $params->items ) : $params->items );

		foreach( $items as $id )
		{
			$manager->moveItem( $id, $params->oldparentid, $params->newparentid, $refId );
			$ids[] = $id;
		}

		$this->clearCache( $ids );

		return array(
			'success' => true,
		);
	}
194409
public function saveItems( \stdClass $params )
	{
		$this->checkParams( $params, array( 'site', 'items' ) );

		$ids = [];
		$manager = $this->getManager();
		$items = ( !is_array( $params->items ) ? array( $params->items ) : $params->items );

		foreach( $items as $entry )
		{
			$langid = ( isset( $entry->{'order.base.languageid'} ) ? $entry->{'order.base.languageid'} : null );
			$currencyid = ( isset( $entry->{'order.base.currencyid'} ) ? $entry->{'order.base.currencyid'} : null );

			$this->setLocale( $params->site, $langid, $currencyid );

			$item = $manager->createItem();
			$item->fromArray( (array) $this->transformValues( $entry ) );
			$item = $manager->saveItem( $item );
			$ids[] = $item->getId();
		}

		return $this->getItems( $ids, $this->getPrefix() );
	}
767209
public function saveItems( stdClass $params )
	{
		$this->_checkParams( $params, array( 'site', 'items' ) );
		$this->_setLocale( $params->site );

		$ids = array();
		$items = ( !is_array( $params->items ) ? array( $params->items ) : $params->items );

		foreach( $items as $entry )
		{
			$item = $this->_createItem( (array) $entry );
			$this->_manager->saveItem( $item );
			$ids[] = $item->getId();
		}

		$this->_clearCache( $ids );

		$search = $this->_manager->createSearch();
		$search->setConditions( $search->compare( '==', 'price.id', $ids ) );
		$search->setSlice( 0, count( $ids ) );
		$items = $this->_toArray( $this->_manager->searchItems( $search ) );

		return array(
			'items' => ( !is_array( $params->items ) ? reset( $items ) : $items ),
			'success' => true,
		);
	}
513141
public function parseParams(\stdClass $params): array
	{
		$params->type = strtolower($params->type);
		$dbtype = ($params->type !== 'postgresql') ? $params->type : 'pgsql';
		$dbtype = ucfirst($dbtype);

		// Make sure the class exists
		if ( ! class_exists("\\Query\\Drivers\\{$dbtype}\\Driver"))
		{
			throw new BadDBDriverException('Database driver does not exist, or is not supported');
		}

		// Set additional PDO options
		$options = [];

		if (isset($params->options))
		{
			$options = (array) $params->options;
		}

		// Create the dsn for the database to connect to
		if(strtolower($dbtype) === 'sqlite')
		{
			$dsn = $params->file;
		}
		else
		{
			$dsn = $this->createDsn($dbtype, $params);
		}


		return [$dsn, $dbtype, $params, $options];
	}
482048
public function addLtiLinkItemExtended($params = array())
    {
        global $CFG;

        // populate the default parameters
        if (empty($params['title']))
            $params['title'] = false;
        if (empty($params['text']))
            $params['text'] = false;
        if (empty($params['icon']))
            $params['icon'] = false;
        if (empty($params['fa_icon']))
            $params['fa_icon'] = false;
        if (empty($params['custom']))
            $params['custom'] = false;
        if (empty($params['points']))
            $params['points'] = false;
        if (empty($params['activityId']))
            $params['activityId'] = false;
        if (empty($params['placementTarget']))
            $params['placementTarget'] = 'iframe';
        if (empty($params['placementWindowTarget']))
            $params['placementWindowTarget'] = '';
        if (empty($params['placementWidth']))
            $params['placementWidth'] = '';
        if (empty($params['placementHeight']))
            $params['placementHeight'] = '';

        $item = '{ "@type" : "LtiLinkItem",
                    "@id" : ":item2",
                    "title" : "A cool tool hosted in the Tsugi environment.",
                    "mediaType" : "application/vnd.ims.lti.v1.ltilink",
                    "text" : "For more information on how to build and host powerful LTI-based Tools quickly, see www.tsugi.org",
                    "url" : "http://www.tsugi.org/",
                    "placementAdvice" : {
                        "presentationDocumentTarget" : "iframe"
                    },
                    "icon" : {
                        "@id" : "https://static.tsugi.org/img/default-icon.png",
                        "fa_icon" : "fa-magic",
                        "width" : 64,
                        "height" : 64
                    },
                    "lineItem" : {
                        "@type" : "LineItem",
                        "label" : "Gradable External Tool",
                        "reportingMethod" : "res:totalScore",
                        "assignedActivity" : {
                            "@id" : "http://toolprovider.example.com/assessment/66400",
                            "activityId" : "a-9334df-33"
                        },
                        "scoreConstraints" : {
                            "@type" : "NumericLimits",
                            "normalMaximum" : 10
                        }
                    }
                }';

        $json = json_decode($item);
        $json->url = $params['url'];
        if ( $params['title'] ) $json->{'title'} = $params['title'];
        if ( $params['text'] ) $json->{'text'} = $params['text'];
        if ( $params['icon'] ) $json->{'icon'}->{'@id'} = $params['icon'];
        if ( $params['fa_icon'] ) $json->icon->fa_icon = $params['fa_icon'];
        if ( $params['custom'] ) $json->custom = $params['custom'];
        if ( $params['points'] && $params['activityId'] ) {
            $json->lineItem->label = $params['title'];
            $json->lineItem->assignedActivity->{'@id'} = $CFG->wwwroot . '/lti/activity/' . $params['activityId'];
            $json->lineItem->assignedActivity->activityId = $params['activityId'];
            $json->lineItem->scoreConstraints->normalMaximum = $params['points'];
        } else {
            unset($json->lineItem);
        }

        if ($params['placementTarget'])
            $json->placementAdvice->presentationDocumentTarget = $params['placementTarget'];
        if ($params['placementWindowTarget'])
            $json->placementAdvice->windowTarget = $params['placementWindowTarget'];
        if (! empty($params['placementWidth']))
            $json->placementAdvice->displayWidth = $params['placementWidth'];
        if (! empty($params['placementHeight']))
            $json->placementAdvice->displayHeight = $params['placementHeight'];

        $json->{'@id'} = ':item'.(count($this->json->{'@graph'})+1);

        $this->json->{'@graph'}[] = $json;
    }
551826
public function deleteItems( \stdClass $params )
	{
		$this->checkParams( $params, array( 'site', 'items' ) );
		$this->setLocale( $params->site );

		$idList = [];
		$context = $this->getContext();
		$manager = \Aimeos\MShop\Factory::createManager( $context, 'media' );
		$cntl = \Aimeos\Controller\Common\Media\Factory::createController( $context );

		$search = $manager->createSearch();
		$search->setConditions( $search->compare( '==', 'media.id', (array) $params->items ) );
		$search->setSlice( 0, count( (array) $params->items ) );

		foreach( $manager->searchItems( $search ) as $id => $item )
		{
			$idList[$item->getDomain()][] = $id;
			$cntl->delete( $item );
		}

		$manager->deleteItems( (array) $params->items );


		foreach( $idList as $domain => $domainIds )
		{
			$manager = \Aimeos\MShop\Factory::createManager( $context, $domain . '/lists' );

			$search = $manager->createSearch();
			$expr = array(
				$search->compare( '==', $domain . '.lists.refid', $domainIds ),
				$search->compare( '==', $domain . '.lists.domain', 'media' )
			);
			$search->setConditions( $search->combine( '&&', $expr ) );
			$search->setSortations( array( $search->sort( '+', $domain . '.lists.id' ) ) );

			$start = 0;

			do
			{
				$result = $manager->searchItems( $search );
				$manager->deleteItems( array_keys( $result ) );

				$count = count( $result );
				$start += $count;
				$search->setSlice( $start );
			}
			while( $count >= $search->getSliceSize() );
		}


		$this->clearCache( (array) $params->items );

		return array(
			'success' => true,
		);
	}
385129
public function setParams( $params )
    {
        if ( $params instanceof Traversable )
        {
            $params = iterator_to_array( $params );
        }
        else if ( is_object( $params ) && ! $params instanceof ArrayAccess )
        {
            $params = (array) $params;
        }

        return parent::setParams( $params );
    }