本文整理汇总了PHP中Part::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Part::add方法的具体用法?PHP Part::add怎么用?PHP Part::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Part
的用法示例。
在下文中一共展示了Part::add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: catch
}
} catch (Exception $e) {
$messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
$fatal_error = true;
}
/********************************************************************************
*
* Execute actions
*
*********************************************************************************/
$print_unsaved_values = false;
if (!$fatal_error) {
switch ($action) {
case 'create_new_part':
try {
$part = Part::add($database, $current_user, $log, $new_name, $new_category_id, $new_description, $new_instock, $new_mininstock, $new_storelocation_id, $new_manufacturer_id, $new_footprint_id, $new_comment, $new_visible);
$is_new_part = false;
} catch (Exception $e) {
$messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
}
break;
case 'apply_attributes':
try {
$new_attributes = array('name' => $new_name, 'description' => $new_description, 'instock' => $new_instock, 'mininstock' => $new_mininstock, 'id_category' => $new_category_id, 'id_storelocation' => $new_storelocation_id, 'visible' => $new_visible, 'comment' => $new_comment);
// do not overwrite (remove!) the footprint or manufacturer if they are disabled (global or in the part's category)
if (isset($_REQUEST['footprint_id'])) {
$new_attributes['id_footprint'] = $new_footprint_id;
}
if (isset($_REQUEST['manufacturer_id'])) {
$new_attributes['id_manufacturer'] = $new_manufacturer_id;
}
示例2: import_parts
/**
* @brief Import Parts (create Parts, and if neccessary, Categories, Footprints and so on)
*
* @note This function uses database transactions. If an error occurs, all changes will be rolled back.
*
* @param Database &$database reference to the database object
* @param User &$current_user reference to the user which is logged in
* @param Log &$log reference to the Log-object
* @param array $data The import data array from "extract_import_data_from_request()"
* @param boolean $only_check_data If true, this function will only check if all values in "$data" are valid.
* In this case, no parts will be imported!
*
* @retval array All new Part objects (only if "$only_check_data == false")
*
* @throws Exception if there was an error (maybe the passed data is not valid)
*/
function import_parts(&$database, &$current_user, &$log, $data, $only_check_data = false)
{
$parts = array();
try {
$transaction_id = $database->begin_transaction();
// start transaction
// Get the category, footprint, storelocation, ... which are named "Import", or create them.
// We need this elements as parent for new elements, which will be created while import parts.
$import_categories = Category::search($database, $current_user, $log, 'Import', true);
if (count($import_categories) > 0) {
$import_category = $import_categories[0];
$import_category_created = false;
} else {
$import_category = Category::add($database, $current_user, $log, 'Import', NULL);
$import_category_created = true;
// we can delete it later if we didn't need it
}
$import_storelocations = Storelocation::search($database, $current_user, $log, 'Import', true);
if (count($import_storelocations) > 0) {
$import_storelocation = $import_storelocations[0];
$import_storelocation_created = false;
} else {
$import_storelocation = Storelocation::add($database, $current_user, $log, 'Import', NULL);
$import_storelocation_created = true;
// we can delete it later if we didn't need it
}
$import_footprints = Footprint::search($database, $current_user, $log, 'Import', true);
if (count($import_footprints) > 0) {
$import_footprint = $import_footprints[0];
$import_footprint_created = false;
} else {
$import_footprint = Footprint::add($database, $current_user, $log, 'Import', NULL);
$import_footprint_created = true;
// we can delete it later if we didn't need it
}
$import_suppliers = Supplier::search($database, $current_user, $log, 'Import', true);
if (count($import_suppliers) > 0) {
$import_supplier = $import_suppliers[0];
$import_supplier_created = false;
} else {
$import_supplier = Supplier::add($database, $current_user, $log, 'Import', NULL);
$import_supplier_created = true;
// we can delete it later if we didn't need it
}
$import_manufacturers = Manufacturer::search($database, $current_user, $log, 'Import', true);
if (count($import_manufacturers) > 0) {
$import_manufacturer = $import_manufacturers[0];
$import_manufacturer_created = false;
} else {
$import_manufacturer = Manufacturer::add($database, $current_user, $log, 'Import', NULL);
$import_manufacturer_created = true;
// we can delete it later if we didn't need it
}
$import_category_used = false;
$import_storelocation_used = false;
$import_footprint_used = false;
$import_supplier_used = false;
$import_manufacturer_used = false;
// start import
$row_index = 0;
foreach ($data as $row) {
$name = $row['part_name'];
$description = $row['part_description'];
$instock = $row['part_instock'];
$mininstock = $row['part_mininstock'];
$comment = $row['part_comment'];
$category_name = $row['part_category_name'];
$footprint_name = $row['part_footprint_name'];
$storelocation_name = $row['part_storelocation_name'];
$manufacturer_name = $row['part_manufacturer_name'];
$supplier_name = $row['part_supplier_name'];
$supplierpartnr = $row['part_supplierpartnr'];
$price = $row['part_price'];
// search elements / create them if they don't exist already
if (strlen($category_name) > 0) {
$categories = Category::search($database, $current_user, $log, $category_name, true);
if (count($categories) > 0) {
$category = $categories[0];
} else {
$category = Category::add($database, $current_user, $log, $category_name, $import_category->get_id());
$import_category_used = true;
}
} else {
throw new Exception('Jedes Bauteil muss eine Kategorie haben!');
//.........这里部分代码省略.........