<?php
class Grad {
var $dbFormExemptio nArray = array();
function Grad ($id = '') {
/*----------------------------------------------------------------------------------------------------------------------
Do note that if you are generating arrays that will not have
their values dynamically placed into the
db insert or update statements you *MUST* place the name
'array' or 'Array' (or any variant capitalization
you like) into the name of the object array else it will be
assumed to be part of the get_class_vars( ) array
call dynamically parsed to produce the SQL strings
-----------------------------------------------------------------------------------------------------------------------*/
// USED FOR SPECIAL CASES WHEN GENERATING SQL STATEMENTS TO
COMPARE FORM NAMES TO DB NAMES OR VICE VERSA
$this->dbFormExemptio nArray =
array('instant_ messenger_servi ce_id' => 'instantMesseng er',
'is_citizen' => 'citizen',
'salary_range' => 'salary',
'grad_preferred _org_descriptio n' =>
'gradPreferredO rgDesc',
'federal_agenci es' => 'agencies',
'has_security_c learance' => 'hasClearance',
'security_clear ance_level_id' => 'clearanceID',
'grad_ideal_job ' => 'idealJob',
'language_id' => 'languages',
'language_rank_ id' => 'proficiency',
'salary' => 'jobSalary',
'start_date' => 'jobStartDate',
'end_date' => 'jobEndDate',
'hours_per_week ' => 'jobHours',
'job_duties_acc omplishments' => 'jobDuties',
'languages_othe r' => 'language_other '
);
}
function arrayStrToUpper (&$elemen t) { // PRIVATE STRING
"METHOD" FOR array_walk
$allCapsArray = array('id', 'gpa');
if (in_array($elem ent, $allCapsArray)) return
strtoupper($ele ment);
return ucfirst($elemen t);
}
function dbNameToFormNam e($formField) { // STRING "METHOD"
$formDBExemptio nArray = array_flip($thi s->dbFormExemptio nArray);
if (array_search($ formField, $formDBExemptio nArray) !== false
&& array_search($f ormField, $formDBExemptio nArray) !== null) {
return array_search($f ormField, $formDBExemptio nArray);
} else {
$dbNameArray = explode('_', $formField);
$classMethodCom partmentArray = array();
$classMethodCom partmentArray[0] = $this;
$classMethodCom partmentArray[1] = 'arrayStrToUppe r';
array_walk($dbN ameArray, $classMethodCom partmentArray);
$dbNameArray[0] = strtolower($dbN ameArray[0]);
return implode('', $dbNameArray);
}
}
}
$grad =& new Grad;
foreach(array(' ethnicity_id', 'ethnicity_othe r', 'start_date',
'fname', 'career_level_i d') as $key => $val) {
print_r("val = $val and converted it is = " .
$grad->dbNameToFormNa me($val) . "<P>");
}
$grad = null;
?>
This block of code fails to do what it is supposed to do: take a
patterned string and convert it to being a mixed-case variable.
Here is the actual output if you ran it now:
val = ethnicity_id and converted it is = ethnicityid
val = ethnicity_other and converted it is = ethnicityother
val = start_date and converted it is = jobStartDate
val = fname and converted it is = fname
val = career_level_id and converted it is = careerlevelid
Here is the way the output is SUPPOSED to look like instead:
val = ethnicity_id and converted it is = ethnicityID
val = ethnicity_other and converted it is = ethnicityOther
val = start_date and converted it is = jobStartDate
val = fname and converted it is = fname
val = career_level_id and converted it is = careerLevelID
the function itself works perfectly, however, as a callback function
it seems to do nothing in array_walk, furthermore, array_walk returns
a 1 meaning the results are valid. Nonetheless, the array elements
remain unchanged, nor is any scalar variable placed into the original
class method that has array_walk.
This is the second time array_walk has failed to do for me what it is
advertised to do (see
http://us2.php.net/manual/en/function.array-walk.php). Is there an
alternative to array_walk in PHP or do I have to search outside of PHP
to do such a simple yet infuriating task?
Phil