Zum Inhalt springen

Subpart schachteln und ersetzen

Erstellt am 4. Juni 2009 · Noch keine Antworten

Tags: PHP, Frage

eschemaster ·

Hallo,

ich schreibe grade eine Extension für eine Benutzerverwaltung. Dabei habe ich ein paar Probleme beim Ersetzen der Subparts.
Irgendwie scheint es "verschatelte Subparts" nicht so zu geben. Ich denke das ich einfach einen Denkfehler drin habe. Deswegen poste ich im folgenden einfach mal das HTML-Template und meine pi1-Klasse. Vielleicht kann mir ja jmd. helfen.

HTML-Template

<!--###SCHOOLSLIST### start-->
	<div id="schools">
		<div class="admin-head"> Schulen </div>
		<table border="0" cellspacing="0" cellpadding="0">
			<thead>
				<tr>
					<th> Schule </th> 
					<th> Strasse </th> 
					<th> PLZ </th> 
					<th> Ort </th> 
					<th> </th> 
					<th> Details </th> 
					<th> Ändern </th> 									
					<th> Löschen </th> 
					<th> Aktivität </th>
				</tr>
			</thead>
			<tbody>
				<!--###SCHOOLCONTENT### start-->
					<!--###SCHOOLITEM### start-->
						<tr id="schoolrow">
							<td> ###sschool### </td> <td> ###sstreet###</td> <td> ###splz###</td> <td> ###scity###</td><td> x</td> x<td> x</td> <td> x</td>
						</tr>
						<tr>
							<td colspan="8" class="nontdstyle">
								<div id="teachers"> 
			                        <div class="admin-head"> Lehrer </div>
			                        <table cellpadding="0" cellspacing="0">
			                        	<thead>
			                            	<tr>
			                                	<th> Vorname </th> 
												<th> Nachname </th> 
												<th> PLZ </th> 
												<th> Ort </th> 
												<th> Details </th> 
												<th> Ändern </th> 
												<th> Löschen </th>
												<th> Aktivität</th>
			                                </tr>
			                            </thead>
			                            <tbody>
											<!-- ###TEACHERCONTENT### begin -->
												<!-- ###TEACHERITEM### begin -->
							                    	<tr id="teacherrow"> 
						                            	<td> ###tfirstname### </td> 
														<td> ###tlastname###</td> 
														<td> ###tplz###</td> 
														<td> ###tcity###</td> 
														<td> x</td> 
														<td> x</td> 
														<td> x</td> 
														<td> x</td> 
						                           </tr>
                                               
							                    <!-- ###TEACHERITEM### end -->
											<!-- ###TEACHERCONTENT### end -->
										</tbody>
									</table>
								</div>
							</td>
						</tr>

					<!--###SCHOOLITEM### stop-->
				<!--###SCHOOLCONTENT### stop-->
			</tbody>

		</table>
	</div>
<!--###SCHOOLSLIST### start-->

PHP PI-Klasse meiner Extension

function main($content, $conf) {
		$this->conf = $conf;
		$this->pi_setPiVarDefaults();
		$this->pi_loadLL();
		

	 $this->templateCode = $this->cObj->fileResource("fileadmin/templates/ce_administrationgui.html");
	 $template['total'] = $this->cObj->getSubpart($this->templateCode,'###SCHOOLSLIST###');
	 $template['schoolcontent'] = $this->cObj->getSubpart($template['total'],'###SCHOOLCONTENT###');

	 $template['schoolitem'] = $this->cObj->getSubpart($template['total'],'###SCHOOLITEM###');
	 $template['teacheritem'] = $this->cObj->getSubpart($template['schoolcontent'],'###TEACHERITEM###');
	//t3lib_div::debug($template['teacheritem']);
	   
	$res = $this->getSchools();
	
	// Fill marker
	while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
		$markerArray['###sschool###'] = $row['username'];
		$markerArray['###sstreet###'] = $row['first_name'];
		$markerArray['###splz###'] = $row['last_name'];
		$markerArray['###scity###'] = $row['email'];
		
		$teachersOfASchool = $this->getTeachersOfASchool($row['uid']);
		while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($teachersOfASchool)) {
			$markerArray['###tfirstname###'] = $row['username'];
			$markerArray['###tlastname###'] = $row['first_name'];
			$markerArray['###tplz###'] = $row['last_name'];
			$markerArray['###tcity###'] = $row['email'];
			
			$teachercontent_item .= $this->cObj->substituteMarkerArrayCached($template['teacheritem'], $markerArray);
		}
		//t3lib_div::debug($subpartArray['###TEACHERCONTENT###']);
		$schoolcontent_item .= $this->cObj->substituteMarkerArrayCached($template['schoolitem'], $markerArray);
	}
	$subpartArray['###SCHOOLCONTENT###'] = $schoolcontent_item;
$subpartArray1['###TEACHERCONTENT###'] .= $teachercontent_item;
	$content .= $this->cObj->substituteMarkerArrayCached($template['total'],$markerArray,$subpartArray,$subpartArray1);

	t3lib_div::debug($subpartArray);
	return $this->pi_wrapInBaseClass($content);
		
	}

	function getSchools() {
		$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery (
      	'uid,username,first_name, last_name, usergroup, email, zip, city, image',
      	'fe_users',
		'usergroup=14 AND deleted=0',
      	'',
      	'username'
      );
		return $res;
	}
	
	function getTeachersOfASchool($school_uid="") {
		$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery (
      	'uid,username,first_name, last_name, usergroup, email, zip, city, image, tx_extendfieldssrfeuser_schools',
      	'fe_users',
		'usergroup=4 AND deleted=0 AND tx_extendfieldssrfeuser_schools ='. $school_uid,
      	'',
      	'username'
      );
		return $res;
	}
	
	function getClassesOfATeacher($teacher_uid="") {
		$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery (
      	'uid,username,first_name, last_name, usergroup, email, zip, city, image, tx_extendfieldssrfeuser_teachers',
      	'fe_users',
		'usergroup=15 AND deleted=0 AND tx_extendfieldssrfeuser_schools ='. $teacher_uid,
      	'',
      	'username'
      );
		return $res;
	}
}

Das komische ist das alle mit diesem Code alle Schulen ausgegeben werden, aber immer der gleiche Lehrer.
Außerdem wird zwar zu jeder Schule der gleiche Lehrer angezeigt (auch obwohl er nicht zu dieser Schule gehört) aber die beiden Marker aus dem Template ###TEACHERCONTENT### ###TEACHERITEM### wird nicht ersetzten, stehen also weiterhin im ausgegebenen Template.
Kommentiere ich Zeile 36 aus, werden alle Lehrer angezeigt.

Ich hoffe Ihr könnt mir helfen. Vielen Dank schon mal an euch
Christopher