<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TYPO3Development &#187; Tips and Tricks</title>
	<atom:link href="http://blog.typoplanet.de/category/tips-and-tricks/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.typoplanet.de</link>
	<description>A blog for professional TYPO3 developers</description>
	<lastBuildDate>Mon, 28 Mar 2011 18:10:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>A book about Extbase and Fluid</title>
		<link>http://blog.typoplanet.de/2010/07/06/book-about-extbase-and-fluid/</link>
		<comments>http://blog.typoplanet.de/2010/07/06/book-about-extbase-and-fluid/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 16:22:38 +0000</pubDate>
		<dc:creator>Jochen Rau</dc:creator>
				<category><![CDATA[books]]></category>
		<category><![CDATA[Development Process]]></category>
		<category><![CDATA[Extbase]]></category>
		<category><![CDATA[My Projects]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://blog.typoplanet.de/?p=382</guid>
		<description><![CDATA[Writing a book is a huge project. I never believed those people saying &#8220;Just double the time of your first estimate&#8221;. Now, after the book is finally available I would say they are wrong. You have to increase it threefold. The book about Extbase and Fluid was written in close collaboration with Sebastian Kurfürst (core [...]]]></description>
			<content:encoded><![CDATA[<p>Writing a book is a huge project. I never believed those people saying &#8220;Just double the time of your first estimate&#8221;. Now, after the book is finally available I would say they are wrong. You have to increase it threefold.</p>
<p>The book about <a href="http://forge.typo3.org/projects/typo3v4-mvc">Extbase</a> and <a href="http://forge.typo3.org/projects/show/package-fluid">Fluid</a> was written in close collaboration with Sebastian Kurfürst (core developer of Fluid) and Inken Kiupel (reader). We hope that it encourages the developers of TYPO3 extensions to get in touch with the fascinating concepts of FLOW3. And we hope that the book eases the migration to TYPO3 v5 (that&#8217;s what Extbase is all about).</p>
<p>We are aware of the fact that many of the English speaking TYPO3 developers are eagerly waiting for more Books about Extbase and Fluid  published in English. Sebastian Kurfürst and I are currently investigating the best way to to get the book translated into English to be published on <a href="http://www.typo3.org">typo3.org</a>.</p>
<p>If you have any questions regarding the book, or found some typos (at least 3), feel free to use the comments facility (if it is positive ;-) ) or write me an <a href="mailto:book@typoplanet.de">e-mail</a>. I am really looking forward to hear from you.</p>
<p>You might want to support our work by <a href="http://www.amazon.de/gp/product/3897219654?ie=UTF8&amp;tag=typoplanet-21&amp;linkCode=as2&amp;camp=1638&amp;creative=6742&amp;creativeASIN=3897219654">ordering the book through this link</a><img style="border: none !important; margin: 0px !important;" src="http://www.assoc-amazon.de/e/ir?t=typoplanet-21&amp;l=as2&amp;o=3&amp;a=3897219654" border="0" alt="" width="1" height="1" />.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.typoplanet.de/2010/07/06/book-about-extbase-and-fluid/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>How to Effectively use the Repository and Query Object of Extbase?</title>
		<link>http://blog.typoplanet.de/2010/01/27/the-repository-and-query-object-of-extbase/</link>
		<comments>http://blog.typoplanet.de/2010/01/27/the-repository-and-query-object-of-extbase/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 17:13:32 +0000</pubDate>
		<dc:creator>Jochen Rau</dc:creator>
				<category><![CDATA[Extbase]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[extension development]]></category>
		<category><![CDATA[persistence]]></category>
		<category><![CDATA[query object]]></category>
		<category><![CDATA[repository]]></category>

		<guid isPermaLink="false">http://blog.typoplanet.de/?p=327</guid>
		<description><![CDATA[Extbase supports very well the idea of Domain-Driven Design. It supplies a Repository class to comfortably fetch your objects from. Some handy methods are already implemented. Let&#8217;s have a look at some example code. 12345678910111213141516171819202122$blog = new Tx_BlogExample_Domain_Model_Blog&#40;'TYPO3 Development'&#41;; $blog-&#62;setDescription&#40;'A blog for professional TYPO3 developers.'&#41;; $administrator = new Tx_BlogExample_Domain_Model_Administrator&#40;&#41;; $administrator-&#62;setName&#40;'Jochen Rau'&#41;; $administrator-&#62;setEmail&#40;'jochen.rau@example.com'&#41;; $blog-&#62;setAdministrator&#40;$administrator&#41;; $post = [...]]]></description>
			<content:encoded><![CDATA[<p>Extbase supports very well the idea of Domain-Driven Design. It supplies a <code class="codecolorer php dawn"><span class="php">Repository</span></code> class to comfortably fetch your objects from. Some handy methods are already implemented. <span id="more-327"></span> Let&#8217;s have a look at some example code.</p>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$blog</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Tx_BlogExample_Domain_Model_Blog<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'TYPO3 Development'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$blog</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDescription</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'A blog for professional TYPO3 developers.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000088;">$administrator</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Tx_BlogExample_Domain_Model_Administrator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$administrator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Jochen Rau'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$administrator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setEmail</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jochen.rau@example.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$blog</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAdministrator</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$administrator</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000088;">$post</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Tx_BlogExample_Domain_Model_Post<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Effectively use the Query Object of Extbase'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setContent</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Extbase is a framework to develop ... hey, we\'re getting recursive now!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000088;">$comment</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Tx_BlogExample_Domain_Model_Comment<span style="color: #339933;">;</span><br />
<span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDate</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> DateTime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAuthor</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Peter Pan'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setEmail</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'peter.pan@example.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setContent</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Do you need some pills?.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addComment</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000088;">$blog</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addPost</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000088;">$blogRepository</span> <span style="color: #339933;">=</span> t3lib_div<span style="color: #339933;">::</span><span style="color: #004000;">makeInstance</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Tx_BlogExample_Domain_Repository_BlogRepository'</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000088;">$blogRepository</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$blog</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>In a first step, we create a new blog with an administrator, and a post with a comment. We instanciate the <code class="codecolorer php dawn"><span class="php">BlogRepository</span></code> in line 21 and add the blog to it. That&#8217;s all we have to do. The blog is now persisted and can be fetched later from the repository again. We don&#8217;t have to say <code class="codecolorer php dawn"><span class="php">save<span style="color: #009900;">&#40;</span><span style="color: #000088;">$blog</span><span style="color: #009900;">&#41;</span></span></code> at any time. The repository &#8220;takes care&#8221; of the blog.</p>
<p>Keep in mind that you have to instanciate the repository with <code class="codecolorer php dawn"><span class="php">t3lib_div<span style="color: #339933;">::</span><span style="color: #004000;">makeInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> as it is a Singleton. If you instanciate it with <code class="codecolorer php dawn"><span class="php"><span style="color: #000000; font-weight: bold;">new</span></span></code> the Repository will be always an empty one if Extbase searches for objects to be persisted.</p>
<p>The <code class="codecolorer php dawn"><span class="php">BlogRepository</span></code> class is as simple as this:</p>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">class</span> Tx_BlogExample_Domain_Repository_BlogRepository <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">extends</span> Tx_Extbase_Persistence_Repository <span style="color: #009900;">&#123;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Most of the methods needed are already implemented in the <code class="codecolorer php dawn"><span class="php">Tx_Extbase_Persistence_Repository</span></code>. These are:</p>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$repository</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$object</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000088;">$repository</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$object</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000088;">$repository</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$existingObject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$newObject</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000088;">$repository</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">update</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$modifiedObject</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000088;">$repository</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000088;">$repository</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">countAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Since Extbase 1.1</span><br />
<span style="color: #000088;">$repository</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">removeAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000088;">$repository</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000088;">$repository</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">countByProperty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Since Extbase 1.1</span><br />
<span style="color: #000088;">$repository</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findByProperty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000088;">$repository</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findOneByProperty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span></div></div>
<p>The methods <code class="codecolorer php dawn"><span class="php">add<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> and <code class="codecolorer php dawn"><span class="php">remove<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> are self-explanatory. <code class="codecolorer php dawn"><span class="php">replace<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> takes an untracked object and puts it at the &#8220;place&#8221; of an existing one where <code class="codecolorer php dawn"><span class="php">update<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> just takes an existing object and updates it with the property values of the modified object.</p>
<p>The <code class="codecolorer php dawn"><span class="php">findByProperty<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> and <code class="codecolorer php dawn"><span class="php">findOneByProperty<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> methods are magic methods where you can replace &#8220;Property&#8221; with the name of a property of the <code class="codecolorer php dawn"><span class="php">Blog</span></code> object. For example we can write <code class="codecolorer php dawn"><span class="php"><span style="color: #000088;">$blogRepository</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findByTitle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'My Blog'</span><span style="color: #009900;">&#41;</span></span></code> to fetch all Blogs with the given title. This also works for objects like in <code class="codecolorer php dawn"><span class="php"><span style="color: #000088;">$blogRepository</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findByAdministrator</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$administrator</span><span style="color: #009900;">&#41;</span></span></code> but not yet for properties holding aggregates. Thus, <code class="codecolorer php dawn"><span class="php"><span style="color: #000088;">$blogRepository</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findByPost</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span></span></code> won&#8217;t work by now. <code class="codecolorer php dawn"><span class="php">findOneByProperty<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> is pretty similar to <code class="codecolorer php dawn"><span class="php">findByProperty<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> but returns the only first Object found.</p>
<p>The <code class="codecolorer php dawn"><span class="php">countAll<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> and <code class="codecolorer php dawn"><span class="php">countByProperty<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> methods are similar to the according <code class="codecolorer php dawn"><span class="php">find</span></code> methods. But the don&#8217;t build objects. They only count resulting objects.</p>
<p>All these methods keep the underlying storage solution (mostly a relational database) transparent to the user. But what if we have special constraints that are not covered with the methods above? Let&#8217;s say we want to find the five most recent posts of a given blog. Then we can use a <code class="codecolorer php dawn"><span class="php">Query</span></code> object.  Let&#8217;s ask the <code class="codecolorer php dawn"><span class="php">PostRepository</span></code> for those posts:</p>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">class</span> Tx_BlogExample_Domain_Repository_PostRepository<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">extends</span> Tx_Extbase_Persistence_Repository <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> findRecentByBlog<span style="color: #009900;">&#40;</span>Tx_BlogExample_Domain_Model_Blog <span style="color: #000088;">$blog</span><span style="color: #339933;">,</span> <span style="color: #000088;">$limit</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">matching</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'blog'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$blog</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setOrderings</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'date'</span> <span style="color: #339933;">=&gt;</span> Tx_Extbase_Persistence_QueryInterface<span style="color: #339933;">::</span><span style="color: #004000;">ORDER_DESCENDING</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLimit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>integer<span style="color: #009900;">&#41;</span><span style="color: #000088;">$limit</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$posts</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$posts</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>The method <code class="codecolorer php dawn"><span class="php">createQuery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> returns an appropriate <code class="codecolorer php dawn"><span class="php">Query</span></code> object suitable for <code class="codecolorer php dawn"><span class="php">Post</span></code> objects. In Line 6 we define the constraint the posts should match: <code class="codecolorer php dawn"><span class="php"><span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">matching</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>constraint<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span></span></code>. The constraint is returned by <code class="codecolorer php dawn"><span class="php"><span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'blog'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$blog</span><span style="color: #009900;">&#41;</span></span></code>. There are some more methods returning a constraint:</p>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">logicalAnd</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$constraint1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$constraint2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">logicalOr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$constraint1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$constraint2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">logicalNot</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$constraint</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">withUid</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$uid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$propertyName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$operand</span><span style="color: #339933;">,</span> <span style="color: #000088;">$caseSensitive</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">in</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$propertyName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$operand</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Since Extbase 1.1</span><br />
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">contains</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$propertyName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$operand</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Since Extbase 1.1</span><br />
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">like</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$propertyName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$operand</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lessThan</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$propertyName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$operand</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lessThanOrEqual</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$propertyName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$operand</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">greaterThan</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$propertyName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$operand</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">greaterThanOrEqual</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$propertyName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$operand</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>We can define the orderings with <code class="codecolorer php dawn"><span class="php"><span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setOrderings</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>orderings<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span></span></code> where <code class="codecolorer php dawn"><span class="php"><span style="color: #009900;">&#91;</span>orderings<span style="color: #009900;">&#93;</span></span></code> is expected to be an array of property-order pairs. There are two constants defining the order:</p>
<ul>
<li>Order ascending: <code class="codecolorer php dawn"><span class="php">Tx_Extbase_Persistence_QueryInterface<span style="color: #339933;">::</span><span style="color: #004000;">ORDER_ASCENDING</span></span></code></li>
<li>Order descending: <code class="codecolorer php dawn"><span class="php">Tx_Extbase_Persistence_QueryInterface<span style="color: #339933;">::</span><span style="color: #004000;">ORDER_DESCENDING</span></span></code></li>
</ul>
<p>We limit the result set to a maximum of five posts with <code class="codecolorer php dawn"><span class="php"><span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLimit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>integer<span style="color: #009900;">&#41;</span><span style="color: #000088;">$limit</span><span style="color: #009900;">&#41;</span></span></code>. And finally invoke <code class="codecolorer php dawn"><span class="php"><span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> which returns us the already build posts with all their comments inside (if we are not &#8220;lazy&#8221; ;-) ). There is also a method <code class="codecolorer php dawn"><span class="php"><span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> which does  not fetch the resulting posts but counts them. Note that the <code class="codecolorer php dawn"><span class="php">Query</span></code> object enables chaining. Thus, the following code does the same as the given above:</p>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> findRecentByBlog<span style="color: #009900;">&#40;</span>Tx_BlogExample_Domain_Model_Blog <span style="color: #000088;">$blog</span><span style="color: #339933;">,</span> <span style="color: #000088;">$limit</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">matching</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'blog'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$blog</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setOrderings</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'date'</span> <span style="color: #339933;">=&gt;</span> Tx_Extbase_Persistence_QueryInterface<span style="color: #339933;">::</span><span style="color: #004000;">ORDER_DESCENDING</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLimit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>integer<span style="color: #009900;">&#41;</span><span style="color: #000088;">$limit</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>That&#8217;s it for today. I hope you got a deeper insight and I am looking forward to your comments. Maybe you want to join the discussion on the related <a href="http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc">mailing list</a>. I have taken most of the code from the extension <code class="codecolorer php dawn"><span class="php">BlogExample</span></code> which is available in the <a href="http://typo3.org/extensions/repository/view/blog_example/current/">Extension Repository (TER)</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.typoplanet.de/2010/01/27/the-repository-and-query-object-of-extbase/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>What I read about development</title>
		<link>http://blog.typoplanet.de/2009/02/23/what-i-read-about-development/</link>
		<comments>http://blog.typoplanet.de/2009/02/23/what-i-read-about-development/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 15:07:01 +0000</pubDate>
		<dc:creator>Jochen Rau</dc:creator>
				<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[patterns]]></category>

		<guid isPermaLink="false">http://blog.typoplanet.de/?p=41</guid>
		<description><![CDATA[Have a look at some of the books I’m reading (again and again). They were really eye-openers to me.]]></description>
			<content:encoded><![CDATA[<p>Here are some of the books I&#8217;m reading (again and again). They were really eye-openers to me.<span id="more-41"></span></p>
<table border="0">
<tbody>
<tr>
<td valign="top"><img class="alignnone size-full wp-image-221" title="31ywgz51v-l_sl110_" src="http://blog.typoplanet.de/wp-content/uploads/2009/03/31ywgz51v-l_sl110_.jpg" alt="31ywgz51v-l_sl110_" width="82" height="110" /></td>
<td style="padding-left: 30px;" valign="top"><strong>Domain-Driven Design</strong><br />
Eric Evans. Addison-Wesley Professional 2003, Hardcover,	 560 pages, $47.48</td>
</tr>
<tr>
<td valign="top"><img class="alignnone size-full wp-image-222" title="51sbuqixz9l_sl110_" src="http://blog.typoplanet.de/wp-content/uploads/2009/03/51sbuqixz9l_sl110_.jpg" alt="51sbuqixz9l_sl110_" width="85" height="110" /></td>
<td style="padding-left: 30px;" valign="top"><strong>Applying Domain-Driven Design and Patterns</strong><br />
Jimmy Nilsson. Addison-Wesley Professional 2006, Hardcover, 576 pages, $39.55</td>
</tr>
<tr>
<td valign="top"><img class="alignnone size-full wp-image-220" title="xUnit Test Patterns" src="http://blog.typoplanet.de/wp-content/uploads/2009/03/21hzfgxe4ql_sl110_.jpg" alt="xUnit Test Patterns" width="82" height="110" /></td>
<td style="padding-left: 30px;" valign="top"><strong>xUnit Test Patterns</strong><br />
Gerard Meszaros. Addison-Wesley 2007, Hardcover, 833 pages, $41.95</td>
</tr>
<tr>
<td valign="top"><img class="alignnone size-full wp-image-223" title="Patterns of Enterprise Application Architecture" src="http://blog.typoplanet.de/wp-content/uploads/2009/03/51x1k7r6fgl_sl110_.jpg" alt="Patterns of Enterprise Application Architecture" width="88" height="110" /></td>
<td style="padding-left: 30px;" valign="top"><strong>Patterns of Enterprise Application Architecture (Addison-Wesley Signature Series)<br />
</strong><br />
Martin Fowler. Addison-Wesley Professional 2002, Hardcover, 560 pages, $44.03</td>
</tr>
<tr>
<td valign="top"><img class="alignnone size-full wp-image-225" title="Refactoring" src="http://blog.typoplanet.de/wp-content/uploads/2009/02/21zcez5jbtl_sl110_.jpg" alt="Refactoring" width="86" height="110" /></td>
<td style="padding-left: 30px;" valign="top"><strong>Refactoring</strong><br />
Martin Fowler. Addison-Wesley Professional 1999, Hardcover, 464 pages, $38.00</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://blog.typoplanet.de/2009/02/23/what-i-read-about-development/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

