Leveling sequentially from very first level up to highest possible until all experiences are spent.

@param Experiences $experiences
@return Level
339105
public function toTotalLevel(Experiences $experiences): Level
    {
        $currentExperiences = 0;
        $usedExperiences = 0;
        $maxLevelValue = 0;
        while ($usedExperiences + $currentExperiences <= $experiences->getValue()) {
            $level = $this->toLevel(new Experiences($currentExperiences, $this));
            if ($maxLevelValue < $level->getValue()) {
                $usedExperiences += $currentExperiences;
                $maxLevelValue = $level->getValue();
            }
            $currentExperiences++;
        }

        return new Level($maxLevelValue, $this);
    }
488021
public function descendants($level = null)
	{
		$instance = self::blank();
		$instance->where('level', '>', $this->level)
		         ->order('lft', 'asc');

		if (isset($level))
		{
			$instance->where('level', '<=', $this->level + $level);
		}

		return $instance->where('lft', '>', $this->lft)
		                ->where('rgt', '<', $this->rgt)
		                ->applyScopesWhere($this);
	}
1220359
public function customFirstOrCreate(array $attributes, array $values = [])
    {
        $instance = $this->newInstance();

        foreach ($attributes as $key => $value) {
            $instance = $instance->where($key, $value);
        }

        if ( ! is_null($first = $instance->first())) return $first;

        $instance = $this->newInstance($attributes + $values);
        $instance->save();

        return $instance;
    }
122663
public function level($level)
    {
        if (empty($level)) {
            $level = [];
        } elseif (is_string($level)) {
            $level = explode(',', str_replace(' ', '', $level));
        } else {
            $level = is_array($level) ? $level : func_get_args();
        }

        $this->setLevel($level);

        return $this;
    }
1329990
function getNextLevel($level)
    {
        $levels = $this->getLevels();
        $level_incdeces = $this->getLevelIndeces();
        $level_index = $level_incdeces[$level];
        if (!isset($levels[$level_index + 1])) {
            return false;
        }
        $next_level = $levels[$level_index + 1];
        return $next_level;
    }
377401
public function loadCount($relations)
    {
        if ($this->isEmpty()) {
            return $this;
        }

        $models = $this->first()->newModelQuery()
            ->whereKey($this->modelKeys())
            ->select($this->first()->getKeyName())
            ->withCount(...func_get_args())
            ->get();

        $attributes = Arr::except(
            array_keys($models->first()->getAttributes()),
            $models->first()->getKeyName()
        );

        $models->each(function ($model) use ($attributes) {
            $this->find($model->getKey())->forceFill(
                Arr::only($model->getAttributes(), $attributes)
            )->syncOriginalAttributes($attributes);
        });

        return $this;
    }
48244
public function multiLevelCount()
    {
        $levelCount = 0;
        foreach ($this->dataValues as $dataValueSet) {
            $levelCount = max($levelCount, count($dataValueSet));
        }
        return $levelCount;
    }
109150
public function withCount($relations) {
        if (empty($relations)) {
            return $this;
        }

        if (empty($this->selects)) {
            $this->select();
        }

        $relations = is_array($relations) ? $relations : func_get_args();

        foreach ($this->parseWithRelations($relations) as $name => $constraints) {
            // First we will determine if the name has been aliased using an "as" clause on the name
            // and if it has we will extract the actual relationship name and the desired name of
            // the resulting column. This allows multiple counts on the same relationship name.
            $segments = explode(' ', $name);

            $alias = null;

            if (count($segments) == 3 && strtolower($segments[1]) == 'as') {
                list($name, $alias) = [$segments[0], $segments[2]];
            }

            $relation = $this->getRelationWithoutConstraints($name);

            // Here we will get the relationship count query and prepare to add it to the main query
            // as a sub-select. First, we'll get the "has" query and use that to get the relation
            // count query. We will normalize the relation name then append _count as the name.
            $query = $relation->getRelationExistenceCountQuery(
                $relation->getRelated()->query(), $this
            );

            // Finally we will add the proper result column alias to the query and run the subselect
            // statement against the query builder. Then we will return the builder instance back
            // to the developer for further constraint chaining that needs to take place on it.
            $column = $alias ?: strtolower($name.'_count');

            $this->selectSub($query->getSql(), $column);
        }

        return $this;
    }
1292123
public function setLogLevel($level= xPDO::LOG_LEVEL_FATAL) {
        $oldLevel = $this->logLevel;
        $this->logLevel= intval($level);
        return $oldLevel;
    }
258049
protected static function create_level_instances() {
        global $DB;

        $sql = "SELECT ".CONTEXT_COURSECAT.", cc.id
                  FROM {course_categories} cc
                 WHERE NOT EXISTS (SELECT 'x'
                                     FROM {context} cx
                                    WHERE cc.id = cx.instanceid AND cx.contextlevel=".CONTEXT_COURSECAT.")";
        $contextdata = $DB->get_recordset_sql($sql);
        foreach ($contextdata as $context) {
            context::insert_context_record(CONTEXT_COURSECAT, $context->id, null);
        }
        $contextdata->close();
    }
160978
public function relations(array $relations)
    {
        foreach ($relations as $column1 => $column2) {
            $this->relation($column1, $column2);
        }

        return $this;
    }
728725
public static function hasLevel(int $level=null) :bool {
		// if we have said level
		return self::$_account ? 
			self::getAccount()->hasLevel($level) : false;
	}
1290274
public function setLevel($level)
    {
        if ($level < 0 || $level > 100) {
            throw new \InvalidArgumentException(sprintf(
                    'Invalid Postrize Level "%s"', (string) $level
            ));
        }
        $this->level = (int) $level;

        return $this;
    }
397979
public function setLevel(int $level = 1) : CNabuDataObject
    {
        if ($level === null) {
            throw new ENabuCoreException(
                    ENabuCoreException::ERROR_NULL_VALUE_NOT_ALLOWED_IN,
                    array("\$level")
            );
        }
        $this->setValue('nb_site_map_level', $level);
        
        return $this;
    }
531208
function getNextLevels($deltaLevel)
    {
        $prevLevels = $this->getPrevLevels($deltaLevel);
        $return = $this->getLevels();
        foreach ($return as $key => $level) {
            if (in_array($level, $prevLevels) || $level == $deltaLevel) {
                unset($return[$key]);
            }
        }
        return array_values($return);
    }
709167
function getPrevLevel($level)
    {
        $levels = $this->getLevels();
        $level_incdeces = $this->getLevelIndeces();
        $level_index = $level_incdeces[$level];
        if (!isset($levels[$level_index - 1])) {
            return false;
        }
        $prev_level = $levels[$level_index - 1];
        return $prev_level;
    }
1034920
public function firstOrNew(array $attributes, array $values = [])
    {
        if (! is_null($instance = $this->where($attributes)->first())) {
            return $instance;
        }

        return $this->newModelInstance($attributes + $values);
    }