<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Hce Web Agency Blog</title>
	<atom:link href="http://hceint.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://hceint.wordpress.com</link>
	<description>Web Design Venezia Mestre Padova Abano Terme</description>
	<lastBuildDate>Wed, 23 Nov 2011 09:24:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='hceint.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/3acd0a0d8ac115c6b9c12b2def6f5dca?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Hce Web Agency Blog</title>
		<link>http://hceint.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://hceint.wordpress.com/osd.xml" title="Hce Web Agency Blog" />
	<atom:link rel='hub' href='http://hceint.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Making a choice (select) widget read-only in Symfony</title>
		<link>http://hceint.wordpress.com/2011/09/20/making-a-choice-select-widget-read-only-in-symfony/</link>
		<comments>http://hceint.wordpress.com/2011/09/20/making-a-choice-select-widget-read-only-in-symfony/#comments</comments>
		<pubDate>Tue, 20 Sep 2011 09:13:19 +0000</pubDate>
		<dc:creator>hceblog</dc:creator>
		
		<guid isPermaLink="false">http://hceint.wordpress.com/?p=222</guid>
		<description><![CDATA[I have a form in Symfony that contains a Choice widget (my database field is called created_group) and I need to show its value to the user but make it not editable, so that the user cannot change the value. Using the HTML disabled attribute won&#8217;t work:    $this -&#62; widgetSchema['created_group']-&#62;setAttribute(&#8216;disabled&#8217;,'disable&#8217;); as this will show &#8230; <a class="more-link" href="http://hceint.wordpress.com/2011/09/20/making-a-choice-select-widget-read-only-in-symfony/">Keep&#160;reading&#160;<span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hceint.wordpress.com&amp;blog=10948636&amp;post=222&amp;subd=hceint&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have a form in Symfony that contains a Choice widget (my database field is called <em>created_group</em>) and I need to show its value to the user but make it not editable, so that the user cannot change the value.</p>
<p>Using the HTML <em>disabled</em> attribute won&#8217;t work:</p>
<blockquote><p>   $this -&gt; widgetSchema['<em>created_group</em>']-&gt;setAttribute(&#8216;disabled&#8217;,'disable&#8217;);</p></blockquote>
<p>as this will show the select field as blurred and thus show the content, but the selected option won&#8217;t be sent on a form submit: Symfony will mark that field as missing and will save it as NULL in the database, or generate a database error if the field cannot be NULL. The more complicated solution would be to also make Symfony skip that field in updates / creation.</p>
<p>The simpler solution is to create a custom widget type that just shows the Select&#8217;s option text and adds a hidden field with the Select&#8217;s option value. This way the users sees the text and Symfony gets the correct value upon update. This solution assumes that you trust that the user won&#8217;t tamper the hidden field with things like Firebug, so keep in mind that <strong>it&#8217;s not a secure option</strong> to make that field read-only and to make sure that the user cannot change it. It&#8217;s more of a cosmetic option.</p>
<p>You must create a custom widget class. The class&#8217;s code is the following:</p>
<blockquote><p>&lt;?php<br />
class sfReadonlySelect extends sfWidgetFormDoctrineChoice<br />
{<br />
public function render($name, $value = null, $attributes = array(), $errors = array())<br />
{<br />
$choices = $this-&gt;getChoices();<br />
$string = $choices[$value];<br />
$string.= &#8216;&lt;input type=&#8221;hidden&#8221; name=&#8221;&#8216;.escape_once($name).&#8217;&#8221; value=&#8221;&#8216;.escape_once($value).&#8217;&#8221;/&gt;&#8217;;<br />
return $string;<br />
}<br />
}</p></blockquote>
<p>all you need to do is to save that in a file called <em>sfReadonlySelect.class.php </em>in the /lib/widget/ directory of your installation.</p>
<p>Then in your /lib/form/doctrine/<em>myForm</em>.php class (where <em>myForm </em>is the name of the object to which your Select field belongs) you initialize  the field as following:</p>
<blockquote><p>$this -&gt; setWidget ( &#8216;created_group&#8217;, new sfReadonlySelect (array(&#8216;model&#8217; =&gt; $this-&gt;getRelatedModelName(&#8216;GroupCreated&#8217;), &#8216;add_empty&#8217; =&gt; true)) );</p></blockquote>
<p>It&#8217;s a simple solution to a fairly simple problem, but I haven&#8217;t found a better one on the web so here it is! Please leave your comments/questions below.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hceint.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hceint.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hceint.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hceint.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hceint.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hceint.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hceint.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hceint.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hceint.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hceint.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hceint.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hceint.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hceint.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hceint.wordpress.com/222/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hceint.wordpress.com&amp;blog=10948636&amp;post=222&amp;subd=hceint&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hceint.wordpress.com/2011/09/20/making-a-choice-select-widget-read-only-in-symfony/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b355b3b24880c2a08949ebbc40011d5a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hceblog</media:title>
		</media:content>
	</item>
		<item>
		<title>Hiding option groups (optgroups) in Chrome and Internet Explorer with Jquery</title>
		<link>http://hceint.wordpress.com/2011/04/09/hiding-option-groups-optgroups-in-chrome-and-internet-explorer-with-jquery/</link>
		<comments>http://hceint.wordpress.com/2011/04/09/hiding-option-groups-optgroups-in-chrome-and-internet-explorer-with-jquery/#comments</comments>
		<pubDate>Sat, 09 Apr 2011 09:47:27 +0000</pubDate>
		<dc:creator>hceblog</dc:creator>
		
		<guid isPermaLink="false">http://hceint.wordpress.com/?p=207</guid>
		<description><![CDATA[If you need to hide a series of optgroups with Jquery, it is easy to do so in Firefox: you just need to call $(this).hide() on the option group, and it and all its children will be hidden and not selectable. If you want to show them back, you just need to call $(this).show() and &#8230; <a class="more-link" href="http://hceint.wordpress.com/2011/04/09/hiding-option-groups-optgroups-in-chrome-and-internet-explorer-with-jquery/">Keep&#160;reading&#160;<span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hceint.wordpress.com&amp;blog=10948636&amp;post=207&amp;subd=hceint&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you need to hide a series of optgroups with Jquery, it is easy to do so in Firefox: you just need to call $(this).hide() on the option group, and it and all its children will be hidden and not selectable. If you want to show them back, you just need to call $(this).show() and they will reappear.</p>
<p>However, other browser like Chrome and IE don&#8217;t allow this: the style rule (display:none) is applied to the element but does not work, and the elements stay visible. I&#8217;ve found out a quick workaround for this problem.</p>
<p>Basically, all you need to do is to</p>
<ol>
<li>disable all the options within the optgroup (and deselect them if they are selected)</li>
<li>move the optgroup to the end of the select&#8217;s optgroups, so that it does not get in the way</li>
</ol>
<p>If you want to reinstate that optgroup (make it selectable again), you must do the opposite:</p>
<ol>
<li>enable all the options within the optgroup</li>
<li>move the optgroup to the beginning of the select&#8217;soptgroups, so that it is visibile again.</li>
</ol>
<p>I&#8217;ve created a couple of custom jquery functions for the purpose:</p>
<pre>$.fn.hideOptionGroup = function() {
 $(this).hide();
 $(this).children().each(function(){
 $(this).attr("disabled", "disabled").removeAttr("selected");
 });
 $(this).appendTo($(this).parent());

}

$.fn.showOptionGroup = function() {
 $(this).show();    
 $(this).children().each(function(){
 $(this).removeAttr("disabled" );
 });
 $(this).prependTo($(this).parent());
 $(this).parent().animate({scrollTop:0},0);
}</pre>
<p>You apply the function to the optgroup as follows:</p>
<pre>$("#myOptgroupId").showOptionGroup();
$("#myOptgroupId").hideOptionGroup();</pre>
<p>What this functions do is:</p>
<ol>
<li>hide/show the element in Firefox directly.</li>
<li>then, it disables/enables all of the optgroup&#8217;s options.</li>
<li>and moves it to the end/beginning of the select&#8217;s optgroups.</li>
<li>scrolls the select to the top, so that the first optgroup is shown even if the user had scrolled down and selected something else (only for the show function).</li>
</ol>
<p>This has been tested with Chrome, will test it with Explorer soon. Hope this helps. Comments and suggestions are welcome.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hceint.wordpress.com/207/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hceint.wordpress.com/207/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hceint.wordpress.com/207/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hceint.wordpress.com/207/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hceint.wordpress.com/207/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hceint.wordpress.com/207/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hceint.wordpress.com/207/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hceint.wordpress.com/207/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hceint.wordpress.com/207/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hceint.wordpress.com/207/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hceint.wordpress.com/207/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hceint.wordpress.com/207/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hceint.wordpress.com/207/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hceint.wordpress.com/207/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hceint.wordpress.com&amp;blog=10948636&amp;post=207&amp;subd=hceint&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hceint.wordpress.com/2011/04/09/hiding-option-groups-optgroups-in-chrome-and-internet-explorer-with-jquery/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b355b3b24880c2a08949ebbc40011d5a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hceblog</media:title>
		</media:content>
	</item>
		<item>
		<title>HCE Crowd #12 &#8211; Remove</title>
		<link>http://hceint.wordpress.com/2011/02/01/hce-crowd-12-remove/</link>
		<comments>http://hceint.wordpress.com/2011/02/01/hce-crowd-12-remove/#comments</comments>
		<pubDate>Tue, 01 Feb 2011 16:51:38 +0000</pubDate>
		<dc:creator>nuvoleonline</dc:creator>
				<category><![CDATA[hcecrowd]]></category>
		<category><![CDATA[online comics]]></category>
		<category><![CDATA[webcomics]]></category>

		<guid isPermaLink="false">http://hceint.wordpress.com/?p=203</guid>
		<description><![CDATA[The latest HCE Crowd webcomic strip is online! Click on the preview to see the full strip<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hceint.wordpress.com&amp;blog=10948636&amp;post=203&amp;subd=hceint&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The latest HCE Crowd webcomic strip is online!</p>
<p><a href="http://hcecrowd.hce.it/en/2011/02/01/hce-crowd-12-remove/#more-282"><img title="12_montata_web_010211_en_ico" src="http://hcecrowd.hce.it/wp-content/uploads/2011/02/12_montata_web_010211_en_ico.jpg" alt="" width="360" height="516" /></a></p>
<p>Click on the <a href="http://hcecrowd.hce.it/en/2011/02/01/hce-crowd-12-remove/#more-282">preview</a> to see the <a href="http://hcecrowd.hce.it/en/2011/02/01/hce-crowd-12-remove/#more-282">full strip</a><em><br />
</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hceint.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hceint.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hceint.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hceint.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hceint.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hceint.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hceint.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hceint.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hceint.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hceint.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hceint.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hceint.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hceint.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hceint.wordpress.com/203/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hceint.wordpress.com&amp;blog=10948636&amp;post=203&amp;subd=hceint&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hceint.wordpress.com/2011/02/01/hce-crowd-12-remove/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/33b1c0779aa40d3a4892609098377997?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nuvoleonline</media:title>
		</media:content>

		<media:content url="http://hcecrowd.hce.it/wp-content/uploads/2011/02/12_montata_web_010211_en_ico.jpg" medium="image">
			<media:title type="html">12_montata_web_010211_en_ico</media:title>
		</media:content>
	</item>
		<item>
		<title>Web marketing campaing for Porto Sosàlinos</title>
		<link>http://hceint.wordpress.com/2010/12/07/web-marketing-campaing-for-porto-sosalinos/</link>
		<comments>http://hceint.wordpress.com/2010/12/07/web-marketing-campaing-for-porto-sosalinos/#comments</comments>
		<pubDate>Tue, 07 Dec 2010 16:11:18 +0000</pubDate>
		<dc:creator>hceblog</dc:creator>
				<category><![CDATA[Marketing]]></category>

		<guid isPermaLink="false">http://hceint.wordpress.com/?p=213</guid>
		<description><![CDATA[We&#8217;ve been entrusted with a marketing campaign to consolidate a client&#8217;s site positions in the search engines. The pages are the following: Sardinien Camping Sardinien Campingplatz one of the two has already entered Google.de&#8217;s top ten. Let&#8217;s see what will happen in the following months&#8230;<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hceint.wordpress.com&amp;blog=10948636&amp;post=213&amp;subd=hceint&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve been entrusted with a marketing campaign to consolidate a client&#8217;s site positions in the search engines. The pages are the following:</p>
<p><a title="Sardinien Camping" href="http://www.portososalinos.it/index_de.php">Sardinien Camping</a><br />
<a title="Sardinien Campingplatz" href="http://www.portososalinos.it/index_de.php">Sardinien Campingplatz</a><br />
one of the two has already entered Google.de&#8217;s top ten. Let&#8217;s see what will happen in the following months&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hceint.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hceint.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hceint.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hceint.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hceint.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hceint.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hceint.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hceint.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hceint.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hceint.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hceint.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hceint.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hceint.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hceint.wordpress.com/213/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hceint.wordpress.com&amp;blog=10948636&amp;post=213&amp;subd=hceint&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hceint.wordpress.com/2010/12/07/web-marketing-campaing-for-porto-sosalinos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b355b3b24880c2a08949ebbc40011d5a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hceblog</media:title>
		</media:content>
	</item>
		<item>
		<title>HCE Crowd #9 – Excellent memory</title>
		<link>http://hceint.wordpress.com/2010/11/23/hce-crowd-9-%e2%80%93-excellent-memory/</link>
		<comments>http://hceint.wordpress.com/2010/11/23/hce-crowd-9-%e2%80%93-excellent-memory/#comments</comments>
		<pubDate>Tue, 23 Nov 2010 17:44:31 +0000</pubDate>
		<dc:creator>nuvoleonline</dc:creator>
				<category><![CDATA[hcecrowd]]></category>
		<category><![CDATA[online comics]]></category>
		<category><![CDATA[webcomics]]></category>

		<guid isPermaLink="false">http://hceint.wordpress.com/?p=199</guid>
		<description><![CDATA[The new strip of our official company comic, HCE Crowd, is online: Excellent Memory. Good reading!<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hceint.wordpress.com&amp;blog=10948636&amp;post=199&amp;subd=hceint&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://hcecrowd.hce.it/en/2010/11/23/hce-crowd-9-ottima-memoria/#more-231"><img class="alignnone" title="Online Comics - HCE Crowd" src="http://hcecrowd.hce.it/wp-content/uploads/2010/11/9_montata_web_23112010_en_ico.jpg" alt="" width="360" height="507" /></a></p>
<p>The new strip of our official company comic, <a href="http://hcecrowd.hce.it/en/"><strong>HCE Crowd</strong></a>, is online: <strong><a title="Webcomics - HCE Crowd" href="http://hcecrowd.hce.it/en/2010/11/23/hce-crowd-9-ottima-memoria/">Excellent Memory</a></strong>.<br />
Good reading!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hceint.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hceint.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hceint.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hceint.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hceint.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hceint.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hceint.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hceint.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hceint.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hceint.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hceint.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hceint.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hceint.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hceint.wordpress.com/199/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hceint.wordpress.com&amp;blog=10948636&amp;post=199&amp;subd=hceint&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hceint.wordpress.com/2010/11/23/hce-crowd-9-%e2%80%93-excellent-memory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/33b1c0779aa40d3a4892609098377997?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nuvoleonline</media:title>
		</media:content>

		<media:content url="http://hcecrowd.hce.it/wp-content/uploads/2010/11/9_montata_web_23112010_en_ico.jpg" medium="image">
			<media:title type="html">Online Comics - HCE Crowd</media:title>
		</media:content>
	</item>
		<item>
		<title>Converting to Title Case in MySQL &#8211; Capitalizing MySQL (a PHP solution)</title>
		<link>http://hceint.wordpress.com/2010/11/11/converting-to-title-case-in-mysql-capitalizing-mysql-a-php-solution/</link>
		<comments>http://hceint.wordpress.com/2010/11/11/converting-to-title-case-in-mysql-capitalizing-mysql-a-php-solution/#comments</comments>
		<pubDate>Thu, 11 Nov 2010 17:01:19 +0000</pubDate>
		<dc:creator>hceblog</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://hceint.wordpress.com/?p=183</guid>
		<description><![CDATA[Ever found some tables in your MySQL database with user-compiled data that is not coherent in terms of case? Some entries are in Title Case, some are all in UPPER CASE, some are all in lower case. If you need to switch everything to upper case or lower case, it&#8217;s as easy as typing the &#8230; <a class="more-link" href="http://hceint.wordpress.com/2010/11/11/converting-to-title-case-in-mysql-capitalizing-mysql-a-php-solution/">Keep&#160;reading&#160;<span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hceint.wordpress.com&amp;blog=10948636&amp;post=183&amp;subd=hceint&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Ever found some tables in your MySQL database with user-compiled data that is not coherent in terms of case? Some entries are in <strong>Title Case</strong>, some are all in <strong>UPPER CASE</strong>, some are all in <strong>lower case</strong>. If you need to switch everything to upper case or lower case, it&#8217;s as easy as typing the following query:<br />
<code>UPDATE `table` SET `field` = UPPER(`field`)</code><br />
(For lower case, just use LOWER() instead of UPPER() ).</p>
<p><span id="more-183"></span></p>
<p>However if you want Title Case there&#8217;s no way to do it internally, since <strong>there&#8217;s no function in MySQL for producing Title Case</strong>. One could think, &#8220;And if I split the string in word chunks and capitalize each word by using SUBSTRING()??&#8221;. Well, that is no solution either, since <strong>there is no MySQL function for splitting strings</strong>, either. There are some solutions for splitting a string and getting the first, second, third chunk <a href="http://dev.mysql.com/doc/refman/5.1/en/string-functions.html">here</a>. But none of this would work for capitalizing each word, as you cannot loop through the words.</p>
<p>You can do this using MySQL by creating a <a href="http://dev.mysql.com/doc/refman/5.1/en/adding-udf.html">User Defined Function in C or C++</a>. Which is quite complicated, and if you don&#8217;t have full access to your MySQL server it is out of the question.</p>
<p>Otherwise ( correct me if I&#8217;m wrong) you must do this operation by <strong>querying the database with a programming language</strong> and <strong>updating each row</strong>, one by one. Here&#8217;s a sample script in PHP.</p>
<p style="padding-left:30px;"><code><br />
$conn = mysql_connect($server, $username, $pass);</code></p>
<p style="padding-left:30px;"><code>mysql_select_db ( $dbname );<br />
</code></p>
<p style="padding-left:30px;"><code> $sql =  ' SELECT `ID_item`, `name` FROM `items` WHERE (`name` REGEXP BINARY "^[a-z0-9 ]+$" OR `name`  REGEXP BINARY "^[A-Z0-9 ]+$" ) ';<br />
$result = mysql_query($sql, $conn);</code><code><br />
echo '&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;td&gt;Id&lt;/td&gt;<br />
&lt;td&gt;Old Name&lt;/td&gt;<br />
&lt;td&gt;New Name&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;/thead&gt;<br />
&lt;tbody&gt;';<br />
while($row = mysql_fetch_array($result)){<br />
$ID = $row["ID_item"];<br />
$name = stripslashes($row["name"]);$newName = mb_convert_case($name, MB_CASE_TITLE, "utf-8");</code><code><br />
echo "<br />
&lt;tr&gt;<br />
&lt;td&gt;$ID&lt;/td&gt;<br />
&lt;td&gt;$name&lt;/td&gt;<br />
&lt;td&gt;$newName&lt;/td&gt;<br />
&lt;/tr&gt;<br />
";</code><code><br />
$sql2 = "UPDATE `items` SET `name` = '".addslashes($newName)."' WHERE `ID_item` = $ID ";<br />
$result2 = mysql_query($sql2, $conn);</code><code><br />
}</code><code><br />
echo '&lt;/tbody&gt;<br />
&lt;/table&gt;<br />
';</code></p>
<p>The code above will select all fields in table &#8220;items&#8221; in which field &#8220;name&#8221;  is all lower case or upper case (this reduces the number of results you have to work on large tables). If you need to check for more irregular patterns, like <strong>mixed CASE</strong> or <strong>MIXed casE</strong>, you can change the regular expressions, or simply act on all rows of the table.</p>
<p>The rest of the code loops through the results, outputs a table with item ID, old name and corrected name (so you can see your results directly) and updates the field. The code assumes that your database is in UTF-8.</p>
<p>We&#8217;ve written this post mostly to let you know that there&#8217;s no MySQL solution for converting to Title Case, obviously the PHP method is very simple and you might write better code than this. As always, your mileage may vary, feel free to write us with any corrections and integrations!!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hceint.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hceint.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hceint.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hceint.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hceint.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hceint.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hceint.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hceint.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hceint.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hceint.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hceint.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hceint.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hceint.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hceint.wordpress.com/183/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hceint.wordpress.com&amp;blog=10948636&amp;post=183&amp;subd=hceint&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hceint.wordpress.com/2010/11/11/converting-to-title-case-in-mysql-capitalizing-mysql-a-php-solution/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b355b3b24880c2a08949ebbc40011d5a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hceblog</media:title>
		</media:content>
	</item>
		<item>
		<title>The second HCE Crowd strip is online!</title>
		<link>http://hceint.wordpress.com/2010/08/03/the-second-hce-crowd-strip-is-online/</link>
		<comments>http://hceint.wordpress.com/2010/08/03/the-second-hce-crowd-strip-is-online/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 10:43:06 +0000</pubDate>
		<dc:creator>nuvoleonline</dc:creator>
				<category><![CDATA[HCE General]]></category>
		<category><![CDATA[hcecrowd]]></category>
		<category><![CDATA[online comics]]></category>
		<category><![CDATA[webcomics]]></category>

		<guid isPermaLink="false">http://hceint.wordpress.com/?p=176</guid>
		<description><![CDATA[The second strip of our official company comic, HCE Crowd, is online. Each strip is drawn by Claudio Calia, while the rest is the work of HCE&#8217;s staff as a whole. Click on the image to see the full strip.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hceint.wordpress.com&amp;blog=10948636&amp;post=176&amp;subd=hceint&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div>
<div>
<p>The second strip of our official company comic, <a href="http://hcecrowd.hce.it/en/"><strong>HCE Crowd</strong></a>, is online. Each strip is drawn by  Claudio Calia, while the rest is the work of <strong><a href="http://www.hce.it/en/allstaff.html">HCE&#8217;s staff</a></strong> as a whole.</p>
<p>Click on the image to see the full strip.<!-- .entry-meta --></p>
<p><a href="http://hcecrowd.hce.it/en/2010/07/30/hce-crowd-2-mandrake/#more-65"><img title="ico_2_30072010_en" src="http://hcecrowd.hce.it/wp-content/uploads/2010/07/ico_2_30072010_en.jpg" alt="" width="360" height="382" /></a></p>
</div>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hceint.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hceint.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hceint.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hceint.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hceint.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hceint.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hceint.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hceint.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hceint.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hceint.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hceint.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hceint.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hceint.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hceint.wordpress.com/176/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hceint.wordpress.com&amp;blog=10948636&amp;post=176&amp;subd=hceint&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hceint.wordpress.com/2010/08/03/the-second-hce-crowd-strip-is-online/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/33b1c0779aa40d3a4892609098377997?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nuvoleonline</media:title>
		</media:content>

		<media:content url="http://hcecrowd.hce.it/wp-content/uploads/2010/07/ico_2_30072010_en.jpg" medium="image">
			<media:title type="html">ico_2_30072010_en</media:title>
		</media:content>
	</item>
		<item>
		<title>HCE Crowd</title>
		<link>http://hceint.wordpress.com/2010/07/12/hce-crowd/</link>
		<comments>http://hceint.wordpress.com/2010/07/12/hce-crowd/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 15:08:28 +0000</pubDate>
		<dc:creator>nuvoleonline</dc:creator>
				<category><![CDATA[HCE General]]></category>

		<guid isPermaLink="false">http://hceint.wordpress.com/?p=170</guid>
		<description><![CDATA[A fortnightly web strip about Information Technology HCE Web Design launches a new website, HCE Crowd. It will be dedicated to the publication of a series of web strips, for now on a fortnightly basis, all set in the office of a fictional Information Technology company in North-Eastern Italy. Any references to historical events, real &#8230; <a class="more-link" href="http://hceint.wordpress.com/2010/07/12/hce-crowd/">Keep&#160;reading&#160;<span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hceint.wordpress.com&amp;blog=10948636&amp;post=170&amp;subd=hceint&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h4>A fortnightly web strip about Information Technology</h4>
<p><a href="http://hcecrowd.hce.it/en/2010/07/12/hcecrowd1/#more-1"><img title="ico_1_12072010_EN" src="http://hcecrowd.hce.it/wp-content/uploads/2010/07/ico_1_12072010_EN1.jpg" alt="" width="350" height="407" /></a><a href="http://www.hce.it/en/"><strong></strong></a></p>
<p><a href="http://www.hce.it/en/"><strong>HCE Web Design</strong></a> launches a new website, <a href="http://hcecrowd.hce.it/en/"><strong>HCE Crowd</strong></a>. It will be dedicated to the publication of a series of <em>web strips</em>, for now on a fortnightly basis, all set in the office of a fictional <em>Information Technology</em> company in North-Eastern Italy. Any references to historical events, real people, or real locales are used fictitiously. Other names, characters, places, and incidents are the product of the authors’ imagination, and any resemblance to actual events or locales or persons, living or dead, is entirely coincidental. Each strip is the work of all <a href="http://www.hce.it/en/allstaff.html">HCE editorial staff</a>: fasten your <em>RSS feeds</em>, ready, steady, go!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hceint.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hceint.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hceint.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hceint.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hceint.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hceint.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hceint.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hceint.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hceint.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hceint.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hceint.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hceint.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hceint.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hceint.wordpress.com/170/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hceint.wordpress.com&amp;blog=10948636&amp;post=170&amp;subd=hceint&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hceint.wordpress.com/2010/07/12/hce-crowd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/33b1c0779aa40d3a4892609098377997?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nuvoleonline</media:title>
		</media:content>

		<media:content url="http://hcecrowd.hce.it/wp-content/uploads/2010/07/ico_1_12072010_EN1.jpg" medium="image">
			<media:title type="html">ico_1_12072010_EN</media:title>
		</media:content>
	</item>
		<item>
		<title>New look for HCE</title>
		<link>http://hceint.wordpress.com/2010/06/30/new-look-for-hce/</link>
		<comments>http://hceint.wordpress.com/2010/06/30/new-look-for-hce/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 08:49:13 +0000</pubDate>
		<dc:creator>nuvoleonline</dc:creator>
				<category><![CDATA[HCE General]]></category>
		<category><![CDATA[Web 2.0]]></category>

		<guid isPermaLink="false">http://hceint.wordpress.com/?p=162</guid>
		<description><![CDATA[In spite of the fact that we&#8217;re full of work to do, we finally managed to renew our website. The new graphic design better reflects what we feel are our main characteristics: clarity of communication, a rock-solid technical foundation, an international vocation and, most of all, the luck of doing a job we love. Thanks &#8230; <a class="more-link" href="http://hceint.wordpress.com/2010/06/30/new-look-for-hce/">Keep&#160;reading&#160;<span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hceint.wordpress.com&amp;blog=10948636&amp;post=162&amp;subd=hceint&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.hce.it/en/"><img class="aligncenter size-full wp-image-163" title="screenshot_nuovo_sito" src="http://hceint.files.wordpress.com/2010/06/screenshot_nuovo_sito.jpg?w=400&#038;h=392" alt="" width="400" height="392" /></a><br />
In spite of the fact that we&#8217;re full of work to do, we finally managed to <a href="http://www.hce.it/en/"><strong>renew our website</strong></a>. The new graphic design better reflects what we feel are our main characteristics: clarity of communication, a rock-solid technical foundation, an international vocation and, most of all, the luck of doing a job we love. Thanks to our partner <a href="http://www.noparking.it/">no.parking studio</a> for their invaluable contribution.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hceint.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hceint.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hceint.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hceint.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hceint.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hceint.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hceint.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hceint.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hceint.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hceint.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hceint.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hceint.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hceint.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hceint.wordpress.com/162/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hceint.wordpress.com&amp;blog=10948636&amp;post=162&amp;subd=hceint&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hceint.wordpress.com/2010/06/30/new-look-for-hce/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/33b1c0779aa40d3a4892609098377997?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nuvoleonline</media:title>
		</media:content>

		<media:content url="http://hceint.files.wordpress.com/2010/06/screenshot_nuovo_sito.jpg" medium="image">
			<media:title type="html">screenshot_nuovo_sito</media:title>
		</media:content>
	</item>
		<item>
		<title>Javascript class member access control</title>
		<link>http://hceint.wordpress.com/2010/03/24/javascript-class-member-access-control/</link>
		<comments>http://hceint.wordpress.com/2010/03/24/javascript-class-member-access-control/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 14:46:46 +0000</pubDate>
		<dc:creator>hceacasaccia</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Access Control]]></category>
		<category><![CDATA[Design-Patterns]]></category>
		<category><![CDATA[Information Hiding]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Scope-Chain]]></category>

		<guid isPermaLink="false">http://hceint.wordpress.com/?p=141</guid>
		<description><![CDATA[Class member access control, that is the possibility of defining private, protected or public class members, is one of the cornerstones of object oriented programming, since it permits hiding and incapsulating implementation details and disciplines access to the resources from the outside granting their consistency is maintained. Unfortunately Javascript does not provide a built-in class &#8230; <a class="more-link" href="http://hceint.wordpress.com/2010/03/24/javascript-class-member-access-control/">Keep&#160;reading&#160;<span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hceint.wordpress.com&amp;blog=10948636&amp;post=141&amp;subd=hceint&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://hceblog.files.wordpress.com/2010/03/lock.png"><img class="alignleft" title="Lock" src="http://hceblog.files.wordpress.com/2010/03/lock.png?w=300&#038;h=199" alt="" width="300" height="199" /></a>Class member access control, that is the possibility of defining <em>private</em>, <em>protected</em> or <em>public</em> class members, is one of the cornerstones of object oriented programming, since it permits hiding and incapsulating implementation details and disciplines access to the resources from the outside granting their consistency is maintained. Unfortunately Javascript does not provide a built-in class member access control: in this article I will describe a pair of techniques which can be applied to implement it.</p>
<p>A first way of disciplining access to a variable or a method of a class could be obtained adopting an appropriate naming convention. For example it is quite common using an underscore as a prefix for the class members that implement the internals of a software component. This obviously doesn&#8217;t really deny access to those resources, but helps a careful programmer not to inadvertently breaking application consistency.</p>
<p><span id="more-141"></span>The most interesting part from the programmer&#8217;s point of view is however understanding how we can use a pair of peculiarity of the language to obtain a real class member access control:</p>
<ol>
<li><em>Lexical</em> (static) function scope  (vs. dynamic) (function scope is the one at <em>definition</em> time, regardless of when and where function is executed).</li>
<li>The opportunity to treat functions as other values, storing them in variables or returning them from functions.</li>
</ol>
<p>Let&#8217;s try to clarify with an example:</p>
<pre>function getFx () {
  var a = "Hello!";
  return function () { alert ( a ); }
}

var fx = getFx();
fx();
</pre>
<p>Here we define &#8216;getFx()&#8217;, a function which returns a function. We store the result of the execution into the variable &#8216;fx&#8217;. Static function scope grants us that the function stored in &#8216;fx&#8217; has access to all the members available at its <em>definition</em> time and not at <em>execution</em> time. Calling &#8216;fx()&#8217; we will obtain &#8216;Hello!&#8217;, despite the function &#8216;getFx()&#8217; has already returned  (those of you used to dynamic function scope could expect that &#8216;a&#8217; would have been already garbage collected&#8230;).</p>
<p>Do you notice anything interesting? We have just realized a kind of encapsulation, having a variable &#8216;a&#8217; whose content is not directly accessible, but can only be accessed through the function stored in &#8216;fx&#8217;. The function definition together with the <em>scope  chain</em> at the moment of defining gets the name of <em>closure</em> (with  <em>scope chain</em> we mean the scope of the function together with the one of the function enclosing it and so on until global scope).</p>
<p>As you have guessed, the concept of <em>closure</em> can be successfully applied to our problem, let&#8217;s see how:</p>
<pre>var Counter = function () {

  // Private variables
  var self = this;
  var value = 0;

  // Private methods
  var setValue = function ( val ) {
    value = val;
  };

  // Privileged methods
  this.get = function () {
    alert( value );
  }

  this.reset = function () {
    value = 0;
  }

  // constructor
  setInterval(
    function () { value++; },
    1000
  );

}
</pre>
<p>Here the variable &#8216;value&#8217; cannot be modified without using one of the methods that have been exposed outside being declared with &#8216;this.x =  function () {}&#8217;. Methods and variables defined with &#8216;var x = function  () {}&#8217; are no more available once the constructor function has returned.</p>
<p>Another thing to point out in this example is that the <em>closure</em> has been used in the &#8216;setInterval()&#8217; call as well. Normally this function accepts as first argument a string which contains the code to be executed in the <em>global scope</em>; but in this case, passing an anonymous funcion defined on the fly, we have the opportunity of reaching variable &#8216;value&#8217; even after the constructor returned, because &#8216;value&#8217; is available in the <em>closure</em> of the function.</p>
<p>When should we use the <em>namespacing</em> approach and when the <em>closures </em>one? Although the first solution may  appear naive, it has the advantage of not interfering with extensibility of the object (using <em>closures</em> private method cannot be easily accessed in an inherited object) and generaly speaking could need less memory, since the prefixed <em>pseudo private</em> members can be included in the prototype of objects.</p>
<p>If you found this post interesting, you will probably find useful reading this <a title="Pro Javascript Design Patterns" href="http://apress.com/book/view/159059908x">book</a> as well, and of course you could stay tuned on this blog for more articles on this topic.</p>
<p><em><a href="http://hceint.wordpress.com/staff/">Andrea Casaccia</a><br />
<a href="http://www.hce.it/en/">HCE Web  Design</a></em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hceint.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hceint.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hceint.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hceint.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hceint.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hceint.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hceint.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hceint.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hceint.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hceint.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hceint.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hceint.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hceint.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hceint.wordpress.com/141/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hceint.wordpress.com&amp;blog=10948636&amp;post=141&amp;subd=hceint&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hceint.wordpress.com/2010/03/24/javascript-class-member-access-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fc16d458d136825975042d09a2453078?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hceacasaccia</media:title>
		</media:content>

		<media:content url="http://hceblog.files.wordpress.com/2010/03/lock.png?w=300" medium="image">
			<media:title type="html">Lock</media:title>
		</media:content>
	</item>
	</channel>
</rss>
