@param string $modelName
@param string $primaryModelClass Can be plugin dot syntaxed

@return string
171783
protected function getEntity($modelName, $primaryModelClass) {
		if ($this->getConfig(static::CONFIG_PLUGIN) && $modelName !== $primaryModelClass && !strpos($modelName, '.')) {
			$modelName = $this->getConfig(static::CONFIG_PLUGIN) . '.' . $modelName;
		}

		try {
			$table = TableRegistry::get($modelName);
			$entityClassName = $table->getEntityClass();
		} catch (Exception $exception) {
			return '\Cake\ORM\Entity';
		}

		return $entityClassName;
	}
1331648
public function setModelName($modelName)
    {
        if (0 === strpos($modelName, '\\')) {
            $this->modelName = substr($modelName, 1);
        } else {
            $this->modelName = $modelName;
        }
        if ($this->modelName && !$this->modelTableMapName) {
            $this->modelTableMapName = constant($this->modelName . '::TABLE_MAP');
        }
        if (!$this->tableMap && $this->modelName) {
            $this->tableMap = Propel::getServiceContainer()->getDatabaseMap($this->getDbName())->getTableByPhpName($this->modelName);
        }

        return $this;
    }
359662
public function get($modelName)
    {
        $modelNamespace = Configuration::read('mvc.model.namespace');
        $modelNamespace = $modelNamespace . '\\' . ucFirst($modelName);
        if (!class_exists($modelNamespace)) {
            trigger_error('Model "' . $modelNamespace . '" doesn\'t exist.', E_USER_ERROR);
            return false;
        }
        return new $modelNamespace();
    }
280498
public function modelFactory($modelName) {
        $modelClass = "\\Modules\\" . RouteController::$currentRoute['module'] . "\\Models\\" . $modelName;

        if (class_exists($modelClass)) {
            return new $modelClass(RouteController::$currentRoute);
        } elseif (class_exists("\\Base\\models\\" . $modelName)) {
            $baseModelClass = "\\Base\\models\\" . $modelName;
            return new $baseModelClass(RouteController::$currentRoute);
        } else {
            HookManager::call("handleModel", $modelName);
        }
    }
704360
public function findModel($modelClass, $id)
    {
        if (($model = $modelClass::findOne([$this->pkColumn => $id])) !== null) {
            return $model;
        } else {
            throw new BadRequestHttpException('Entity not found by primary key ' . $id);
        }
    }
895138
public function createPrimary( $model, $config = [] ) {

		$model->type = Address::TYPE_PRIMARY;

		return $this->create( $model, $config );
	}
1073107
public function getModelName($modelName = null)
    {
        $modelName = is_null($modelName) ? $this->argument('name') : $modelName;
        $model_name = ucfirst(class_basename($modelName));
        $plural_model_name = str_plural($model_name);
        $modelPath = $this->getModelPath($modelName);
        $modelNamespace = $this->getModelNamespace($modelPath);

        return $this->modelNames = [
            'model_namespace'           => $modelNamespace,
            'full_model_name'           => $modelNamespace.'\\'.$model_name,
            'plural_model_name'         => $plural_model_name,
            'model_name'                => $model_name,
            'table_name'                => snake_case($plural_model_name),
            'lang_name'                 => snake_case($model_name),
            'collection_model_var_name' => camel_case($plural_model_name),
            'single_model_var_name'     => camel_case($model_name),
            'model_path'                => $modelPath,
        ];
    }
1145438
public function setPrimary($primaryName) {
		if (is_array($primaryName)) {
			$idProperty = self::COMPOSITE_ID_PROPERTY . $this->_collectionId;
			
			foreach ($this->_data as &$dataPart) {
				$dataHashParts = [];
				
				foreach ($primaryName as $keyPart) {
					if (! isset($dataPart[$keyPart])) {
						throw new Exception('Undefined property can\'t been used as a part of a composite primary');
					}
					
					$dataHashParts[] = $dataPart[$keyPart];
				}
				
				$dataPart[$idProperty] = $this->arrayHashFunction($dataHashParts);
			}
			unset($dataPart);
			
			$this->_primaryDefinition = $primaryName;
			
			$primaryName = $idProperty;
		} else {
			$this->_primaryDefinition = $primaryName;
		}
		
		$tempData = $this->_data;
		$this->_data = [];
		
		foreach ($tempData as &$item) {
			if (! isset($item[$primaryName])) {
				throw new Exception('Undefined property can\'t been used as a primary');
			}
			
			$this->_data[$item[$primaryName]] = &$item;
		}
		unset($item, $tempData);
		
		if (! empty($this->_models)) {
			$tempData = $this->_models;
			$this->_models = [];
			
			foreach ($tempData as $item) {
				$this->_models[$item->$primaryName] = $item;
			}
			
			unset($tempData);
		}
		
		$this->_pointer = 0;
		$this->_map     = array_keys($this->_data);
		$this->_primary = $primaryName;
		
		return $this;
	}
12412
public static function createForModelName($modelName)
    {
        if (!class_exists($modelName)) {
            throw new \Parable\ORM\Exception("Model '{$modelName}' does not exist.");
        }
        return self::createForModel($modelName::create());
    }
704128
protected function getParameterModel($paramName, $modelClassName, $requestParams)
    {
        $paramModel = new $modelClassName;

        if (!$paramModel instanceof \yii\base\Model) {
            throw new \yii\base\InvalidParamException("Parameter '{$paramName}' must be instance of \yii\base\Model");
        }

        if (in_array($this->scenario, $paramModel->scenarios())) {
            $paramModel->scenario = $this->scenario;
            $paramModel->setAttributes($requestParams[$paramName], true);
        } else {
            $paramModel->setAttributes($requestParams[$paramName], false);
        }

        if (!$paramModel->validate()) {
            throw new ValidationException('Invalid JSON-RPC request parameters.', 0, $paramModel->getErrors());
        }

        return $paramModel;
    }
996674
private function addDatatableFields($modelName, $modelData)
    {
        $fields = '';
        $firstIteration = true;

        foreach ($modelData->fields as $field)
        {
            if ($field->hideInListings === false)
            {
                if ($firstIteration)
                {
                    $fields .= sprintf("{ data: '%s', name: '%s' }," . PHP_EOL, $field->name, $field->name);
                    $firstIteration = false;
                }
                else
                {
                    $fields .= sprintf($this->tab(4) . "{ data: '%s', name: '%s' }," . PHP_EOL, $field->name, $field->name);
                }
            }
        }

        $this->stub = str_replace('{{datatable_fields}}', $fields, $this->stub);
        $this->stub = str_replace('{{datatable_url}}', ucfirst($modelName), $this->stub);

        return $this;
    }
433567
public function results($modelName)
    {
        $dataTable = app('admin_datatable');

        //get the sort options and filters
        $page        = $this->request->input('page', 1);
        $sortOptions = $this->request->input('sortOptions', array());
        $filters     = $this->request->input('filters', array());

        //return the rows
        return response()->json($dataTable->getRows(app('db'), $filters, $page, $sortOptions));
    }
927648
public function customModelAction($modelName)
	{
		$config = app('itemconfig');
		$actionFactory = app('admin_action_factory');
		$actionName = $this->request->input('action_name', false);
		$dataTable = app('admin_datatable');

		//get the sort options and filters
		$page = $this->request->input('page', 1);
		$sortOptions = $this->request->input('sortOptions', array());
		$filters = $this->request->input('filters', array());

		//get the prepared query options
		$prepared = $dataTable->prepareQuery(app('db'), $page, $sortOptions, $filters);

		//get the action and perform the custom action
		$action = $actionFactory->getByName($actionName, true);
		$result = $action->perform($prepared['query']);

		//if the result is a string, return that as an error.
		if (is_string($result))
		{
			return response()->json(array('success' => false, 'error' => $result));
		}
		//if it's falsy, return the standard error message
		else if (!$result)
		{
			$messages = $action->getOption('messages');

			return response()->json(array('success' => false, 'error' => $messages['error']));
		}
		else
		{
			$response = array('success' => true);

			//if it's a download response, flash the response to the session and return the download link
			if (is_a($result, 'Symfony\Component\HttpFoundation\BinaryFileResponse'))
			{
				$file = $result->getFile()->getRealPath();
				$headers = $result->headers->all();
				$this->session->put('administrator_download_response', array('file' => $file, 'headers' => $headers));

				$response['download'] = route('admin_file_download');
			}
			//if it's a redirect, put the url into the redirect key so that javascript can transfer the user
			else if (is_a($result, '\Illuminate\Http\RedirectResponse'))
			{
				$response['redirect'] = $result->getTargetUrl();
			}

			return response()->json($response);
		}
	}
302757
public static function modelAlias($className = null)
    {
        if (is_null($className)) {
            $className = get_called_class();
        } elseif (is_object($className)) {
            $className = get_class($className);
        }
        if (!strncmp($className, ':', 1)) {
            // already an alias
            return $className;
        }
        $class = new ReflectionClass($className);
        if ($class->getNamespaceName() === 'app\models') {
            return ':app\\' . $class->getShortName();
        } elseif (($alias = array_search($class->getNamespaceName(), Yii::$app->modelAliases)) !== false) {
            return $alias . '\\' . $class->getShortName();
        }

        return $className;
    }
1006192
public function findByParam($modelName, $param)
    {
        /**
         * @var ModelStorageDecorator $storedModel
         */
        foreach ($this->storage as $key => $storedModel) {
            if ($modelName != get_class($storedModel)) {
                continue;
            }

            if ($this->containsParam($storedModel, $param)) {
                return $storedModel->getModel();
            }
        }

        return null;
    }
386124
public function afterFind(Model $model, $results, $primary = true) {
        $alias = $model->alias;

        if (!$this->format || ($model->id && !$this->onUpdate) || empty($this->_enums[$alias])) {
            return $results;
        }

        if ($results) {
            $enum = $this->_enums[$alias];

            foreach ($results as &$result) {
                foreach ($enum as $key => $nop) {
                    if (isset($result[$alias][$key])) {
                        $value = $result[$alias][$key];

                        if ($this->format === self::REPLACE) {
                            $result[$alias][$key] = $this->enum($model, $key, $value);

                            if ($this->persist) {
                                $result[$alias][$key . $this->suffix] = $value;
                            }
                        } else if ($this->format === self::APPEND) {
                            $result[$alias][$key . $this->suffix] = $this->enum($model, $key, $value);
                        }
                    }
                }
            }
        }

        return $results;
    }
1285528
private function saveModelTable($tableName, $modelClass) {
        $modelTables = array();
        $mt = DATA . 'mapper' . DIRECTORY_SEPARATOR . '__modelTables.php';
        if (is_readable($mt))
            $modelTables = include $mt;

        if (!$modelTables[$tableName] || ($modelTables[$tableName] && is_a($this, $modelTables[$tableName]))) {
            $modelTables[$tableName] = $modelClass;
            return file_put_contents($mt, '<' . '?php' . "\n\t" . 'return ' . stripslashes(var_export($modelTables, true)) . ";");
        }

        return true;
    }