Ejemplo n.º 1
0
function getRecordAsEditTableCells( IdStack $idPath, Editor $editor, Structure $visibleStructure, Record $record, &$startColumn = 0 ) {
	$result = '';
	$childEditorMap = $editor->getAttributeEditorMap();
	
	foreach ( $visibleStructure->getAttributes() as $visibleAttribute ) {
		$childEditor = $childEditorMap->getEditorForAttribute( $visibleAttribute );
		
		if ( $childEditor != null ) {
			$attribute = $childEditor->getAttribute();
			$type = $attribute->type;
			$value = $record->getAttributeValue( $attribute );
			$idPath->pushAttribute( $attribute );
				
			if ( $childEditor instanceof RecordTableCellEditor ) {
				$result .= getRecordAsEditTableCells( $idPath, $childEditor, $visibleAttribute->type, $value, $startColumn );
			} else {
				if ( $childEditor->showEditField( $idPath ) ) {
					$displayValue = $childEditor->edit( $idPath, $value );
				} else {
					$displayValue = "";
				}
				$result .= '<td class="' . getHTMLClassForType( $type, $attribute ) . ' column-' . parityClass( $startColumn ) . '">' . $displayValue . '</td>';
					
				$startColumn++;
			}
			
			$idPath->popAttribute();
		}
		else {
			$result .= "<td/>";
		}
	}
	return $result;
}
Ejemplo n.º 2
0
	public function edit( IdStack $idPath, $value ) {
		global $wgScriptPath ;

		$result = '<table id="' . $idPath->getId() . '" class="wiki-data-table">';
		$key = $value->getKey();
		$rowAttributes = $this->getRowAttributesText();
		$visibleStructure = $this->getTableStructureForEdit( $idPath, $value );
		
		$columnOffset = $this->allowRemove ? 1 : 0;
		$headerRows = getStructureAsTableHeaderRows( $visibleStructure, $columnOffset, $idPath );

		if ( $this->allowRemove )
			$headerRows[0] = '<th class="remove" rowspan="' . count( $headerRows ) . '"><img src="' . $wgScriptPath . '/extensions/Wikidata/Images/Delete.png"  title="' . wfMsgSc( "RemoveHint" ) . '" alt="' . wfMsgSc( "Remove" ) . '"/></th>' . $headerRows[0];

		if ( $this->repeatInput )
			$headerRows[0] .= '<th class="add" rowspan="' . count( $headerRows ) . '">Input rows</th>';

		foreach ( $headerRows as $headerRow )
			$result .= '<tr id="' . $idPath->getId() . '" ' .  $rowAttributes . '>' . $headerRow . '</tr>' . EOL;

		$recordCount = $value->getRecordCount();

		for ( $i = 0; $i < $recordCount; $i++ ) {
			$result .= '<tr>';
			$record = $value->getRecord( $i );
			$idPath->pushKey( project( $record, $key ) );

			if ( $this->allowRemove ) {
				$result .= '<td class="remove">';
				
				if ( $this->permissionController->allowRemovalOfValue( $idPath, $record ) )
				 	$result .= getRemoveCheckBox( 'remove-' . $idPath->getId() );
				 	
				$result .= '</td>' . EOL;
			}
			
			if ( $this->permissionController->allowUpdateOfValue( $idPath, $record ) )
				$result .= getRecordAsEditTableCells( $idPath, $this, $visibleStructure, $record );
			else
				$result .= getRecordAsTableCells( $idPath, $this, $visibleStructure, $record );
			
			$idPath->popKey();

			if ( $this->repeatInput )
				$result .= '<td/>' . EOL;

			$result .= '</tr>' . EOL;
		}
		
		if ( $this->allowAddController->check( $idPath ) )
			$result .= $this->getAddRowAsHTML( $idPath, $this->repeatInput, $this->allowRemove );

		$result .= '</table>' . EOL;

		return $result;
	}