/** * @param ModelMapping $modelMapping * @return $this * @throws MappingException */ public function addModelMapping(ModelMapping $modelMapping) { $modelClassName = $modelMapping->getClassName(); if ($this->hasModelMapping($modelClassName)) { throw new MappingException("Mapping already exists for class '{$modelClassName}'."); } $this->modelMappings[$modelClassName] = $modelMapping; return $this; }
<?php require_once "../../phplib/util.php"; assert_options(ASSERT_BAIL, 1); debug_off(); $dbResult = mysql_query('select * from model_mappings'); $mms = ModelMapping::populateFromDbResult($dbResult); foreach ($mms as $mm) { print "Creating {$mm->modelType}{$mm->slaveNumber} from " . "{$mm->modelType}{$mm->masterNumber}\n"; $master = Model::loadByTypeNumber($mm->modelType, $mm->masterNumber); // Create the model $slave = Model::create($mm->modelType, $mm->slaveNumber, "Derivat din {$mm->modelType}{$mm->masterNumber}"); $slave->save(); $slave->id = db_getLastInsertedId(); // Clone the model descriptions $mds = ModelDescription::loadByModelId($master->id); foreach ($mds as $md) { $md->id = 0; $md->modelId = $slave->id; $md->save(); } // Clone the participle model if ($mm->modelType == 'V') { $pm = ParticipleModel::loadByVerbModel($mm->masterNumber); $clonePm = ParticipleModel::create($mm->slaveNumber, $pm->participleModel); $clonePm->save(); } // Delete the mapping mysql_query("delete from model_mappings where model_type = " . " '{$mm->modelType}' and slave_no = '{$mm->slaveNumber}'"); // Regenerate the lexems. In theory the paradigm won't change, but we want // to actually see it.
function saveModel($modelNumber, $infinitive, $longInfinitive, $imperative, $slaveModels, $participle, $gerund, $participleModel, $present, $subjonctive, $imperfect, $perfectSimple, $pastPerfect) { $forms = array(); $inflections = array(); $forms[] = $infinitive; $inflections[] = INFL_INFINITIVE; $forms[] = $longInfinitive; $inflections[] = INFL_LONG_INFINITIVE; $forms[] = $imperative; $inflections[] = INFL_IMPERATIVE; $forms[] = $participle; $inflections[] = INFL_PARTICIPLE; $forms[] = $gerund; $inflections[] = INFL_GERUND; addPersonalForms($forms, $inflections, $present, INFL_PRESENT); addPersonalForms($forms, $inflections, $subjonctive, INFL_SUBJONCTIVE); addPersonalForms($forms, $inflections, $imperfect, INFL_IMPERFECT); addPersonalForms($forms, $inflections, $perfectSimple, INFL_PERFECT_SIMPLE); addPersonalForms($forms, $inflections, $pastPerfect, INFL_PAST_PERFECT); saveCommonModel('V', $modelNumber, $forms, '', $inflections); // Add the mapping from this verb model to the corresponding adjective model $pm = ParticipleModel::create($modelNumber, $participleModel); $pm->save(); foreach ($slaveModels as $sm) { $mm = ModelMapping::create('V', $sm, $modelNumber); $mm->save(); } }