Im trying to import online registrations into my cakephp application.
The registration data is stored in a db table. Currently my
application queries the pending registration data and loops through
the result set. Splits the data into relevant pieces that are inserted
into cakephp db tables via model.
Models:
Person
CourseRegistration
AdminController with import_registrations() action
I would like to create a "person" record for each registration the
first time the import is run. Thereafter I check the people table if a
record for this name exists. If the person is already in the db I want
to skip the record creation and only retrieve the id for this
person...
The find query does not seem to find any results the first time.
Although when I look at the database table multiple records with the
same firstname lastname combination are created. When I run the action
once again the find operation is successfull and no additional records
are inserted.
Could it be that there is a query caching mechanism involved that
prevents the query operation from reloading the table data? Has anyone
had this problem with batch importing/inserting records before?
Here is some of the relevant code. Any help would be great! Thanks.
--------
#########################
in the AdminController function import_registrations() I get the
registration data from db with and call the parseRegistrationData()
function for each row...
function import_registrations()
{
uses('model' . DS . 'connection_manager');
$this->db = ConnectionManager::getInstance();
$this->connected = $this->db->getDataSource('default');
$sql = "SELECT uid, submittedfields, date FROM ".$importtable." WHERE
downloaded ='n' AND date > '".$date."' ORDER BY date ASC LIMIT 150";
$result = $this->connected->query($sql);
$total = count($result);
for($i=0; $i < $total; $i++) {
$this->currentRecordId = $result[$i][$importtable]['uid'];
$output .= $this->parseRegistrationData($result[$i][$importtable]
['submittedfields']);
$this->recordCount++;
}
...
}
and then I pass each result row to the parseRegistration function...
/**************
* parseRegistrationData
* split row and create Person and Registration records
* @param array row with registration data
**************/
function parseRegistrationData($row)
{
check data etc..
...
// prepare course data
$courses = split(",", $courses);
if(count($courses > 0)) {
$name = ucwords(trim($regData[0])) ."
".ucwords(trim($regData[1]));
// check result of this array with db result!
if(!array_key_exists($name,$this->names)) {
$this->names[$name] = "uid :".$this->currentRecordId;
}
$criteria = "name ='".$name."'";
$sql = "SELECT id FROM people WHERE ".$criteria;
$result = $this->connected->query($sql);
if(count($result)) {
// person already exists in db!
$person1_id = $result[0]['people']['id'];
} else {
// create person1 from form data
$data['Person']['id'] = '';
$data['Person']['firstname'] = ucwords(trim($regData[0]));
$data['Person']['lastname'] = ucwords(trim($regData[1]));
$data['Person']['name'] = $name;
$data['Person']['birthdate'] = null;
$data['Person']['sex'] = $regData[2];
$data['Person']['street'] = trim($regData[3]);
$data['Person']['zip'] = $regData[4];
$data['Person']['city'] = $regData[5];
$data['Person']['telephone1'] = $regData[6];
$data['Person']['telephone2'] = '';
$data['Person']['cell'] = $regData[7];
$data['Person']['email'] = $regData[8];
$data['Person']['membership_type'] = $regData[9] ?
$regData[9] : 'KM'; // tarif1
$data['Person']['referal'] = $regData[11];
$data['Person']['note'] = '';
$data['Person']['newsletter'] = 1;
$data['Person']['assistent'] = 0;
$data['Person']['membership_start'] = null;
$data['Person']['membership_end'] = null;
$data['Person']['credit'] = 0;
$data['Person']['checked'] = 0;
$data['Person']['created'] = date("Y-m-d H:i:s", time());
$data['Person']['modified'] = $data['Person']
['created'];
if($data['Person']['sex'] == 'männlich') {
$data['Person']['prefix'] = 'Herr';
} else {
$data['Person']['prefix'] = 'Frau';
}
$this->Person->save($data);
$person1_id = $this->Person->getID($list = 0);
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---