Joshua Williams

Joshua Williams
Job Title: 
Engineer

I am a programmer, web developer, webmaster and graphic-designer-in-training. I live in Estes Park, Colorado with my wife and three children. After connecting through their e-learning site, HomeGrownProgrammers.com, I have worked with Automation Excellence since the summer of 2009 and also have some freelance programming experience prior to that.

My uncle introduced me to programming in 2001 and since then I cannot remember a time when I did not have at least one project in progress just for my own enjoyment. I love programming and have worked with Java, PHP, Dark Basic, Ruby, and C++ while dabbling in a few others.

Currently I do some of the online teaching on the Home Grown Programmers site and I love the thrill of introducing the next generation to the intricacies of information technology.

My Blog

Mon, 04/30/2012 - 13:03
After getting the message, "There is data for this field in the database. The field settings can no longer be changed." while trying to extend the character limit for a text field in a Drupal 7 instance, I used the code below to increase the character limit. It modifies the relevant parts of the database to allow more characters. I ran the SQL code through a content node with the PHP Code Text Filter enabled, but it could also be run in a custom module. Of course, I took care to back up my site database first!
<?php
$field_to_update = 'field_text_field_to_extend'; //Replace with field slug
$new_chars = '500';  //Replace with extended character limit
 
$result1 = db_query('ALTER TABLE {field_data_'.$field_to_update.'} CHANGE '.$field_to_update.'_value '.$field_to_update.'_value VARCHAR('.$new_chars.')');
$result2 = db_query('ALTER TABLE {field_revision_'.$field_to_update.'} CHANGE '.$field_to_update.'_value '.$field_to_update.'_value VARCHAR('.$new_chars.')');
 
$result3 = db_query('SELECT CAST(data AS CHAR(10000) CHARACTER SET utf8) data FROM {field_config} WHERE field_name = \''.$field_to_update.'\'');
foreach ($result3 as $result) {
	$data = $result->data;
}
$data_array = unserialize($data);
$data_array['settings']['max_length'] = $new_chars;
$new_data = serialize($data_array);
 
$result4 = db_query('UPDATE {field_config} SET data = :data WHERE field_name = :field', array(':data' => $new_data, ':field' => $field_to_update));
?>
Tue, 01/18/2011 - 14:20

While setting up a local copy of a Magento based e-commerce site on my Windows machine, I was presented with a number of messages stating, "Fatal error: Call to undefined function money_format()." After a little research I was able to discover that this particular PHP function is not available on the Windows platform.

In order to get access to a version of the function that would be available from anywhere in the site's php code, I used the Apache auto_prepend_file directive in my php.ini file:

auto_prepend_file = "C:\path\to\money_format.php"

Then I created a money_format.php file containing a function called money_format() that wraps the PHP function number_format() (which does work on Windows) and voila, after restarting Apache, all the calls to money_format in my Magento site resolve using my custom function.

Here is the code I used for my (admittedly basic) wrapper function in case it may help anyone.

<?php
  function money_format($junk, $number) {
    return number_format($number, 2);
  }
?>
Wed, 08/18/2010 - 12:00

Blocks created by a view in Drupal do not have access to the page URL and thus arguments won't work normally. However, by using some custom PHP code in the argument default setting, we can pass information from the URL to the block as if it were a page.

The best tutorial I was able to find on this is here: Drupal View Block With Arguments

The PHP code I used to get a user's blog to show under his team profile page on this site is below. Used as default argument code for "User: Name."

$path = drupal_get_path_alias($_GET['q']); //get alias of URL
$path = explode('/', $path); //break path into an array
if ($path[0] == 'team' && $path[1] != '') {
  return $path[1];
}