Merges and returns current query data with defined data and returns as query string

@param string $ns Target namespace (Group)
@param array $data Data to be merged
@param boolean $mark Whether to prepend question mark
@return string
853
public function getWithNsQuery($ns, array $data, $mark = true)
    {
        if ($this->hasQuery($ns)) {
            $query = $this->getQuery($ns);
            $url = null;

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

            $url .= http_build_query(array($ns => array_merge($query, $data)));
            $url = str_replace('%25s', '%s', $url);

            return $url;
        } else {
            return null;
        }
    }
242414
private function processRspan($data) {
		$last = Array();
		$cspan = Array();
		for ($i = 0; $i < count($data); $i++) {
			$cspan[$i] = Array();
			for ($j = 0; $j < count($data[$i]); $j++) {
				$cspan[$i][$j] = 0;
				if (!isset($last[$j])) $last[$j] = 0;
				if ($data[$i][$j] === '#rspan') {
					$cspan[$last[$j]][$j]++;
				} else {
					$last[$j] = $i;
				}
			}
		}
		return $cspan;
	}
1190041
public function provide($data = null, array $options = [])
    {
        $result = parent::provide($data, $options);

        if (empty($result)) {
            return $result;
        }

        $config = [
            'html_input' => 'escape',
            'allow_unsafe_links' => false
        ];

        $converter = new CommonMarkConverter($config);

        return $converter->convertToHtml($result);
    }
1282708
public function merge(array $data)
    {
        $this->isMergingWidgetData = true;

        $data = $this->setCoreData($data);

        $this->mergePropertyData($data);

        $this->isMergingWidgetData = false;

        return $this;
    }
980042
public function merge($query, array $data)
    {
        $expression = "/(\\?)(?=(?:[^']|'[^']*')*$)/";
        $callback   = function () use (&$data) {
            if (!$data) {
                return '?';
            }

            return $this->quote(array_shift($data));
        };

        return preg_replace_callback($expression, $callback, $query);
    }
569703
function getPrefixFromNamespace($ns)
    {
        foreach ($this->namespaces as $p => $n) {
            if ($ns == $n || $ns == $p) {
                $this->usedNamespaces[$p] = $n;

                return $p;
            }
        }

        return FALSE;
    }
1067344
public function merge($data)
    {
        foreach ($data as $key => $val) {
            if ($key === 'paths') {
                $this->addPaths((array)$val);
            } elseif ($key === 'cache') {
                $this->setCache($val);
            } else {
                $this->offsetReplace($key, $val);
            }
        }

        return $this;
    }
527441
public static function create($data) {
        global $DB;
        $data = (object)$data;
        $tagcolls = self::get_collections();
        $tagcoll = (object)array(
            'name' => $data->name,
            'isdefault' => 0,
            'component' => !empty($data->component) ? $data->component : null,
            'sortorder' => count($tagcolls),
            'searchable' => isset($data->searchable) ? (int)(bool)$data->searchable : 1,
            'customurl' => !empty($data->customurl) ? $data->customurl : null,
        );
        $tagcoll->id = $DB->insert_record('tag_coll', $tagcoll);

        // Reset cache.
        cache::make('core', 'tags')->delete('tag_coll');

        \core\event\tag_collection_created::create_from_record($tagcoll)->trigger();
        return $tagcoll;
    }
1091080
public function update( $data = array(), $stripTags = TRUE ){
		if( !( is_array( $data ) && $data ) )
			throw new \InvalidArgumentException( 'Data for update must be an array and have atleast 1 pair' );
		$this->validateFocus();
		$has	= $this->get( FALSE );
		if( !$has )
			throw new \InvalidArgumentException( 'No data sets focused for update' );
		$updates	= array();
		foreach( $this->columns as $column ){
			if( !array_key_exists($column, $data) )
				continue;
			$value	= $data[$column];
			if( $stripTags && $value !== NULL )
				$value	= strip_tags( $value );
			$value	= $this->secureValue( $value );
			$updates[] = '`'.$column.'`='.$value;
		}
		if( sizeof( $updates ) ){
			$updates	= implode( ', ', $updates );
			$query	= 'UPDATE '.$this->getTableName().' SET '.$updates.' WHERE '.$this->getConditionQuery( array() );
			$result	= $this->dbc->exec( $query );
			return $result;
		}
	}
408769
public function tagData(array $tags, $data, User $user = null, $replace = false)
    {
        $taggedObjects = [];
        $uniqueTags = [];

        foreach ($tags as $tag) {
            $value = trim($tag);

            if (!empty($value)) {
                $uniqueTags[strtolower($value)] = $value;
            }
        }
        $tagsList = [];

        foreach ($uniqueTags as $tagName) {
            $tagsList[$tagName] = $this->getOrCreateTag($tagName, $user);
        }

        foreach ($data as $objectData) {
            $objectId = $objectData['id'];
            $objectClass = $objectData['class'];
            $objectName = isset($objectData['name']) ? $objectData['name'] : null;

            if ($replace) {
                $this->removeUnusedTags($objectClass, $objectId, $tags);
            }

            foreach ($uniqueTags as $tagName) {
                $tag = $tagsList[$tagName];
                $taggedObject = null;

                if ($tag->getId()) {
                    $taggedObject = $this->getOneTaggedObjectByTagAndObject($tag, $objectId, $objectClass);
                }

                if (is_null($taggedObject)) {
                    $taggedObject = new TaggedObject();
                }

                $taggedObject->setTag($tag);
                $taggedObject->setObjectId($objectId);
                $taggedObject->setObjectClass($objectClass);
                $tag->addTaggedObject($taggedObject);

                if ($objectName) {
                    $taggedObject->setObjectName($objectName);
                }

                $this->om->persist($taggedObject);
                $taggedObjects[] = $taggedObject;
            }
        }

        $this->om->flush();

        return $taggedObjects;
    }
659645
public function query($query, ...$data)
    {
        if ($data) {
            $query = $this->merge($query, $data);
        }

        try {
            $statement = $this->pdo->query($query);

            return new Result($statement);
        } catch (PDOException $exception) {
            throw new QueryException($exception, $query);
        }
    }
297069
function xmlize($data) {
		$vals = $index = $array = array();
		$parser = xml_parser_create();
		xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);

    // XML_OPTION_SKIP_WHITE is disabled as it clobbers valid 
    // newlines in instant messages
		xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0);
		xml_parse_into_struct($parser, $data, $vals, $index);
		xml_parser_free($parser);

		$i = 0;

		$tagname = $vals[$i]['tag'];
		$array[$tagname]['@'] = $vals[$i]['attributes'];
		$array[$tagname]['#'] = $this->_xml_depth($vals, $i);

		return $array;
	}
1286825
protected function mergeData($data, $index, $merge, $numericKeys)
    {
        if ($numericKeys) {
            return $this->removeMissingValues(array_merge(
                array_merge(array_slice($data, 0, $index, true), $merge),
                $this->filter(array_values(array_slice($data, $index + 1, null, true)))
            ));
        }

        return $this->removeMissingValues(array_slice($data, 0, $index, true) +
                $merge +
                $this->filter(array_slice($data, $index + 1, null, true)));
    }
810052
public function process_match($data) {
        global $DB;

        $data = (object)$data;
        $oldid = $data->id;

        // Detect if the question is created or mapped.
        $oldquestionid   = $this->get_old_parentid('question');
        $newquestionid   = $this->get_new_parentid('question');
        $questioncreated = $this->get_mappingid('question_created', $oldquestionid) ? true : false;

        if ($questioncreated) {
            // If the question has been created by restore, we need to create its
            // qtype_match_subquestions too.

            // Adjust some columns.
            $data->questionid = $newquestionid;
            // Insert record.
            $newitemid = $DB->insert_record('qtype_match_subquestions', $data);
            // Create mapping (there are files and states based on this).
            if (isset($data->code)) {
                $this->set_mapping('qtype_match_subquestion_codes', $data->code, $newitemid);
            }

        } else {
            // Match questions require mapping of qtype_match_subquestions, because
            // they are used by question_states->answer.

            // Have we cached the current question?
            if ($this->questionsubcacheid !== $newquestionid) {
                // The question changed, purge and start again!
                $this->questionsubcache = array();

                $params = array('question' => $newquestionid);
                $potentialsubs = $DB->get_records('qtype_match_subquestions',
                    array('questionid' => $newquestionid), '', 'id, questiontext, answertext');

                $this->questionsubcacheid = $newquestionid;
                // Cache all cleaned answers and questiontext.
                foreach ($potentialsubs as $potentialsub) {
                    // Clean in the same way than {@link xml_writer::xml_safe_utf8()}.
                    $cleanquestion = preg_replace('/[\x-\x8\xb-\xc\xe-\x1f\x7f]/is',
                            '', $potentialsub->questiontext); // Clean CTRL chars.
                    $cleanquestion = preg_replace("/\r\n|\r/", "\n", $cleanquestion); // Normalize line ending.

                    $cleananswer = preg_replace('/[\x-\x8\xb-\xc\xe-\x1f\x7f]/is',
                            '', $potentialsub->answertext); // Clean CTRL chars.
                    $cleananswer = preg_replace("/\r\n|\r/", "\n", $cleananswer); // Normalize line ending.

                    $this->questionsubcache[$cleanquestion][$cleananswer] = $potentialsub->id;
                }
            }

            if (!isset($this->questionsubcache[$data->questiontext][$data->answertext])) {
                throw new restore_step_exception('error_qtype_match_subquestion_missing_in_db', $data);
            }
            $newitemid = $this->questionsubcache[$data->questiontext][$data->answertext];
        }

        // Found one. Let's create the mapping.
        $this->set_mapping('qtype_match_subquestions', $oldid, $newitemid);
    }
1316144
public static function parseSignature($data)
    {
        if (empty($data)) {
            return null;
        }

        $signatureData = array();

        $list = explode(';', rtrim($data, ';'));
        if (empty($list)) {
            return null;
        }

        foreach ($list as $value) {
            $explode = explode('=', $value);
            if (count($explode) != 2) {
                return null;
            }
            $signatureData[$explode[0]] = $explode[1];
        }

        return $signatureData;
    }
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;
        }
    }
10552
public function add($data, $namespace='default')
    {
        Type::force($data, ArrayAccess::class);

        if (!isset($this->addedData[$namespace])) {
            $this->addedData[$namespace] = [];
        }

        $this->addedData[$namespace][] = $data;

        return $this;
    }