Ublaboo\DataGrid\DataModel::__construct PHP Method

__construct() public method

public __construct ( Ublaboo\DataGrid\DataSource\IDataSource | array | DibiFluen\DibiFluent | Selection | Doctrine\ORM\QueryBuilder | Doctrine\Common\Collections\Collection $source, string $primary_key )
$source Ublaboo\DataGrid\DataSource\IDataSource | array | DibiFluen\DibiFluent | Nette\Database\Table\Selection | Doctrine\ORM\QueryBuilder | Doctrine\Common\Collections\Collection
$primary_key string
    public function __construct($source, $primary_key)
    {
        if ($source instanceof IDataSource || $source instanceof ApiDataSource) {
            /**
             * Custom user datasource is ready for use
             *
             * $source = $source;
             */
        } else {
            if (is_array($source)) {
                $source = new DataSource\ArrayDataSource($source);
            } else {
                if ($source instanceof DibiFluent) {
                    $driver = $source->getConnection()->getDriver();
                    if ($driver instanceof DibiOdbcDriver) {
                        $source = new DataSource\DibiFluentMssqlDataSource($source, $primary_key);
                    } else {
                        if ($driver instanceof DibiMsSqlDriver) {
                            $source = new DataSource\DibiFluentMssqlDataSource($source, $primary_key);
                        } else {
                            $source = new DataSource\DibiFluentDataSource($source, $primary_key);
                        }
                    }
                } else {
                    if ($source instanceof Selection) {
                        $driver = NetteDatabaseSelectionHelper::getDriver($source);
                        if ($driver instanceof NDBDrivers\MsSqlDriver || $driver instanceof NDBDrivers\SqlsrvDriver) {
                            $source = new DataSource\NetteDatabaseTableMssqlDataSource($source, $primary_key);
                        } else {
                            $source = new DataSource\NetteDatabaseTableDataSource($source, $primary_key);
                        }
                    } else {
                        if ($source instanceof QueryBuilder) {
                            $source = new DataSource\DoctrineDataSource($source, $primary_key);
                        } else {
                            if ($source instanceof Collection) {
                                $source = new DataSource\DoctrineCollectionDataSource($source, $primary_key);
                            } elseif ($source instanceof ICollection) {
                                $source = new DataSource\NextrasDataSource($source, $primary_key);
                            } else {
                                throw new DataGridWrongDataSourceException(sprintf("DataGrid can not take [%s] as data source.", is_object($source) ? get_class($source) : 'NULL'));
                            }
                        }
                    }
                }
            }
        }
        $this->data_source = $source;
    }