Zum Inhalt springen

Nur Records vom aktuellen Workspace anzeigen

Erstellt am 9. Mai 2007 · 10 Antworten · letzte Antwort am 28. Mai 2007

Tags: Frage

xtensionar ·

Hi,

ich wuerde mir gerne nur die Records von dem aktuell selektierten Workspace anzeigen lassen. Meine Query:

$sql = "select * from tx_e where deleted = 0 and hidden = 0";
$res = $GLOBALS['TYPO3_DB']->sql_query($sql);
while ($temp = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
	echo($temp['uid']);
}

Koennte da jemand noch paar Zeilen hinzufuegen? Vielen Dank!

steffenk ·
# Es gibt extra eine DB-API in Typo3, die sollte man auch nutzen, um kompatibel zu sein
$sql = "select * from tx_e where deleted = 0 and hidden = 0";
#siehe oben
$res = $GLOBALS['TYPO3_DB']->sql_query($sql);
while ($temp = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
      echo($temp['uid']);
} 
#ok, war wohl nicht die Antwort ?

:p

$GLOBALS['TSFE']->sys_page->versionOL('tx_e',$temp);
if (!$temp['uid']) { // if versionOL returns nothing the record is not visible in the selected Workspace
	echo($temp['uid']);
}

das ist wohl das was Du suchst

xtensionar ·
steffenk schrieb
# Es gibt extra eine DB-API in Typo3, die sollte man auch nutzen, um kompatibel 
#ok, war wohl nicht die Antwort ?

:p

$GLOBALS['TSFE']->sys_page->versionOL('tx_e',$temp);
if (!$temp['uid']) { // if versionOL returns nothing the record is not visible in the selected Workspace
	echo($temp['uid']);
}

das ist wohl das was Du suchst

Erst mal danke.

- Was hat denn die Verwendung der API fuer Vorteile?
- Das ist das, was ich suche, allerdings tut das nicht so wie ich will... 😉 Auch kapiere ich nicht, warum das Ausrufezeichen in folgendem Code gesetzt ist.

if (!$temp['uid']) 
	echo($temp['uid']); // wenn es nicht gesetzt ist, warum soll ich es dann ausgeben?

Welches DB-Feld ist denn ausschlaggebend fuer den Workspace? Danke!

xtensionar ·

ps:

Vielleicht sage ich noch kurz was nicht funktioniert.

Ich lege einen Eintrag im Draft-Workspace an. Wenn ich zu live wechsel, ist er in der "List" als nicht sichtbar markiert, in der "View" aber sichtbar.

Habe ich mit den Workspaces was missverstanden?

xtensionar ·

pps:

In der Datenbank existieren fuer den angelegten Eintrag zwei Rows?

Diese haben verschiedene "t3ver_label": INITIAL PLACEHOLDER und FIRST DRAFT VERSION.

"t3ver_wsid" (was wahrscheinlich die workspace id ist) ist in beiden auf '-1', was ja richtig waere.

"t3ver_state" unterscheidet sich noch mit '1' und '-1'.

Kann mir jemand erklaeren, warum das so ist, ob das alles korrekt ist und was versionOL() dabei macht? Danke!

steffenk ·

hi,

erstmal zur API - das hat mehrere Gründe, der wichtigste ist, das es so DBAL-kompatibel ist, so ist man nicht auf MySQL beschränkt.

versionOL() ist eine Funktion, die den passenden Eintrag für den Workspace zurückliefert. Ist er im Workspace nicht vorhanden, wird ein leeres Array zurückgeliefert. Daher die Abfrage
if(!temp['uid']) echo "gibts in diesem Workspace nicht!";

Das Handling habe ich bei tt_news abgeschaut, da Rupi sich mit dem Thema Workspaces eingehend befasst hat.

xtensionar ·

Hi,

das tut nicht wie es soll. Es werden zwar Drafts im Live-Workspace ausgeblendet, jedoch erscheinen diese auch nicht im Draft-Workspace.

Ich habe dieses versucht, jedoch erfolglos: http://www.typo24.com/137273.html

Hat jemand eine Idee?

$table = "tx_e";
 		$order = "date";
 		$query = $GLOBALS['TYPO3_DB']->SELECTquery($table.'.*', $table, $whereClause, '', $order); // no enableFields! and no limit!
 		$res = $GLOBALS['TYPO3_DB']->sql(TYPO3_db, $query);
		while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
		
			$GLOBALS['TSFE']->sys_page->versionOL($table, &$row);
			
			if (is_array($row) && $row['t3ver_state'] != 1 && $row['pid'] != -1) {
				
				// check if it is still there with enableFields
				$query = $GLOBALS['TYPO3_DB']->SELECTquery($table.'.uid', $table, $table.'.uid='.$row['uid'].''.$GLOBALS['TSFE']->cObj->enableFields($table), '', $order);
				$restmp = $GLOBALS['TYPO3_DB']->sql(TYPO3_db, $query);
				if ($GLOBALS['TYPO3_DB']->sql_num_rows($restmp) > 0) {
				
					// build model object.
					$e = new E();
					$e->setId($row['uid']);
					
				}				
			} // end if			
		} // end while
Spyker ·

wieso hast du denn in der ersten Query:
// no enableFields!

bzw. wieso nutzt du die Funktion dort nicht?
Die sorgt doch dafür das im Live System die Draft einträge ausgeschlossen werden.

Beste Grüße,
Tim

xtensionar ·

So, versionOL() darf anscheinend nur genutzt werden, wenn workspace == 0 (live) ist!?

while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {

	if ($GLOBALS['TSFE']->sys_page->versioningWorkspaceId == 0) {
		// overlay just for live workspace
		$GLOBALS['TSFE']->sys_page->versionOL($table, &$row);

		// see implementation guides: http://typo3.org/documentation/document-library/core-documentation/doc_core_api/4.1.0/view/3/2/#id3546785
		if (is_array($row) && $row['t3ver_state'] != 1 && $row['pid'] != -1) {

			// check if it is still there with enableFields
			$query = $GLOBALS['TYPO3_DB']->SELECTquery($table.'.uid', $table, $table.'.uid='.$row['uid'].''.$GLOBALS['TSFE']->cObj->enableFields($table), '', $order);
			$restmp = $GLOBALS['TYPO3_DB']->sql(TYPO3_db, $query);
			if ($GLOBALS['TYPO3_DB']->sql_num_rows($restmp) > 0) {
				// show
			}
		}
	} else if (is_array($row) && $row['t3ver_state'] != 1) {
		// live workspace is not selected

		// check if it is still there with enableFields
		$query = $GLOBALS['TYPO3_DB']->SELECTquery($table.'.uid', $table, $table.'.uid='.$row['uid'].''.$GLOBALS['TSFE']->cObj->enableFields($table), '', $order);
		$restmp = $GLOBALS['TYPO3_DB']->sql(TYPO3_db, $query);
		if ($GLOBALS['TYPO3_DB']->sql_num_rows($restmp) > 0) {
			// show
		}
	}
}

So funktioniert es zumindest, auch wenn ich glaube dass sich da noch Fehler verstecken...

Was ich noch nicht genau feststellen konnte, was ist enableFields und für was steht das feld p_id?

Wenn das noch jemand weiss, bitte posten.