Short description of method buildDeleterBehaviour

@access public
@author Jerome Bogaerts, <jerome@taotesting.com>
@return string
510550
public function buildDeleterBehaviour()
    {
        return '$(document).ready(function() {
                    $("#' . $this->buildDeleteButtonId() . '").click(function() {
                        var $form = $(this).parents("form"),
                            $fileHandling = $form.find("[name=\'' . $this->getName() . '\']");
                        if(!$fileHandling.length) {
                            $fileHandling = $("<input>", { name: "' . $this->getName() . '", type: "hidden" });
                            $form.prepend($fileHandling); 
                        }
                        $fileHandling.val("{\\"action\\":\\"delete\\"}");
                        $("#' . $this->buildWidgetContainerId() . '").empty();
                        ' . $this->buildUploaderBehaviour(true) . '
                    });
                });';
    }
758305
protected function buildFrom()
    {
        if (!$this->from) {
            return '';
        }

        $refs = array();
        foreach ($this->from as $from) {
            $refs[] = implode(' ', $from);
        }
        return ' FROM' . $this->indentCsv($refs);
    }
805877
private function buildPipeline()
    {
        $nextCallable = function ($item) {
            // the final callable is a no-op
        };

        foreach ($this->getStepsSortedDescByPriority() as $step) {
            $nextCallable = function ($item) use ($step, $nextCallable) {
                return $step->process($item, $nextCallable);
            };
        }

        return $nextCallable;
    }
739409
public function build()
    {
        $lines = [];

        $lines[] = sprintf('BEGIN:%s', $this->getType());

        /** @var $property Property */
        foreach ($this->buildPropertyBag() as $property) {
            foreach ($property->toLines() as $l) {
                $lines[] = $l;
            }
        }

        $this->buildComponents($lines);

        $lines[] = sprintf('END:%s', $this->getType());

        $ret = [];

        foreach ($lines as $line) {
            foreach (ComponentUtil::fold($line) as $l) {
                $ret[] = $l;
            }
        }

        return $ret;
    }
40078
public function build()
    {
        /**
         * Query to be returned.
         *
         * @var string
         */
        $query = '';

        /**
         * Clauses which were built already.
         *
         * It is required to keep track of built clauses because some fields,
         * for example `join` is used by multiple clauses (`JOIN`, `LEFT JOIN`,
         * `LEFT OUTER JOIN`, etc.). The same happens for `VALUE` and `VALUES`.
         *
         * A clause is considered built just after fields' value
         * (`$this->field`) was used in building.
         *
         * @var array
         */
        $built = [];

        /**
         * Statement's clauses.
         *
         * @var array
         */
        $clauses = $this->getClauses();

        foreach ($clauses as $clause) {
            /**
             * The name of the clause.
             *
             * @var string
             */
            $name = $clause[0];

            /**
             * The type of the clause.
             *
             * @see self::$CLAUSES
             *
             * @var int
             */
            $type = $clause[1];

            /**
             * The builder (parser) of this clause.
             *
             * @var Component
             */
            $class = Parser::$KEYWORD_PARSERS[$name]['class'];

            /**
             * The name of the field that is used as source for the builder.
             * Same field is used to store the result of parsing.
             *
             * @var string
             */
            $field = Parser::$KEYWORD_PARSERS[$name]['field'];

            // The field is empty, there is nothing to be built.
            if (empty($this->$field)) {
                continue;
            }

            // Checking if this field was already built.
            if ($type & 1) {
                if (! empty($built[$field])) {
                    continue;
                }
                $built[$field] = true;
            }

            // Checking if the name of the clause should be added.
            if ($type & 2) {
                $query = trim($query) . ' ' . $name;
            }

            // Checking if the result of the builder should be added.
            if ($type & 1) {
                $query = trim($query) . ' ' . $class::build($this->$field);
            }
        }

        return $query;
    }
1220154
public function build()
    {
        $callback = $this->callback;

        $callback($this);

        if (is_null($this->primary)) {
            $this->primary = self::$defaultPrimary;
        }

        return $this;
    }
353221
public function buildDraftValue() {
		if ($this->rawValue === null) return null;
	
		return $this->dm->find($baseEntityObj, $this->rawValue, $this->targetDraftDefinition);
	}
411663
public function buildMock()
    {
        if (empty($this->className)) {
            throw new \Exception('Class name is required for default buildMock');
        }
        $config = $this->config;
        $mock = $this->testCase->getMockBuilder($this->className)
            ->disableOriginalConstructor()
            ->getMock();

        foreach ($config as $key => $returnValue) {
            $mock->method($key)
                ->will($this->testCase->returnValue($returnValue));
        }

        return $mock;
    }
255255
public function getBetterTrace() {
        $trace = $this->betterTrace;

        if (!$trace) {
            // transform the original stacktrace into a better one
            $trace = DebugHelper::fixTrace($this->getTrace(), $this->getFile(), $this->getLine());

            // drop the first frame if the exception was created in the registered error handler
            if (DebugHelper::getFQFunctionName($trace[0]) == ErrorHandler::class.'::handleError') {
                \array_shift($trace);

                // if the error was triggered by include/require/_once: fix the next frame, it's wrong
                if (sizeof($trace) > 1) {
                    $function = DebugHelper::getFQFunctionName($trace[0]);
                    if ($function=='include' || $function=='include_once' || $function=='require' || $function=='require_once') {
                        if (isset($trace[0]['file']) && isset($trace[1]['file'])) {
                            if ($trace[0]['file'] == $trace[1]['file']) {
                                if (isset($trace[0]['line']) && isset($trace[1]['line'])) {
                                    if ($trace[0]['line'] == $trace[1]['line']) {
                                        unset($trace[0]['file'], $trace[0]['line']);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // store the new stacktrace
            $this->betterTrace = $trace;
        }
        return $trace;
    }
765528
protected function getElementErrorsHelper()
    {
        if ($this->elementErrorsHelper) {
            return $this->elementErrorsHelper;
        }

        if (method_exists($this->view, 'plugin')) {
            $this->elementErrorsHelper = $this->view->plugin('bootstrap_form_element_errors');
        }

        if (!$this->elementErrorsHelper instanceof FormElementErrors) {
            $this->elementErrorsHelper = new FormElementErrors();
        }

        return $this->elementErrorsHelper;
    }
1201443
public function build()
    {
        if (isset($this->component)) {
            return $this->component;
        }

        $this->component = BuildUtil::removeNullElements([
            'type' => ComponentType::SPACER,
            'size' => $this->size,
        ]);

        return $this->component;
    }
704662
public function build()
    {
        $result = new Finder();
        if (method_exists($result, 'useBestAdapter')) {
            $result->useBestAdapter();
        }
        $result->ignoreDotFiles(false);
        $result->ignoreVCS(false);

        return $result;
    }
1074654
private function buildValidation() {
        $validation = new Object\Index($this->getConfiguration());
        $validation->setNamespace(
            $this->getConfiguration()->getRootNamespace()
            . '\Services\Behavior\\' . $this->getConfiguration()->getModelSubNamespace()
            . '\Generated'
        );
        $validation->setName($this->getAbstractClass()->getName());
        $validation->setAbstract(true);
        $validation->setExtends('BehaviorBase');
        $validation->addUse(str_replace('\Generated', '', $this->getAbstractClass()->getNamespace()) . '\\' . $this->getAbstractClass()->getName() . ' as Model');
        $validation->addUse('Phalcon\Mvc\Model\Message');
        $validation->addUse('Bullhorn\FastRest\Api\Services\Behavior\BehaviorBase');


        $method = new Object\Method();
        $method->setAccess('public');
        $method->setName('getEntity');
        $method->setReturnType('Model');
        $method->setContent('return parent::getEntity();');
        $validation->addMethod($method);


        //Before Delete Method
        $content = '';
        foreach($this->getRelationships() as $relationship) {
            if($relationship->isPlural() && !$relationship->isNullable() && $relationship->getAction() != 'ACTION_CASCADE') {
                $content .= 'parent::beforeDelete();
        if($this->isUnitTestingChildren()) {
            return;
        }
        $entity = $this->getEntity();
        if ($entity->count' . ucfirst($relationship->getAlias()) . '()>0) {
			$entity->appendMessage(new Message(\'Multiple ' . ucfirst($relationship->getAlias()) . ' found\'));
		}';
            }
        }
        $method = new Object\Method();
        $method->setAccess('protected');
        $method->setDescription('Validates if the entity can be deleted');
        $method->setReturnType('void');
        $method->setName('beforeDelete');
        $method->setContent($content);
        $validation->addMethod($method);
        //End Before Delete Method


        //Validation Method
        $content = 'parent::validation();
        if($this->isUnitTestingChildren()) {
            return;
        }
        $entity = $this->getEntity();
        //Check to see if it is automatically updated
		$automaticAttributes = $entity->getModelsMetaData()->getAutomaticCreateAttributes($entity);
		$columnMap = $entity->getModelsMetaData()->getColumnMap($entity);
		$automaticFields = array_fill_keys($entity->getAutomaticallyUpdatedFields(), null);
		foreach($automaticAttributes as $fullName=>$null) {
			$automaticFields[$columnMap[$fullName]] = null;
		}
';
        foreach($this->getFields() as $field) {
            if(!is_null($field->getEnumOptions())) {
                $validation->addUse('Phalcon\Mvc\Model\Validator\Inclusionin as ValidateEnum');
                $subMethod = new Object\Method();
                $subMethod->setAccess('private');
                $subMethod->setDescription('Validates ' . $field->getShortName() . ' is in the enum list');
                $subMethod->setReturnType('void');
                $subMethod->setName('validate' . ucfirst($field->getShortName()) . 'Enum');
                $subMethod->setContent(
                    '$this->validate(
			new ValidateEnum(
				array(
					\'field\' => \'' . $field->getShortName() . '\',
					\'domain\' => [\'' . implode('\',\'', $field->getEnumOptions()) . '\']
				)
			)
		);'
                );
                $validation->addMethod($subMethod);
                $content .= '		$this->validate' . ucfirst($field->getShortName()) . 'Enum();
';
            }
            if(!$field->isNullable()) {
                $subMethod = new Object\Method();
                $subMethod->setAccess('private');
                $subMethod->setDescription('Validates ' . $field->getShortName() . ' is not null');
                $subMethod->setReturnType('void');
                $subMethod->setName('validate' . ucfirst($field->getShortName()) . 'NotNull');
                $parameter = new Object\Parameter();
                $parameter->setName('entity');
                $parameter->setType('Model');
                $parameter->setStrictType(true);
                $subMethod->addParameter($parameter);
                $parameter = new Object\Parameter();
                $parameter->setName('automaticFields');
                $parameter->setType('array');
                $parameter->setStrictType(true);
                $subMethod->addParameter($parameter);
                $subMethod->setContent(
                    'if(!array_key_exists(\'' . $field->getShortName() . '\', $automaticFields) && is_null($entity->readAttribute(\'' . $field->getShortName() . '\'))) {
			$entity->appendMessage(new Message(\'Null Error with the field: ' . $field->getShortname() . ', Expected Type: ' . $field->getType() . '\'));
		}'
                );
                $validation->addMethod($subMethod);
                $content .= '		$this->validate' . ucfirst($field->getShortName()) . 'NotNull($entity, $automaticFields);
';
            }
        }

        foreach($this->getIndexes() as $index) {
            if($index->isUnique() && !$index->isPrimary()) {
                $validation->addUse('Bullhorn\FastRest\Api\Services\Validator\Unique as ValidateUnique');
                $fields = array();
                foreach($index->getColumns() as $column) {
                    $fields[] = $this->getField($column)->getShortName();
                }
                $name = 'validate';
                foreach($fields as $field) {
                    $name .= ucfirst($field);
                }
                $name .= 'Unique';
                $subMethod = new Object\Method();
                $subMethod->setAccess('private');
                $subMethod->setDescription('Validates this combination of ' . implode(', ', $fields) . ' is unique in the database');
                $subMethod->setReturnType('void');
                $subMethod->setName($name);
                $subMethod->setContent(
                    '$this->validate(
			$validation = new ValidateUnique(
				[
					\'fields\'  => [\'' . implode('\',\'', $fields) . '\'],
					\'message\' => \'A unique constraint failed on: ' . implode(',', $fields) . '\'
				]
			)
		);'
                );
                $validation->addMethod($subMethod);
                $content .= '		$this->' . $name . '();
';
            }
        }

        foreach($this->getRelationships() as $relationship) {
            $field = $this->getField($relationship->getLocalColumn());
            if(!$relationship->isPlural()) {
                //Ex: Not Required relationship, make sure if the value isn't null, it is valid
                $subMethod = new Object\Method();
                $subMethod->setAccess('private');
                $subMethod->setDescription('Validates the ' . ucfirst($relationship->getAlias()) . ' Relationship');
                $subMethod->setReturnType('void');
                $subMethod->setName('validate' . ucfirst($relationship->getAlias()) . 'Relationship');
                $parameter = new Object\Parameter();
                $parameter->setName('entity');
                $parameter->setType('Model');
                $parameter->setStrictType(true);
                $subMethod->addParameter($parameter);
                $subMethod->setContent(
                    'if ($entity->get' . ucfirst($relationship->getAlias()) . '()===false '
                    . ($field->isNullable() ? '&& !is_null($entity->get' . ucfirst($field->getShortName()) . '())' : '') . ') {
			$entity->appendMessage(new Message(\'No ' . ucfirst($relationship->getAlias()) . ' found with the id \'.$entity->get' . ucfirst($field->getShortName()) . '()));
		}'
                );
                $validation->addMethod($subMethod);
                $content .= '		$this->validate' . ucfirst($relationship->getAlias()) . 'Relationship($entity);
';
            }
        }
        $method = new Object\Method();
        $method->setAccess('protected');
        $method->setDescription('Validates if the entity can be updated or inserted');
        $method->setReturnType('void');
        $method->setName('validation');
        $method->setContent($content);
        $validation->addMethod($method);
        //End Validation Method

        $this->setValidationClass($validation);

        $childValidation = new Object\Index($this->getConfiguration());
        $childValidation->setNamespace(
            $this->getConfiguration()->getRootNamespace()
            . '\Services\Behavior\\' . $this->getConfiguration()->getModelSubNamespace()
        );
        $childValidation->setName($this->getAbstractClass()->getName());
        $childValidation->setExtends('Generated\\' . $this->getAbstractClass()->getName());
        $childValidation->addUse(str_replace('\Generated', '', $this->getAbstractClass()->getNamespace()) . '\\' . $this->getAbstractClass()->getName() . ' as Model');

        $this->setValidationChildClass($childValidation);
        $this->getAbstractClass()->addUse($childValidation->getNamespace() . '\\' . $childValidation->getName() . ' as ModelValidator');
        return '		$this->addBehavior(new ModelValidator());' . "\n";
    }
1209045
function build(): string
    {
        if ($this->host !== null && $this->preferredFormat === static::ABSOLUTE) {
            return $this->buildAbsolute();
        } else {
            return $this->buildRelative();
        }
    }
1339793
public function buildCode()
    {
        $code = '';

        if ($this->documentation) {
            $code .= '    /**'."\n";
            $code .= '     * '.str_replace("\n", "\n     * ", wordwrap($this->documentation, 73))."\n";
            $code .= '     */'."\n";
        }

        $code .= '    public function '.$this->name.'('.implode(', ', $this->parameters).')'."\n";
        $code .= '    {'."\n";
        $code .= '        '.str_replace("\n", "\n        ", $this->body)."\n";
        $code .= '    }';

        // Trim trailing whitespaces
        $code = preg_replace('/[ ]+$/m', '', $code);

        return $code;
    }
1347805
public function build()
    {
        $sql = [
            $this->table->build(),
            $this->set->build(),
            $this->where->build(),
            $this->orderBy->build(),
            $this->limit->build(),
        ];

        $this->values = array_merge(
            array_values($this->set->getValues()),
            $this->where->getValues());

        return implode(' ', array_filter($sql));
    }
1248669
public function buildSlug()
    {
        $name = $this->getAttribute($this->getSluggableColumn());
        return str_slug($name . '-' . $this->getAttribute('id'));
    }