Пример #1
0
 /**
  * Process the interface to assign new hierarchy links
  *
  * @return null
  *
  * @param $graph_element The graph element object to which to add parent or children
  */
 public static function processGraphAdminUI($graph_element, &$errMsg)
 {
     $db = AbstractDb::getObject();
     $object_id = $db->escapeString($graph_element->getHgeId());
     $allparents = array();
     // Process the parents
     // Process any remove element command
     $parent_rows = HotspotGraph::getParents($object_id);
     $allparents = array();
     if ($parent_rows) {
         foreach ($parent_rows as $parent_row) {
             $allparents[$parent_row['next_element_id']] = $parent_row['name'];
             $name = $object_id . "_parent_" . $parent_row['next_element_id'] . "_remove";
             if (!empty($_REQUEST[$name])) {
                 $parentIdStr = $db->escapeString($parent_row['next_element_id']);
                 $sql = "DELETE FROM hotspot_graph WHERE parent_element_id='{$parentIdStr}' AND child_element_id='{$object_id}';";
                 $db->execSqlUpdate($sql, false);
             }
         }
     }
     // Did we add an element?
     $name = $object_id . "_parent_add";
     if (!empty($_REQUEST[$name])) {
         $element = HotspotGraphElement::processSelectGraphElementUI($object_id . "_parent_add_element", $errMsg);
         if ($element) {
             //The user and role exist
             if (isset($allparents[$element->getHgeId()])) {
                 $errMsg .= sprintf(_("Element %s is already a parent of this object"), $allparents[$element->getHgeId()]);
             } elseif (HotspotGraph::detectCycle($graph_element, $element->getHgeId(), false)) {
                 $errMsg .= sprintf(_("Cycle detected while adding element '%s' as a parent of this object: this element is already among the children of this object."), $element->__toString());
             } else {
                 // the user doesn't already have that role
                 $sql = "INSERT INTO hotspot_graph (parent_element_id, child_element_id) VALUES ('{$element->getHgeId()}', '{$object_id}');";
                 $db->execSqlUpdate($sql, false);
             }
         }
     }
     // Process the children
     // Process any remove element command
     $children_rows = HotspotGraph::getChildren($object_id);
     $allchildren = array();
     if ($children_rows) {
         foreach ($children_rows as $child_row) {
             $allchildren[$child_row['next_element_id']] = $child_row['name'];
             $name = $object_id . "_child_" . $child_row['next_element_id'] . "_remove";
             if (!empty($_REQUEST[$name])) {
                 $childIdStr = $db->escapeString($child_row['next_element_id']);
                 $sql = "DELETE FROM hotspot_graph WHERE parent_element_id='{$object_id}' AND child_element_id='{$childIdStr}';";
                 $db->execSqlUpdate($sql, false);
             }
         }
     }
     // Did we add an element?
     $name = $object_id . "_child_add";
     if (!empty($_REQUEST[$name])) {
         $element = HotspotGraphElement::processSelectGraphElementUI($object_id . "_child_add_element", $errMsg);
         if ($element) {
             //The user and role exist
             if (isset($allchildren[$element->getHgeId()])) {
                 $errMsg .= sprintf(_("Element '%s' is already a child of this object"), $allchildren[$element->getHgeId()]);
             } elseif (HotspotGraph::detectCycle($graph_element, $element->getHgeId(), true)) {
                 $errMsg .= sprintf(_("Cycle detected while adding element '%s' as a child of this object: this element is already among the parents of this object."), $element->__toString());
             } else {
                 // the user doesn't already have that role
                 $sql = "INSERT INTO hotspot_graph (child_element_id, parent_element_id) VALUES ('{$element->getHgeId()}', '{$object_id}');";
                 $db->execSqlUpdate($sql, false);
             }
         }
     }
     return null;
 }