Get the select object to use for RawTokenAnswerRows

@param array $filter
@param type $surveyId
@param type $sourceSurveyId
@return \Zend_Db_Select
437419
public function getRawTokenAnswerRowsSelect(array $filter, $surveyId, $sourceSurveyId = null)
    {
        $survey = $this->getSurvey($surveyId, $sourceSurveyId);
        $model  = $survey->getModel();

        $select = $model->getSelect();
        $this->filterLimitOffset($filter, $select);

        return $select;
    }
955988
public function fetchAll($source, $filter = [], $options = [], $secondaryPreferred = true)
    {
        $namespace = strpos($source, '.') !== false ? $source : ($this->_default_db . '.' . $source);

        $this->eventsManager->fireEvent('mongodb:beforeQuery', $this, compact('namespace', 'filter', 'options'));

        /** @var \ManaPHP\Mongodb\ConnectionInterface $connection */
        $connection = $this->poolManager->pop($this);
        try {
            $start_time = microtime(true);
            $result = $connection->fetchAll($namespace, $filter, $options, $secondaryPreferred);
            $elapsed = round(microtime(true) - $start_time, 3);
        } finally {
            $this->poolManager->push($this, $connection);
        }

        $this->eventsManager->fireEvent('mongodb:afterQuery', $this, compact('namespace', 'filter', 'options', 'result', 'elapsed'));

        $this->logger->debug(compact('namespace', 'filter', 'options', 'result', 'elapsed'), 'mongodb.query');
        return $result;
    }
1072033
public function getSurveySelect($name, $post) {
        $surveys = $this->surveys;

        $select = \MUtil_Html::create()->select(['name' => $name]);

        $empty = $this->util->getTranslated()->getEmptyDropdownArray();
        $select->option(reset($empty), ['value' => '']);

        return $select;
    }
602676
protected function getQueryCondition(
        Criterion $filter,
        SelectQuery $query,
        array $languageFilter
    ) {
        $condition = $query->expr->lAnd(
            $this->criteriaConverter->convertCriteria($query, $filter, $languageFilter),
            $query->expr->eq(
                'ezcontentobject.status',
                ContentInfo::STATUS_PUBLISHED
            ),
            $query->expr->eq(
                'ezcontentobject_version.status',
                VersionInfo::STATUS_PUBLISHED
            )
        );

        // If not main-languages query
        if (!empty($languageFilter['languages'])) {
            $condition = $query->expr->lAnd(
                $condition,
                $query->expr->gt(
                    $query->expr->bitAnd(
                        $this->handler->quoteColumn('language_mask', 'ezcontentobject'),
                        $query->bindValue(
                            $this->getLanguageMask($languageFilter),
                            null,
                            PDO::PARAM_INT
                        )
                    ),
                    $query->bindValue(0, null, PDO::PARAM_INT)
                )
            );
        }

        return $condition;
    }
397334
public function dataSourceFilter($sourceIdent)
    {
        if (!is_string($sourceIdent)) {
            throw new InvalidArgumentException('Data source identifier must be a string');
        }

        $filters = array_merge($this->defaultDataSourceFilters(), $this->dataSourceFilters);

        if (isset($filters[$sourceIdent])) {
            return $filters[$sourceIdent];
        }

        return null;
    }
241867
public function convert(AbstractPaginationQuery $filter, ArrayAccess $response)
    {
        $entities = [];
        $ids = [];
        $return = [];

        if (!isset($response['response'])
            || !isset($response['response']['docs'])
            || !is_array($response['response']['docs'])) {
            throw new InvalidArgumentException('invalid response');
        }
        
        foreach ($response['response']['docs'] as $doc) {
            $ids[] = $doc->id;
        }

        // fetch entities with given IDs
        $repository = $this->repositories->get($filter->getRepositoryName());
        $qb = $repository->createQueryBuilder() /* @var $repository \Core\Repository\AbstractRepository */
            ->field('id')
            ->in($ids);
        $result = $qb->getQuery()->execute();
        
        foreach ($result as $document) {
            $entities[$document->getId()] = $document;
        }
        
        // iterate over Solr response to preserve sorting
        foreach ($response['response']['docs'] as $doc) {
            $entity = isset($entities[$doc->id]) ? $entities[$doc->id] : $repository->create();
            $return[] = $filter->proxyFactory($entity, $doc);
        }
        
        return $return;
    }
35668
public function find(array $filter = [], array $orderBy = [], $limit = 0,
        $offset = 0, array $associate = []
    ) {
        try {

            $query = $this->query()
                ->select()
                ->associate($associate)
                ->setFilter($filter);

            foreach ($orderBy as $orderByRule) {
                $query->orderBy($orderByRule[0], $orderByRule[1]);
            }

            return $query->limit($limit)->offset($offset)->run($this->connection);
        } catch (Exception\QueryException $e) {
            throw new Exception\RepositoryException($e->getMessage());
        }
    }
683916
public function buildFilterRulesForUsedOnly($filter, $idList = [])
    {
        $builder = $this->connection->createQueryBuilder()
            ->select($this->getColName())
            ->from($this->getMetaModel()->getTableName())
            ->groupBy($this->getColName());

        if (!empty($idList)) {
            $builder
                ->where('id IN (:ids)')
                ->setParameter('ids', $idList, Connection::PARAM_STR_ARRAY);
        }

        $arrUsedValues = $builder->execute()->fetchAll(\PDO::FETCH_COLUMN);
        $arrUsedValues = \array_filter(
            $arrUsedValues,
            function ($value) {
                return !empty($value);
            }
        );

        $filter->addFilterRule(new StaticIdList($arrUsedValues));
    }
979438
public function getIterator(IteratorFilter $filter = null)
    {
        if (is_null($filter)) {
            $filter = new IteratorFilter();
        }

        $param = [];
        $formatter = new IteratorFilterSqlFormatter();
        $sql = $formatter->getFilter($filter->getRawFilters(), $param);

        $query = Query::getInstance()
            ->table($this->getUserDefinition()->table())
            ->where($sql, $param);

        return $this->userRepository->getByQuery($query);
    }
582669
public static function getSkusByProduct($productId, $filter = array())
    {
        $filter = Filter::create($filter);
        return self::getCollection('/products/'.$productId.'/skus' . $filter->toQuery(), 'Sku');
    }
462318
public static function getCustomersCount($filter = array())
    {
        $filter = Filter::create($filter);
        return self::getCount('/customers/count' . $filter->toQuery());
    }
682780
public function getSurveyInfo($sourceSurveyId)
    {
        $db = $this->getSourceDatabase();

        $select = $db->select();
        $select->from('gems__openrosaforms')
            ->where('gof_id = ?', $sourceSurveyId);

        return $db->fetchRow($select);
    }
413827
private function getParamsFromFilter(FilterBuilder $filter)
    {
        $result  = [];
        $must    = [];
        $mustNot = [];

        $params = $filter->getParams();

        if ($params['entities']) {
            $result['index'] = $params['entities'];
        }

        if (isset($params['keyword'])) {
            $must[] = new MultiMatchQuery($params['keyword']['value'], $params['keyword']['fields']);
        }

        foreach ($params['params'] ?? [] as $param) {
            list($query, $operator) = $param->createFilter();

            if ($operator == FilterOperators::IN) {
                $must[] = $query;
            } else {
                $mustNot[] = $query;
            }

        }

        if ($mustNot || $must) {

            $query = new QueryBuilder();
            if ($mustNot) {
                $query->setMustNot(new MustNotQuery($mustNot));
            }
            if ($must) {
                $query->setMust(new MustQuery($must));
            }

            $result['query'] = $query->toArray();
        }

        return $result;
    }
267231
function select($fields,$filter=NULL,array $options=NULL,$ttl=0) {
		list($sql,$args)=$this->stringify($fields,$filter,$options);
		$result=$this->db->exec($sql,$args,$ttl);
		$out=[];
		foreach ($result as &$row) {
			foreach ($row as $field=>&$val) {
				if (array_key_exists($field,$this->fields)) {
					if (!is_null($val) || !$this->fields[$field]['nullable'])
						$val=$this->db->value(
							$this->fields[$field]['pdo_type'],$val);
				}
				unset($val);
			}
			$out[]=$this->factory($row);
			unset($row);
		}
		return $out;
	}
798276
private function doFilter(TokenFilterInterface $filter, array $tokens): array
    {
        $result = [];
        foreach ($tokens as $token) {
            $result = array_merge($result, $filter->filter($token));
        }

        return $result;
    }
448215
public function getSurveyAnswerModel(\Gems_Tracker_Survey $survey, $language = null, $sourceSurveyId = null)
    {
        if (null === $sourceSurveyId) {
            $sourceSurveyId = $this->_getSid($survey->getSurveyId());
        }

        $model         = $this->createModel($survey);
        $model->set('gto_id_token', 'label', $this->_('Token'), 'elementClass', 'Exhibitor');

        $surveyForm  = $this->getSurvey($survey->getSurveyId(), $sourceSurveyId);
        $surveyModel   = $this->getSurvey($survey->getSurveyId(), $sourceSurveyId)->getModel();

        $model->setMeta('openroseTableName', $surveyForm->getTableName());
        $model->setMeta('internalAttributes', true);

        /*$questionsList = $this->getQuestionList($language, $survey->getSurveyId(), $sourceSurveyId);
        foreach($questionsList as $item => $question) {
            $allOptions = $surveyModel->get($item);
            $allowed = array_fill_keys(array('storageFormat', 'dateFormat', 'label', 'multiOptions', 'maxlength', 'type', 'itemDisplay', 'formatFunction'),1);
            $options = array_intersect_key($allOptions, $allowed);

            $options['label']           = strip_tags($question);
            $options['survey_question'] = true;

            //Should also do something to get the better titles...
            $model->set($item, $options);
        }

        return $model;
        */

        foreach($surveyModel->getItemsOrdered() as $name) {
            $label = $surveyModel->get($name, 'label');
            if ($label) {
                $options = $surveyModel->get($name);
                unset($options['table']);

                $options['label']           = strip_tags($label);
                $options['label_raw']       = $label;
                $options['survey_question'] = true;

                //Should also do something to get the better titles...
                $model->set($name, $options);
            }
        }

        if ($tableIdField = $model->getTableIdField()) {
            if ($surveyModel->has($tableIdField) && !$surveyModel->get($tableIdField, 'label')) {
                $options = $surveyModel->get($name);
                unset($options['table']);
                $model->set($tableIdField, $options);
            }
        }

        if ($surveyModel->getMeta('nested', false)) {
            $model->setMeta('nested', true);
            // We have a nested model, add the nested questions
            $nestedNames = $surveyModel->getMeta('nestedNames');
            $model->setMeta('nestedNames', $nestedNames);
            foreach($nestedNames as $nestedName) {

                $nestedModel = $surveyModel->get($nestedName, 'model');
                if ($nestedModel instanceof \MUtil_Model_ModelAbstract) {
                    $model->addListModel($nestedModel, array('orf_id' => 'orfr_response_id'));
                    $model->set($nestedName, 'label', $surveyModel->get($nestedName, 'label'),
                        'elementClass', 'FormTable'
                    );
                    $model->setMeta('nestedNames', $nestedNames);
                }
            }
        }
        $model->del('token');

        return $model;
    }
1106844
protected function _checkReturnURI($sourceSurveyId, \Gems_Tracker_Survey $survey, array &$messages)
    {
        $lsSurvLang = $this->_getSurveyLanguagesTableName();
        $sql = 'SELECT surveyls_language FROM ' . $lsSurvLang . ' WHERE surveyls_survey_id = ?';

        $lsDb = $this->getSourceDatabase();

        $languages = $lsDb->fetchAll($sql, array($sourceSurveyId));
        $langChanges = 0;
        foreach ($languages as $language)
        {
            $langChanges = $langChanges + $lsDb->update(
                $lsSurvLang,
                array(
                    'surveyls_urldescription' => $this->_getReturnURIDescription($language['surveyls_language'])
                    ),
                array(
                    'surveyls_survey_id = ?' => $sourceSurveyId,
                    'surveyls_language = ?'  => $language
                    )
                );
        }

        if ($langChanges > 0) {
            $messages[] = sprintf($this->_('The description of the exit url description was changed for %s languages in survey \'%s\'.'), $langChanges, $survey->getName());
        }
    }