本文整理汇总了PHP中OperationsData::addAircraft方法的典型用法代码示例。如果您正苦于以下问题:PHP OperationsData::addAircraft方法的具体用法?PHP OperationsData::addAircraft怎么用?PHP OperationsData::addAircraft使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OperationsData
的用法示例。
在下文中一共展示了OperationsData::addAircraft方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: importaircraft
public function importaircraft()
{
if (!file_exists($_FILES['uploadedfile']['tmp_name'])) {
$this->render('import_aircraftform.tpl');
return;
}
echo '<h3>Processing Import</h3>';
# Get the column headers
$allaircraft = OperationsData::getAllAircraft(false);
$headers = array();
$dbcolumns = DB::get_cols();
foreach ($dbcolumns as $col) {
if ($col->name == 'id' || $col->name == 'minrank' || $col->name == 'ranklevel') {
continue;
}
$headers[] = $col->name;
}
# Open the import file
# Fix for bug VMS-325
$temp_name = $_FILES['uploadedfile']['tmp_name'];
$new_name = CACHE_PATH . $_FILES['uploadedfile']['name'];
move_uploaded_file($temp_name, $new_name);
$fp = fopen($new_name, 'r');
if (isset($_POST['header'])) {
$skip = true;
}
$added = 0;
$updated = 0;
$total = 0;
echo '<div style="overflow: auto; height: 400px;
border: 1px solid #666; margin-bottom: 20px;
padding: 5px; padding-top: 0px; padding-bottom: 20px;">';
while ($fields = fgetcsv($fp, 1000, ',')) {
// Skip the first line
if ($skip == true) {
$skip = false;
continue;
}
# Map the read in values to the columns
$aircraft = array();
$aircraft = @array_combine($headers, $fields);
if (empty($aircraft)) {
continue;
}
# Enabled or not
if ($aircraft['enabled'] == '1') {
$aircraft['enabled'] = true;
} else {
$aircraft['enabled'] = false;
}
# Get the rank ID
$rank = RanksData::getRankByName($aircraft['rank']);
$aircraft['minrank'] = $rank->rankid;
unset($aircraft['rank']);
# Does this aircraft exist?
$ac_info = OperationsData::getAircraftByReg($aircraft['registration']);
if ($ac_info) {
echo "Editing {$aircraft['name']} - {$aircraft['registration']}<br>";
$aircraft['id'] = $ac_info->id;
OperationsData::editAircraft($aircraft);
$updated++;
} else {
echo "Adding {$aircraft['name']} - {$aircraft['registration']}<br>";
OperationsData::addAircraft($aircraft);
$added++;
}
$total++;
}
unlink($new_name);
echo "The import process is complete, added {$added} aircraft, updated {$updated}, for a total of {$total}<br />";
}