 <?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>Christoph Hautzinger's Blog - diginights.com</title>
    <link>http://blog.hautzinger.info/</link>
    <description>Freakshow 2.0</description>
    <dc:language>de</dc:language>
    <generator>Serendipity 1.3.1 - http://www.s9y.org/</generator>
    <pubDate>Sun, 14 Oct 2007 14:30:58 GMT</pubDate>

    <image>
        <url>http://blog.hautzinger.info/templates/default/img/s9y_banner_small.png</url>
        <title>RSS: Christoph Hautzinger's Blog - diginights.com - Freakshow 2.0</title>
        <link>http://blog.hautzinger.info/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>Gartenlaube Homepage online</title>
    <link>http://blog.hautzinger.info/archives/32-Gartenlaube-Homepage-online.html</link>
            <category>diginights.com</category>
            <category>Fun</category>
    
    <comments>http://blog.hautzinger.info/archives/32-Gartenlaube-Homepage-online.html#comments</comments>
    <wfw:comment>http://blog.hautzinger.info/wfwcomment.php?cid=32</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://blog.hautzinger.info/rss.php?version=2.0&amp;type=comments&amp;cid=32</wfw:commentRss>
    

    <author>nospam@example.com (Christoph Hautzinger)</author>
    <content:encoded>
    Seit dieser Woche ist die neue &lt;a href=&quot;http://www.gartenlaube.com&quot; target=&quot;_blank&quot;&gt;Homepage der Heilbronner Gartenlaube&lt;/a&gt; online - bei genauerer Betrachtung fällt auf, dass es sich bei den eingebunden Partypics um Bilder von diginights handelt - sogar zu meiner Shooterzeit von 2004 sind noch einige Galerien mit dabei.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.gartenlaube.com/index.php?option=com_wrapper&amp;Itemid=37&quot; target=&quot;_blank&quot;&gt;&lt;br /&gt;
&lt;!-- s9ymdb:15 --&gt;&lt;img width=&quot;500&quot; height=&quot;576&quot; style=&quot;border: 0px; padding-left: 5px; padding-right: 5px;&quot; src=&quot;http://blog.hautzinger.info/uploads/img/gartenlaube/gartenlaube.jpg&quot; alt=&quot;&quot; /&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Um die Integration einfach zu gestalten, bieten wir seit geraumer Zeit einen speziellen Service an, der es externen Webseitenbetreibern ermöglicht, anhand eines speziell definierten Filters eine Teilmenge unseres Bilderrepositories (also beispielsweise sämtliche Bilder zu einer Location) auf ihrer Webseite in einem iFrame einzubinden, um so immer über aktuelle Bilder zu verfügen. Dieser Service wird auch von anderen Heilbronnern Clubs wie dem &lt;a href=&quot;http://creme21derclub.de&quot; target=&quot;_blank&quot;&gt;Creme 21&lt;/a&gt; oder dem &lt;a href=&quot;http://www.barococo-nightclub.de&quot; target=&quot;_blank&quot; target=&quot;_blank&quot;&gt;Barococo&lt;/a&gt; eingesetzt. Ein Webservice stand zur Designzeit damals garnicht zur Debatte, da die meisten Agenturen, die diese Clubwebseiten erstellen garnicht wissen, was das ist, geischweige denn, wie man gegen ihn programmiert &lt;img src=&quot;http://blog.hautzinger.info/templates/default/img/emoticons/wink.png&quot; alt=&quot;;-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt; .&lt;br /&gt;
&lt;br /&gt;
Bei noch genauerer Betrachtung der Galerien fällt auf, dass es sich hierbei um eine unbeabsichtigte optische Täuschung handelt - unser Gehirn denkt sich zwischen die einzelnen Bildquadrate dunkle Kreise, wie man im folgenden Bild noch besser erkennen kann:&lt;br /&gt;
&lt;br /&gt;
&lt;!-- s9ymdb:16 --&gt;&lt;img width=&quot;200&quot; height=&quot;276&quot; style=&quot;border: 0px; padding-left: 5px; padding-right: 5px;&quot; src=&quot;http://blog.hautzinger.info/uploads/img/gartenlaube/opttaeusch.gif&quot; alt=&quot;&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
  
    </content:encoded>

    <pubDate>Sun, 14 Oct 2007 16:30:00 +0200</pubDate>
    <guid isPermaLink="false">http://blog.hautzinger.info/archives/32-guid.html</guid>
    
</item>
<item>
    <title>Google Maps Coordinate Picker</title>
    <link>http://blog.hautzinger.info/archives/23-Google-Maps-Coordinate-Picker.html</link>
            <category>diginights.com</category>
            <category>Javascript</category>
            <category>PHP</category>
            <category>Symfony</category>
    
    <comments>http://blog.hautzinger.info/archives/23-Google-Maps-Coordinate-Picker.html#comments</comments>
    <wfw:comment>http://blog.hautzinger.info/wfwcomment.php?cid=23</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://blog.hautzinger.info/rss.php?version=2.0&amp;type=comments&amp;cid=23</wfw:commentRss>
    

    <author>nospam@example.com (Christoph Hautzinger)</author>
    <content:encoded>
    Lets have a look at one &lt;a href=&quot;http://diginights.com/location/creme21.html&quot; target=&quot;_blank&quot;&gt;diginights location-detail page&lt;/a&gt;: There is a Google Map on the bottom of the page which displays the locations&#039; accurate position. The database-table therfore holds three columns: The two coordinate values for lattitude an longitude and the zoom factor.&lt;br /&gt;
&lt;br /&gt;
Our problem was the missing userfriendly admin interface, so i wrote a little class for this purpose which uses the Google Maps API to select a coordinate by double clicking the map. Additionaly an adress can be looked up which uses Google&#039;s Geocoder class internally.&lt;br /&gt;
&lt;br /&gt;
&lt;fieldset&gt;&lt;legend&gt;&lt;strong&gt;See the code in action&lt;/strong&gt;&lt;/legend&gt;&lt;script src=&quot;http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;key=ABQIAAAA4qg3RjPmw94FWwwSfPHZjBTJ4WgYfy1epERbhjESjVKkK-giZBQ_peTKWrLb7P0z7pfACQnmqltvXg&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;&lt;script src=&quot;http://diginights.com/sf/prototype/js/prototype.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;&lt;script src=&quot;http://diginights.com/js/GMapsCoordPicker.class.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;lattitude: &lt;input type=&quot;text&quot; id=&quot;coordinate_x&quot; value=&quot;0&quot; /&gt; &lt;br /&gt;
longitude: &lt;input type=&quot;text&quot; id=&quot;coordinate_y&quot; value=&quot;0&quot; /&gt;&lt;br /&gt;
zoom: &lt;input type=&quot;text&quot; id=&quot;default_zoom&quot; value=&quot;0&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;width:100%;height:400px&quot;&gt;Zoom in first and then double click map to set coordinate!&lt;br /&gt;
&lt;div id=&quot;map&quot; style=&quot;width: 100%; height: 95%&quot;&gt;&lt;/div&gt;&lt;input type=&quot;text&quot; id=&quot;GMapCoordPickerQuery&quot; style=&quot;width:300px&quot; /&gt;&lt;input type=&quot;button&quot; onclick=&quot;gmcp.query($(&#039;GMapCoordPickerQuery&#039;).value)&quot; value=&quot;Lookup&quot; /&gt;&lt;br /&gt;
&lt;/div&gt;&lt;script language=&quot;JavaScript&quot; &gt;gmcp = new GMapsCoordPicker(&#039;coordinate_x&#039;,&#039;coordinate_y&#039;,&#039;default_zoom&#039;,&#039;map&#039;); &lt;/script&gt;&lt;/fieldset&gt;&lt;br /&gt;
&lt;br /&gt;
Feel free to download all necessary files here: &lt;a href=&quot;http://blog.hautzinger.info/uploads/GMapsCoordPicker.zip&quot; title=&quot;GMapsCoordPicker.zip&quot; target=&quot;_blank&quot;&gt;GMapsCoordPicker.zip&lt;/a&gt;. The zip-archive contains 4 files:&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;GMapsCoordPicker.class.js&lt;/strong&gt;&lt;br /&gt;
Put this file in your project&#039;s javascript directory (/web/js), it handls client side logic.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;GoogleMapsHelper.php&lt;/strong&gt;&lt;br /&gt;
Put this file in your project&#039;s helper dir (/lib/helper). It supplies a helper function &lt;em&gt;google_maps_coord_picker()&lt;/em&gt;. The following example shows the usage in a symfony template:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;php&quot; style=&quot;text-align: left&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; use_helper&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;GoogleMaps&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;longitunde: &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; input_tag&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;lon&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ?&amp;gt;&amp;lt;br /&amp;gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;lattitude: &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; input_tag&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;lat&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ?&amp;gt;&amp;lt;br /&amp;gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;zoom: &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; input_tag&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;zoom&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ?&amp;gt;&amp;lt;br /&amp;gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; google_maps_coord_picker&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;lon&#039;&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;lat&#039;&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;zoom&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt; &lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;br /&gt;
This helper includes the Google Maps API, thus &lt;a href=&quot;http://www.google.com/apis/maps/signup.html&quot; target=&quot;_blank&quot;&gt;an API key has to be generated&lt;/a&gt; and set up in the application configuration (/apps/[appname]/config/app.yml):&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&lt;ol&gt;# default values&lt;br /&gt;all:&lt;br /&gt;&amp;#160; google:&lt;br /&gt;&amp;#160; &amp;#160; api_key:&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;[your-api-key-here]&lt;/ol&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;_google_maps_coordinate_picker.php&lt;/strong&gt;&lt;br /&gt;
To simply integrate in the admin generator, we need a tremplate that includes the helper showed above and displays the map. You have to replace the parameters passed to &lt;em&gt;google_maps_coord_picker()&lt;/em&gt; with the input field ids of your form. Note that symfony uses &lt;em&gt;object_input_tag()&lt;/em&gt; for its form elements which builds unconvenional form-field-ids.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;generator.yml&lt;/strong&gt;&lt;br /&gt;
This file displays the integration of _google_maps_coordinate_picker.php in the admin generator.  
    </content:encoded>

    <pubDate>Sun, 13 May 2007 17:38:16 +0200</pubDate>
    <guid isPermaLink="false">http://blog.hautzinger.info/archives/23-guid.html</guid>
    
</item>
<item>
    <title>Time Warp 2007</title>
    <link>http://blog.hautzinger.info/archives/20-Time-Warp-2007.html</link>
            <category>diginights.com</category>
            <category>Fun</category>
    
    <comments>http://blog.hautzinger.info/archives/20-Time-Warp-2007.html#comments</comments>
    <wfw:comment>http://blog.hautzinger.info/wfwcomment.php?cid=20</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://blog.hautzinger.info/rss.php?version=2.0&amp;type=comments&amp;cid=20</wfw:commentRss>
    

    <author>nospam@example.com (Christoph Hautzinger)</author>
    <content:encoded>
    Nächsten Samstag werden wieder tausende feierwütige Freunde des Techno nach Mannheim auf die Time Warp pilgern. Nachdem ich letztes Jahr seit vier Jahren zum ersten Mal leider nicht dabei war, wird es dieses Jahr bestimmt wieder richtig geil, auch wenn mich das &lt;a href=&quot;http://www.tdktimewarp.de/e4/e447/e2113/e2799/TW07_TimetableFlyer_70322_ger.pdf&quot; target=&quot;_blank&quot;&gt;Line Up&lt;/a&gt; nicht so wirklich anspricht. Ganz besonders freu ich mich auf DJ Murphy, der letztes Jahr auf der After Hour zur Street Parade im Rohstofflager mit seinem kompromisslos hartem Sound überzeugt hat.&lt;br /&gt;
&lt;br /&gt;
Sogar auf der Wikipedia gibt es eine Seite zur &lt;a href=&quot;http://de.wikipedia.org/wiki/TDK_Time_Warp&quot; target=&quot;_blank&quot;&gt;Time Warp&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Hin geht es mit dem &lt;a href=&quot;http://diginights.com/bustrips/eventshuttle/detail/2007-03-31_EventShuttle_zur_TDK_Timewarp.html&quot; target=&quot;_blank&quot;&gt;diginights Eventshuttle&lt;/a&gt;... da beginnt die Party schon im Bus &lt;img src=&quot;http://blog.hautzinger.info/templates/default/img/emoticons/wink.png&quot; alt=&quot;;-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;. Die Eventshuttle-Sektion ist auch zugleich ein neuer Bereich auf &lt;a href=&quot;http://diginights.com&quot; target=&quot;_blank&quot;&gt;diginights&lt;/a&gt;, die von der Logik her nichts neues bietet, sondern auf die der &lt;a href=&quot;http://diginights.com/bustrips/jomotours/list.html&quot; target=&quot;_blank&quot;&gt;Jomotours Busreisen&lt;/a&gt; setzt.&lt;br /&gt;
&lt;br /&gt;
&lt;!--s9ymdb:11--&gt;&lt;img width=&#039;448&#039; height=&#039;299&#039; style=&quot;border: 0px; padding-left: 5px; padding-right: 5px;&quot; src=&quot;http://blog.hautzinger.info/uploads/img/time_warp.jpg&quot; alt=&quot;&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Nach der Party will ich feiertechnisch ein wenig kürzer treten und mich mal wieder etwas mehr um diginights kümmern... da gibt es ja auch genügend zu tun &lt;img src=&quot;http://blog.hautzinger.info/templates/default/img/emoticons/wink.png&quot; alt=&quot;;-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;.  
    </content:encoded>

    <pubDate>Sun, 25 Mar 2007 21:50:09 +0200</pubDate>
    <guid isPermaLink="false">http://blog.hautzinger.info/archives/20-guid.html</guid>
    
</item>
<item>
    <title>Gewinnspiele auf diginights.com</title>
    <link>http://blog.hautzinger.info/archives/17-Gewinnspiele-auf-diginights.com.html</link>
            <category>diginights.com</category>
            <category>PHP</category>
            <category>Symfony</category>
    
    <comments>http://blog.hautzinger.info/archives/17-Gewinnspiele-auf-diginights.com.html#comments</comments>
    <wfw:comment>http://blog.hautzinger.info/wfwcomment.php?cid=17</wfw:comment>

    <slash:comments>3</slash:comments>
    <wfw:commentRss>http://blog.hautzinger.info/rss.php?version=2.0&amp;type=comments&amp;cid=17</wfw:commentRss>
    

    <author>nospam@example.com (Christoph Hautzinger)</author>
    <content:encoded>
    Wie dem ein oder anderen Leser hier sicherlich schon aufgefallen ist, gibt es auf &lt;a href=&quot;http://diginights.com&quot; target=&quot;_blank&quot;&gt;diginights.com&lt;/a&gt; seit geraumer Zeit nun eine &lt;a href=&quot;http://diginights.com/lifestyle/lottery/list.html&quot; target=&quot;_blank&quot;&gt;Gewinnspiel-Section&lt;/a&gt;. Die grundlegende Idee dahinter war, dem User mehr Funktionalität auf der Seite zu bieten, was uns mit dieser Idee (denke ich zumindest) auch ziemlich gut gelungen ist. Um automatische Eintragungen zu verhindern wurde ein &lt;a href=&quot;http://de.wikipedia.org/wiki/Captcha&quot; target=&quot;_blank&quot;&gt;Captcha-Schutz&lt;/a&gt; eingebaut, der nun auf allen anderen Formularseiten Verwendung findet, da es in der Vergangenheit öfters vorkam, dass Spamer die Location-eintragen Seite für ihre Zwecke missbrauchten.&lt;br /&gt;
&lt;br /&gt;
In diesem Beitrag will ich aber ein wenig über die Verlosung schreiben, bzw. die der zu Grunde liegenden Logik. &lt;br /&gt;
&lt;br /&gt;
Es existieren drei von Propel generierte Klassen: &lt;em&gt;LotteryItem&lt;/em&gt; enthält die allgemeinen Infos zu einem Gewinnspiel, wie Name und Beschreibung oder das Auslosedatum, in &lt;em&gt;LotteryPrize&lt;/em&gt; finden sich die einzelnen Preise, die zu einem Gewinnspiel gewonnen werden können und &lt;em&gt;LotteryParticipant&lt;/em&gt; hält die Teilnehmer der jeweiligen Gewinnspiele. Um die Komplexität zu verringern sind die folgenden Codebeispiele auf das Nötigste gekürzt, zudem sind die PHPDoc Kommentare leider auch nicht dabei, da sie von meiner Blogsoftware in strong-Tags umgebaut werden (das muss ich mir nochmal anschauen):&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;1. Die naive Implementierung&lt;/strong&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;php&quot; style=&quot;text-align: left&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;private &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; drawSingleLottery&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;LotteryItem &lt;span style=&quot;color: #0000ff;&quot;&gt;$l&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$prizes&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$l&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getLotteryPrizes&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &amp;#160;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// TODO: this is pretty slow and should be replaced with a piece of faster code in future&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$participants&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$l&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getLotteryParticipants&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &amp;#160;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// determine winner array keys - exactly the amount of available prizes&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$winnersKeys&lt;/span&gt; = &lt;a href=&quot;http://www.php.net/array_rand&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array_rand&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$participants&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;countTotalWinnersForPrizes&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$prizes&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;!&lt;a href=&quot;http://www.php.net/is_array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;is_array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$winnersKeys&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$winnersKeys&lt;/span&gt; = &lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$winnersKeys&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$winners&lt;/span&gt; = &lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$j&lt;/span&gt; = &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #b1b100;&quot;&gt;foreach&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$prizes&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$prize&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// loop all prizes &lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &amp;#160; &lt;span style=&quot;color: #b1b100;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$i&lt;/span&gt; = &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;; &lt;span style=&quot;color: #0000ff;&quot;&gt;$i&lt;/span&gt; &amp;lt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$prize&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getPrizeAmount&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;span style=&quot;color: #0000ff;&quot;&gt;$i&lt;/span&gt;++, &lt;span style=&quot;color: #0000ff;&quot;&gt;$j&lt;/span&gt;++&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$winner&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$participants&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$winnersKeys&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$j&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$winner&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setLotteryPrize&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$prize&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$l&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setIsDrawn&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$l&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;save&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Der Code läuft zwar, ist aber nicht schön: Die Methode &lt;em&gt;LotteryItem::getLotteryParticipants()&lt;/em&gt; liefert in einem Array sämtliche Objekte der Personen, die am Gewinnspiel teilgenommen haben. Desto mehr Teilnehmer es werden, desto langsamer wird es, da für jede Zeile des Datenbankresultats ein Objekt gebaut wird und die Instanziierung dessen eine teuere Operation ist. &lt;br /&gt;
&lt;br /&gt;
Über &lt;em&gt;array_rand()&lt;/em&gt; werden genausoviele Schlüssel dieses Arrays zurückgegeben wie die in der selben Klasse definierte Methode &lt;em&gt;countTotalWinnersForPrizes()&lt;/em&gt; zurückgibt - sie zählt die gesamte Anzahl aller zu vergebenden Preise. &lt;br /&gt;
&lt;em&gt;mixed &lt;strong&gt;array_rand&lt;/strong&gt; ( array input [, int num_req] )&lt;/em&gt; gibt ein Array mit den Schlüsseln zurück, wenn der 2. Parameter größer als 1 ist, ansonsten einen Schlüssel, also kein Array (als integer in unserem Falle), was ich an der Methodendefinition nicht besonders schön finde, da dieser Fall hier extra abgefragt werden muss.&lt;br /&gt;
&lt;br /&gt;
Zum Schluss wird über die eigentlichen Preise iteriert, jedem Gewinner einen Preis zugeordnet und das Gewinnspiel gespeichert. Konstrukte wie &lt;em&gt;$participants[$winnersKeys[$j]];&lt;/em&gt; sind unschön weil sie schwer zu lesen sind bzw. es schwer fällt, diese später wieder zu verstehen.&lt;br /&gt;
&lt;br /&gt;
Ein &lt;a href=&quot;http://de.wikipedia.org/wiki/Refactoring&quot; target=&quot;_blank&quot;&gt;Refactoring&lt;/a&gt; muss also her ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;2. Die wesentlich eleganter-/performantere Implementierung&lt;/strong&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;php&quot; style=&quot;text-align: left&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;private &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; drawSingleLottery&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;LotteryItem &lt;span style=&quot;color: #0000ff;&quot;&gt;$l&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$prizes&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$l&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getLotteryPrizes&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$winners&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$l&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;determineWinners&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// set for every winner a prize&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$winner_i&lt;/span&gt; = &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #b1b100;&quot;&gt;foreach&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$prizes&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$prize&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// loop all prizes&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &amp;#160; &lt;span style=&quot;color: #b1b100;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$i&lt;/span&gt; = &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;; &lt;span style=&quot;color: #0000ff;&quot;&gt;$i&lt;/span&gt; &amp;lt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$prize&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getPrizeAmount&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;span style=&quot;color: #0000ff;&quot;&gt;$i&lt;/span&gt;++&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$winner&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$winners&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$winner_i&lt;/span&gt;++&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$winner&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setLotteryPrize&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$prize&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$l&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setIsDrawn&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$l&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;save&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Alles, was im ersten Codefetzen hässlich war ist verschwunden und die neue Methode &lt;em&gt;LotteryItem::determineWinners()&lt;/em&gt; erblickt das Licht der Welt - diese scheint wohl direkt die Gewinner anstatt nur deren Keys zurückzuliefern, was nach einem Blick in den Code klar wird:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;php&quot; style=&quot;text-align: left&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; determineWinners&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$amount&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;countTotalWinnersForPrizes&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getLotteryPrizes&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; LotteryParticipantPeer::&lt;span style=&quot;color: #006600;&quot;&gt;retrieveRandomAmount&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$amount&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Durch das Refactoring hat die &lt;em&gt;countTotalWinnersForPrizes()&lt;/em&gt; Methode die Klasse gewechselt, ihr Innenleben bleibt jedoch unverändert.&lt;br /&gt;
&lt;br /&gt;
Abschließend interessiert nur noch die performantere Implementierung von &lt;em&gt;LotteryParticipantPeer::retrieveRandomAmount()&lt;/em&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;php&quot; style=&quot;text-align: left&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;public &lt;a href=&quot;http://www.php.net/static&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;static&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; retrieveRandomAmount&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;LotteryItem &lt;span style=&quot;color: #0000ff;&quot;&gt;$l&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$amount&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;!&lt;a href=&quot;http://www.php.net/is_numeric&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;is_numeric&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$amount&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; || &lt;span style=&quot;color: #0000ff;&quot;&gt;$amount&lt;/span&gt; &amp;lt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; throw &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; Exception&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;amount should be a positive integer&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$con&lt;/span&gt; = sfContext::&lt;span style=&quot;color: #006600;&quot;&gt;getInstance&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getDatabaseConnection&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;propel&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;SELECT &#039;&lt;/span&gt;.self::&lt;span style=&quot;color: #006600;&quot;&gt;ID&lt;/span&gt;.&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039; FROM &#039;&lt;/span&gt;.self::&lt;span style=&quot;color: #006600;&quot;&gt;TABLE_NAME&lt;/span&gt;.&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039; &#039;&lt;/span&gt;.&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;WHERE &#039;&lt;/span&gt;.self::&lt;span style=&quot;color: #006600;&quot;&gt;LOTTERY_ITEM_ID&lt;/span&gt;.&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039; = &#039;&lt;/span&gt;.&lt;span style=&quot;color: #0000ff;&quot;&gt;$l&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getId&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039; &#039;&lt;/span&gt;.&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;ORDER BY RAND() &#039;&lt;/span&gt;.&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;LIMIT &#039;&lt;/span&gt;.&lt;span style=&quot;color: #0000ff;&quot;&gt;$amount&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$q&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; Query&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$con&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; self::&lt;span style=&quot;color: #006600;&quot;&gt;retrieveByPKs&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$q&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getCol&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$con&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
...Diese baut lediglich eine Query von Hand mit dem in der aktuellen Propel-Version noch nicht abbildbaren MySQL-spezifischen &lt;em&gt;ORDER BY RAND()&lt;/em&gt;, das zufällig so viele Gewinner-IDs liefert, wie die Funktion als zweiten Parameter übergeben bekommt (MySQL &lt;em&gt;LIMIT&lt;/em&gt;). Das Resultat liefert über &lt;em&gt;LotteryParticipantPeer::retrieveByPKs()&lt;/em&gt; die gewünschten Objekte als Array zurück.&lt;br /&gt;
&lt;br /&gt;
...So weit also mal ein kleiner Einblick in die Technik, die dahintersteckt - Ich habe euch hoffentlich nicht zu sehr gelangweilt &lt;img src=&quot;http://blog.hautzinger.info/templates/default/img/emoticons/laugh.png&quot; alt=&quot;:-D&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;  
    </content:encoded>

    <pubDate>Sat, 17 Feb 2007 19:51:39 +0100</pubDate>
    <guid isPermaLink="false">http://blog.hautzinger.info/archives/17-guid.html</guid>
    
</item>
<item>
    <title>Kleine Wbb2-Mysql-Triggerei</title>
    <link>http://blog.hautzinger.info/archives/14-Kleine-Wbb2-Mysql-Triggerei.html</link>
            <category>diginights.com</category>
    
    <comments>http://blog.hautzinger.info/archives/14-Kleine-Wbb2-Mysql-Triggerei.html#comments</comments>
    <wfw:comment>http://blog.hautzinger.info/wfwcomment.php?cid=14</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://blog.hautzinger.info/rss.php?version=2.0&amp;type=comments&amp;cid=14</wfw:commentRss>
    

    <author>nospam@example.com (Christoph Hautzinger)</author>
    <content:encoded>
    Die &lt;a href=&quot;http://diginights.com/partypics/useralbum/userlist/s.html&quot; target=&quot;_blank&quot;&gt;Usergallerien&lt;/a&gt; auf &lt;a href=&quot;http://diginights.com&quot; target=&quot;_blank&quot;&gt;diginights.com&lt;/a&gt; halten die Daten für Usernamen, Userid und ersten Buchstaben des Usernamens in einer eigenen, vom Forum separaten Tabelle. Auf der Spalte ersten Buchstaben des Namens liegt ein INDEX, sodess danach schnell gesucht werden kann. Diese Vorgehensweise spart eine DB-Connection, da die Forumstabellen in einer eigenen Datenbank liegen und Symfony bzw. Propel leider nicht mehrere Datenbanken über einen &lt;a href=&quot;http://de.wikipedia.org/wiki/Database_Source_Name&quot; target=&quot;_blank&quot;&gt;DSN&lt;/a&gt; handeln können.&lt;br /&gt;
&lt;br /&gt;
Ein Nachteil liegt hierbei auf der Hand: Sollte im Forum ein Username geändert werden bleibt dieser ohne Eingriff in den Forumscode in den Usergallerien unverändert.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://mysql.org&quot; target=&quot;_blank&quot;&gt;MySQL&lt;/a&gt; bietet nur hierfür (eeeendlich) ab der Version 5 eine elegante Lösung des Problems: &lt;a href=&quot;http://de.wikipedia.org/wiki/Datenbanktrigger&quot; target=&quot;_blank&quot;&gt;Trigger&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Und so sieht das kleine Triggerlein aus:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;mysql&quot; style=&quot;text-align: left&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;DELIMITER //&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;CREATE&lt;/span&gt; TRIGGER t_rename_boarduser&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;AFTER &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;UPDATE&lt;/span&gt; ON forum_users&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;FOR EACH ROW&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;BEGIN&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;DECLARE&lt;/span&gt; initial_cap &lt;span style=&quot;color: #aa9933; font-weight: bold;&quot;&gt;CHAR&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;SET&lt;/span&gt; initial_cap = &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;LOWER&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;SUBSTRING&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;NEW.username, &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; IF initial_cap REGEXP &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;[^a-z]&#039;&lt;/span&gt; &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;THEN&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &amp;#160; &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;SET&lt;/span&gt; initial_cap := &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;@&#039;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;END&lt;/span&gt; IF;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&amp;#160; &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;REPLACE&lt;/span&gt; &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;INTO&lt;/span&gt; siteusers &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;userid, name, name_initial_cap&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;NEW.userid, NEW.username, initial_cap&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; color: black; font-weight: normal; font-style: normal;&quot;&gt;&lt;div style=&quot;font-family: &#039;Courier New&#039;, Courier, monospace; font-weight: normal;&quot;&gt;&lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;END&lt;/span&gt;// &lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Die Funktionsweise erklärt sich fast von selbst: Nach einem Update wird für jede aktualisierte Zeile der erste Buchstabe des Usernamens als Kleinbuchstabe in der Variablen initial_cap gespeichert. Sollte es ein Sonderzeichen (bzw. ein Zeichen, das nicht zwischen a und z liegt) sein, wird der Inhalt der Variablen mit einem &#039;@&#039; übeschrieben. Zum Schluss werden die Daten in die Tabelle aus der später die Daten für die Usergallerien gezogen werden, mit einem &lt;a href=&quot;http://dev.mysql.com/doc/refman/5.0/en/replace.html&quot; target=&quot;_blank&quot;&gt;REPLACE&lt;/a&gt; gespeichert. &quot;NEW&quot; steht für einen Cursor, der auf die Zeile nach dem Update steht - synonym dazu steht OLD für den alten Wert, so wäre beispielsweise in OLD.username der alte Username vor dem Update gespeichert. &lt;br /&gt;
&lt;br /&gt;
...somit entfällt die Manipulation des Forumscodes.&lt;br /&gt;
&lt;br /&gt;
Mit Triggern zu arbeiten macht Spass und kann die Effizienz einer Anwendung deutlich erhöhen, allerdings kann es auch zu bösen Endlosschleifen kommen, wenn man beim Programmieren nicht aufpasst &lt;img src=&quot;http://blog.hautzinger.info/templates/default/img/emoticons/wink.png&quot; alt=&quot;;-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;  
    </content:encoded>

    <pubDate>Tue, 23 Jan 2007 01:58:57 +0100</pubDate>
    <guid isPermaLink="false">http://blog.hautzinger.info/archives/14-guid.html</guid>
    
</item>
<item>
    <title>Webseiten als Graph!?</title>
    <link>http://blog.hautzinger.info/archives/9-Webseiten-als-Graph!.html</link>
            <category>diginights.com</category>
            <category>Fun</category>
    
    <comments>http://blog.hautzinger.info/archives/9-Webseiten-als-Graph!.html#comments</comments>
    <wfw:comment>http://blog.hautzinger.info/wfwcomment.php?cid=9</wfw:comment>

    <slash:comments>1</slash:comments>
    <wfw:commentRss>http://blog.hautzinger.info/rss.php?version=2.0&amp;type=comments&amp;cid=9</wfw:commentRss>
    

    <author>nospam@example.com (Christoph Hautzinger)</author>
    <content:encoded>
    Gestern bin ich auf eine Seite aufmerksam geworden, auf der man &lt;a href=&quot;http://www.aharef.info/static/htmlgraph/&quot; target=&quot;_blank&quot;&gt;Webseiten als Graphen&lt;/a&gt; darstellen kann. Man gibt in einem Eingabefeld seine gewünschte Seite an, worauf ein Java-Applet sich diese herunterläd, das Markup parst und daraus einen Baum generiert:&lt;br /&gt;
&lt;br /&gt;
Das Ergebnis der Seite &lt;a href=&quot;http://diginights.com&quot; target=&quot;_new&quot;&gt;diginights.com&lt;/a&gt; sieht zum Beispiel so aus:&lt;br /&gt;
&lt;br /&gt;
&lt;a title=&quot;http://www.aharef.info/static/htmlgraph/?url=http%3A%2F%2Fdiginights.com&quot; id=&quot;s9yisp4&quot;&gt;&lt;/a&gt;&lt;a class=&#039;serendipity_image_link&#039; href=&#039;http://blog.hautzinger.info/serendipity_admin_image_selector.php?serendipity[step]=showItem&amp;amp;serendipity[image]=4&#039; id=&quot;s9yisphref4&quot; onclick=&quot;javascript:this.href = this.href + &#039;&amp;amp;serendipity[from]=&#039; + self.location.href;&quot;&gt;&lt;!--s9ymdb:4--&gt;&lt;img width=&#039;597&#039; height=&#039;378&#039; style=&quot;border: 0px; padding-left: 5px; padding-right: 5px;&quot; src=&quot;http://blog.hautzinger.info/uploads/sitegraphs/sitegraph_diginights.jpg&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Was bedeuten nun die einzelnen Farben? Die Legende lässt sich auf der &lt;a href=&quot;http://www.aharef.info/static/htmlgraph/?url=http%3A%2F%2Fdiginights.com&quot; target=&quot;_blank&quot;&gt;Webseite des Applets&lt;/a&gt; finden (auf der man übrigens auch den Java Sourcecode findet):&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;span style=&quot;color: #000099; font-weight: bold&quot;&gt;blue&lt;/span&gt;: for links (the A tag)&lt;br /&gt;&lt;span style=&quot;color: #ff0000; font-weight: bold&quot;&gt;red&lt;/span&gt;: for tables (TABLE, TR and TD tags)&lt;br /&gt;&lt;span style=&quot;color: #009900; font-weight: bold&quot;&gt;green&lt;/span&gt;: for the DIV tag&lt;br /&gt;&lt;span style=&quot;color: #cc00ff; font-weight: bold&quot;&gt;violet&lt;/span&gt;: for images (the IMG tag)&lt;br /&gt;&lt;span style=&quot;color: #ffff33; font-weight: bold&quot;&gt;yellow&lt;/span&gt;: for forms (FORM, INPUT, TEXTAREA, SELECT and OPTION tags)&lt;br /&gt;&lt;span style=&quot;color: #ff9933; font-weight: bold&quot;&gt;orange&lt;/span&gt;: for linebreaks and blockquotes (BR, P, and BLOCKQUOTE tags)&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold&quot;&gt;black&lt;/span&gt;: the HTML tag, the root node&lt;br /&gt;&lt;span style=&quot;color: #999999; font-weight: bold&quot;&gt;gray&lt;/span&gt;: all other tags&lt;br /&gt;
&lt;/blockquote&gt;&lt;br /&gt;
&lt;br /&gt;
Eine &quot;neue&quot; Seite sollte State of the Art keine Tabellen (rot) zur Positionierung mehr verwenden, sondern dies durch dies über div-Tags (div) und deren CSS Attribute lösen.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ein regionales Negativbeispiel hierzu habe ich natürlich auch gefunden:&lt;br /&gt;
&lt;br /&gt;
&lt;a title=&quot;http://www.aharef.info/static/htmlgraph/?url=http%3A%2F%2Fstimme.de&quot; id=&quot;s9yisp5&quot;&gt;&lt;/a&gt;&lt;a class=&#039;serendipity_image_link&#039; href=&#039;http://blog.hautzinger.info/serendipity_admin_image_selector.php?serendipity[step]=showItem&amp;amp;serendipity[image]=5&#039; id=&quot;s9yisphref5&quot; onclick=&quot;javascript:this.href = this.href + &#039;&amp;amp;serendipity[from]=&#039; + self.location.href;&quot;&gt;&lt;!--s9ymdb:5--&gt;&lt;img width=&#039;599&#039; height=&#039;430&#039; style=&quot;border: 0px; padding-left: 5px; padding-right: 5px;&quot; src=&quot;http://blog.hautzinger.info/uploads/sitegraphs/sitegraph_stimme.jpg&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
(von &lt;a href=&quot;http://www.stimme.de&quot; target=&quot;_blank&quot;&gt;www.stimme.de&lt;/a&gt;) &lt;img src=&quot;http://blog.hautzinger.info/templates/default/img/emoticons/wink.png&quot; alt=&quot;;-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;  
    </content:encoded>

    <pubDate>Sun, 10 Dec 2006 15:11:31 +0100</pubDate>
    <guid isPermaLink="false">http://blog.hautzinger.info/archives/9-guid.html</guid>
    
</item>
<item>
    <title>diginights goes symfony</title>
    <link>http://blog.hautzinger.info/archives/8-diginights-goes-symfony.html</link>
            <category>diginights.com</category>
            <category>PHP</category>
            <category>Symfony</category>
    
    <comments>http://blog.hautzinger.info/archives/8-diginights-goes-symfony.html#comments</comments>
    <wfw:comment>http://blog.hautzinger.info/wfwcomment.php?cid=8</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://blog.hautzinger.info/rss.php?version=2.0&amp;type=comments&amp;cid=8</wfw:commentRss>
    

    <author>nospam@example.com (Christoph Hautzinger)</author>
    <content:encoded>
    Endlich ist es so weit... &lt;a href=&quot;http://www.diginights.com&quot; target=&quot;_blank&quot;&gt;diginights.com&lt;/a&gt; ist nun auf mein heißgeliebtes &lt;a href=&quot;http://www.symfony-project.com&quot; target=&quot;_blank&quot;&gt;symfony Framework&lt;/a&gt; umgestellt. Die endgültige Umstellung hat leider länger als erwartet gedauert, sodass wir Freitag bis 6 Uhr und Samstag bis 4 Uhr morgens gearbeitet haben &lt;img src=&quot;http://blog.hautzinger.info/templates/default/img/emoticons/wink.png&quot; alt=&quot;;-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Symfony skaliert deutlich besser als unsere alte Seite, außerdem erleichtert es mir mein Leben in Zukunft enorm, weil sehr viele coole Sachen wie z.B.&lt;br /&gt;
&lt;br /&gt;
- Session/User Management&lt;br /&gt;
- sehr cleveres Caching&lt;br /&gt;
- ORM (Object Relational Mapper via &lt;a href=&quot;http://propel.tigris.org&quot; target=&quot;_blank&quot;&gt;Propel&lt;/a&gt; - komplette Spezifikation über XML, generierung der Klassen über Kommandozeile)&lt;br /&gt;
- Ajax Support&lt;br /&gt;
- Formularvalidierung&lt;br /&gt;
- Routing&lt;br /&gt;
- Admin Generator, der die Adminstrationsoberflächen einer Tabelle an Hand eines Config-Files erzeugt&lt;br /&gt;
&lt;br /&gt;
von Haus aus dabei sind (um nur ein paar Dinge zu nennen).&lt;br /&gt;
&lt;br /&gt;
Der Name Symfony steht übrigens für die Zusammenschnürung mehrerer Open Source Technologien wie z.B. dem bereits erwähnten &lt;a href=&quot;http://propel.tigris.org&quot; target=&quot;_blank&quot;&gt;Propel&lt;/a&gt;, &lt;a href=&quot;http://creole.tigris.org&quot; target=&quot;_blank&quot;&gt;Creole&lt;/a&gt; zur Datenbankabstraktion,  &lt;a href=&quot;http://prototype.conio.net/&quot; target=&quot;_blank&quot;&gt;Prototype&lt;/a&gt; einer sehr umfangreichen Javascript Library, &lt;a href=&quot;http://pear.php.net/&quot; target=&quot;_blank&quot;&gt;PEAR&lt;/a&gt;, etc.&lt;br /&gt;
&lt;br /&gt;
Diese Woche über werde ich die kleineren Bugs fixen, die uns noch aufgefallen sind, sodass wir danach die schon länger geplanten Gewinnspiele in Angriff nehmen können. Intern wollen wir die Struktur der Party-Bilder im Dateisystem ändern und diese auf den 2. Server legen wovon wir uns nochmals einen Performanceschub erhoffen.&lt;br /&gt;
&lt;br /&gt;
Zudem ist noch viel mehr geplant für die Zukunft, davon will ich aber noch nichts verraten &lt;img src=&quot;http://blog.hautzinger.info/templates/default/img/emoticons/tongue.png&quot; alt=&quot;:-P&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;  
    </content:encoded>

    <pubDate>Mon, 20 Nov 2006 00:01:23 +0100</pubDate>
    <guid isPermaLink="false">http://blog.hautzinger.info/archives/8-guid.html</guid>
    
</item>

</channel>
</rss>