Перестановка значений индекса сортировки между двумя записями
@param ActiveRecordInterface $row1
@param ActiveRecordInterface $row2
334228
protected static function swapRows(ActiveRecordInterface $row1, ActiveRecordInterface $row2)
    {
        $id     = $row1->getRoleField('id');
        $column = $row1->getRoleField('sort-index');
        $value1 = $row1->getRoleValue('sort-index');
        $value2 = $row2->getRoleValue('sort-index');
        $row1::query()->update([$column=>$value2], QueryCriteria::createAND([[$id, '=', $row1->getRoleValue('id')]]))->execute();
        $row2::query()->update([$column=>$value1], QueryCriteria::createAND([[$id, '=', $row2->getRoleValue('id')]]))->execute();
    }
206714
public function execute($row, $name = null)
    {
        parent::execute($row, $name);
        return $row[MemberNames::ROW_ID];
    }
1237869
public function write_record($record, $rownum) {
        echo \html_writer::start_tag('tr');
        foreach ($record as $cell) {
            echo \html_writer::tag('td', $cell);
        }
        echo \html_writer::end_tag('tr');
    }
37193
private function populateRecord($query,$row)
	{
		// determine the primary key value
		if(is_string($this->_pkAlias))  // single key
		{
			if(isset($row[$this->_pkAlias]))
				$pk=$row[$this->_pkAlias];
			else	// no matching related objects
				return null;
		}
		else // is_array, composite key
		{
			$pk=array();
			foreach($this->_pkAlias as $name=>$alias)
			{
				if(isset($row[$alias]))
					$pk[$name]=$row[$alias];
				else	// no matching related objects
					return null;
			}
			$pk=serialize($pk);
		}

		// retrieve or populate the record according to the primary key value
		if(isset($this->records[$pk]))
			$record=$this->records[$pk];
		else
		{
			$attributes=array();
			$aliases=array_flip($this->_columnAliases);
			foreach($row as $alias=>$value)
			{
				if(isset($aliases[$alias]))
					$attributes[$aliases[$alias]]=$value;
			}
			$record=$this->model->populateRecord($attributes,false);
			foreach($this->children as $child)
			{
				if(!empty($child->relation->select))
					$record->addRelatedRecord($child->relation->name,null,$child->relation instanceof CHasManyRelation);
			}
			$this->records[$pk]=$record;
		}

		// populate child records recursively
		foreach($this->children as $child)
		{
			if(!isset($query->elements[$child->id]) || empty($child->relation->select))
				continue;
			$childRecord=$child->populateRecord($query,$row);
			if($child->relation instanceof CHasOneRelation || $child->relation instanceof CBelongsToRelation)
				$record->addRelatedRecord($child->relation->name,$childRecord,false);
			else // has_many and many_many
			{
				// need to double check to avoid adding duplicated related objects
				if($childRecord instanceof CActiveRecord)
					$fpk=serialize($childRecord->getPrimaryKey());
				else
					$fpk=0;
				if(!isset($this->_related[$pk][$child->relation->name][$fpk]))
				{
					if($childRecord instanceof CActiveRecord && $child->relation->index!==null)
						$index=$childRecord->{$child->relation->index};
					else
						$index=true;
					$record->addRelatedRecord($child->relation->name,$childRecord,$index);
					$this->_related[$pk][$child->relation->name][$fpk]=true;
				}
			}
		}

		return $record;
	}
1026906
public function castRow($row)
    {
        if ($this->isLocked) {
            // schema is locked, no more inferring is needed
            return parent::castRow($row);
        } else {
            // add the row to the inferrer, update the descriptor according to the best inferred fields
            $this->fieldsInferer->addRows([$row]);
            $this->descriptor->fields = [];
            foreach ($this->fieldsInferer->infer() as $fieldName => $inferredField) {
                /* @var Fields\BaseField $inferredField */
                $this->descriptor->fields[] = $inferredField->descriptor();
            }
            $this->castRows = $this->fieldsInferer->castRows();

            return $this->castRows[count($this->castRows) - 1];
        }
    }
881788
function Set(&$row)
	{
	global $ACTIVE_RECORD_SAFETY;

		$db = $this->DB();

		if (!$row) {
			$this->_saved = false;
			return false;
		}

		$this->_saved = true;

		$table = $this->TableInfo();
		$sizeofFlds = sizeof($table->flds);
		$sizeofRow  = sizeof($row);
		if ($ACTIVE_RECORD_SAFETY && $table->_colsCount != $sizeofRow && $sizeofFlds != $sizeofRow) {
			# <AP>
			$bad_size = TRUE;
			if($sizeofRow == 2 * $table->_colsCount || $sizeofRow == 2 * $sizeofFlds) {
				// Only keep string keys
				$keys = array_filter(array_keys($row), 'is_string');
				if (sizeof($keys) == sizeof($table->flds)) {
					$bad_size = FALSE;
				}
			}
			if ($bad_size) {
				$this->Error("Table structure of $this->_table has changed","Load");
				return false;
			}
			# </AP>
		}
		else {
			$keys = array_keys($row);
		}

		# <AP>
		reset($keys);
		$this->_original = array();
		foreach($table->flds as $name=>$fld) {
			$value = $row[current($keys)];
			$this->$name = $value;
			$this->_original[] = $value;
			if(!next($keys)) {
				break;
			}
		}
		$table =& $this->TableInfo();
		foreach($table->_belongsTo as $foreignTable) {
			$ft = $foreignTable->TableInfo();
			$propertyName = $ft->name;
			foreach($ft->flds as $name=>$fld) {
				$value = $row[current($keys)];
				$foreignTable->$name = $value;
				$foreignTable->_original[] = $value;
				if(!next($keys)) {
					break;
				}
			}
		}
		foreach($table->_hasMany as $foreignTable) {
			$ft = $foreignTable->TableInfo();
			foreach($ft->flds as $name=>$fld) {
				$value = $row[current($keys)];
				$foreignTable->$name = $value;
				$foreignTable->_original[] = $value;
				if(!next($keys)) {
					break;
				}
			}
		}
		# </AP>

		return true;
	}
45245
public function addRowWithCount($row, $writer, $rowNumber)
    {
        $exportRow   = $this->filterRow($row);
        $labeledCols = $this->getLabeledColumns();
        $exportRow   = array_replace(array_flip($labeledCols), $exportRow);
        $writer->addRow($exportRow);
    }
209090
public static void swapRows(Matrix matrix, long row1, long row2) {
		double temp = 0;
		long cols = matrix.getColumnCount();
		for (long col = 0; col < cols; col++) {
			temp = matrix.getAsDouble(row1, col);
			matrix.setAsDouble(matrix.getAsDouble(row2, col), row1, col);
			matrix.setAsDouble(temp, row2, col);
		}
	}
38667
public static function addRowsToMap($rows)
    {
        $firstRow = reset($rows);
        $idAttribute = static::getIdAttribute();
        if ($firstRow instanceof ActiveRecord) {
            foreach ($rows as $row) {
                self::$identityMap[$row[$idAttribute]] = $row->toArray();
                foreach (static::getUniqueAttributes() as $uniqueAttribute) {
                    self::$uniqueAttributeToId[$uniqueAttribute][$row[$uniqueAttribute]] = $row[$idAttribute];
                }
            }
        } else {
            foreach ($rows as $row) {
                self::$identityMap[$row[$idAttribute]] = $row;
                foreach (static::getUniqueAttributes() as $uniqueAttribute) {
                    self::$uniqueAttributeToId[$uniqueAttribute][$row[$uniqueAttribute]] = $row[$idAttribute];
                }
            }
        }
        $maxSize = self::getIdentityMapMaxSize();
        if ($maxSize !== -1) {
            $count = count(self::$identityMap);
            if ($count > $maxSize) {
                self::$identityMap = array_slice(
                    self::$identityMap,
                    $count - $maxSize,
                    $maxSize
                );
            }
        }
    }
1316818
public function filterSubTable(Row $row)
    {
        if (!$this->enableRecursive) {
            return;
        }
        $subTable = $row->getSubtable();
        if ($subTable) {
            $this->filter($subTable);
        }
    }
855179
public function create($rowOrName, $type = null, array $data = [])
    {
        // Check if row or name is defined
        if (!(
            $rowOrName instanceof Model\RowInterface ||
            (is_string($rowOrName) && 0 < strlen($rowOrName))
        )
        ) {
            throw new InvalidOperationException("Excepted instance of RowInterface or string.");
        }

        // Default type if null
        if (null === $type) {
            $type = $this->defaultType;
        }

        // New instance
        $block = $this->editor->getRepository()->createBlock();
        $block->setType($type);

        // Layout creation
//        $this->editor->getLayoutAdapter()->createBlock($block, $data);

        // Plugin creation
        $this->editor->getBlockPlugin($type)->create($block, $data);

        // Add to row if available
        if ($rowOrName instanceof Model\RowInterface) {
            $count = $rowOrName->getBlocks()->count();
            $block
                ->setPosition($count);

            $rowOrName->addBlock($block);
        } else {
            $block->setName($rowOrName);
        }

        return $block;
    }
1305332
public function fill($model, $row)
    {
        if ($this->constant == false) {
            if (isset($this->defaultValue) && $this->defaultValue != null) {
                $model->{$this->nameInModel} = $this->defaultValue;
            }
            foreach ($this->nameInFile as $subkey) {
                if (isset($row[$subkey])) {
                    $model->{$this->nameInModel} = $this->parse($row[$subkey], $row);
                    return true;
                }
            }
        } else {
            $model->{$this->nameInModel} = $this->constant;
            return true;
        }
        return false;
    }
817710
public function on($column1, $column2 = null, $operator = '=')
    {
        return $this->addJoinCondition($column1, $column2, $operator);
    }
565080
public function add(Row $row) : bool
    {
        if ($row->getTable()->getName() !== $this->table->getName()) {
            throw InvalidArgumentException::format(
                    'The supplied row does not match the table: expecting %s, %s given',
                    $this->table->getName(),
                    $row->getTable()->getName()
            );
        }

        if ($this->primaryKey && $row->hasColumn($this->primaryKey) && $this->has($row->getColumn($this->primaryKey))) {
            return false;
        }

        $this->rows[] = $row;

        return true;
    }
689353
public function withPredefinedRowValues(FieldBuilderBase $field, array $rowValues) : TableCellValueFieldDefiner
    {
        $this->fieldBuilder->attr(TableType::ATTR_PREDEFINED_ROWS, array_values($rowValues));
        return $this->withRowKeyAs($field);
    }
618537
public function addRowAction(RowAction $rowAction, callable $rowActionInit = null) : self
    {
        $this->rowActions[] = $rowAction;
        $this->rowActionInit[] = $rowActionInit;

        return $this;
    }
30272
private function resolvePermissions(Row $row, UserInterface $user = null)
    {
        $permissions = [];
        if (null !== $user) {
            foreach ($user->getRoleObjects() as $role) {
                foreach (array_filter(explode(' ', $row->getValue(sprintf('role%s', $role->getId())))) as $permission) {
                    $permissions[$role->getId()][$permission] = true;
                }
            }
        }

        return $permissions;
    }