Custom method to find all attached details or by section.

@param Model $model Model to query.
@param string $func
@param string $state Either "before" or "after"
@param array $query
@param array $result
@return array
329708
public function details(Model $Model, $queryData = null, $schema = false, $format = true) {
		$DetailModel = ClassRegistry::init($this->settings[$Model->alias]['alias']);

		if (is_string($queryData)) {
			$queryData = array('section' => $queryData);
		}

		$conditions = array($DetailModel->alias . '.foreign_key' => $Model->getID());
		if (!empty($queryData['section'])) {
			$section = $queryData['section'];
			$conditions[$DetailModel->alias . '.field LIKE'] = $section . '.%';
			unset($queryData['section']);
		}
		if (!empty($queryData['conditions'])) {
			$queryData['conditions'] = Hash::merge($conditions, $queryData['conditions']);
		}

		$fields = array($DetailModel->alias . '.field', $DetailModel->alias . '.value', $DetailModel->alias . '.label', 'foreign_key', 'foreign_model');
		if ($schema) {
			$fields = array($DetailModel->alias . '.field', $DetailModel->alias . '.input', $DetailModel->alias . '.data_type', $DetailModel->alias . '.label');
		}

		$order = array('position' => 'ASC');
		$recursive = -1;

		$results = $DetailModel->find('all', array_merge(compact('conditions', 'fields', 'order', 'recursive'), $queryData));

		return $this->detailsExtractSections($Model, $results, $section, $schema, $format);
	}
466103
public function map(Builder $builder, $results, $model)
    {
        if (is_null($results['ids']) || count($results['ids']) === 0) {
            return Collection::make();
        }

        $keys = collect($results['ids'])->values()->all();

        $builder = $this->getBuilder($model);

        if ($this->builder->queryCallback) {
            call_user_func($this->builder->queryCallback, $builder);
        }

        $models = $builder->whereIn(
            $model->getQualifiedKeyName(), $keys
        )->get()->keyBy($model->getKeyName());

        // sort models by user choice
        if (!empty($this->builder->orders)) {
            return $models->values();
        }

        // sort models by tnt search result set
        return collect($results['ids'])->map(function ($hit) use ($models) {
            if (isset($models[$hit])) {
                return $models[$hit];
            }
        })->filter()->values();
    }
499107
public function afterGetSectionData(\Magento\Customer\CustomerData\Customer $subject, $result)
    {
        $customerId = $subject->currentCustomer->getCustomerId();
        if ($customerId) {
            $customer = $subject->currentCustomer->getCustomer();
            $result['id'] = $customerId;
            $result['email'] = $customer->getEmail();
        }

        return $result;
    }
1300943
private function visitOuterObject(
        Parameter $model,
        ResultInterface $result,
        ResponseInterface $response,
        array &$context
    ) {
        $parentLocation = $model->getLocation();

        // If top-level additionalProperties is a schema, then visit it
        $additional = $model->getAdditionalProperties();
        if ($additional instanceof Parameter) {
            // Use the model location if none set on additionalProperties.
            $location = $additional->getLocation() ?: $parentLocation;
            $result = $this->triggerBeforeVisitor($location, $model, $result, $response, $context);
        }

        // Use 'location' from all individual defined properties, but fall back
        // to the model location if no per-property location is set. Collect
        // the properties that need to be visited into an array.
        $visitProperties = [];
        foreach ($model->getProperties() as $schema) {
            $location = $schema->getLocation() ?: $parentLocation;
            if ($location) {
                $visitProperties[] = [$location, $schema];
                // Trigger the before method on each unique visitor location
                if (!isset($context['visitors'][$location])) {
                    $result = $this->triggerBeforeVisitor($location, $model, $result, $response, $context);
                }
            }
        }

        // Actually visit each response element
        foreach ($visitProperties as $property) {
            $result = $this->responseLocations[$property[0]]->visit($result, $response, $property[1]);
        }

        return $result;
    }
728285
function collectionResultList (context, results) {
    // apply views to each result
    return Promise.each(results, (raw, num) => {
        // get result
        return this.applyModelViewCollection(context, num, raw)
        // merge result to context
        .then(ctx => {
            _.merge(context, ctx)
        })
    })
    // resolve with context
    .then(() => context)
}
415509
public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary) {
		$query->formatResults(function (ResultSetInterface $results) {
			return $results->map(function ($row) {
				$this->processItems($row, 'output');
				return $row;
			});
		});
	}
193391
public function beforeFind(Model $Model, $query) {
		$this->settings[$Model->alias] = $this->modelDefaults[$Model->alias];

		// check if $this->modelDefaultsPersist has been set
		if (isset($this->modelDefaultsPersist[$Model->alias])) {
			// if persist equals equals true
			if (!isset($this->modelDefaults[$Model->alias]['persist']) || $this->modelDefaults[$Model->alias]['persist'] == false) {
				$this->modelDefaults[$Model->alias] = $this->modelDefaultsPersist[$Model->alias];
			}
		}

		if (isset($query['permit']) && isset($this->settings[$Model->alias]['rules'][$query['permit']])) {
			$rules = $this->settings[$Model->alias]['rules'][$query['permit']];
			if (isset($rules['rules'])) {
				unset($rules['rules']);
			}

			$this->settings[$Model->alias] = array_merge($this->settings[$Model->alias], $rules);
		}

		foreach (array('message', 'check', 'value', 'field', 'skip', 'rules') as $key) {
			if (isset($query['permit_' . $key])) {
				$this->settings[$Model->alias][$key] = $query['permit_' . $key];
			}
		}

		return $query;
	}
1230499
protected function getFiltersViewData(DocumentIterator $result, SearchRequest $request)
    {
        $out = [];

        /** @var FilterInterface[] $filters */
        $filters = $this->container->all();

        foreach ($filters as $name => $filter) {
            if ($filter instanceof ViewDataFactoryInterface) {
                $viewData = $filter->createViewData();
            } else {
                $viewData = new ViewData();
            }
            $viewData->setName($name);
            $viewData->setUrlParameters($this->composeUrlParameters($request, $filter));
            $viewData->setState($request->get($name));
            $viewData->setTags($filter->getTags());
            $viewData->setResetUrlParameters($this->composeUrlParameters($request, $filter, [$name]));
            $out[$name] = $filter->getViewData($result, $viewData);
        }

        return $out;
    }
457417
private function _groupBy(&$result, $k, $v, $func)
    {
        if ($v instanceof self) {
            foreach ($v->each() as $kk => $vv) {
                $this->_groupBy($result, $kk, $vv, $func);
            }
        } else {
            $aggregate_key = call_user_func($func, $v, $k);
            $result[$aggregate_key][] = $v;
        }
    }
376134
public function fetch($query, $mode)
    {
        $context = $this->getCommandContext();
        $context->mode = $mode;
        $context->query = $query;
        $context->repository = $query->getRepository();

        if ($this->getCommandChain()->run('before.fetch', $context) !== false) {
            $modes = array(
                    AnDomain::FETCH_ROW => AnDatabase::FETCH_ARRAY,
                    AnDomain::FETCH_ROW_LIST => AnDatabase::FETCH_ARRAY_LIST,
                    AnDomain::FETCH_ENTITY => AnDatabase::FETCH_ARRAY,
                    AnDomain::FETCH_ENTITY_SET => AnDatabase::FETCH_ARRAY_LIST,
                    AnDomain::FETCH_ENTITY_LIST => AnDatabase::FETCH_ARRAY_LIST,
                    AnDomain::FETCH_VALUE => AnDatabase::FETCH_FIELD,
                    AnDomain::FETCH_VALUE_LIST => AnDatabase::FETCH_FIELD_LIST,
            );

            $mode = $modes[$mode];

            $context['data'] = $this->_adapter->select(to_str($query), $mode);

            $this->getCommandChain()->run('after.fetch', $context);
        }

        return $context->data;
    }
146917
protected function parse($old, $query, Model $model, &$transformed)
    {
        $key = $old;
        $value = $model->$old;

        foreach (explode('|', $query) as $command) {
            list($function, $args) = explode(':', $command);

            $args = array_merge([&$key, &$value, $model], explode(',', $args));

            call_user_func_array([$this, $function], $args);
        }

        return $transformed[$key] = $value;
    }
833509
private function triggerBeforeVisitor(
        $location,
        Parameter $model,
        ResultInterface $result,
        ResponseInterface $response,
        array &$context
    ) {
        if (!isset($this->responseLocations[$location])) {
            throw new \RuntimeException("Unknown location: $location");
        }

        $context['visitors'][$location] = $this->responseLocations[$location];

        $result = $this->responseLocations[$location]->before(
            $result,
            $response,
            $model
        );

        return $result;
    }
271359
protected function loadField($modelFieldInfo, &$parameter, $result) {
    if ($modelFieldInfo->isMABIModel) {
      if (empty($result)) {
        $parameter = NULL;
      }
      else {
        /**
         * @var $model \MABI\Model
         */
        $model = call_user_func($modelFieldInfo->type . '::init', $this->app);
        $model->load($result);
        $parameter = $model;
      }
    }
    else {
      switch ($modelFieldInfo->type) {
        case 'string':
          $parameter = $result;
          break;
        case 'int':
          $parameter = intval($result);
          break;
        case 'bool':
          $parameter = $result == TRUE;
          break;
        case 'float':
          $parameter = floatval($result);
          break;
        case 'DateTime':
        case '\DateTime':
          if (empty($result)) {
            $parameter = NULL;
          }
          else {
            $parameter = new \DateTime('@' . $result);
          }
          break;
        case '':
        case 'array':
          $parameter = $result;
      }
    };
  }
21809
public function scopeWhereSubject(Builder $query, $model)
    {
        $query->whereSubjectModel(get_class($model))
            ->where('subject_id', $model->id);
    }
1105512
function executeRelatedResultWithQuery (result, relatedName) {
    // get custom args for related model query
    var relatedArgs = this.args.with[relatedName]
    // get relation
    var relation = this.model.relation(relatedName)
    // build query args
    var queryArgs = {
        all: true,
        allow: this.args.allow,
        session: this.session,
        where: { relation: { name: this.model.name } },
    }
    // relation is via a linking table
    if (relation.via) {
        queryArgs.where.relation[relation.viaModelIdColumn] = result[relation.modelIdColumn] || result[model.defaultColumns[relation.modelIdColumn]]
    }
    // relation is direct
    else {
        queryArgs.where.relation[relation.relationIdColumn] = result[relation.modelIdColumn] || result[model.defaultColumns[relation.modelIdColumn]]
    }
    // merge args
    if (typeof relatedArgs === 'object') {
        _.merge(queryArgs, relatedArgs)
    }
    // do query on related model
    return relation.model.query(queryArgs)
    // merge related records once loaded
    .then(results => {
        result._related[relatedName] = results
    })
}
1313517
public static function array_all( array $result, callable $callable ) {
    foreach ( $result as $value ) {
      $check = $callable($value);
      if (!$check) {
        return $check;
      }
    }
    return true;
  }
403264
public function select( $request, $query_params = [] )
	{
		if( is_array($request) )
		{
			$template = reset($request);
			$query_params = end($request);
		}
		else if( is_string($request) )
		{
			$template = $request;
		}

		$statement = $this->_query_( $template, $query_params );

		$results = [];
		try {
			$results = $statement->fetchAll( \PDO::FETCH_ASSOC );
		} catch (PDOException $e) {
			if( DB_DEBUG_QUERY )
			{
				debug($e->getMessage());
			} 
			else
			{
				debug('Query Error');
			}
			exit;
		}

		return $results;
	}