Returns the dataTable instance for dispaying a list of object

@param array $instances
@param string $model
@param number $totalCount
@param number $page
@return DataTable
498843
protected function getDataTableInstance($instances, $model, $totalCount, $page = 1): DataTable {
		$semantic = $this->jquery->semantic ();
		$recordsPerPage = $this->recordsPerPage ( $model, $totalCount );
		if (is_numeric ( $recordsPerPage )) {
			$grpByFields = $this->getGroupByFields ();
			if (is_array ( $grpByFields )) {
				$dataTable = $semantic->dataTable ( "lv", $model, $instances );
				$dataTable->setGroupByFields ( $grpByFields );
			} else {
				$dataTable = $semantic->jsonDataTable ( "lv", $model, $instances );
			}
			$dataTable->paginate ( $page, $totalCount, $recordsPerPage, 5 );
			$dataTable->onActiveRowChange ( '$("#table-details").html("");' );
			$dataTable->onSearchTerminate ( '$("#search-query-content").html(data);$("#search-query").show();$("#table-details").html("");' );
		} else {
			$dataTable = $semantic->dataTable ( "lv", $model, $instances );
		}
		return $dataTable;
	}
310550
protected function getModelTable($model)
    {
        if (!is_object($model)) {
            $model = new $model;
        }

        return DB::getTablePrefix().$model->getTable();
    }
124676
public function getModelInstanceIfId($instance, $table)
    {
        if ($instance instanceof Model) {
            return $instance;
        }

        if ($instance instanceof Collection) {
            return $instance->current();
        }

        return $this->findModelInstanceByPk($table, $instance);
    }
22061
protected function generateModelInstances($query, $totalCount)
    {
        $chunkSize = $this->getChunkSize();

        $chunkCount = ceil($totalCount / $chunkSize);

        for ($x = 0; $x < $chunkCount; $x++) {

            $skip = $x * $chunkSize;

            yield $query
                ->skip($skip)
                ->take($chunkSize)
                ->get();
        }
    }
942013
protected function _buildInstance($instance, array $parameters = [])
  {
    if(is_scalar($instance) && class_exists($instance))
    {
      return Objects::create($instance, $parameters);
    }
    return $instance;
  }
451383
function generate(model, count) {
  count = count || 1;
  var registry = {};
  var models = [];

  if (model) {
    models = typeof model === 'string' ? [model] : model;
  } else {
    models = Object.keys(schemas);
  }

  function build(model) {
    var instance = jsf(schemas[model]);
    var invalid = validate(instance);
    if (invalid) {
      var errors = JSON.stringify(invalid, null, 2);
      throw new Error('Invalid "' + model + '" instance:\n' + errors);
    }
    return instance;
  }

  function factory(model) {
    var instances = [];
    for (var i = 0, len = count; i < len; i++) {
      var instance = build(model);
      instances.push(instance);
    }
    registry[model] = instances;
  }

  models.forEach(factory);
  return registry;
}
813011
protected function renderExtraRow($model, $key, $index, $totals)
    {
        if ($this->extraRowValue instanceof Closure) {
            $content = call_user_func($this->extraRowValue, $model, $index, $totals);
        } else {
            $values = [];
            foreach ($this->extraRowColumns as $name) {
                $values[] = ArrayHelper::getValue($model, $name);
            }

            $content = '<strong>' . implode(' :: ', $values) . '</strong>';
        }

        $colspan = count($this->columns);

        $cell = Html::tag('td', $content, ['class' => $this->extraRowClass, 'colspan' => $colspan]);

        return Html::tag('tr', $cell);
    }
391414
public function listData($list, $page = 1, $size = 10)
    {
        $reData['totalPages'] = (int)$list->lastPage();
        $reData['totalCount'] = (int)$list->total();
        $reData['page'] = (int)$page;
        $reData['limit'] = (int)$size;
        $reData['count'] = (int)$list->count();

        if ($page == 1) {
            $reData['firstPage'] = true; //是否为首页
            $reData['hasPrePage'] = false; //是否有上一页
            $reData['prePage'] = 0; //上一页的页数
            if ($reData['totalPages'] == 1) {
                $reData['hasNextPage'] = false; //是否有下一页
                $reData['nextPage'] = 0;
            } else {
                $reData['hasNextPage'] = true; //是否有下一页
                $reData['nextPage'] = 2; //下一页的页数
            }
        } else {
            $reData['firstPage'] = false; //是否为首页
            if ($reData['totalPages'] == 1) {
                $reData['hasPrePage'] = false; //是否有上一页
                $reData['hasNextPage'] = false; //是否有下一页
                $reData['prePage'] = 1; //上一页的页数
                $reData['nextPage'] = 0; //下一页的页数
            } elseif ($page < $reData['totalPages']) {
                $reData['hasPrePage'] = true; //是否有上一页
                $reData['hasNextPage'] = true; //是否有下一页
                $reData['prePage'] = $page - 1; //上一页的页数
                $reData['nextPage'] = $page + 1; //下一页的页数
            } else {
                $reData['hasPrePage'] = true; //是否有上一页
                $reData['hasNextPage'] = false; //是否有下一页
                $reData['prePage'] = $page - 1; //上一页的页数
                $reData['nextPage'] = 0; //下一页的页数
            }
        }

        if ($page == $reData['totalPages']) {
            $reData['lastPage'] = true; //是否是最末页
        } else {
            $reData['lastPage'] = false; //是否是最末页
        }

        $reData['data'] = $list->toArray()['data'];

        return $reData;
    }
1172446
public function showPager(int $page = 0, int $total_rows = 0, int $per_page = 0)
    {
        $this->show_pager = true;
        $per_page = $per_page ?? $this->per_page;

        if (isset($_GET['per_page']) && ctype_digit((string)$_GET['per_page'])) {
            $per_page = (int)$_GET['per_page'];
        }

        $this->pager = new TablePager($page, $total_rows, $per_page);

        return $this;
    }
908355
public function import(Page $page, ImportRecordsDataTable $importRecordsDataTable)
    {
        return $importRecordsDataTable->with([
            'resource' => $page,
            'tabs' => 'managerarea.pages.tabs',
            'url' => route('managerarea.pages.stash'),
            'id' => "managerarea-pages-{$page->getRouteKey()}-import-table",
        ])->render('cortex/foundation::managerarea.pages.datatable-dropzone');
    }
943661
private function createCollectionPaginator(Collection $collection, $page, $count)
    {
        return $this->createPaginator(new DoctrineCollectionAdapter($collection), $page, $count);
    }
875709
public function setResult($items, $totalCount = null)
    {
        $this->items = Type::toArray($items);
        $this->totalCount = $totalCount;
        $this->pages = null;
        return $this;
    }
62278
protected function getTotalOfRecordsString(int $totalOfRecords, array $data)
    {
        $show = $data['show'];
        $page = $data['page'];

        $startRecord = 0;
        if (intval($totalOfRecords) > 0) {
            $startRecord = ($show * ($page - 1)) + 1;
        }
        $endRecord = $show * $page;

        if ($endRecord > $totalOfRecords) {
            $endRecord = $totalOfRecords;
        }
        return $this->trans('totalOfRecordsString', [
            '%$startRecord%' => $startRecord,
            '%$endRecord%' => $endRecord,
            '%$totalOfRecords%' => $totalOfRecords,
        ], 'messages');
    }
1212480
final public static function setInstance($instance)
    {
        if ($instance instanceof PDO) {
            $instance = $instance->getAttribute(PDO::ATTR_DRIVER_NAME);
        }
        if (is_string($instance)) {
            if (class_exists('SQL\Writer\\' . $instance)) {
                $class = 'SQL\Writer\\' . $instance ;
                $instance = new $class;
            } else {
                $instance = new self;
            }
        }

        if (!($instance instanceof self)) {
            throw new RuntimeException('$instance must an instanceof SQL\Writer');
        }

        self::$instance = $instance;
    }
1035484
protected function newRowClasses($total, $index, $record)
    {
        $classes = array('ss-gridfield-item');

        if ($index == 0) {
            $classes[] = 'first';
        }

        if ($index == $total - 1) {
            $classes[] = 'last';
        }

        if ($index % 2) {
            $classes[] = 'even';
        } else {
            $classes[] = 'odd';
        }

        $this->extend('updateNewRowClasses', $classes, $total, $index, $record);

        return $classes;
    }
284207
protected function handleGetDefault(Request $request, $model)
    {
        $total = null;
        if (empty($request->id)) {
            if (!empty($request->filter)) {
                $model = $this->handleFilterRequest($request->filter, $model);
            }
            if (!empty($request->sort)) {
                //if sorting AND paginating, get total count before sorting!
                if ($request->pageNumber) {
                    $total = $model->count();
                }
                $model = $this->handleSortRequest($request->sort, $model);
            }
        } else {
            $model = $model->where($model->getKeyName(), '=', $request->id);
        }

        try {
            if ($request->pageNumber && empty($request->id)) {
                $results = $this->handlePaginationRequest($request, $model, $total);
            } else {
                $results = $model->get();
            }
        } catch (\Illuminate\Database\QueryException $e) {
            throw new Exception(
                'Database Request Failed',
                static::ERROR_SCOPE | static::ERROR_UNKNOWN_ID,
                BaseResponse::HTTP_INTERNAL_SERVER_ERROR,
                array('detail' => $e->getMessage())
            );
        }
        return $results;
    }
914006
public function findByIdAndInstanceName($id, $instanceName)
    {
        return $this->getConnection()->table($this->getTableName())
            ->where('id', $id)
            ->where('instance', $instanceName)
            ->first(['id', 'instance', 'content']);
    }