@param string $structure

@return bool
7604
public static function validate($structure)
    {
        if (12 !== strlen($structure)
        ) {
            return false;
        }

        $sequences = substr($structure, 0, 10);
        $key = substr($structure, -2);
        $control = $sequences % 97; // final control must be a 2-digits:
        $control = (1 < strlen($control)) ? $control : sprintf('0%d', $control);

        return $key === $control;
    }
189378
public function getEncoding($structure) {
        if (property_exists($structure, 'parameters')) {
            foreach ($structure->parameters as $parameter) {
                if (strtolower($parameter->attribute) == "charset") {
                    return EncodingAliases::get($parameter->value);
                }
            }
        }elseif (is_string($structure) === true){
            return mb_detect_encoding($structure);
        }

        return 'UTF-8';
    }
392620
public function save( & $structure )
    {
        if ( ! $structure instanceof Structure\ProxyAbstract ||
             empty( $structure->type ) )
        {
            return 0;
        }

        $data   = ArrayUtils::iteratorToArray( $structure->getBaseIterator() );
        $result = parent::save( $data );

        if ( $result > 0 )
        {
            if ( empty( $structure->id ) )
            {
                $structure->setOption( 'id', $id = $data['id'] );
            }
            else
            {
                $id = $structure->id;
            }

            foreach ( $structure->getPropertiesIterator() as $property => $value )
            {
                $result += $this->saveProperty(
                    $id, $structure::isPropertyLocaleAware( $property ),
                    $property, $value
                );
            }

            $tags = (array) $structure->getTags();
            $result += $this->deleteTagsNotIn( $id, $tags );

            foreach ( $tags as $tag )
            {
                $result += $this->setTagFor( $id, $tag );
            }
        }

        foreach ( $structure->getDependentStructures() as $depStruct )
        {
            if ( empty( $depStruct ) )
            {
                continue;
            }

            if ( $depStruct instanceof MapperAwareAbstract )
            {
                $result += $depStruct->save();
            }
            else if ( $depStruct instanceof MapperAwareInterface )
            {
                $result += $depStruct->getMapper()
                                     ->save( $depStruct );
            }
        }

        return $result;
    }
914320
protected function getAlterTableSql(\SimpleXMLElement $structure)
	{
		// Initialise variables.
		$table     = $this->getRealTableName($structure['name']);
		$oldFields = $this->db->getTableColumns($table);
		$oldKeys   = $this->db->getTableKeys($table);
		$alters    = array();

		// Get the fields and keys from the XML that we are aiming for.
		$newFields = $structure->xpath('field');
		$newKeys   = $structure->xpath('key');

		// Loop through each field in the new structure.
		foreach ($newFields as $field)
		{
			$fName = (string) $field['Field'];

			if (isset($oldFields[$fName]))
			{
				// The field exists, check it's the same.
				$column = $oldFields[$fName];

				// Test whether there is a change.
				$change = ((string) $field['Type'] !== $column->Type) || ((string) $field['Null'] !== $column->Null)
					|| ((string) $field['Default'] !== $column->Default) || ((string) $field['Extra'] !== $column->Extra);

				if ($change)
				{
					$alters[] = $this->getChangeColumnSql($table, $field);
				}

				// Unset this field so that what we have left are fields that need to be removed.
				unset($oldFields[$fName]);
			}
			else
			{
				// The field is new.
				$alters[] = $this->getAddColumnSql($table, $field);
			}
		}

		// Any columns left are orphans
		foreach ($oldFields as $name => $column)
		{
			// Delete the column.
			$alters[] = $this->getDropColumnSql($table, $name);
		}

		// Get the lookups for the old and new keys.
		$oldLookup = $this->getKeyLookup($oldKeys);
		$newLookup = $this->getKeyLookup($newKeys);

		// Loop through each key in the new structure.
		foreach ($newLookup as $name => $keys)
		{
			// Check if there are keys on this field in the existing table.
			if (isset($oldLookup[$name]))
			{
				$same     = true;
				$newCount = \count($newLookup[$name]);
				$oldCount = \count($oldLookup[$name]);

				// There is a key on this field in the old and new tables. Are they the same?
				if ($newCount === $oldCount)
				{
					// Need to loop through each key and do a fine grained check.
					for ($i = 0; $i < $newCount; $i++)
					{
						$same = (((string) $newLookup[$name][$i]['Non_unique'] === $oldLookup[$name][$i]->Non_unique)
							&& ((string) $newLookup[$name][$i]['Column_name'] === $oldLookup[$name][$i]->Column_name)
							&& ((string) $newLookup[$name][$i]['Seq_in_index'] === $oldLookup[$name][$i]->Seq_in_index)
							&& ((string) $newLookup[$name][$i]['Collation'] === $oldLookup[$name][$i]->Collation)
							&& ((string) $newLookup[$name][$i]['Index_type'] === $oldLookup[$name][$i]->Index_type));

						/*
						Debug.
						echo '<pre>';
						echo '<br>Non_unique:   '.
							((string) $newLookup[$name][$i]['Non_unique'] == $oldLookup[$name][$i]->Non_unique ? 'Pass' : 'Fail').' '.
							(string) $newLookup[$name][$i]['Non_unique'].' vs '.$oldLookup[$name][$i]->Non_unique;
						echo '<br>Column_name:  '.
							((string) $newLookup[$name][$i]['Column_name'] == $oldLookup[$name][$i]->Column_name ? 'Pass' : 'Fail').' '.
							(string) $newLookup[$name][$i]['Column_name'].' vs '.$oldLookup[$name][$i]->Column_name;
						echo '<br>Seq_in_index: '.
							((string) $newLookup[$name][$i]['Seq_in_index'] == $oldLookup[$name][$i]->Seq_in_index ? 'Pass' : 'Fail').' '.
							(string) $newLookup[$name][$i]['Seq_in_index'].' vs '.$oldLookup[$name][$i]->Seq_in_index;
						echo '<br>Collation:    '.
							((string) $newLookup[$name][$i]['Collation'] == $oldLookup[$name][$i]->Collation ? 'Pass' : 'Fail').' '.
							(string) $newLookup[$name][$i]['Collation'].' vs '.$oldLookup[$name][$i]->Collation;
						echo '<br>Index_type:   '.
							((string) $newLookup[$name][$i]['Index_type'] == $oldLookup[$name][$i]->Index_type ? 'Pass' : 'Fail').' '.
							(string) $newLookup[$name][$i]['Index_type'].' vs '.$oldLookup[$name][$i]->Index_type;
						echo '<br>Same = '.($same ? 'true' : 'false');
						echo '</pre>';
						 */

						if (!$same)
						{
							// Break out of the loop. No need to check further.
							break;
						}
					}
				}
				else
				{
					// Count is different, just drop and add.
					$same = false;
				}

				if (!$same)
				{
					$alters[] = $this->getDropKeySql($table, $name);
					$alters[] = $this->getAddKeySql($table, $keys);
				}

				// Unset this field so that what we have left are fields that need to be removed.
				unset($oldLookup[$name]);
			}
			else
			{
				// This is a new key.
				$alters[] = $this->getAddKeySql($table, $keys);
			}
		}

		// Any keys left are orphans.
		foreach ($oldLookup as $name => $keys)
		{
			if (strtoupper($name) === 'PRIMARY')
			{
				$alters[] = $this->getDropPrimaryKeySql($table);
			}
			else
			{
				$alters[] = $this->getDropKeySql($table, $name);
			}
		}

		return $alters;
	}
770724
public function addStructureNodeRelatedByStructureNodeId(ChildStructureNode $structureNodeRelatedByStructureNodeId)
    {
        if ($this->collStructureNodesRelatedByStructureNodeId === null) {
            $this->initStructureNodesRelatedByStructureNodeId();
        }

        if (!$this->getStructureNodesRelatedByStructureNodeId()->contains($structureNodeRelatedByStructureNodeId)) {
            // only add it if the **same** object is not already associated
            $this->collStructureNodesRelatedByStructureNodeId->push($structureNodeRelatedByStructureNodeId);
            $this->doAddStructureNodeRelatedByStructureNodeId($structureNodeRelatedByStructureNodeId);
        }

        return $this;
    }
591293
public function extract( $structure )
    {
        if ( $structure instanceof StructureAbstract )
        {
            return $structure->toArray();
        }

        if ( $structure instanceof Traversable )
        {
            return ArrayUtils::iteratorToArray( $structure );
        }

        return (array) $structure;
    }
1038260
public function save( & $structure )
    {
        $id = $this->getSaveProperty( $structure, 'id' );

        if ( empty( $id ) )
        {
            $selector = $this->getSaveProperty( $structure, 'selector', '' );
            $media    = $this->getSaveProperty( $structure, 'media', '' );
            $rootId   = $this->getSaveProperty( $structure, 'rootParagraphId' );
            $sql      = $this->sql();
            $select   = $sql->select()
                            ->columns( array( 'id' ) )
                            ->where( array(
                                'selector'        => $selector,
                                'media'           => $media,
                                'rootParagraphId' => $rootId,
                            ) )
                            ->limit( 1 );

            $result = $sql->prepareStatementForSqlObject( $select )
                          ->execute();

            if ( $result->getAffectedRows() )
            {
                foreach ( $result as $row )
                {
                    $this->setSaveProperty( $structure, 'id', $row['id'] );
                }
            }
        }

        $result = parent::save( $structure );
        $id     = $this->getSaveProperty( $structure, 'id' );

        if ( $result > 0 && ! empty( $id ) )
        {
            switch ( true )
            {
                case $structure instanceof Structure:
                    $properties = $structure->getRawProperties();
                    break;

                case is_array( $structure ):
                    $properties = isset( $structure['properties'] )
                        ? $structure['properties']
                        : array();
                    break;

                case is_object( $structure ):
                    $properties = isset( $structure->properties )
                        ? $structure->properties
                        : array();
                    break;

                default:
                    return $result;
            }

            $sql = $this->sql( $this->getTableInSchema(
                static::$propertyTableName
            ) );

            if ( empty( $properties ) )
            {
                $delete = $sql->delete()
                              ->where( array(
                                  'ruleId' => $id,
                              ) );

                $result += $sql->prepareStatementForSqlObject( $delete )
                               ->execute()
                               ->getAffectedRows();
            }
            else
            {
                $propNames = array();

                foreach ( $properties as $name => $spec )
                {
                    $propNames[] = $propName = empty( $spec['name'] )
                        ? $name : $spec['name'];

                    $result += $this->saveProperty(
                        $id,
                        $propName,
                        $spec['value'],
                        $spec['priority']
                    );
                }

                $delete = $sql->delete()
                              ->where( array(
                                  'ruleId' => $id,
                                  new NotIn( 'name', $propNames ),
                              ) );

                $result += $sql->prepareStatementForSqlObject( $delete )
                               ->execute()
                               ->getAffectedRows();
            }
        }

        return $result;
    }
804204
protected function getSectionStructureFromIncomingStructure($section)
    {
        $pos = strpos($section, '.');
        if ($pos === false) {
            $section = (int) $section;
            if ($section === 0) {
                return $this->structure;
            }

            return $this->structure->parts[($section - 1)];
        }
        $sections = explode('.', $section);
        $count = count($sections);
        $outObject = null;
        foreach ($sections as $section) {
            $section = (int) $section;
            if (!isset($outObject)) {
                $outObject = $this->getObjectStructureFromParts($this->structure, ($section - 1));
            } else {
                $outObject = $this->getObjectStructureFromParts($outObject, ($section - 1));
            }
        }

        return $outObject;
    }
1059
private function resolveView(StructureInterface $structure, array $data)
    {
        $structure->setWebspaceKey($this->getWebspaceKey());

        $view = [];
        foreach ($structure->getProperties(true) as $child) {
            if (array_key_exists($child->getName(), $data)) {
                $child->setValue($data[$child->getName()]);
            }

            $contentType = $this->contentTypeManager->get($child->getContentTypeName());
            $view[$child->getName()] = $contentType->getViewData($child);
        }

        return $view;
    }
990157
public function section_shuffle_questions(structure $structure, $section) {
        $checkboxattributes = array(
            'type' => 'checkbox',
            'id' => 'shuffle-' . $section->id,
            'value' => 1,
            'data-action' => 'shuffle_questions',
            'class' => 'cm-edit-action',
        );

        if (!$structure->can_be_edited()) {
            $checkboxattributes['disabled'] = 'disabled';
        }
        if ($section->shufflequestions) {
            $checkboxattributes['checked'] = 'checked';
        }

        if ($structure->is_first_section($section)) {
            $help = $this->help_icon('shufflequestions', 'quiz');
        } else {
            $help = '';
        }

        $helpspan = html_writer::span($help, 'shuffle-help-tip');
        $progressspan = html_writer::span('', 'shuffle-progress');
        $checkbox = html_writer::empty_tag('input', $checkboxattributes);
        $label = html_writer::label(get_string('shufflequestions', 'quiz'),
                $checkboxattributes['id'], false);
        return html_writer::span($progressspan . $checkbox . $label. ' ' . $helpspan,
                'instanceshufflequestions', array('data-action' => 'shuffle_questions'));
    }
693939
public function save( & $structure )
    {
        if ( is_object( $structure ) )
        {
            $name = (string) $structure->name;
            $code = (string) $structure->code;
        }
        else if ( is_array( $structure ) )
        {
            $name = (string) $structure['name'];
            $code = (string) $structure['code'];
        }
        else
        {
            return 0;
        }

        if ( empty( $name ) )
        {
            return 0;
        }

        $ext = strrchr( $name, '.' );

        if ( empty( $ext ) || ! in_array( $ext, $this->allowedExtensions ) )
        {
            return 0;
        }

        return @ file_put_contents( $this->getSavePath() . $name, $code ) ? 1 : 0;
    }
170400
private static function appendValueIntoStructure(
        array &$structure,
        $key,
        $value
    ) {
        $pointer = &$structure;
        while (!empty($pointer)) {
            $currentKey = key($pointer);
            $pointer = &$pointer[$currentKey];
        }
        $pointer[$key] = $value;
    }
1080608
public function structureMetadata()
    {
        if ($this->structureMetadata === null || $this->isStructureFinalized === false) {
            $this->structureMetadata = $this->loadStructureMetadata();
        }

        return $this->structureMetadata;
    }
704635
public function __HANDLER($structure = null)
    {
        $this->view('www/index')
            ->table(new Table($structure))
            ->structures($structure)
            ->title('Выгрузка материалов');
    }
778636
public function hasExtension($structureType, $name)
    {
        $extensions = $this->getExtensions($structureType);

        return isset($extensions[$name]);
    }
310410
public function hydrate( array $data, $structure )
    {
        if ( $structure instanceof Structure )
        {
            if ( isset( $data[self::PROPERTIES_FIELD] ) )
            {
                $properties = $data[self::PROPERTIES_FIELD] ?: array();
                unset( $data[self::PROPERTIES_FIELD] );

                if ( is_string( $properties ) )
                {
                    $properties = $this->parseProperties( $properties );
                }

                if ( is_array( $properties ) )
                {
                    $data[self::PROPERTIES_FIELD] = $properties;
                }
            }
            else
            {
                $data[self::PROPERTIES_FIELD] = array();
            }
        }

        return parent::hydrate( $data, $structure );
    }
1237295
public function addStructureNodeRelatedByParentId(ChildStructureNode $structureNodeRelatedByParentId)
    {
        if ($this->collStructureNodesRelatedByParentId === null) {
            $this->initStructureNodesRelatedByParentId();
        }

        if (!$this->getStructureNodesRelatedByParentId()->contains($structureNodeRelatedByParentId)) {
            // only add it if the **same** object is not already associated
            $this->collStructureNodesRelatedByParentId->push($structureNodeRelatedByParentId);
            $this->doAddStructureNodeRelatedByParentId($structureNodeRelatedByParentId);
        }

        return $this;
    }