コード例 #1
0
ファイル: class.Part.php プロジェクト: AlexanderS/Part-DB
 /**
  * @copydoc DBElement::check_values_validity()
  */
 public static function check_values_validity(&$database, &$current_user, &$log, &$values, $is_new, &$element = NULL)
 {
     // first, we let all parent classes to check the values
     parent::check_values_validity($database, $current_user, $log, $values, $is_new, $element);
     // set "last_modified" to current datetime
     $values['last_modified'] = date('Y-m-d H:i:s');
     // set the datetype of the boolean attributes
     settype($values['visible'], 'boolean');
     settype($values['manual_order'], 'boolean');
     // check "instock"
     if (!is_int($values['instock']) && !ctype_digit($values['instock'])) {
         debug('warning', '"instock" ist keine gültige Zahl: "' . $values['instock'] . '"!', __FILE__, __LINE__, __METHOD__);
         throw new Exception('Der neue Lagerbestand ist ungültig!');
     } elseif ($values['instock'] < 0) {
         throw new Exception('Der neue Lagerbestand von "' . $values['name'] . '" wäre negativ und kann deshalb nicht gespeichert werden!');
     }
     // check "order_orderdetails_id"
     try {
         if ($values['order_orderdetails_id'] == 0) {
             $values['order_orderdetails_id'] = NULL;
         }
         if (!$is_new && $values['order_orderdetails_id'] == NULL && ($values['instock'] < $values['mininstock'] || $values['manual_order']) && ($element->get_instock() >= $element->get_mininstock() && !$element->get_manual_order())) {
             // if this part will be added now to the list of parts to order (instock is now less than mininstock, or manual_order is now true),
             // and this part has only one orderdetails, we will set that orderdetails as orderdetails to order from (attribute "order_orderdetails_id").
             // Note: If that part was already in the list of parts to order, wo mustn't change the orderdetails to order!!
             $orderdetails = $element->get_orderdetails();
             $order_orderdetails_id = count($orderdetails) == 1 ? $orderdetails[0]->get_id() : NULL;
             $values['order_orderdetails_id'] = $order_orderdetails_id;
         }
         if ($values['order_orderdetails_id'] != NULL) {
             $order_orderdetails = new Orderdetails($database, $current_user, $log, $values['order_orderdetails_id']);
         }
     } catch (Exception $e) {
         debug('error', 'Ungültige "order_orderdetails_id": "' . $values['order_orderdetails_id'] . '"' . "\n\nUrsprüngliche Fehlermeldung: " . $e->getMessage(), __FILE__, __LINE__, __METHOD__);
         throw new Exception('Die gewählte Einkaufsinformation existiert nicht!');
     }
     // check "order_quantity"
     if (!is_int($values['order_quantity']) && !ctype_digit($values['order_quantity']) || $values['order_quantity'] < 1) {
         debug('error', 'order_quantity = "' . $values['order_quantity'] . '"', __FILE__, __LINE__, __METHOD__);
         throw new Exception('Die Bestellmenge ist ungültig!');
     }
     // check if we have to reset the order attributes ("instock" is now less than "mininstock")
     if ($values['instock'] < $values['mininstock'] && ($is_new || $element->get_instock() >= $element->get_mininstock())) {
         if (!$values['manual_order']) {
             $values['order_quantity'] = $values['mininstock'] - $values['instock'];
         }
         $values['manual_order'] = false;
     }
     // check "mininstock"
     if (!is_int($values['mininstock']) && !ctype_digit($values['mininstock']) || $values['mininstock'] < 0) {
         debug('warning', '"mininstock" ist keine gültige Zahl: "' . $values['mininstock'] . '"!', __FILE__, __LINE__, __METHOD__);
         throw new Exception('Der neue Mindestlagerbestand ist ungültig!');
     }
     // check "id_category"
     try {
         // id_category == NULL means "no category", and this is not allowed!
         if ($values['id_category'] == NULL) {
             throw new Exception('"id_category" ist Null!');
         }
         $category = new Category($database, $current_user, $log, $values['id_category']);
     } catch (Exception $e) {
         debug('warning', 'Ungültige "id_category": "' . $values['id_category'] . '"' . "\n\nUrsprüngliche Fehlermeldung: " . $e->getMessage(), __FILE__, __LINE__, __METHOD__);
         throw new Exception('Die gewählte Kategorie existiert nicht!');
     }
     // check "id_footprint"
     try {
         if ($values['id_footprint'] == 0 && $values['id_footprint'] !== NULL) {
             $values['id_footprint'] = NULL;
         }
         $footprint = new Footprint($database, $current_user, $log, $values['id_footprint']);
     } catch (Exception $e) {
         debug('warning', 'Ungültige "id_footprint": "' . $values['id_footprint'] . '"' . "\n\nUrsprüngliche Fehlermeldung: " . $e->getMessage(), __FILE__, __LINE__, __METHOD__);
         throw new Exception('Der gewählte Footprint existiert nicht!');
     }
     // check "id_storelocation"
     try {
         if ($values['id_storelocation'] == 0 && $values['id_storelocation'] !== NULL) {
             $values['id_storelocation'] = NULL;
         }
         $storelocation = new Storelocation($database, $current_user, $log, $values['id_storelocation']);
     } catch (Exception $e) {
         debug('warning', 'Ungültige "id_storelocation": "' . $values['id_storelocation'] . '"' . "\n\nUrsprüngliche Fehlermeldung: " . $e->getMessage(), __FILE__, __LINE__, __METHOD__);
         throw new Exception('Der gewählte Lagerort existiert nicht!');
     }
     // check "id_manufacturer"
     try {
         if ($values['id_manufacturer'] == 0 && $values['id_manufacturer'] !== NULL) {
             $values['id_manufacturer'] = NULL;
         }
         $manufacturer = new Manufacturer($database, $current_user, $log, $values['id_manufacturer']);
     } catch (Exception $e) {
         debug('warning', 'Ungültige "id_manufacturer": "' . $values['id_manufacturer'] . '"' . "\n\nUrsprüngliche Fehlermeldung: " . $e->getMessage(), __FILE__, __LINE__, __METHOD__);
         throw new Exception('Der gewählte Hersteller existiert nicht!');
     }
     // check "id_master_picture_attachement"
     try {
         if ($values['id_master_picture_attachement']) {
             $master_picture_attachement = new Attachement($database, $current_user, $log, $values['id_master_picture_attachement']);
         } else {
             $values['id_master_picture_attachement'] = NULL;
         }
         // this will replace the integer "0" with NULL
     } catch (Exception $e) {
         debug('warning', 'Ungültige "id_master_picture_attachement": "' . $values['id_master_picture_attachement'] . '"' . "\n\nUrsprüngliche Fehlermeldung: " . $e->getMessage(), __FILE__, __LINE__, __METHOD__);
         throw new Exception('Die gewählte Datei existiert nicht!');
     }
 }
コード例 #2
0
ファイル: class.User.php プロジェクト: AlexanderS/Part-DB
 /**
  * @copydoc DBElement::check_values_validity()
  */
 public static function check_values_validity(&$database, &$current_user, &$log, &$values, $is_new, &$element = NULL)
 {
     // first, we let all parent classes to check the values
     parent::check_values_validity($database, $current_user, $log, $values, $is_new, $element);
     // check "group_id"
     try {
         $group = new Group($database, $current_user, $log, $values['group_id']);
     } catch (Exception $e) {
         debug('warning', 'Ungültige "group_id": "' . $values['group_id'] . '"' . "\n\nUrsprüngliche Fehlermeldung: " . $e->getMessage(), __FILE__, __LINE__, __METHOD__);
         throw new Exception('Die gewählte Gruppe existiert nicht!');
     }
 }
コード例 #3
0
 /**
  * @copydoc DBElement::check_values_validity()
  */
 public static function check_values_validity(&$database, &$current_user, &$log, &$values, $is_new, &$element = NULL)
 {
     if ($values['parent_id'] == 0) {
         $values['parent_id'] = NULL;
     }
     // NULL is the root node
     // first, we let all parent classes to check the values
     parent::check_values_validity($database, $current_user, $log, $values, $is_new, $element);
     if (!$is_new && $values['id'] == 0) {
         throw new Exception('Die Oberste Ebene kann nicht bearbeitet werden!');
     }
     // with get_called_class() we can get the class of the element which will be edited/created.
     // example: if you write "$new_cat = Category::add(...);", get_called_class() returns "Category"
     $classname = get_called_class();
     // check "parent_id"
     if (!$is_new && $values['parent_id'] == $values['id']) {
         throw new Exception('Ein Element kann nicht als Unterelement von sich selber zugeordnet werden!');
     }
     try {
         $parent_element = new $classname($database, $current_user, $log, $values['parent_id'], true);
     } catch (Exception $e) {
         debug('warning', 'Ungültige "parent_id": "' . $values['parent_id'] . '"' . "\n\nUrsprüngliche Fehlermeldung: " . $e->getMessage(), __FILE__, __LINE__, __METHOD__);
         throw new Exception('Das ausgewählte übergeordnete Element existiert nicht!');
     }
     // to avoid infinite parent_id loops (this is not the same as the "check parent_id" above!)
     if (!$is_new && $parent_element->get_parent_id() == $values['id']) {
         throw new Exception('Ein Element kann nicht einem seiner direkten Unterelemente zugeordnet werden!');
     }
     // check "name" + "parent_id" (the first check of "name" was already done by
     // "parent::check_values_validity", here we check only the combination of "parent_id" and "name")
     // we search for an element with the same name and parent ID, there shouldn't be one!
     $id = $is_new ? -1 : $values['id'];
     $query_data = $database->query('SELECT * FROM ' . $parent_element->get_tablename() . ' WHERE name=? AND parent_id <=> ? AND id<>?', array($values['name'], $values['parent_id'], $id));
     if (count($query_data) > 0) {
         throw new Exception('Es existiert bereits ein Element auf gleicher Ebene (' . $classname . '::' . $parent_element->get_full_path() . ') mit gleichem Namen (' . $values['name'] . ')!');
     }
 }