* You should have received a copy of the GNU General Public License * along with MMC; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require "modules/base/computers/localSidebar.php"; require "graph/navbar.inc.php"; require_once "modules/pulse2/includes/locations_xmlrpc.inc.php"; // Receiving form data if (isset($_POST['name'], $_POST['parent'], $_POST['description'])) { if (empty($_GET['id'])) { addEntity($_POST['name'], $_POST['parent'], $_POST['description']); if (!isXMLRPCError()) { new NotifyWidgetSuccess(_T("The entity has been added successfully.", "glpi")); } } else { editEntity($_GET['id'], $_POST['name'], $_POST['parent'], $_POST['description']); if (!isXMLRPCError()) { new NotifyWidgetSuccess(_T("The entity has been edited successfully.", "glpi")); } } } $page_title = _T("Add entity", 'glpi'); // Init form vars $entity_name = ''; $parent = 1; $description = ''; if (isset($_GET['id'])) { $page_title = _T("Edit entity", 'glpi'); // Edition mode : init vars // Get the corresponding entity $params = array();
foreach ($tables as $className => $table) { foreach ($table as $name => $cols) { if (!file_exists(REPOSITORY_PATH . $className . '.php')) { //$entity_name = readline($className . ": "); $entity_name = readline_predefined($className . ": ", Inflector::singularize($className)); newEntity($cols, $entity_name); } else { $repository = file_get_contents(REPOSITORY_PATH . $className . '.php'); preg_match('/(?<=@entity \\\\).*/', $repository, $matches); if (!$matches) { continue; } $matches = explode("\\", $matches[0]); $entity_name = end($matches); if (file_exists(ENTITY_PATH . $entity_name . '.php')) { editEntity($cols, $entity_name); } else { newEntity($cols, $entity_name); } } } if (!file_exists(REPOSITORY_PATH . $className . '.php')) { // Repozitář $properties = " * @table {$name}\n * @entity \\" . NS . 'Model\\Entity\\' . $entity_name; $buffer = "namespace " . NS . "Model\\Repository;\n\n/**\n{$properties}\n */\nfinal class {$className} extends Base\n{\n\n}"; file_put_contents(REPOSITORY_PATH . $className . '.php', "<?php\n\n{$buffer}\n"); } } echo "\r\n"; echo "\r\n"; /**
function generateEntity($className, $cols) { if (!file_exists(REPOSITORY_PATH . $className . '.php')) { $entity_name = readline_predefined(" Entity name for repo '" . $className . "': ", Inflector::singularize($className)); newEntity($cols, $entity_name); drawRow("Entity '{$entity_name}' generated"); } else { $repository = file_get_contents(REPOSITORY_PATH . $className . '.php'); preg_match('/(?<=@entity \\\\).*/', $repository, $matches); if (!$matches) { return null; } $matches = explode("\\", $matches[0]); $entity_name = end($matches); if (file_exists(ENTITY_PATH . $entity_name . '.php')) { editEntity($cols, $entity_name); drawRow("Entity '{$entity_name}' updated"); } else { newEntity($cols, $entity_name); drawRow("Entity '{$entity_name}' generated"); } } return $entity_name; }