Returns current query with merged data

@param array $data Data to be merged with current query
@param boolean $mark Whether to prepend question mark
@return string
438054
public function getWithQuery(array $data, $mark = true)
    {
        if ($this->hasQuery()) {
            $url = null;

            if ($mark === true) {
                $url = '?';
            }

            $url .= http_build_query(array_merge($this->getQuery(), $data));
            $url = str_replace('%25s', '%s', $url);

            return $url;

        } else {
            return null;
        }
    }
459323
protected function fetchRemainingSegment(array $data, $value)
    {
        $segment = implode($this->delimiter, $data);
        if ('' == $value) {
            if ($index = array_search('', $data, true)) {
                $left = array_slice($data, 0, $index);
                $right = array_slice($data, $index+1);

                return implode($this->delimiter, array_merge($left, $right));
            }

            return $segment;
        }

        $part = implode($this->delimiter, $this->formatRemoveSegment($value));

        $regexStart = '@(:?^|\\'.$this->delimiter.')';

        if (! preg_match($regexStart.preg_quote($part, '@').'@', $segment, $matches, PREG_OFFSET_CAPTURE)) {
            return null;
        }

        $pos = $matches[0][1];

        return substr($segment, 0, $pos).substr($segment, $pos + strlen($part) + 1);
    }
627088
public function getQueryData($table, array $data)
    {
        $columns = $this->getSchemaManager()->listTableColumns($table);

        $allColumnTypes = $this->getColumnTypes($table);
        $columnTypes = [];
        foreach ($columns as $column) {
            $columnName = $column->getName();
            if (\array_key_exists($columnName, $data)) {
                $columnTypes[$this->connection->quoteIdentifier($columnName)] = $allColumnTypes[$columnName];
            }
        }

        $quotedData = [];
        foreach ($data as $column => $value) {
            $quotedColumn = $this->connection->quoteIdentifier($column);
            if (\array_key_exists($quotedColumn, $columnTypes)) {
                $quotedData[$quotedColumn] = $value;
            }
        }

        \ksort($quotedData);
        \ksort($columnTypes);

        return new QueryData(
            $this->connection->quoteIdentifier($table),
            $quotedData,
            \array_values($columnTypes)
        );
    }
491105
public function matchesMarks(array $marks)
    {
        if (!$this->markFilter) {
            return true;
        }

        foreach ($this->markFilter as $mark => $mustBe) {

            // $mustBe has to be boolean or string, for performance reasons
            // it will not be checked again here

            if ($mustBe === true) {
                if (!isset($marks[$mark]) || !$marks[$mark]) {
                    return false;
                }
            }

            if ($mustBe === false) {
                if (!isset($marks[$mark])) {
                    continue;
                }
                if ((bool)$marks[$mark]) {
                    return false;
                }
            }

            // $mustBe cannot be boolean until here

            $shouldMatch = true;

            if (strpos($mustBe, '!') === 0) {
                $mustBe = substr($mustBe, 1);
                $shouldMatch = false;
            }

            if (!isset($marks[$mark]) && $shouldMatch) {
                return false;
            }

            if (!isset($marks[$mark]) && !$shouldMatch) {
                continue;
            }

            if ( ($marks[$mark] == $mustBe) !== $shouldMatch) {
                return false;
            }

        }

        return true;
    }
1292348
protected function questionVersioning($data = [])
    {
        $data += [
            'ignoreQuestionIDs' => '',
            'pendingDeleteIDs' => '',
        ];
        $db = Database::connection();
        $oldBID = intval($data['bID']);

        //if this block is being edited a second time, remove edited questions with the current bID that are pending replacement
        //if( intval($oldBID) == intval($this->bID) ){
            $vals = [intval($data['oldQsID'])];
        $pendingQuestions = $db->getAll('SELECT msqID FROM btFormQuestions WHERE bID=0 && questionSetId=?', $vals);
        foreach ($pendingQuestions as $pendingQuestion) {
            $vals = [intval($this->bID), intval($pendingQuestion['msqID'])];
            $db->query('DELETE FROM btFormQuestions WHERE bID=? AND msqID=?', $vals);
        }
        //}

        //assign any new questions the new block id
        $vals = [intval($data['bID']), intval($data['qsID']), intval($data['oldQsID'])];
        $rs = $db->query('UPDATE btFormQuestions SET bID=?, questionSetId=? WHERE bID=0 && questionSetId=?', $vals);

        //These are deleted or edited questions.  (edited questions have already been created with the new bID).
        $ignoreQuestionIDsDirty = explode(',', $data['ignoreQuestionIDs']);
        $ignoreQuestionIDs = [0];
        foreach ($ignoreQuestionIDsDirty as $msqID) {
            $ignoreQuestionIDs[] = intval($msqID);
        }
        $ignoreQuestionIDstr = implode(',', $ignoreQuestionIDs);

        //remove any questions that are pending deletion, that already have this current bID
        $pendingDeleteQIDsDirty = explode(',', $data['pendingDeleteIDs']);
        $pendingDeleteQIDs = [];
        foreach ($pendingDeleteQIDsDirty as $msqID) {
            $pendingDeleteQIDs[] = intval($msqID);
        }
        $vals = [$this->bID, intval($data['qsID'])];
        $pendingDeleteQIDs = implode(',', $pendingDeleteQIDs);
        $unchangedQuestions = $db->query('DELETE FROM btFormQuestions WHERE bID=? AND questionSetId=? AND msqID IN (' . $pendingDeleteQIDs . ')', $vals);
    }
769581
public function getCurrentTag()
    {
        /**
         * @var Blog $dataRecord
         */
        $dataRecord = $this->dataRecord;
        $tag = $this->request->param('Tag');
        if ($tag) {
            $filter = URLSegmentFilter::create();
            // url encode unless it's multibyte (already pre-encoded in the database)
            // see https://github.com/silverstripe/silverstripe-cms/pull/2384
            if (!$filter->getAllowMultibyte()) {
                $tag = rawurlencode($tag);
            }

            return $dataRecord->Tags()
                ->filter('URLSegment', $tag)
                ->first();
        }
        return null;
    }
173374
public function review($completion, $mark = true) {
        global $DB;

        $course = $DB->get_record('course', array('id' => $completion->course));
        $cm = $DB->get_record('course_modules', array('id' => $this->moduleinstance));
        $info = new completion_info($course);

        $data = $info->get_data($cm, false, $completion->userid);

        // If the activity is complete
        if (in_array($data->completionstate, array(COMPLETION_COMPLETE, COMPLETION_COMPLETE_PASS, COMPLETION_COMPLETE_FAIL))) {
            if ($mark) {
                $completion->mark_complete();
            }

            return true;
        }

        return false;
    }
1231377
public static function get($data)
    {
        if (!$data || (!is_string($data) && !is_array($data))) {
            return '';
        }

        $isString = false;
        $url = false;
        if (is_string($data)) {
            $isString = true;
            if (CommonUtil::isURL($data)) {
                $url = $data;
                $data = Arrays::get(parse_url($data), 'query', '');
            }
            $queryArr = [];
            parse_str($data, $queryArr);
            $data = $queryArr;
        }

        unset($data['sign']);
        ksort($data);
        if ($query = urldecode(http_build_query($data))) {
            $data = $query;
        }

        $sign = md5($data . '&secret=' . self::$secret);
        if ($url) {
            return URLUtil::addParameter($url, ['sign' => $sign]);
        } else if ($isString) {
            return $data . '&sign=' . $sign;
        } else {
            return $sign;
        }
    }
44412
public function _flush($data)
    {
        $id = array_pop($this->_idStack);
        if ($id === null) {
            Zend_Cache::throwException('use of _flush() without a start()');
        }
        if ($this->_extension) {
            $this->save(serialize(array($data, $this->_extension)), $id, $this->_tags);
        } else {
            $this->save($data, $id, $this->_tags);
        }
        return $data;
    }
1270859
public function mergeData(array $data)
    {
        $data = $this->setIdFromData($data);

        foreach ($data as $propIdent => $val) {
            if (!$this->hasProperty($propIdent)) {
                $this->logger->warning(sprintf(
                    'Cannot set property "%s" on object; not defined in metadata.',
                    $propIdent
                ));
                continue;
            }

            $property = $this->p($propIdent);
            if ($property->l10n() && is_array($val)) {
                $currentValue = json_decode(json_encode($this[$propIdent]), true);
                if (is_array($currentValue)) {
                    $this[$propIdent] = array_merge($currentValue, $val);
                } else {
                    $this[$propIdent] = $val;
                }
            } else {
                $this[$propIdent] = $val;
            }
        }

        return $this;
    }
592573
protected function getQueryParams (array $data) {
        $add = '';
        foreach ($data as $k => $arr) {
            if (is_array($arr)) {
                foreach ($arr as $value) {
                    $add .= "&$k=" . urlencode($value);
                }
                unset($data[$k]);
            } else if ($arr === null) {
                unset($data[$k]);
            } else if (is_bool($arr)) {
                $data[$k] = $arr ? 'true' : 'false';
            }
        }

        $params = http_build_query($data) . $add;

        return $params;
    }
270433
public function getData($data)
    {
        if ($this->hasData($data)) {
            return $this->getAttribute(sprintf('data-%s', $data));
        } else {
            return false;
        }
    }
1332628
public function process_question(array $data, array $raw) {
        global $CFG;

        // firstly make sure that the category data and the <questions> wrapper are written
        // note that because of MDL-27693 we can't use {@link self::process_question_category()}
        // and {@link self::on_questions_start()} to do so

        if (empty($this->currentcategorywritten)) {
            $this->xmlwriter->begin_tag('question_category', array('id' => $this->currentcategory['id']));
            foreach ($this->currentcategory as $name => $value) {
                if ($name === 'id') {
                    continue;
                }
                $this->xmlwriter->full_tag($name, $value);
            }
            $this->currentcategorywritten = true;
        }

        if (empty($this->questionswrapperwritten)) {
            $this->xmlwriter->begin_tag('questions');
            $this->questionswrapperwritten = true;
        }

        $qtype = $data['qtype'];

        // replay the upgrade step 2008050700 {@see question_fix_random_question_parents()}
        if ($qtype == 'random' and $data['parent'] <> $data['id']) {
            $data['parent'] = $data['id'];
        }

        // replay the upgrade step 2010080900 and part of 2010080901
        $data['generalfeedbackformat'] = $data['questiontextformat'];
        $data['oldquestiontextformat'] = $data['questiontextformat'];

        if ($CFG->texteditors !== 'textarea') {
            $data['questiontext'] = text_to_html($data['questiontext'], false, false, true);
            $data['questiontextformat'] = FORMAT_HTML;
            $data['generalfeedback'] = text_to_html($data['generalfeedback'], false, false, true);
            $data['generalfeedbackformat'] = FORMAT_HTML;
        }

        // Migrate files in questiontext.
        $this->fileman->contextid = $this->currentcategory['contextid'];
        $this->fileman->component = 'question';
        $this->fileman->filearea  = 'questiontext';
        $this->fileman->itemid    = $data['id'];
        $data['questiontext'] = moodle1_converter::migrate_referenced_files($data['questiontext'], $this->fileman);

        // Migrate files in generalfeedback.
        $this->fileman->filearea  = 'generalfeedback';
        $data['generalfeedback'] = moodle1_converter::migrate_referenced_files($data['generalfeedback'], $this->fileman);

        // replay the upgrade step 2010080901 - updating question image
        if (!empty($data['image'])) {
            if (core_text::substr(core_text::strtolower($data['image']), 0, 7) == 'http://') {
                // it is a link, appending to existing question text
                $data['questiontext'] .= ' <img src="' . $data['image'] . '" />';

            } else {
                // it is a file in course_files
                $filename = basename($data['image']);
                $filepath = dirname($data['image']);
                if (empty($filepath) or $filepath == '.' or $filepath == '/') {
                    $filepath = '/';
                } else {
                    // append /
                    $filepath = '/'.trim($filepath, './@#$ ').'/';
                }

                if (file_exists($this->converter->get_tempdir_path().'/course_files'.$filepath.$filename)) {
                    $this->fileman->contextid = $this->currentcategory['contextid'];
                    $this->fileman->component = 'question';
                    $this->fileman->filearea  = 'questiontext';
                    $this->fileman->itemid    = $data['id'];
                    $this->fileman->migrate_file('course_files'.$filepath.$filename, '/', $filename);
                    // note this is slightly different from the upgrade code as we put the file into the
                    // root folder here. this makes our life easier as we do not need to create all the
                    // directories within the specified filearea/itemid
                    $data['questiontext'] .= ' <img src="@@PLUGINFILE@@/' . $filename . '" />';

                } else {
                    $this->log('question file not found', backup::LOG_WARNING, array($data['id'], $filepath.$filename));
                }
            }
        }
        unset($data['image']);

        // replay the upgrade step 2011060301 - Rename field defaultgrade on table question to defaultmark
        $data['defaultmark'] = $data['defaultgrade'];

        // write the common question data
        $this->xmlwriter->begin_tag('question', array('id' => $data['id']));
        foreach (array(
            'parent', 'name', 'questiontext', 'questiontextformat',
            'generalfeedback', 'generalfeedbackformat', 'defaultmark',
            'penalty', 'qtype', 'length', 'stamp', 'version', 'hidden',
            'timecreated', 'timemodified', 'createdby', 'modifiedby'
        ) as $fieldname) {
            if (!array_key_exists($fieldname, $data)) {
                throw new moodle1_convert_exception('missing_common_question_field', $fieldname);
            }
            $this->xmlwriter->full_tag($fieldname, $data[$fieldname]);
        }
        // unless we know that the given qtype does not append any own structures,
        // give the handler a chance to do so now
        if (!in_array($qtype, array('description', 'random'))) {
            $handler = $this->get_qtype_handler($qtype);
            if ($handler === false) {
                $this->log('question type converter not found', backup::LOG_ERROR, $qtype);

            } else {
                $this->xmlwriter->begin_tag('plugin_qtype_'.$qtype.'_question');
                $handler->use_xml_writer($this->xmlwriter);
                $handler->process_question($data, $raw);
                $this->xmlwriter->end_tag('plugin_qtype_'.$qtype.'_question');
            }
        }

        $this->xmlwriter->end_tag('question');
    }
1161241
public function insert(array $data)
    {
        if (false === $this->trigger('before_insert', $this)) {
            return false;
        }

        if($this->dateFormat && $this->updateTime && $this->createTime){
            $time = date('Y-m-d H:i:s', time());
            $data[$this->updateTime] = $time;
            $data[$this->createTime] = $time;
        } else {
            $time =  time();
            $data[$this->updateTime] =  $time;
            $data[$this->createTime] =  $time;
        }

        $response = $this->getQuery()->insert($data);

        if (false === $this->trigger('after_insert', $this)) {
            return false;
        }
        return $response;
    }
584357
protected static function buildQuestionMarks($data)
    {
        $row = self::getFirstRow($data);
        $questionMarks = array_fill(0, count($row), '?');

        $line = '(' . implode(',', $questionMarks) . ')';
        $lines = array_fill(0, count($data), $line);

        return implode(', ', $lines);
    }
1059212
private function _merge(array $data) : array
    {
        $values = $this->getValues();
        $values = array_merge($values, $data);
        return $values;
    }
1021684
public function _flush($data)
    {
        if ($this->_cancel) {
            return $data;
        }
        $contentType = null;
        $storedHeaders = array();
        $headersList = headers_list();
        foreach($this->_specificOptions['memorize_headers'] as $key=>$headerName) {
            foreach ($headersList as $headerSent) {
                $tmp = explode(':', $headerSent);
                $headerSentName = trim(array_shift($tmp));
                if (strtolower($headerName) == strtolower($headerSentName)) {
                    $headerSentValue = trim(implode(':', $tmp));
                    $storedHeaders[] = array($headerSentName, $headerSentValue);
                }
            }
        }
        $array = array(
            'data' => $data,
            'headers' => $storedHeaders
        );
        $this->save($array, null, $this->_activeOptions['tags'], $this->_activeOptions['specific_lifetime'], $this->_activeOptions['priority']);
        return $data;
    }