Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Frozennode/Administrator/Actions/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public function getByName($name, $global = false)
public function getActions($override = false)
{
//make sure we only run this once and then return the cached version
if (!sizeof($this->actions) || $override) {
if (empty($this->actions) || $override) {
$this->actions = array();

//loop over the actions to build the list
Expand All @@ -194,7 +194,7 @@ public function getActions($override = false)
public function getActionsOptions($override = false)
{
//make sure we only run this once and then return the cached version
if (!sizeof($this->actionsOptions) || $override) {
if (empty($this->actionsOptions) || $override) {
$this->actionsOptions = array();

//loop over the actions to build the list
Expand All @@ -216,7 +216,7 @@ public function getActionsOptions($override = false)
public function getGlobalActions($override = false)
{
//make sure we only run this once and then return the cached version
if (!sizeof($this->globalActions) || $override) {
if (empty($this->globalActions) || $override) {
$this->globalActions = array();

//loop over the actions to build the list
Expand All @@ -238,7 +238,7 @@ public function getGlobalActions($override = false)
public function getGlobalActionsOptions($override = false)
{
//make sure we only run this once and then return the cached version
if (!sizeof($this->globalActionsOptions) || $override) {
if (empty($this->globalActionsOptions) || $override) {
$this->globalActionsOptions = array();

//loop over the global actions to build the list
Expand All @@ -260,7 +260,7 @@ public function getGlobalActionsOptions($override = false)
public function getActionPermissions($override = false)
{
//make sure we only run this once and then return the cached version
if (!sizeof($this->actionPermissions) || $override) {
if (empty($this->actionPermissions) || $override) {
$this->actionPermissions = array();
$model = $this->config->getDataModel();
$options = $this->config->getOption('action_permissions');
Expand Down
10 changes: 5 additions & 5 deletions src/Frozennode/Administrator/DataTable/Columns/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function parseOptions($name, $options)
public function getColumns()
{
//make sure we only run this once and then return the cached version
if (!sizeof($this->columns)) {
if (empty($this->columns)) {
foreach ($this->config->getOption('columns') as $name => $options) {
//if only a string value was supplied, may sure to turn it into an array
$object = $this->make($this->parseOptions($name, $options));
Expand All @@ -219,7 +219,7 @@ public function getColumns()
public function getColumnOptions()
{
//make sure we only run this once and then return the cached version
if (!sizeof($this->columnOptions)) {
if (empty($this->columnOptions)) {
foreach ($this->getColumns() as $column) {
$this->columnOptions[] = $column->getOptions();
}
Expand All @@ -238,7 +238,7 @@ public function getColumnOptions()
public function getIncludedColumns(array $fields)
{
//make sure we only run this once and then return the cached version
if (!sizeof($this->includedColumns)) {
if (empty($this->includedColumns)) {
$model = $this->config->getDataModel();

foreach ($this->getColumns() as $column) {
Expand Down Expand Up @@ -273,7 +273,7 @@ public function getIncludedColumns(array $fields)
public function getRelatedColumns()
{
//make sure we only run this once and then return the cached version
if (!sizeof($this->relatedColumns)) {
if (empty($this->relatedColumns)) {
foreach ($this->getColumns() as $column) {
if ($column->getOption('is_related')) {
$this->relatedColumns[$column->getOption('column_name')] = $column->getOption('column_name');
Expand All @@ -292,7 +292,7 @@ public function getRelatedColumns()
public function getComputedColumns()
{
//make sure we only run this once and then return the cached version
if (!sizeof($this->computedColumns)) {
if (empty($this->computedColumns)) {
foreach ($this->getColumns() as $column) {
if (!$column->getOption('is_related') && $column->getOption('is_computed')) {
$this->computedColumns[$column->getOption('column_name')] = $column->getOption('column_name');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public function build()
$this->tablePrefix = $this->db->getTablePrefix();
$nested = $this->getNestedRelationships($options['relationship']);

$relevantName = $nested['pieces'][sizeof($nested['pieces']) - 1];
$relevantModel = $nested['models'][sizeof($nested['models']) - 2];
$relevantName = $nested['pieces'][!empty($nested['pieces']) - 1];

@JimChenWYU JimChenWYU Mar 27, 2018

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think it can simply replace sizeof with !empty here, it need a number to calculate, not a boolean value.

$relevantModel = $nested['models'][!empty($nested['models']) - 2];
$options['nested'] = $nested;

$relationship = $relevantModel->{$relevantName}();
Expand All @@ -56,7 +56,7 @@ public function getNestedRelationships($name)
{
$pieces = explode('.', $name);
$models = array();
$num_pieces = sizeof($pieces);
$num_pieces = !empty($pieces);

//iterate over the relationships to see if they're all valid
foreach ($pieces as $i => $rel) {
Expand Down Expand Up @@ -89,7 +89,7 @@ public function filterQuery(&$selects)
$joins = $where = '';
$columnName = $this->getOption('column_name');
$nested = $this->getOption('nested');
$num_pieces = sizeof($nested['pieces']);
$num_pieces = !empty($nested['pieces']);

//if there is more than one nested relationship, we need to join all the tables
if ($num_pieces > 1) {
Expand Down
12 changes: 6 additions & 6 deletions src/Frozennode/Administrator/Fields/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public function findFilter($field)
*/
public function getEditFields($loadRelationships = true, $override = false)
{
if (!sizeof($this->editFields) || $override) {
if (empty($this->editFields) || $override) {
$this->editFields = array();

//iterate over each supplied edit field
Expand Down Expand Up @@ -453,7 +453,7 @@ public function getFilters()
$configFilters = $this->config->getOption('filters');

//make sure that the filters array hasn't been created before and that there are supplied filters in the config
if (!sizeof($this->filters) && $configFilters) {
if (empty($this->filters) && $configFilters) {
//iterate over the filters and create field objects for them
foreach ($configFilters as $name => $filter) {
if ($fieldObject = $this->make($name, $filter)) {
Expand All @@ -473,7 +473,7 @@ public function getFilters()
*/
public function getFiltersArrays()
{
if (!sizeof($this->filtersArrays)) {
if (empty($this->filtersArrays)) {
foreach ($this->getFilters() as $name => $filter) {
$this->filtersArrays[$name] = $filter->getOptions();
}
Expand Down Expand Up @@ -548,7 +548,7 @@ public function updateRelationshipOptions($field, $type, $constraints, $selected

//if this is an autocomplete field, check if there is a search term. If not, just return the selected items
if ($fieldObject->getOption('autocomplete') && !$term) {
if (sizeof($selectedItems)) {
if (!empty($selectedItems)) {
$this->filterQueryBySelectedItems($query, $selectedItems, $fieldObject, $relatedKeyTable);

return $this->formatSelectOptions($fieldObject, $query->get());
Expand Down Expand Up @@ -653,11 +653,11 @@ public function applyConstraints($constraints, EloquentBuilder &$query, Field $f
{
$configConstraints = $fieldObject->getOption('constraints');

if (sizeof($configConstraints)) {
if (!empty($configConstraints)) {
//iterate over the config constraints
foreach ($configConstraints as $key => $relationshipName) {
//now that we're looping through the constraints, check to see if this one was supplied
if (isset($constraints[$key]) && $constraints[$key] && sizeof($constraints[$key])) {
if (isset($constraints[$key]) && $constraints[$key] && !empty($constraints[$key])) {
//first we get the other model and the relationship field on it
$model = $this->config->getDataModel();
$relatedModel = $model->{$fieldObject->getOption('field_name')}()->getRelated();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function setUpConstraints(&$options)
$model = $this->config->getDataModel();

//set up and check the constraints
if (sizeof($constraints)) {
if (!empty($constraints)) {
$validConstraints = array();

//iterate over the constraints and only include the valid ones
Expand Down
6 changes: 3 additions & 3 deletions tests/DataTable/Columns/Relationships/BelongsToTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function testGetNestedRelationshipsSingle()

$this->assertEquals($nested['pieces'], array($name));
$this->assertEquals($nested['models'][0], $stub);
$this->assertEquals(sizeof($nested['models']), 2);
$this->assertEquals(!empty($nested['models']), 2);
}

public function testGetNestedRelationshipsNest()
Expand All @@ -119,7 +119,7 @@ public function testGetNestedRelationshipsNest()

$this->assertEquals($nested['pieces'], array('bt', 'btnest'));
$this->assertEquals($nested['models'][0], $stub);
$this->assertEquals(sizeof($nested['models']), 3);
$this->assertEquals(!empty($nested['models']), 3);
}

public function testGetNestedRelationshipsDeepNest()
Expand All @@ -131,7 +131,7 @@ public function testGetNestedRelationshipsDeepNest()

$this->assertEquals($nested['pieces'], array('bt', 'btnest', 'btdeepnest'));
$this->assertEquals($nested['models'][0], $stub);
$this->assertEquals(sizeof($nested['models']), 4);
$this->assertEquals(!empty($nested['models']), 4);
}

/**
Expand Down