Settings lazy loading.

@param SettingsOwnerInterface|null $owner

@return SettingsManager
4986
private function loadSettings(SettingsOwnerInterface $owner = null)
    {
        // Global settings
        if ($this->globalSettings === null) {
            $this->globalSettings = $this->getSettingsFromRepository();
        }

        // User settings
        if ($owner !== null && ($this->ownerSettings === null || !array_key_exists(
                    $owner->getSettingIdentifier(),
                    $this->ownerSettings
                ))
        ) {
            $this->ownerSettings[$owner->getSettingIdentifier()] = $this->getSettingsFromRepository($owner);
        }

        return $this;
    }
1070478
public function setSettings( $settings )
    {
        if ( ! empty( $settings ) )
        {
            foreach ( $settings as $name => $value )
            {
                $this->setSetting( $name, $value );
            }
        }

        return $this;
    }
1278258
public function setOwner(\WobbleCode\UserBundle\Document\User $owner)
    {
        $this->owner = $owner;
        return $this;
    }
368700
public void setOwner(ListenerOwner owner)
    {
        super.setOwner(owner);
        if (owner != null)
        {
            this.setupGridOrder();      // Set the initial grid order
            if (m_gridScreen != null)
            {
                m_gridScreen.setConverter(this.getOwner());   // The grid screen will automatically change this field to match the key order.
                this.getOwner().addComponent(m_gridScreen);
            }
        }
    }
955341
public function findSettingItem($owner, $code)
    {
        if ($this->items === null) {
            $this->loadItems();
        }

        $owner = strtolower($owner);
        $code = strtolower($code);

        foreach ($this->items as $item) {
            if (strtolower($item->owner) == $owner && strtolower($item->code) == $code) {
                return $item;
            }
        }

        return false;
    }
1033918
public function attach($owner) {
		parent::attach($owner);
		if ($this->name === null) {
			throw new InvalidConfigException("No name specified for ".get_class($this));
		}
		if (method_exists($owner, "getPrimaryKey")) {
			$this->_oldName = $this->name;

			$pk = $owner->getPrimaryKey();
			if (is_array($pk)) {
				foreach($pk as $key => $value) {
					$pk[$key] = $key.":".$value;
				}
				$pk = implode(":",$pk);
			}
			$this->name = get_class($owner).":".$pk.":".$this->name;
		}
	}
827581
private function _createPreferenceEntity( $owner = null )
    {
        $prefClass = $this->_getFullClassname() . 'Preference';
        $pref = new $prefClass();

        if( $owner !== null )
        {
            $pref->{ 'set' . $this->_getShortClassname() }( $owner );
            $owner->{ 'add' . $this->_getPreferenceClassName() }( $pref );
        }

        return $pref;
    }
603822
public static synchronized @CheckForNull PermissionGroup get(Class owner) {
        for (PermissionGroup g : PERMISSIONS) {
            if (g.owner == owner) {
                return g;
            }
        }
        return null;
    }
517993
protected function manage(Request $request, SettingsOwnerInterface $owner = null)
    {
        $form = $this->createForm(SettingsType::class, $this->get('settings_manager')->all($owner));

        if ($request->isMethod('post')) {
            $form->handleRequest($request);

            if ($form->isValid()) {
                $this->get('settings_manager')->setMany($form->getData(), $owner);
                $this->get('session')->getFlashBag()->add(
                    'success',
                    $this->get('translator')->trans('settings_updated', array(), 'settings')
                );

                return $this->redirect($request->getUri());
            }
        }

        return $this->render(
            $this->container->getParameter('settings_manager.template'),
            array(
                'settings_form' => $form->createView(),
            )
        );
    }
720324
public function findByOwner(BlockInterface $owner, $version = false)
    {
        $blocks = $this->getRepository()->findBy(['owner' => $owner], ['sort' => 'asc']);

        if ($version) {
            foreach ($blocks as $key => $block) {
                $this->revertSingle($block, $version);

                if ($block->getDeletedAt() && $block->getDeletedAt() < new \DateTime) {
                    unset($blocks[$key]);
                }
            }
        }

        usort($blocks, function ($a, $b) {
            return ($a->getSort() < $b->getSort()) ? -1 : 1;
        });

        return $blocks;
    }
184927
public function setOwner(\Haven\SecurityBundle\Entity\Role $owner = null) {
        $this->owner = $owner;

        return $this;
    }
335933
public void setOwner(ListenerOwner owner)
    {
        super.setOwner(owner);
        if (this.getOwner() != null)
            this.syncBehaviorToRecord(this.getOwner().getRecord().getField(m_iMainFilesFieldSeq));  // Init now
    }
970390
public void setOwner(ListenerOwner owner)
    {
        super.setOwner(owner);
        if (this.getOwner() != null)
        {
            InitFieldHandler behavior = (InitFieldHandler)this.getOwner().getListener(InitFieldHandler.class.getName());
            if (this.getOwner().getRecord().getEditMode() == DBConstants.EDIT_CURRENT)
                behavior = null;    // Special case - if there is a current record, make sure initonce works.
            if (behavior != null)
                this.setFirstTime(false);  // If InitFieldHandler already set the initial value, don't set the first time.
        }
    }
361846
public function getSettingsByUser($user)
    {
        $userId = $user;
        $userEntity = null;
        if ($user instanceof EntityInterface) {
            $userId = $user->getId();
            $userEntity = $user;
        }
        if (isset($this->settingsByUser[$userId])) {
            return $this->settingsByUser[$user];
        }
        if (empty($userEntity)) {
            $UserRepository = $this->getUserRepository();
            $userEntity = $UserRepository->find($userId);
        }
        
        if (isset($userEntity)) {
            $settingsData = $userEntity->getSettings();
            $this->settingsByUser[$userId] = new SettingsEntity($this);
            $this->settingsByUser[$userId]->setData($settingsData)->spawnAsEntities();
            return $this->settingsByUser[$userId];
        }
        return null;
    }
58452
protected function prepareOwnerOptions()
    {
        $ownerOptions = ['' => '-'];
        foreach ($this->userService->getUsers() as $user) {
            /** @var User $user */
            $ownerOptions[$this->persistenceManager->getIdentifierByObject($user)] = $user->getLabel();
        }

        return $ownerOptions;
    }
36214
public void setOwner(ListenerOwner owner)
    {
        super.setOwner(owner);
        if (owner == null)
            return;
        boolean bEnabledFlag = this.setEnabledListener(true);   // Disabled automatically on setOwner.
        try   {     // Open this table and move to the control record
            if (!this.getOwner().isOpen())
                if (this.isEnabled()) // Not on a slave
                    this.getOwner().open();     // Open the control file
            if (this.getOwner().getEditMode() == Constants.EDIT_NONE)
                if (this.isEnabled()) // Not on a slave
                    this.doNewRecord(true);     // Read the control file
        } catch (DBException ex)   {
            ex.printStackTrace();
        } finally   {
            this.setEnabledListener(bEnabledFlag);  // Set back
        }
    }
6154
public function setSetting( $name, $value )
    {
        $old = isset( $this->settings[$name] )
            ? $this->settings[$name]
            : null;

        if ( $old instanceof self || $value instanceof self )
        {
            if ( $old instanceof self && $value instanceof self )
            {
                $old->setSettings( $value->settings );
            }
            else if ( $old instanceof self )
            {
                if ( $value instanceof Traversable )
                {
                    $value = ArrayUtils::iteratorToArray( $value );
                }

                $old->setSettings( (array) $value );
            }
            else
            {
                $this->settings[$name] = $value;
            }
        }
        else
        {
            $method = array( $this, 'update' . ucfirst( $name ) );

            if ( is_callable( $method ) &&
                 ( ( isset( $value )    && isset( $this->settings[$name] )
                                        && $value != $this->settings[$name] ) ||
                   ( isset( $value )    && ! isset( $this->settings[$name] ) ) ||
                   ( ! isset( $value )  && isset( $this->settings[$name] ) ) ) )
            {
                $value = $method( $value, $old );
            }

            if ( null === $value )
            {
                unset( $this->settings[$name] );
            }
            else
            {
                $this->settings[$name] = $value;
            }
        }

        return $this;
    }