/*
Get a student's name with the Course from the student's array
@param $arrStudent
@param $long If true, add 'Klasse', etc
@param $withClass If false, remove course completely
481974
public static function studentToString($arrStudent,$long = false,$withClass = true) {
		$res = $arrStudent['firstname'] . ' ' . $arrStudent['lastname'];
		if($withClass && static::course($arrStudent['course'])) 
			$res .= ' (' . static::course($arrStudent['course'],$long) . ')';
		
		return $res;
	}
262369
protected function initSpec($methodName, array $with)
    {
        return new StaticSpec($this->testCase, $this->className, $methodName, $with, Shmock::$policies);
    }
846441
public function setLongdesc($longdesc)
    {
        if (Format::isUri($longdesc) === true || (is_string($longdesc) === true && empty($longdesc) === true)) {
            $this->longdesc = $longdesc;
        } else {
            $msg = "The 'longdesc' argument must be a valid URI, '" . $longdesc . "' given.";
            throw new InvalidArgumentException($msg);
        }
    }
274386
public function hasFirst(string $relation, array $where = [], array $with = [], int $hasAtLeast = 1)
    {
        $query = $this->make($with);

        $query = $this->applyWhere($query, $where);

        return $query->has($relation, '>=', $hasAtLeast)->first();
    }
544872
public static function addClassesToLabels($arrRow, $return) {
    // Grid-Klassen dem Typ hinzufügen
    $grid = "(";

    if($arrRow['grid_columns'] != "" ) {
      $strField = "grid_columns";
      $env = "BE";
      $arrGridClasses = deserialize($arrRow['grid_columns']);

      // HOOK: create and manipulate grid classes
      if (isset($GLOBALS['TL_HOOKS']['manipulateGridClasses']) && is_array($GLOBALS['TL_HOOKS']['manipulateGridClasses']))
      {
        foreach ($GLOBALS['TL_HOOKS']['manipulateGridClasses'] as $callback)
        {
          $this->import($callback[0]);
          $arrGridClassesManipulated = array();

          foreach ($arrGridClasses as $class) {
            $arrGridClassesManipulated[] = $this->{$callback[0]}->{$callback[1]}($env, $strField, $class);
          }

          $arrGridClasses = $arrGridClassesManipulated;
        }
      }

      $grid .= implode(deserialize($arrGridClasses), ", ");

      if($arrRow['grid_options'] != "" ) {
        $grid .= ", ";
      }
    }

    if($arrRow['grid_options'] != "" ) {
      $env = "BE";
      $strField = "grid_options";
      $arrGridClasses = deserialize($arrRow['grid_options']);

      // HOOK: create and manipulate grid classes
      if (isset($GLOBALS['TL_HOOKS']['manipulateGridClasses']) && is_array($GLOBALS['TL_HOOKS']['manipulateGridClasses']))
      {
        foreach ($GLOBALS['TL_HOOKS']['manipulateGridClasses'] as $callback)
        {
          $this->import($callback[0]);
          $arrGridClassesManipulated = array();

          foreach ($arrGridClasses as $class) {
            $arrGridClassesManipulated[] = $this->{$callback[0]}->{$callback[1]}($env, $strField, $class);
          }

          $arrGridClasses = $arrGridClassesManipulated;
        }
      }

      $grid .= implode(deserialize($arrGridClasses), ", ");
    }

    // close classes
    $grid .= ")";

    if($arrRow['grid_columns'] == "" && $arrRow['grid_options'] == "") {
      $grid = "";
    }

    // Klasse hinzufügen, wenn $grid gesetzt
    if($grid!=="") {
      $type .= " <span class='tl_gray'>".$grid."</span>";

      $return .= '<div class="tl_gray tl_content_right">'.$grid.'</div>';
    }

    return $return;
  }
1212951
public function getByOrder(string $orderBy, array $where = [], array $with = [], string $order = 'desc', int $limit = 0)
    {
        $query = $this->make($with);

        $query = $this->applyWhere($query, $where);

        $query = $query->orderBy($orderBy, $order);

        if ($limit) {
            $query = $query->take($limit);
        }

        return $query->get();
    }
243275
public function toString($withUnit = false)
    {
        $width = $this->getWidth($withUnit);
        $height = $this->getHeight($withUnit);

        return sprintf('%s%s%s', $width, $this->separator, $height);
    }
792727
@Override
	public void inferLocalClass(AnonymousClass anonymousClass, String localClassName, JvmFeature container) {
		// Issue #356: do not generate if the class has no name.
		assert anonymousClass != null;
		assert container != null;
		if (Strings.isNullOrEmpty(localClassName)) {
			return;
		}
		// Issue #363: do not generate the class if the SARL library is incompatible.
		if (!Utils.isCompatibleSARLLibraryOnClasspath(this.typeReferences, anonymousClass)) {
			return;
		}

		// Create the inner type
		// --- Begin Xtend Part
		try {
			final JvmGenericType inferredJvmType = this.typesFactory.createJvmGenericType();
			inferredJvmType.setSimpleName(localClassName);
			inferredJvmType.setAnonymous(!hasAdditionalMembers(anonymousClass));
			inferredJvmType.setFinal(true);
			setVisibility(inferredJvmType, anonymousClass);
			inferredJvmType.getSuperTypes().add(this.typeBuilder.inferredType(anonymousClass));
			container.getLocalClasses().add(inferredJvmType);
			this.associator.associatePrimary(anonymousClass, inferredJvmType);
			// --- End Xtend Part

			// Create the generation context that is used by the other transformation functions.
			final GenerationContext parentContext = getContext(
					EcoreUtil2.getContainerOfType(container, JvmType.class));
			final GenerationContext context = openContext(anonymousClass, inferredJvmType, Arrays.asList(
					SarlField.class, SarlConstructor.class, SarlAction.class));
			context.setParentContext(parentContext);
			try {
				// --- Begin Xtend Part
				for (final XtendMember member : anonymousClass.getMembers()) {
					if (context.isSupportedMember(member)) {
						transform(member, inferredJvmType, true);
					}
				}

				appendSyntheticDispatchMethods(anonymousClass, inferredJvmType);
				this.nameClashResolver.resolveNameClashes(inferredJvmType);
				// --- End Xtend Part

				// Add SARL synthetic functions
				appendSyntheticDefaultValuedParameterMethods(
						anonymousClass,
						inferredJvmType,
						context);
			} finally {
				closeContext(context);
			}
		} catch (AssertionError | InternalError internalError) {
			throw internalError;
		} catch (Exception exception) {
			logInternalError(exception);
		}
	}
125150
public static function with( $with, $callback = null ) 
	{	
		if ( !is_array( $with ) )
		{
			$with = array( $with );
		}
		
		$settings = static::_model();
		
		$query = DB::select( $settings['table'] );
		
		// run the callback
		if ( !is_null( $callback ) )
		{
			call_user_func_array( $callback, array( &$query ) );
		}
		
		// alway group the result and fetch assoc
		$query->forward_key( $settings['primary_key'] );
		$query->fetch_arguments = array( 'assoc' );
		
		// get the main result set
		$results = static::assign( $query->run() );
		$singleton = false;
		
		if ( !is_array( $results ) )
		{
			$results = array( $results );
			$singleton = true;
		}
		
		$ref_object = reset( $results );
		
		// we have to sort the relationships to make sure that
		// select the relations in the right order.	
		asort( $with );
		
		foreach( $with as $relation => $callback )
		{
			if ( is_int( $relation ) && is_string( $callback ) )
			{
				$relation = $callback;
				$callback = null;
			}
			
			if ( strpos( $relation, '.' ) !== false )
			{	
				$relation_layers = explode( '.', $relation );
				
				$relation_name = array_pop( $relation_layers );
				
				$relation_collection = array();
				
				foreach( $results as $key => &$item )
				{
					$curr_item = $item;
					
					foreach( $relation_layers as $layer )
					{
						$curr_item = $curr_item->raw( $layer );
					}
					
					$relation_collection[] = $curr_item;
				}
				
				$ref_object = reset( $relation_collection );
				
				$relation_object = call_user_func( array( $ref_object, $relation_name ) );
				if ( $relation_object instanceof Model_Relation )
				{
					$relation_object->collection_assign( $relation_name, $relation_collection, $callback );
				}
			}
			else
			{
				$relation_object = call_user_func( array( $ref_object, $relation ) );
				if ( $relation_object instanceof Model_Relation )
				{
					$relation_object->collection_assign( $relation, $results, $callback );
				}
				
			}
		}
		
		if ( $singleton )
		{
			return reset( $results );
		}
		
		// and assign
		return $results;
	}
1129603
public function getArgInfoName(ClassDefinition $classDefinition = null)
    {
        if (null != $classDefinition) {
            return sprintf(
                'arginfo_%s_%s_%s',
                strtolower($classDefinition->getCNamespace()),
                strtolower($classDefinition->getName()),
                strtolower($this->getName())
            );
        }

        return sprintf('arginfo_%s', strtolower($this->getInternalName()));
    }
574718
public static function teacherToString($arrTeacher,$long = true) {
		if($long == true) {
			switch ($arrTeacher['gender']) {
				case 'female': $strName = $GLOBALS['TL_LANG']['MSC']['mrs']; break;
				case 'male': $strName = $GLOBALS['TL_LANG']['MSC']['mr']; break;
				default: $strName = '';
			}
			if (TL_MODE == 'BE') {
				$strName .= ' ' . substr($arrTeacher['firstname'], 0, 1) . '.';
			}
			$strName .= ' ';
		}
		else $strName = '';
		
		$strName .= $arrTeacher['lastname'];
		return $strName;
	}
273074
public function getHas(string $relation, array $where = [], array $with = [], int $hasAtLeast = 1)
    {
        $query = $this->make($with);

        $query = $this->applyWhere($query, $where);

        return $query->has($relation, '>=', $hasAtLeast)->get();
    }
541677
protected function getRequiredUseClasses(array $fields, $withAuth)
    {
        $commands = [];
        if ($withAuth) {
            $commands[] = $this->getUseClassCommand('Auth');
        }

        foreach ($fields as $field) {
            // Extract the name spaces fromt he custom rules
            $customRules = $this->extractCustomValidationRules($field->getValidationRule());
            $namespaces = $this->extractCustomValidationNamespaces($customRules);
            foreach ($namespaces as $namespace) {
                $commands[] = $this->getUseClassCommand($namespace);
            }
        }

        usort($commands, function ($a, $b) {
            return strlen($a) - strlen($b);
        });

        return implode(PHP_EOL, array_unique($commands));
    }
316705
public static function fromMethod(
        string $method,
        string $class = null,
        bool $withParents = false
    ): array
    {
        if ($class) {

            try {

                $refMethod = new \ReflectionMethod($class, $method);
            }
            catch (\ReflectionException $e) {

                throw new Exception(
                    "Method '{$class}::{$method}' not found.",
                    Exception::METHOD_NOT_FOUND
                );
            }
        }
        else {

            try {

                $refMethod = new \ReflectionMethod($method);
            }
            catch (\ReflectionException $e) {

                throw new Exception(
                    "Method '{$method}' not found.",
                    Exception::METHOD_NOT_FOUND
                );
            }
        }

        $docComment = $refMethod->getDocComment();

        if ($withParents) {

            $refClass = $refMethod->getDeclaringClass();

            while (1) {

                if ($refClass = $refClass->getParentClass()) {

                    try {

                        $refMethod = $refClass->getMethod($method);
                    }
                    catch (\ReflectionException $e) {

                        break;
                    }

                    if (!$refMethod) {

                        continue;
                    }

                    if ($parentDoc = $refMethod->getDocComment()) {

                        $docComment = $docComment === false ?
                            $parentDoc :
                            "{$parentDoc}{$docComment}";
                    }
                }
                else {

                    break;
                }
            }
        }

        unset($refMethod, $refClass);

        if ($docComment === false) {

            return [];
        }

        return Parser::parseDocComment($docComment);
    }
526068
public function getPathByClass($class, $with_app_namespace = true)
    {
        $class_path = str_replace('\\', DS, $class);
        $class_path = str_replace('_', DS, $class_path) . '.php';

        foreach ($this->app->config('directory.apps') as $app) {
            $file = ($with_app_namespace ? $app['root'] : $app['dir']) . DS . $class_path;
            $file = new FileSystem\File($file);
            if ($file->isExists()) return $file;
        }
        return null;
    }
1237907
protected function getAffirmMethod($withFormRequest, array $fields, $requestNamespace, $input)
    {
        if ($withFormRequest || Helpers::isNewerThanOrEqualTo('5.5')) {
            return '';
        }

        $stub = $this->getStubContent('controller-affirm-method');

        $this->replaceValidationRules($stub, $this->getValidationRules($fields))
            ->replaceFileValidationSnippet($stub, $this->getFileValidationSnippet($fields, $input, $this->requestVariable))
            ->replaceRequestFullName($stub, $requestNamespace);

        return $stub;
    }
416511
public function get_course_formatted_name($course, $options = array()) {
        $options = (array)$options;
        if (!isset($options['context'])) {
            $options['context'] = context_course::instance($course->id);
        }
        $name = format_string(get_course_display_name_for_list($course), true, $options);
        if (!empty($this->searchcriteria['search'])) {
            $name = highlight($this->searchcriteria['search'], $name);
        }
        return $name;
    }