本文整理汇总了PHP中Device::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Device::add方法的具体用法?PHP Device::add怎么用?PHP Device::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Device
的用法示例。
在下文中一共展示了Device::add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: catch
$selected_device = NULL;
}
} catch (Exception $e) {
$messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
$fatal_error = true;
}
/********************************************************************************
*
* Execute actions
*
*********************************************************************************/
if (!$fatal_error) {
switch ($action) {
case 'add':
try {
$new_device = Device::add($database, $current_user, $log, $new_name, $new_parent_id);
$html->set_variable('refresh_navigation_frame', true, 'boolean');
if (!$add_more) {
$selected_device = $new_device;
$selected_id = $selected_device->get_id();
}
} catch (Exception $e) {
$messages[] = array('text' => 'Die neue Baugruppe konnte nicht angelegt werden!', 'strong' => true, 'color' => 'red');
$messages[] = array('text' => 'Fehlermeldung: ' . nl2br($e->getMessage()), 'color' => 'red');
}
break;
case 'delete':
try {
if (!is_object($selected_device)) {
throw new Exception('Es ist keine Baugruppe markiert oder es trat ein Fehler auf!');
}
示例2: Device
public static function Device($type, $data)
{
require_once 'device.class.php';
$class = new Device();
$status = false;
$class->setData($data);
$class->filter = ManagementFunction::getPostVariable('filter');
switch ($type) {
case 'add':
$status = $class->add();
break;
case 'update':
$status = $class->update();
break;
case 'delete':
$status = $class->delete();
break;
case 'getsingle':
$status = $class->getsingle();
break;
case 'getpage':
$status = $class->getpage();
break;
case 'search':
$status = $class->search();
break;
default:
break;
}
if ($status) {
wp_send_json_success($status);
} else {
wp_send_json_error($class->error);
}
}
示例3: copy
/**
* @brief Create a new Device as a copy from this one. All DeviceParts will be copied too.
*
* @param string $name The name of the new device
* @param integer $parent_id The ID of the new device's parent device
* @param boolean $with_subdevices If true, all subdevices will be copied too
*
* @throws Exception if there was an error
*/
public function copy($name, $parent_id, $with_subdevices = false)
{
try {
if ($with_subdevices && $parent_id > 0) {
// check if $parent_id is NOT a child of this device
$parent_device = new Device($this->database, $this->current_user, $this->log, $parent_id);
if ($parent_device->get_id() == $this->get_id() || $parent_device->is_child_of($this)) {
throw new Exception('Eine Baugruppe kann nicht in sich selber kopiert werden!');
}
}
$transaction_id = $this->database->begin_transaction();
// start transaction
$new_device = Device::add($this->database, $this->current_user, $this->log, $name, $parent_id);
$device_parts = $this->get_parts();
foreach ($device_parts as $part) {
$new_part = DevicePart::add($this->database, $this->current_user, $this->log, $new_device->get_id(), $part->get_part()->get_id(), $part->get_mount_quantity(), $part->get_mount_names());
}
if ($with_subdevices) {
$subdevices = $this->get_subelements(false);
foreach ($subdevices as $device) {
$device->copy($device->get_name(), $new_device->get_id(), true);
}
}
$this->database->commit($transaction_id);
// commit transaction
} catch (Exception $e) {
$this->database->rollback();
// rollback transaction
throw new Exception("Die Baugruppe \"" . $this->get_name() . "\"konnte nicht kopiert werden!\nGrund: " . $e->getMessage());
}
}