/* (non-PHPdoc)
@see \rocket\ei\manage\draft\DraftValueSelection::buildDraftValue()
349999
public function buildDraftValue() {
		if ($this->rawValue === null) return null;
		
		$targetId = $this->targetEntityModel->getIdDef()->getEntityProperty()->parseValue($this->rawValue, 
				$this->em->getPdo());
		return $this->em->find($this->targetEntityModel->getClass(), $targetId);
	}
701258
public function buildCriteria()
    {
        $criteria = new Criteria(PersonTeamLinkTableMap::DATABASE_NAME);

        if ($this->isColumnModified(PersonTeamLinkTableMap::ID)) $criteria->add(PersonTeamLinkTableMap::ID, $this->id);
        if ($this->isColumnModified(PersonTeamLinkTableMap::PERSON_ID)) $criteria->add(PersonTeamLinkTableMap::PERSON_ID, $this->person_id);
        if ($this->isColumnModified(PersonTeamLinkTableMap::TEAM_ID)) $criteria->add(PersonTeamLinkTableMap::TEAM_ID, $this->team_id);
        if ($this->isColumnModified(PersonTeamLinkTableMap::CREATED_AT)) $criteria->add(PersonTeamLinkTableMap::CREATED_AT, $this->created_at);
        if ($this->isColumnModified(PersonTeamLinkTableMap::UPDATED_AT)) $criteria->add(PersonTeamLinkTableMap::UPDATED_AT, $this->updated_at);

        return $criteria;
    }
985179
protected function addOnlyDrafted(Builder $builder): void
    {
        $builder->macro('onlyDrafted', function (Builder $builder) {
            return $builder->withoutGlobalScope($this)->whereNotNull('drafted_at');
        });
    }
1219317
public static function getDrafts()
    {
        if (self::$drafts === null) {
            self::$drafts = (new Query())
            ->select(['cms_nav.id', 'nav_container_id', 'parent_nav_id', 'is_hidden', 'is_offline', 'is_draft', 'is_home', 'cms_nav_item.title'])
            ->from('cms_nav')
            ->leftJoin('cms_nav_item', 'cms_nav.id=cms_nav_item.nav_id')
            ->orderBy('cms_nav.sort_index ASC')
            ->where(['cms_nav_item.lang_id' => Lang::getDefault()['id'], 'cms_nav.is_deleted' => false, 'cms_nav.is_draft' => true])
            ->all();
        }
        
        return self::$drafts;
    }
14120
public function createContentDraft(FormActionEvent $event): void
    {
        /** @var ContentTranslationData $data */
        $data = $event->getData();

        if (!$data instanceof ContentTranslationData) {
            return;
        }

        $contentDraft = $this->contentService->createContentDraft($data->content->contentInfo);
        $fields = array_filter($data->fieldsData, function (FieldData $fieldData) use ($contentDraft, $data) {
            $mainLanguageCode = $contentDraft->getVersionInfo()->getContentInfo()->mainLanguageCode;

            return $mainLanguageCode === $data->initialLanguageCode
                || ($mainLanguageCode !== $data->initialLanguageCode && $fieldData->fieldDefinition->isTranslatable);
        });
        $contentUpdateData = new ContentUpdateData([
            'initialLanguageCode' => $data->initialLanguageCode,
            'contentDraft' => $contentDraft,
            'fieldsData' => $fields,
        ]);

        $event->setData($contentUpdateData);
    }
352464
protected function buildColumnDispatch()
    {
        $this->columnDispatch = array();

        foreach ($this->getComponents() as $item) {
            if ($item instanceof GridField_ColumnProvider) {
                $columns = $item->getColumnsHandled($this);

                foreach ($columns as $column) {
                    $this->columnDispatch[$column][] = $item;
                }
            }
        }
    }
604767
public function createValueBuilder() {
		try {
			return new EagerValueBuilder(FileFactory::createFromInputStream(
					new ResourceStream($this->resource)));
		} catch (\InvalidArgumentException $e) {
			throw new CorruptedDataException(null, 0, $e);
		}
	}
885053
public function createGraph()
    {
        $graphResult = $this->startVertex->getGraph()->createGraphClone();

        // initialize null flow and check edges
        foreach ($graphResult->getEdges() as $edge) {
            if (!($edge instanceof EdgeDirected)) {
                throw new UnexpectedValueException('Undirected edges not supported for edmonds karp');
            }
            $edge->setFlow(0);
        }

        $idA = $this->startVertex->getId();
        $idB = $this->destinationVertex->getId();

        do {
            // Generate new residual graph and repeat
            $residualAlgorithm = new ResidualGraph($graphResult);
            $graphResidual = $residualAlgorithm->createGraph();

            // 1. Search _shortest_ (number of hops and cheapest) path from s -> t
            $alg = new BreadthFirst($graphResidual->getVertex($idA));
            try {
                $pathFlow = $alg->getWalkTo($graphResidual->getVertex($idB));
            } catch (OutOfBoundsException $e) {
                $pathFlow = NULL;
            }

            // If path exists add the new flow to graph
            if ($pathFlow) {
                // 2. get max flow from path
                $maxFlowValue = $pathFlow->getEdges()->getEdgeOrder(Edges::ORDER_CAPACITY)->getCapacity();

                // 3. add flow to path
                foreach ($pathFlow->getEdges() as $edge) {
                    // try to look for forward edge to increase flow
                    try {
                        $originalEdge = $graphResult->getEdgeClone($edge);
                        $originalEdge->setFlow($originalEdge->getFlow() + $maxFlowValue);
                    // forward edge not found, look for back edge to decrease flow
                    } catch (UnderflowException $e) {
                        $originalEdge = $graphResult->getEdgeCloneInverted($edge);
                        $originalEdge->setFlow($originalEdge->getFlow() - $maxFlowValue);
                    }
                }
            }

        // repeat while we still finds paths with residual capacity to add flow to
        } while ($pathFlow);

        return $graphResult;
    }
711241
public function addDraftIsTransformedToMessageIdList($value)
    {
        if ($this->DraftIsTransformedToMessageIdList === null) {
            $this->DraftIsTransformedToMessageIdList = new \Protobuf\ScalarCollection();
        }

        $this->DraftIsTransformedToMessageIdList->add($value);
    }
465756
protected function buildValuesArray() {

		foreach($this->whereClauses as $where) {

			if(is_null($where->value)) {
				continue;
			}
			if(is_array($where->value)) {
				$this->valuesToBind = array_merge($this->valuesToBind, $where->value);
			}
			else {
				$this->valuesToBind[] = $where->value;
			}

		}

	}
505946
public function createValueHolder($apply_default_values = false)
    {
        if (!$this->value_holder_implementor) {
            $implementor = $this->hasOption(self::OPTION_VALUE_HOLDER)
                ? $this->getOption(self::OPTION_VALUE_HOLDER)
                : $this->buildDefaultValueHolderClassName();

            if (!class_exists($implementor)) {
                throw new InvalidConfigException(
                    sprintf(
                        "Invalid valueholder implementor '%s' configured for attribute '%s' on entity '%s'.",
                        $implementor,
                        $this->getName(),
                        $this->getType() ? $this->getType()->getName() : 'undefined'
                    )
                );
            }

            $test_value_holder = new $implementor($this);

            if (!$test_value_holder instanceof ValueHolderInterface) {
                throw new InvalidTypeException(
                    sprintf(
                        "Invalid valueholder implementation '%s' given for attribute '%s' on entity type '%s'. " .
                        "Make sure to implement '%s'.",
                        $implementor,
                        $this->getName(),
                        $this->getType() ? $this->getType()->getName() : 'undefined',
                        ValueHolderInterface::CLASS
                    )
                );
            }

            $this->value_holder_implementor = $implementor;
        }

        $value_holder = new $this->value_holder_implementor($this);
        if ($apply_default_values === true) {
            $value_holder->setValue($this->getDefaultValue());
        } elseif ($apply_default_values === false) {
            $value_holder->setValue($this->getNullValue());
        } else {
            throw new InvalidTypeException(
                sprintf(
                    "Only boolean arguments are acceptable for attribute '%s' on entity type '%s'. ",
                    $this->getName(),
                    $this->getType() ? $this->getType()->getName() : 'undefined'
                )
            );
        }

        return $value_holder;
    }
1256079
protected function buildSelect()
	{
		//define a container fields array
		$fields = array();

		//
		$where = $order = $limit = $join ="";

		//
		$template = "SELECT %s %s FROM %s %s %s %s %s";

		//loop through the fields
		foreach ($this->fields as $table => $tableFields) 
		{
			//loop through the fields checking for aliases
			foreach ($tableFields as $field => $alias) 
			{
				//if field is string, return field name
				if ( is_string($field) && $field != 'COUNT(1)')
				{
					//add to fields array
					$fields[] = "{$table}.{$field} AS {$alias}";

				}
				elseif (is_string($field) && $field == 'COUNT(1)') 
				{
					//add to fields array
					$fields[] = "{$field} AS {$alias}";

				}
				//not an array, return alias
				else
				{
					//get alias as field name
					$fields[] = "{$table}.{$alias}";

				}

			}

		}

		//turn the fields into a string
		$fields = join(", ", $fields);

		//get the query joins
		$queryJoin = $this->joins;

		//check if the join parameter is empty
		if ( ! empty($queryJoin) ) 
		{
			$joinTables = "(" . join(", ", $queryJoin['tables']) . ")";
			$joinConditions = "(" . join(" AND ", $queryJoin['conditions']) . ")";
			//add the joins
			$join = " LEFT JOIN $joinTables ON $joinConditions";

		}

		//get the where clause
		$queryWhere = $this->wheres;

		//check if the wheres clause is empty
		if ( ! empty($queryWhere) ) 
		{
			//append where clause
			$joined = join(" AND ", $queryWhere);

			//assign string to $where var
			$where = "WHERE {$joined}";

		}

		//get the order clause
		$queryOrder = $this->orders;

		//check if the orders clause is empty
		if ( ! empty($queryOrder) ) 
		{
			//get the direction if order
			$orderDirection = $this->directions;

			//assign string to order variable
			$order = "ORDER BY {$queryOrder} {$orderDirection}";

		}

		//get the limits clause
		$queryLimit = $this->limits;

		//check if the limits clause is empty
		if ( ! empty($queryLimit) ) 
		{
			//get the offset
			$limitOffset = $this->offset;

			//if offset has been defined
			if ( $limitOffset ) 
			{
				//get the limit string with offset
				$limit = "LIMIT {$limitOffset}, {$queryLimit}";

			}
			//limit offset undefined
			else
			{
				//get the limit string
				$limit = "LIMIT {$queryLimit}";

			}

		}

		//return the formated query string in the format of $template
		return sprintf($template, $this->distinct, $fields, $this->froms, $join, $where, $order, $limit);

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

            return $builder->update(['drafted_at' => null]);
        });
    }
268022
public function getDraftCollectionAction()
    {
        $contents = $this->getEntityManager()
            ->getRepository('BackBee\ClassContent\Revision')
            ->getAllDrafts($this->getApplication()->getBBUserToken())
        ;

        $contents = $this->sortDraftCollection($contents);

        return $this->addContentRangeHeadersToResponse($this->createJsonResponse($contents), $contents, 0);
    }
169883
private void buildSelect(final StringBuilder selectBuilder, final List<Projection> projections) {
        selectBuilder.append("SELECT ");
        if (null == projections || projections.isEmpty()) {
            selectBuilder.append(" * ");

            return;
        }

        selectBuilder.append(projections.stream().map(Projection::getKey).collect(Collectors.joining(", ")));
    }
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));
	}
1128781
protected function buildValuesForUpdate()
    {
        $values = array();
        foreach ($this->col_values as $col => $value) {
            $values[] = "{$col} = {$value}";
        }
        return ' SET' . $this->indentCsv($values);
    }