Get a wheres array for finding the row that matches an entity

@return array
351086
protected function getPrimaryKeyWheres(AbstractEntity $entity)
    {
        $wheres = [];

        $arrayCopy = $entity->getArrayCopy();
        foreach ($this->primaryKey as $keyColumn) {
            $wheres[$keyColumn] = $arrayCopy[$keyColumn];
        }

        return $wheres;
    }
221660
protected static function _finders() {
		$self = static::_object();

		return [
			'all' => function($params, $next) {
				return $next($params);
			},
			'first' => function($params, $next) {
				$options =& $params['options'];
				$options['limit'] = 1;

				$data = $next($params);

				if (isset($options['return']) && $options['return'] === 'array') {
					$data = is_array($data) ? reset($data) : $data;
				} else {
					$data = is_object($data) ? $data->rewind() : $data;
				}
				return $data ?: null;
			},
			'list' => function($params, $next) use ($self) {
				$result = [];
				$meta = $self::meta();
				$name = $meta['key'];

				foreach ($next($params) as $entity) {
					$key = $entity->{$name};
					$result[is_scalar($key) ? $key : (string) $key] = $entity->title();
				}
				return $result;
			},
			'count' => function($params, $next) use ($self) {
				$options = array_diff_key($params['options'], $self->_query);

				if ($options && !isset($params['options']['conditions'])) {
					$options = ['conditions' => $options];
				} else {
					$options = $params['options'];
				}
				$options += ['type' => 'read', 'model' => $self];
				$query = $self::invokeMethod('_instance', ['query', $options]);
				return $self::connection()->calculation('count', $query, $options);
			}
		];
	}
521232
public function findPage()
    {
        $_where    = ($this->where != '') ? ' WHERE ' . $this->where : '';
        $this->sql = $this->_read_sql();
        if ($this->expire < 0) {
            $_table_name = $this->_get_table_name();
            $sql_cout    = 'SELECT count(*) AS countrows FROM ' . $_table_name . $this->join . $_where;

            $data['data']       = $this->conn()->fetch_arrays($this->sql);
            $data['data_count'] = $this->db->fetch_object($sql_cout)->countrows;
        } else {
            $cache     = Cache::init();
            $cachename = 'db/findPage_' . md5($this->sql);
            if (false == ($data = $cache->get($cachename))) {
                $_table_name = $this->_get_table_name();
                $sql_cout    = 'SELECT count(*) AS countrows FROM ' . $_table_name . $this->join . $_where;

                $data['data']       = $this->conn()->fetch_arrays($this->sql);
                $data['data_count'] = $this->db->fetch_object($sql_cout)->countrows;

                $cache->set($cachename, $data, $this->expire);
                $this->expire = -1;
            }
        }
        return $data;
    }
886173
public function getAffectedEntityIds()
    {
        $categoryIds = [];
        while ($bunch = $this->_dataSourceModel->getNextBunch()) {
            foreach ($bunch as $rowNum => $rowData) {
                $this->filterRowData($rowData);
                if (!$this->isRowAllowedToImport($rowData, $rowNum)) {
                    continue;
                }
                if (!isset($this->newCategory[$rowData[self::COL_ROOT]][$rowData[self::COL_CATEGORY]]['entity_id'])) {
                    continue;
                }
                $categoryIds[] = $this->newCategory[$rowData[self::COL_ROOT]][$rowData[self::COL_CATEGORY]]['entity_id'];
            }
        }
        return $categoryIds;
    }
75769
public function getSearchedEntities()
    {
        $entities = array();

        if (!empty($_REQUEST['Entities'])) {
            if (is_array($_REQUEST['Entities'])) {
                $entities = Convert::raw2att($_REQUEST['Entities']);
            } else {
                $entities = explode(',', Convert::raw2att($_REQUEST['Entities']));
                $entities = array_combine($entities, $entities);
            }
        }
        
        return $entities;
    }
431247
public function getRawValue(): array
	{
		$primaryValues = [];
		foreach ($this->getIterator() as $entity) {
			if ($entity->isPersisted()) {
				$primaryValues[] = $entity->getValue('id');
			}
		}
		return $primaryValues;
	}
510763
protected function getSearchResults()
    {
        $callback = $this->getSearchFunction();
        if ($callback) {
            return call_user_func($callback, $this->getSourceObject(), $this->getLabelField(), $this->search);
        }

        $sourceObject = $this->getSourceObject();
        $filters = array();
        $sourceObjectInstance = DataObject::singleton($sourceObject);
        $candidates = array_unique([
            $this->getLabelField(),
            $this->getTitleField(),
            'Title',
            'Name'
        ]);
        foreach ($candidates as $candidate) {
            if ($sourceObjectInstance->hasDatabaseField($candidate)) {
                $filters["{$candidate}:PartialMatch"] = $this->search;
            }
        }

        if (empty($filters)) {
            throw new InvalidArgumentException(sprintf(
                'Cannot query by %s.%s, not a valid database column',
                $sourceObject,
                $this->getTitleField()
            ));
        }
        return DataObject::get($this->getSourceObject())->filterAny($filters);
    }
917131
public function getBranchesList() {
    $locations_to_be_displayed = [];
    $db = \Drupal::database();
    if (!empty($this->nodeId) && $node = $this->entityTypeManager->getStorage('node')->load($this->nodeId)) {
      $query = $db->select('node_field_data', 'n');
      // Field on Session that has Class.
      $query->innerJoin('node__field_session_class', 'fc', 'n.nid = fc.entity_id');
      $query->innerJoin('node_field_data', 'fdc', 'fc.field_session_class_target_id = fdc.nid');
      $query->condition('fdc.status', 1);
      // Field on Class that has Activity.
      $query->innerJoin('node__field_class_activity', 'fa', 'fc.field_session_class_target_id = fa.entity_id');
      $query->innerJoin('node_field_data', 'fda', 'fa.field_class_activity_target_id = fda.nid');
      $query->condition('fda.status', 1);
      // Field on Activity that has Programs Subcategory
      $query->innerJoin('node__field_activity_category', 'fps', 'fa.field_class_activity_target_id = fps.entity_id');
      $query->innerJoin('node_field_data', 'fds', 'fa.field_class_activity_target_id = fda.nid');
      // Field on Session that has Location.
      $query->innerJoin('node__field_session_location', 'fl', 'n.nid = fl.entity_id');
      $query->fields('fl', ['field_session_location_target_id']);
      $query->condition('n.type', 'session');
      $query->condition('fps.field_activity_category_target_id', $this->nodeId);
      $query->condition('n.status', 1);
      $query->groupBy('fl.field_session_location_target_id');
      $items = $query->execute()->fetchAll();

      foreach ($items as $item) {
        $locations_to_be_displayed[$item->field_session_location_target_id] = $item->field_session_location_target_id;
      }
    }
    return self::getLocations($locations_to_be_displayed);
    
  }
105018
public function getMeta()
    {
        $arrReturn = [];
        if (null !== $this->entity->getMeta()) {
            foreach ($this->entity->getMeta() as $meta) {
                if (!$meta->getLocale() || $meta->getLocale() === $this->locale) {
                    array_push(
                        $arrReturn,
                        [
                            'id' => $meta->getId(),
                            'key' => $meta->getKey(),
                            'value' => $meta->getValue(),
                        ]
                    );
                }
            }

            return $arrReturn;
        }

        return;
    }
1247602
protected function compileWheres()
	{
		if (!$this->wheres) return array();

		// The new list of compiled wheres
		$wheres = array();

		foreach ($this->wheres as $i => &$where)
		{
			// Convert id's
			if (isset($where['column']) && $where['column'] == '_id')
			{
				// Multiple values
				if (isset($where['values']))
				{
					foreach ($where['values'] as &$value)
					{
						$value = $this->convertKey($value);
					}
				}
				// Single value
				elseif (isset($where['value']))
				{
					$where['value'] = $this->convertKey($where['value']);
				}
			}

			// Convert dates
			if (isset($where['value']) && $where['value'] instanceof DateTime)
			{
				$where['value'] = $where['value']->format(DateTime::ISO8601);
			}

			// First item of chain
			if ($i == 0 && count($this->wheres) > 1 && $where['boolean'] == 'and')
			{
				// Copy over boolean value of next item in chain
				$where['boolean'] = $this->wheres[$i+1]['boolean'];
			}

			// Delegate
			$method = "compileWhere{$where['type']}";
			$compiled = $this->{$method}($where);

			// Check for or
			if ($where['boolean'] == 'or')
			{
				$compiled = array('$or' => array($compiled));
			}

			// Merge compiled where
			$wheres = array_merge_recursive($wheres, $compiled);
		}

		return $wheres;
	}
344243
public function findAll()
    {
        $this->updateMap();

        return $this->entityRepository->findAll()->with('id', Operator::IN, $this->map);
    }
32241
public function find($table, $fields = null, $where = null, $order = null, $limit = null, $offset = null, $array = array(), $fetchMode = \PDO::FETCH_ASSOC)
     {
         $sql = ' SELECT '.(($fields) ?? '*').' FROM '.(($table)).(($where) ? ' WHERE '.$where : ' ')
            .(($limit) ? ' LIMIT '.$limit : ' ')
            .(($offset && $limit) ? ' OFFSET '.$offset : ' ')
            .(($order) ? ' ORDER BY '.$order : ' ');

         $stmt = $this->conn->prepare($sql);

         foreach ($array as $key => $values) {
             return  $stmt->bindValue("$key", $values);
         }
         $stmt->execute();

         do {
             return $stmt->fetchAll($fetchMode);
         } while (
            $stmt->nextRowset());
         $stmt->close();
     }
619362
public function getWhere()
    {
        $template = "WHERE %s";
        $where = null;
        if (count($this->_sql->conditions->predicates) > 0) {
            $where = trim(
                sprintf($template, $this->_sql->conditions->toString())
            );
        }

        return $where;
    }
758979
public function getSearchResults()
    {
        $term = $this->getRequest()->get('search', null);

        // Avoid querying ALL content when no search value is provided
        if (!$term) {
            return [];
        }

        $host = $this->getRequest()->getHost();
        $locale = $this->getRequest()->attributes->get('content')->getLocale();

        return $this->contentManager->getRepository()->search($term, $host, $locale);
    }
444425
private function getMatches(): array
    {
        // Extract URI of current query
        $uri = $this->getRequest()->getUri()->getPath();

        // Extract method of current request
        $method = $this->getRequest()->getMethod();
        $method = strtolower($method);

        // Foreach emulation
        return $this->checkMatches($uri, $method);
    }
78422
function Find($whereOrderBy,$bindarr=false,$pkeysArr=false,$extra=array())
	{
		$db = $this->DB();
		if (!$db || empty($this->_table)) {
			return false;
		}
		$table =& $this->TableInfo();
		$arr = $db->GetActiveRecordsClass(get_class($this),$this, $whereOrderBy,$bindarr,$pkeysArr,$extra,
			array('foreignName'=>$this->foreignName, 'belongsTo'=>$table->_belongsTo, 'hasMany'=>$table->_hasMany));
		return $arr;
	}
621895
public function getMatchers(): array
    {
        return [
            'verifyNative' => function (DataType $subject, $value) {

                $isClass = (false === $subject->isClass());
                $isClassOrInterface = (false === $subject->isClassOrInterface() || $value === Type::COUNTABLE);
                $isInterface = (false === $subject->isInterface() || $value === Type::COUNTABLE);
                $isNative = (true === $subject->isNative());
                $isTrait = (false === $subject->isTrait());
                $isValid = (true === $subject->isValid());
                $isChildOf = (false === $subject->isChildOf($value));
                $isTypeOf = (true === $subject->isTypeOf($value));


                return $isClass && $isClassOrInterface && $isInterface && $isNative && $isTrait && $isValid && $isChildOf && $isTypeOf;
            },
            'verifyInterface' => function (DataType $subject, $value) {

                $isClass = (false === $subject->isClass());
                $isClassOrInterface = (true === $subject->isClassOrInterface());
                $isInterface = (true === $subject->isInterface());
                $isNative = (false === $subject->isNative());
                $isTrait = (false === $subject->isTrait());
                $isValid = (true === $subject->isValid());
                $isChildOf = (false === $subject->isChildOf($value));
                $isTypeOf = (true === $subject->isTypeOf($value));


                return $isClass && $isClassOrInterface && $isInterface && $isNative && $isTrait && $isValid && $isChildOf && $isTypeOf;
            },
            'verifyClass' => function (DataType $subject, $value) {

                $isClass = (true === $subject->isClass());
                $isClassOrInterface = (true === $subject->isClassOrInterface());
                $isInterface = (false === $subject->isInterface());
                $isNative = (false === $subject->isNative());
                $isTrait = (false === $subject->isTrait());
                $isValid = (true === $subject->isValid());
                $isChildOf = (true === $subject->isChildOf($value));
                $isTypeOf = (true === $subject->isTypeOf($value));

                return $isClass && $isClassOrInterface && $isInterface && $isNative && $isTrait && $isValid && $isChildOf && $isTypeOf;
            },
            'verifyTrait' => function (DataType $subject, $value) {

                $isClass = (false === $subject->isClass());
                $isClassOrInterface = (false === $subject->isClassOrInterface());
                $isInterface = (false === $subject->isInterface());
                $isNative = (false === $subject->isNative());
                $isTrait = (true === $subject->isTrait());
                $isValid = (true === $subject->isValid());
                $isChildOf = (false === $subject->isChildOf($value));
                $isTypeOf = (true === $subject->isTypeOf($value));

                return $isClass  && $isClassOrInterface && $isInterface && $isNative && $isTrait && $isValid && $isChildOf && $isTypeOf;
            }
        ];
    }