コード例 #1
0
ファイル: class.Part.php プロジェクト: AlexanderS/Part-DB
 /**
  * @brief Create a new part
  *
  * @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 string    $name               the name of the new part (see Part::set_name())
  * @param integer   $category_id        the category ID of the new part (see Part::set_category_id())
  * @param string    $description        the description of the new part (see Part::set_description())
  * @param integer   $instock            the instock of the new part (see Part::set_instock())
  * @param integer   $mininstock         the mininstock of the new part (see Part::set_mininstock())
  * @param integer   $storelocation_id   the storelocation ID of the new part (see Part::set_storelocation_id())
  * @param integer   $manufacturer_id    the manufacturer ID of the new part (see Part::set_manufacturer_id())
  * @param integer   $footprint_id       the footprint ID of the new part (see Part::set_footprint_id())
  * @param string    $comment            the comment of the new part (see Part::set_comment())
  * @param boolean   $visible            the visible attribute of the new part (see Part::set_visible())
  *
  * @retval Part     the new part
  *
  * @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, $name, $category_id, $description = '', $instock = 0, $mininstock = 0, $storelocation_id = NULL, $manufacturer_id = NULL, $footprint_id = NULL, $comment = '', $visible = false)
 {
     return parent::add($database, $current_user, $log, 'parts', array('name' => $name, 'id_category' => $category_id, 'description' => $description, 'instock' => $instock, 'mininstock' => $mininstock, 'id_storelocation' => $storelocation_id, 'id_manufacturer' => $manufacturer_id, 'id_footprint' => $footprint_id, 'visible' => $visible, 'comment' => $comment, 'id_master_picture_attachement' => NULL, 'manual_order' => false, 'order_orderdetails_id' => NULL, 'order_quantity' => 1));
     // the column "datetime_added" will be automatically filled by MySQL
     // the column "last_modified" will be filled in the function check_values_validity()
 }
コード例 #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'] . ')!');
     }
 }