public function addSites(array $list) : int
    {
        $count = $this->getObjectsCount();
        $nb_customer = $this->getCustomer();

        foreach ($list as $item) {
            if (!($item instanceof CNabuSite) &&
                is_numeric($nb_site_id = nb_getMixedValue($item, NABU_SITE_FIELD_ID))
            ) {
                $nb_site = $nb_customer->getSite($nb_site_id);
                if (!$nb_site instanceof CNabuSite) {
                    throw new ENabuCoreException(ENabuCoreException::ERROR_SITE_NOT_FOUND);
                }
            } elseif ($item instanceof CNabuSite) {
                $nb_site = $item;
                if (!$nb_site->validateCustomer($nb_customer)) {
                    throw new ENabuSecurityException(ENabuSecurityException::ERROR_CUSTOMER_NOT_OWNER);
                }
            } else {
                throw new ENabuCoreException(ENabuCoreException::ERROR_SITE_NOT_FOUND);
            }

            $nb_site->refresh(true, true);
            $this->nb_site_list->addItem($nb_site);
            $this->nb_language_list->merge($nb_site->getLanguages(true));
            $this->nb_role_list->merge($nb_site->getRoles(true));
        }

        return $this->getObjectsCount() - $count;
    }
public function addSites(array $list) : int
    {
        $count = $this->getObjectsCount();
        $nb_customer = $this->getCustomer();

        foreach ($list as $item) {
            if (!($item instanceof CNabuSite) &&
                is_numeric($nb_site_id = nb_getMixedValue($item, NABU_SITE_FIELD_ID))
            ) {
                $nb_site = $nb_customer->getSite($nb_site_id);
                if (!$nb_site instanceof CNabuSite) {
                    throw new ENabuCoreException(ENabuCoreException::ERROR_SITE_NOT_FOUND);
                }
            } elseif ($item instanceof CNabuSite) {
                $nb_site = $item;
                if (!$nb_site->validateCustomer($nb_customer)) {
                    throw new ENabuSecurityException(ENabuSecurityException::ERROR_CUSTOMER_NOT_OWNER);
                }
            } else {
                throw new ENabuCoreException(ENabuCoreException::ERROR_SITE_NOT_FOUND);
            }

            $nb_site->refresh(true, true);
            $this->nb_site_list->addItem($nb_site);
            $this->nb_language_list->merge($nb_site->getLanguages(true));
            $this->nb_role_list->merge($nb_site->getRoles(true));
        }

        return $this->getObjectsCount() - $count;
    }
public function addSites ( array $ list ) : int { $ count = $ this -> getObjectsCount ( ) ; $ nb_customer = $ this -> getCustomer ( ) ; foreach ( $ list as $ item ) { if ( ! ( $ item instanceof CNabuSite ) && is_numeric ( $ nb_site_id = nb_getMixedValue ( $ item , NABU_SITE_FIELD_ID ) ) ) { $ nb_site = $ nb_customer -> getSite ( $ nb_site_id ) ; if ( ! $ nb_site instanceof CNabuSite ) { throw new ENabuCoreException ( ENabuCoreException :: ERROR_SITE_NOT_FOUND ) ; } } elseif ( $ item instanceof CNabuSite ) { $ nb_site = $ item ; if ( ! $ nb_site -> validateCustomer ( $ nb_customer ) ) { throw new ENabuSecurityException ( ENabuSecurityException :: ERROR_CUSTOMER_NOT_OWNER ) ; } } else { throw new ENabuCoreException ( ENabuCoreException :: ERROR_SITE_NOT_FOUND ) ; } $ nb_site -> refresh ( true , true ) ; $ this -> nb_site_list -> addItem ( $ nb_site ) ; $ this -> nb_language_list -> merge ( $ nb_site -> getLanguages ( true ) ) ; $ this -> nb_role_list -> merge ( $ nb_site -> getRoles ( true ) ) ; } return $ this -> getObjectsCount ( ) - $ count ; }
Add a list of Sites and their dependencies to this package instance.
@param array $list Mixed list of CNabuList instances and/or Site Ids.
@return int Returns the number of Sites added.
Add a list of Sites and their dependencies to this package instance .