/* (non-PHPdoc)
@see \rocket\ei\manage\draft\DraftValueSelection::buildDraftValue()
353221
public function buildDraftValue() {
		if ($this->rawValue === null) return null;
	
		return $this->dm->find($baseEntityObj, $this->rawValue, $this->targetDraftDefinition);
	}
623155
public function setParam($key, $value = null)
    {

        return null !== $this->getDraft() ? $this->getDraft()->setParam($key, $value) : parent::setParam($key, $value);
    }
138787
function exportValue(&$submitValues, $assoc = false) {
        global $USER;

        $draftitemid = $this->_findValue($submitValues);
        if (null === $draftitemid) {
            $draftitemid = $this->getValue();
        }

        // make sure max one file is present and it is not too big
        if (!is_null($draftitemid)) {
            $fs = get_file_storage();
            $usercontext = context_user::instance($USER->id);
            if ($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id DESC', false)) {
                $file = array_shift($files);
                if ($this->_options['maxbytes']
                    and $this->_options['maxbytes'] !== USER_CAN_IGNORE_FILE_SIZE_LIMITS
                    and $file->get_filesize() > $this->_options['maxbytes']) {

                    // bad luck, somebody tries to sneak in oversized file
                    $file->delete();
                }
                foreach ($files as $file) {
                    // only one file expected
                    $file->delete();
                }
            }
        }

        return $this->_prepareValue($draftitemid, true);
    }
1006677
public function write(Eiu $eiu, $value) {
		CastUtils::assertTrue(is_array($value));
	
		if ($eiu->object()->isDraftProp($this)) {
			$targetDrafts = array();
			foreach ($value as $targetEiObject) {
				CastUtils::assertTrue($targetEiObject instanceof EiObject);
				$targetDrafts[] = $targetEiObject->getDraft();
			}
			$eiu->entry()->writeNativeValue($this, $targetDrafts);
			return;
		}
	
		$targetEntityObjs = new \ArrayObject();
		foreach ($value as $targetEiObject) {
			CastUtils::assertTrue($targetEiObject instanceof EiObject);
			$targetEntityObjs[] = $targetEiObject->getEiEntityObj()->getEntityObj();
		}
		$eiu->entry()->writeNativeValue($this, $targetEntityObjs);
	}
341027
protected function addOnlyDrafted(Builder $builder): void
    {
        $builder->macro('onlyDrafted', function (Builder $builder) {
            return $builder->withoutGlobalScope($this)->where('is_drafted', 1);
        });
    }
448858
public function build()
    {
        foreach ($this->datasource as $index => $val) {

            $option = $this->createOption();

            // inner will always be used
            $option->setInner($val);
            $option->setValue($this->index_is_value ? $index : $val);

            // in dependence of the data type is value to be selected $val or $inner
            if (!empty($this->selected)) {
                // A list of selected?
                if (is_array($this->selected)) {
                    if (array_search(($this->index_is_value ? $index : $val), $this->selected)) {
                        $option->isSelected(1);
                    }
                } // Or a value to look for?
                else {
                    if ($this->selected == ($this->index_is_value ? $index : $val)) {
                        $option->isSelected(1);
                    }
                }
            }
        }

        return parent::build();
    }
1190295
protected function getSelectedValueFromSelect(Crawler $select)
    {
        $selected = [];

        foreach ($select->children() as $option) {
            if ($option->nodeName === 'optgroup') {
                foreach ($option->childNodes as $child) {
                    if ($child->hasAttribute('selected')) {
                        $selected[] = $this->getOptionValue($child);
                    }
                }
            } elseif ($option->hasAttribute('selected')) {
                $selected[] = $this->getOptionValue($option);
            }
        }

        return $selected;
    }
298188
public function buildEiField(Eiu $eiu): ?EiField {
		if (!$eiu->entry()->isDraft()) {
			return parent::buildEiField($eiu);
		}
	
		return new SimpleEiField($eiu, 
				$this->getObjectPropertyAccessProxy(true)->getConstraint()->getLenientCopy(), 
				$this, $this, ($this->isReadOnly($eiu) ? null : $this));
	}
169295
public function build()
    {
        if (is_null($this->selectFields) || is_null($this->fromReportType)) {
            throw new RuntimeException('The `select()` and `from()` functions' .
                ' must be called prior to this function');
        }

        $awql = $this->buildSelectClause();
        $awql = $this->appendFromClause($awql);
        $awql = $this->appendWhereClause($awql);
        $awql = $this->appendDuringClause($awql);

        return new ReportQuery(
            $awql
        );
    }
734392
protected function addUndoDraft(Builder $builder): void
    {
        $builder->macro('undoDraft', function (Builder $builder) {
            $builder->withDrafted();

            return $builder->update(['drafted_at' => null]);
        });
    }
1310908
public function supplyPersistDraftStmtBuilder($targetDrafts, $oldTargetDrafts,
			PersistDraftStmtBuilder $persistDraftStmtBuilder, PersistDraftAction $persistDraftAction) {
		$relationDraftAction = $this->createRelationDraftAction($persistDraftStmtBuilder, $persistDraftAction);
		
		$draftActionQueue = $persistDraftAction->getQueue();
		$targetDraftDefinition = $this->getEiPropRelation()->getTargetEiMask()->getEiEngine()->getDraftDefinition();
		$orderIndex = 0;
		$targetDraftIds = array();
		foreach ((array) $targetDrafts as $targetDraft) {
			$targetAction = $draftActionQueue->persist($targetDraft, $targetDraftDefinition);
			if (!$targetDraft->isNew()) {
				$targetDraftId = $targetDraft->getId();
				$targetDraftIds[$targetDraftId] = $targetDraftId;
				$relationDraftAction->addTargetDraftId($targetDraft->getId(), $orderIndex++);
				continue;
			}
			
			$relationDraftAction->addDependent($targetAction);
			$targetAction->executeAtEnd(function () use ($relationDraftAction, $targetDraft, $orderIndex) {
				$relationDraftAction->addTargetDraftId($targetDraft->getId(), $orderIndex);
			});
			$orderIndex++;
		}
		
		foreach ((array) $oldTargetDrafts as $oldTargetDrafts) {
			if (!isset($targetDraftIds[$oldTargetDrafts->getId()])) {
				$persistDraftAction->getQueue()->remove($oldTargetDrafts, true);
			}
		}
	}
781648
public function build()
    {
        parent::build();

        $value = $this->validator->arrayGet($this->suppliedOptions, 'value', true);

        //we need to set the value to 'false' when it is falsey so it plays nicely with select2
        if (!$value && $value !== '') {
            $this->suppliedOptions['value'] = 'false';
        }
    }
1039827
public function build()
    {
        if (is_null($this->selectFields)) {
            throw new RuntimeException('The `select()` function must be' .
                ' called prior to this function');
        }

        $awql = $this->buildSelectClause();
        $awql = $this->appendWhereClause($awql);
        $awql = $this->appendOrderByClause($awql);

        if (is_null($this->startIndex) && is_null($this->pageSize)) {
            return new ServiceQuery($awql);
        }
        return new ServiceQuery(
            $awql,
            $this->startIndex,
            $this->pageSize
        );
    }
704008
protected function _buildSelect()
        {
            // If the query is raw, just set the $this->_values to be
            // the raw query parameters and return the raw query
            if ($this->_is_raw_query) {
                $this->_values = $this->_raw_parameters;
                return $this->_raw_query;
            }

            // Build and return the full SELECT statement by concatenating
            // the results of calling each separate builder method.
            return $this->_joinIfNotEmpty(
                " ",
                array(
                    $this->_buildSelectStart(),
                    $this->_buildJoin(),
                    $this->_buildWhere(),
                    $this->_buildGroupBy(),
                    $this->_buildHaving(),
                    $this->_buildOrderBy(),
                    $this->_buildLimit(),
                    $this->_buildOffset(),
                )
            );
        }
1104203
public function forceValues()
    {
        $forceConfig = $this->config->getSubConfig(self::FORCE);
        foreach ($forceConfig->getArrayCopy() as $key => $value) {
            add_filter("genesis_pre_get_option_{$key}", function () use ($value) {
                return $value;
            });
        }
    }
750312
private function buildSelect()
	{
		$selects = [];

		foreach ($this->select as $select)
		{
			$string = ($select['count']) ? "COUNT({$select['column']})" : $select['column'];

			// See if we're including an alias
			if (isset($select['as']))
			{
				$string .= " AS {$select['as']}";
			}

			// @FIXME: not quoting name here because we could have a function here as well
			// $selects[] = $this->connection->quoteName($string, $select['as']);
			$selects[] = $string;
		}

		return 'SELECT ' . implode(',', $selects);
	}
1165266
public function read(Eiu $eiu) {
		if ($eiu->object()->isDraftProp($this)) {
			$targetDraft = $eiu->entry()->readNativValue($this);
			if ($targetDraft === null) return null;
			
			return new DraftEiObject($targetDraft);
		}
		
		$targetEntityObj = $eiu->entry()->readNativValue($this);
		if ($targetEntityObj === null) return null;
		
		return LiveEiObject::create($this->eiPropRelation->getTargetEiType(), $targetEntityObj);
	}