/**
  * @brief Create a new device-part
  *
  * @param Database  &$database          reference to the database object
  * @param User      &$current_user      reference to the current user which is logged in
  * @param Log       &$log               reference to the Log-object
  * @param integer   $device_id          the ID of the device
  * @param integer   $part_id            the ID of the part
  * @param integer   $quantity           the mount quantity (see DevicePart::set_mount_quantity())
  * @param string    $mountnames         the mountname(s) (see DevicePart::set_mount_name())
  * @param boolean   $increase_if_exist  @li if true, and there is already a DevicePart with the same
  *                                          part ID + device ID, the mount quantity of the existing
  *                                          DevicePart will be incremented by $quantity. In addition,
  *                                          the new mount name ($mountname) will be attached (with a
  *                                          comma) at the end of the mount name of the existing DevicePart.
  *                                      @li if false, and there is already a DevicePart with the same
  *                                          part ID + device ID, this method will throw an exception.
  *
  * @retval DevicePart   the new device-part
  * @retval DevicePart   the existing device-part, if there is already a DevicePart with
  *                      the same part ID + device ID and "$increment_if_exist == true"
  *
  * @throws Exception    if (this combination of) values is not valid
  * @throws Exception    if there was an error
  *
  * @see DBElement::add()
  */
 public static function add(&$database, &$current_user, &$log, $device_id, $part_id, $quantity, $mountnames = '', $increase_if_exist = false)
 {
     $existing_devicepart = DevicePart::get_device_part($database, $current_user, $log, $device_id, $part_id);
     if (is_object($existing_devicepart)) {
         if ($increase_if_exist) {
             if (!is_int($quantity) && !ctype_digit($quantity) || $quantity < 0) {
                 debug('error', 'quantity = "' . $quantity . '"', __FILE__, __LINE__, __METHOD__);
                 throw new Exception('Die Bestückungs-Anzahl ist ungültig!');
             }
             $quantity = $existing_devicepart->get_mount_quantity() + $quantity;
             $old_mountnames = $existing_devicepart->get_mount_names();
             if (strlen($mountnames) > 0) {
                 if (strlen($old_mountnames) > 0) {
                     $mountnames = $old_mountnames . ', ' . $mountnames;
                 }
             } else {
                 $mountnames = $old_mountnames;
             }
             $existing_devicepart->set_attributes(array('quantity' => $quantity, 'mountnames' => $mountnames));
             return $existing_devicepart;
         } else {
             $device = new Device($database, $current_user, $log, $device_id);
             $part = new Part($database, $current_user, $log, $part_id);
             throw new Exception('Die Baugruppe "' . $device->get_name() . '" enthält bereits das Bauteil "' . $part->get_name() . '"!');
         }
     }
     // there is no such DevicePart, so we will create it
     return parent::add($database, $current_user, $log, 'device_parts', array('id_device' => $device_id, 'id_part' => $part_id, 'quantity' => $quantity, 'mountnames' => $mountnames));
 }