Get Comparison Field

@param $parameters
@return null
@throws ComparisonFieldIsRequiredException
164696
protected function getComparisonField($parameters)
    {
        $comparisonField = isset($parameters[0]) ? $parameters[0] : null;

        if (empty($comparisonField)) {
            throw new ComparisonFieldIsRequiredException('Comparison field is missing');
        }

        return $comparisonField;
    }
483695
protected static function getRequestRelationships($parameters)
    {
        //work with objects
        if (!is_object($parameters) && is_array($parameters)) {
            $parameters = (object) $parameters;
        }

        //Require data
        Request::requireParameters($parameters, ['data']);

        //Require data['relationships']
        if (isset($parameters->data->relationships)) {
            return (object) $parameters->data->relationships;
        } else {
            return new \stdClass();
        }
    }
1110852
public function getSdkCommand($parameters = [])
    {
        if ($this instanceof Query) {
            return parent::getSdkCommand($parameters);
        }

        if (isset($parameters['TotalSegments'])) {
            $segments = $parameters['TotalSegments'];
        } elseif (isset($this->parameters['TotalSegments'])) {
            $segments = $this->parameters['TotalSegments'];
        }

        if (isset($segments)) {
            $commands = [];
            for ($i = 0; $i < $segments; $i++) {
                $commandParams            = $parameters;
                $commandParams['Segment'] = $i;
                $commands[]               = parent::getSdkCommand($commandParams);
            }

            return $commands;
        }

        return parent::getSdkCommand($parameters);
    }
1159580
public static function getCustomFields($parameters)
    {
        // get custom fields
        $customFields   = CustomField::getRecords([
            'lang_026'      => $parameters['lang'],
            'group_id_026'  => $parameters['customFieldGroup']
        ]);

        if($parameters['object'])
        {
            if(!empty($parameters['action']) && $parameters['action'] == 'storeLang')
                // if is a new object translated
                $langFieldResults = base_lang2()->id_001;
            else
                $langFieldResults = $parameters['lang'];

            // get results if there is a object
            $customFieldResults = CustomFieldResult::where('lang_id_028', $langFieldResults)
                ->where('object_id_028', $parameters['object'])
                ->where('resource_id_028', $parameters['resource'])
                ->get();
        }

        $html = '';
        foreach($customFields as $customField)
        {
            $setValue = isset($customFieldResults) && $customFieldResults->where('field_id_028', $customField->id_026)->count() > 0;

            // add suffix '_custom' to avoid conflict with other field names
            if(collect(config('pulsar.fieldTypes'))->keyBy('id')[$customField->field_type_id_026]->key == 'selectMultiple' || collect(config('pulsar.fieldTypes'))->keyBy('id')[$customField->field_type_id_026]->key == 'selectMultiple2')
            {
                // TODO: se pueden coger todos los valores antes del foreach para evitar multiples consultas
                $customFieldValues = $customField
                    ->getValues()
                    ->where('lang_id_027', base_lang2()->id_001)
                    ->get();
                
                $multipleSelectValue = null;

                if($setValue)
                {
                    if(collect(config('pulsar.dataTypes'))->keyBy('id')[$customField->data_type_id_026]->type == 'array')
                    {
                        $multipleSelectValue = $customFieldResults
                            ->where('field_id_028', $customField->id_026)
                            ->first()
                            ->value_028;
                    }
                    else
                    {
                        $multipleSelectValue = $customFieldResults
                            ->where('field_id_028', $customField->id_026)
                            ->pluck('value_028')
                            ->toArray();
                    }
                }

                // check if is select2 plugin
                $isSelect2 = collect(config('pulsar.fieldTypes'))->keyBy('id')[$customField->field_type_id_026]->key == 'selectMultiple2';

                $html .= view(collect(config('pulsar.fieldTypes'))->keyBy('id')[$customField->field_type_id_026]->view, ['label' => $customField['label_026'],'name' => $customField['name_026'] . '_custom[]', 'fieldSize' => empty($customField['field_size_026'])? 10 : $customField['field_size_026'], 'objects' => $customFieldValues, 'idSelect' => 'id_027', 'nameSelect' => 'name_027', 'required' => $customField->required_026, 'class' => $isSelect2? 'select2' : null, 'id' => $customField['name_026'] . '_custom', 'multiple' => true, 'data' => $isSelect2? ['language' => config('app.locale'), 'width' => '100%', 'error-placement' => 'select2-' . $customField['name_026'] . '_custom' . '-outer-container'] : null, 'value' => $setValue? $multipleSelectValue : null])->render();
            }
            elseif(collect(config('pulsar.fieldTypes'))->keyBy('id')[$customField->field_type_id_026]->key == 'select' || collect(config('pulsar.fieldTypes'))->keyBy('id')[$customField->field_type_id_026]->key == 'select2')
            {
                $customFieldValues      = $customField->getValues()->where('lang_id_027', base_lang2()->id_001)->get();

                // check if is select2 plugin
                $isSelect2 = collect(config('pulsar.fieldTypes'))->keyBy('id')[$customField->field_type_id_026]->key == 'select2';

                $html .= view(collect(config('pulsar.fieldTypes'))->keyBy('id')[$customField->field_type_id_026]->view, ['label' => $customField['label_026'], 'name' => $customField['name_026'] . '_custom', 'fieldSize' => empty($customField['field_size_026'])? 10 : $customField['field_size_026'], 'objects' => $customFieldValues, 'idSelect' => 'id_027', 'nameSelect' => 'name_027', 'required' => $customField->required_026, 'class' => $isSelect2? 'select2' : null, 'id' => $customField['name_026'] . '_custom', 'data' => $isSelect2? ['language' => config('app.locale'), 'width' => '100%', 'error-placement' => 'select2-' . $customField['name_026'] . '_custom' . '-outer-container'] : null, 'value' => $setValue? $customFieldResults->where('field_id_028', $customField->id_026)->first()->value_028 : null])->render();
            }
            elseif(collect(config('pulsar.fieldTypes'))->keyBy('id')[$customField->field_type_id_026]->key == 'checkbox')
            {
                $html .= view(collect(config('pulsar.fieldTypes'))->keyBy('id')[$customField->field_type_id_026]->view, ['label' => $customField['label_026'], 'name' => $customField['name_026'] . '_custom', 'fieldSize' => empty($customField['field_size_026'])? 10 : $customField['field_size_026'], 'required' => $customField->required_026, 'checked' => $setValue? $customFieldResults->where('field_id_028', $customField->id_026)->first()->value_028 : null])->render();
            }
            else
            {
                $html .= view(collect(config('pulsar.fieldTypes'))->keyBy('id')[$customField->field_type_id_026]->view, ['label' => $customField['label_026'], 'name' => $customField['name_026'] . '_custom', 'fieldSize' => empty($customField['field_size_026'])? 10 : $customField['field_size_026'], 'required' => $customField->required_026, 'value' => $setValue? $customFieldResults->where('field_id_028', $customField->id_026)->first()->value_028 : null])->render();
            }
        }

        return $html;
    }
424195
public function getParameter($parameter)
    {
        $param_array = $this->getParameters();

        if (!empty($param_array) && array_key_exists($parameter, $param_array)) {
            return $param_array[$parameter];
        } else {
            throw new \Exception('UNKNOWN_PARAMETER');
        }
    }
1307469
public static function listAllOptionValuesAsync(array $parameters = [])
    {
        return self::listAllOptionValuesAsyncWithHttpInfo($page, $size, $sort)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }
45740
protected function SelectByRole($Parameters) {
      if (!is_array($Parameters)) {
         $RoleID = $Parameters;
      } else {
         $RoleID = GetValue('RoleID', $Parameters, NULL);
      }
      
      // Lookup role name -> roleID
      if (is_string($RoleID)) {
         $RoleModel = new RoleModel();
         $Roles = explode(',', $RoleID);
         $RoleID = array();
         foreach ($Roles as $TestRoleID) {
            $TestRoleID = trim($TestRoleID);
            $Role = $RoleModel->GetByName($TestRoleID);
            if (!$Role) {
               continue;
            } else {
               $Role = array_shift($Role);
               $RoleID[] = GetValue('RoleID', $Role);
            }
         }
      }
      
      if (empty($RoleID) || !sizeof($RoleID)) return FALSE;
      
      // Check cache
      $SelectorRoleCacheKey = "modules.promotedcontent.role.{$RoleID}";
      $Content = Gdn::Cache()->Get($SelectorRoleCacheKey);
      
      if ($Content == Gdn_Cache::CACHEOP_FAILURE) {
      
         // Get everyone with this Role
         $UserIDs = Gdn::SQL()->Select('ur.UserID')
            ->From('UserRole ur')
            ->Where('ur.RoleID', $RoleID)
            ->GroupBy('UserID')
            ->Get()->Result(DATASET_TYPE_ARRAY);
         $UserIDs = ConsolidateArrayValuesByKey($UserIDs, 'UserID');
         
         // Get matching Discussions
         $Discussions = Gdn::SQL()->Select('d.*')
            ->From('Discussion d')
            ->WhereIn('d.InsertUserID', $UserIDs)
            ->OrderBy('DateInserted', 'DESC')
            ->Limit($this->Limit)
            ->Get()->Result(DATASET_TYPE_ARRAY);

         // Get matching Comments
         $Comments = Gdn::SQL()->Select('c.*')
            ->From('Comment c')
            ->WhereIn('InsertUserID', $UserIDs)
            ->OrderBy('DateInserted', 'DESC')
            ->Limit($this->Limit)
            ->Get()->Result(DATASET_TYPE_ARRAY);
         
         $this->JoinCategory($Comments);
         
         // Interleave
         $Content = $this->Union('DateInserted', array(
            'Discussion'   => $Discussions, 
            'Comment'      => $Comments
         ));
         $this->Prepare($Content);
         
         // Add result to cache
         Gdn::Cache()->Store($SelectorRoleCacheKey, $Content, array(
            Gdn_Cache::FEATURE_EXPIRY  => $this->Expiry
         ));
      }
      
      $this->Security($Content);
      $this->Condense($Content, $this->Limit);
      return $Content;
   }
1192033
public function getPath($parameters = null)
    {
        if (empty($parameters) || !is_array($parameters) || empty($this->patternString)) {
            return $this->path;
        }

        //If an array of parameters is specified and a pattern string exists, we can build a path for the route
        $pattern = $this->patternString;
        foreach ($parameters as $parameterName => $parameterValue) {
            $pattern = preg_replace('#\[?\{[^:]+:' . preg_quote($parameterName, '#') . '\}\]?#', $parameterValue, $pattern);
        }

        //Delete remaining unmatched parameters
        $pattern = preg_replace('#\/\[?\{[^}]+\}\]?#', '', $pattern);

        return $this->path . $pattern;
    }
164695
public function validateBeforeOrEqual($attribute, $value, $parameters)
    {
        $this->requireParameterCount(1, $parameters, 'before_or_equal');

        return $this->compareDates($attribute, $value, $parameters, '<=');
    }
1290657
private static function compareParameters(\ReflectionParameter $a, \ReflectionParameter $b) : int
    {
        if (0 !== $result = self::compareParameterClasses($a, $b)) {
            return $result;
        }

        if ($a->isArray() ^ $b->isArray()) {
            return $b->isArray() << 1 - 1;
        }

        if ($a->isCallable() ^ $b->isCallable()) {
            return $b->isCallable() << 1 - 1;
        }

        return $a->getPosition() - $b->getPosition();
    }
1133415
public static function findFirst($parameters = null)
    {
        $result = parent::findFirst($parameters);

        if ($result) {
            $customFields = $result->getAllCustomFields();

            if (is_array($customFields)) {
                //field the object
                foreach ($result->getAllCustomFields() as $key => $value) {
                    $result->{$key} = $value;
                }
            }
        }

        return $result;
    }
1012287
public function neqFieldValidator($val, string $compareField): bool
    {
        return $compareField && ($val !== $this->getByPath($compareField));
    }
30583
public function comparisons()
    {
        if (is_null($this->comparisonRequests)) {
            $this->comparisonRequests = new ComparisonRequests($this->client);
        }

        return $this->comparisonRequests;
    }
241973
protected function parameterValues($parameters)
    {
        $values = array();
        foreach ($parameters as $value) {
            $values[] = is_array($value) ? $value['value'] : $value;
        }
        return $values;
    }
535518
public function requestComparisonStrategy(): ComparisonStrategy {
		if ($this->comparisonStrategy !== null) {
			return $this->comparisonStrategy;
		}
		
		$selectedQueryPoints = array_merge($this->queryModel->getNamedSelectQueryPoints(),
				$this->queryModel->getUnnamedSelectQueryPoints());
		if (1 != count($selectedQueryPoints)) {
			throw new CriteriaConflictException('Subselect not comparable.');
		}
		
		$comparisonStrategy = current($selectedQueryPoints)->requestComparisonStrategy();
		CastUtils::assertTrue($comparisonStrategy instanceof ComparisonStrategy);
		if ($comparisonStrategy->getType() != ComparisonStrategy::TYPE_COLUMN) {
			throw new CriteriaConflictException();
		}
		
		$columnComparable = $comparisonStrategy->getColumnComparable();
		
		$this->queryModel->getQueryItemSelect()->selectQueryItem($columnComparable
				->buildQueryItem(CriteriaComparator::OPERATOR_EQUAL));
		
		$selectBuilder  = $this->queryState->getPdo()->getMetaData()->createSelectStatementBuilder();
		$this->queryModel->apply($selectBuilder);
				
		return $this->comparisonStrategy = new ComparisonStrategy(new CriteriaColumnComparable(
				$selectBuilder->toQueryResult(), $columnComparable));
	}
487489
final public function getQuery(array $parameters = [])
    {
        $parameters = $this->getOptionsResolver()->resolve($parameters);
        $query = $this->buildQuery();

        $sortDefinitions = $parameters['sort'];
        if (!is_array($sortDefinitions)) {
            $sortDefinitions = [$sortDefinitions];
        }

        $query->query = $this->getQueryCriterion($parameters);
        $query->filter = $this->resolveFilterCriteria($parameters);
        $query->facetBuilders = $this->getFacetBuilders($parameters);
        $query->sortClauses = $this->getSortClauses($sortDefinitions);
        $query->limit = $parameters['limit'];
        $query->offset = $parameters['offset'];

        return $query;
    }
1329087
public function get($parameter)
    {
        return isset($this->credentials[$parameter]) ? $this->credentials[$parameter] : null;
    }