Exemplo n.º 1
0
 private function generateNoSuchModelException(Entity $entity)
 {
     $className = "NoSuch{$entity->getName()}Exception";
     $content = "<?php\nclass {$className} extends Exception {\n\n}\n?>";
     $destination = "src/exceptions/{$className}.php";
     FileUtil::storeFileContents($destination, $content);
 }
Exemplo n.º 2
0
 public function save(Entity $entity)
 {
     $data = array('name' => $entity->getName(), 'email' => $entity->getEmail(), 'phone' => $entity->getPhone(), 'message' => $entity->getMessage(), 'date' => $entity->getDate());
     if ($entity->getId() > 0) {
         $this->db->update($this->table, $data, $entity->getId());
     } else {
         $entity->setId($this->db->insert($this->table, $data));
     }
 }
Exemplo n.º 3
0
 public function save(Entity $entity)
 {
     $item = array('name' => $entity->getName(), 'address' => $entity->getAddress(), 'image' => $entity->getImage(), 'date_added' => $entity->getDateAdded());
     if ($entity->getId() > 0) {
         $this->update($item, array('id' => $entity->getId()));
     } else {
         $this->add($item);
     }
 }
Exemplo n.º 4
0
 public function save(Entity $entity)
 {
     $item = array('user_id' => $entity->getUserId(), 'name' => $entity->getName(), 'price' => $entity->getPrice(), 'quantity' => $entity->getQuantity(), 'image' => $entity->getImage(), 'date_added' => $entity->getDateAdded());
     if ($entity->getId() > 0) {
         $this->update($item, array('id' => $entity->getId()));
     } else {
         $this->add($item);
     }
 }
Exemplo n.º 5
0
 public function save(Entity $entity)
 {
     $data = array('product_id' => $entity->getProductId(), 'date' => $entity->getDate(), 'name' => $entity->getName(), 'email' => $entity->getEmail(), 'phone' => $entity->getPhone(), 'is_complete' => $entity->getIsComplete(), 'user_id' => $entity->getUserId());
     if ($entity->getId() > 0) {
         $this->db->update($this->table, $data, $entity->getId());
     } else {
         $entity->setId($this->db->insert($this->table, $data));
     }
 }
Exemplo n.º 6
0
 public function save(Entity $entity)
 {
     $data = array('name' => $entity->getName(), 'content' => $entity->getContent(), 'date' => date('Y-m-d H:i:s', strtotime($entity->getDate())), 'news_id' => $this->news_id);
     if ($entity->getId() > 0) {
         $this->db->update($this->table, $data, $entity->getId());
     } else {
         $entity->setId($this->db->insert($this->table, $data));
     }
 }
Exemplo n.º 7
0
 public function save(Entity $entity)
 {
     $dataInput = array('name' => $entity->getName(), 'image' => $entity->getImage(), 'category_id' => $entity->getCategoryId(), 'description' => $entity->getDescription());
     if ($entity->getId() > 0) {
         $this->update($entity->getId(), $dataInput);
     } else {
         $this->create($dataInput);
     }
 }
Exemplo n.º 8
0
 public function save(Entity $entity)
 {
     $item = array('product_id' => $entity->getProductId(), 'name' => $entity->getName(), 'image' => $entity->getImage(), 'is_cover' => $entity->getIsCover(), 'date_added' => $entity->getDateAdded());
     if ($entity->getId() > 0) {
         $this->update($item, array('id' => $entity->getId()));
     } else {
         $this->add($item);
     }
 }
Exemplo n.º 9
0
 public function generate(Entity $entity)
 {
     $className = "{$entity->getName()}Service";
     $destination = "src/impl/service/{$className}.php";
     if (FileUtil::fileExists($destination)) {
         return;
     }
     $content = "<?php\nclass {$className} extends {$className}Base {\n\n}\n?>";
     FileUtil::storeFileContents($destination, $content);
 }
 public function getOppositeEntity(Entity $entity)
 {
     if ($entity == $this->getOneEntity()) {
         return $this->getOtherEntity();
     } else {
         if ($entity == $this->getOtherEntity()) {
             return $this->getOneEntity();
         } else {
             throw new Exception("Entity '" . $entity->getName() . "' is related to neither '" . $this->getOneEntity()->getName() . "' nor '" . $this->getOtherEntity()->getName() . "'.");
         }
     }
 }
Exemplo n.º 11
0
 public function generate(Entity $entity)
 {
     $className = "{$entity->getName()}Model";
     $content = "<?php\nabstract class {$className} extends Model {\n\n";
     $content .= $this->gettersAndSetters($entity);
     $content .= $this->getOneToManyGetters($entity);
     $content .= $this->getOneToManyMappedGettersSetters($entity);
     $content .= $this->getManyToManyGetters($entity);
     $content .= "}\n?>";
     // Write file to class
     $destination = "src/service/model/{$className}.php";
     FileUtil::storeFileContents($destination, $content);
 }
 private function generateCustomServices(Entity $entity)
 {
     $result = "";
     $methods = ReflectionUtil::getSubclassMethods($entity->getName() . "Service");
     foreach ($methods as $method) {
         if (!$method->isPublic()) {
             continue;
         }
         $name = $method->name;
         $paramNames = array();
         foreach ($method->getParameters() as $param) {
             $paramNames[] = "\$" . $param->name;
         }
         $skeleton = $name . "(" . implode(", ", $paramNames) . ")";
         $result .= "\tpublic static function {$skeleton} {\n" . "\t\treturn self::getService()->{$skeleton};\n" . "\t}\n\n";
     }
     return $result;
 }
Exemplo n.º 13
0
 /**
  * Show users of an entity
  *
  * @param $entity Entity object
  **/
 static function showForEntity(Entity $entity)
 {
     global $DB;
     $ID = $entity->getField('id');
     if (!$entity->can($ID, READ)) {
         return false;
     }
     $canedit = $entity->canEdit($ID);
     $canshowuser = User::canView();
     $nb_per_line = 3;
     $rand = mt_rand();
     if ($canedit) {
         $headerspan = $nb_per_line * 2;
     } else {
         $headerspan = $nb_per_line;
     }
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form name='entityuser_form{$rand}' id='entityuser_form{$rand}' method='post' action='";
         echo Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'><th colspan='6'>" . __('Add an authorization to a user') . "</tr>";
         echo "<tr class='tab_bg_1'><td class='tab_bg_2 center'>" . __('User') . "&nbsp;";
         echo "<input type='hidden' name='entities_id' value='{$ID}'>";
         User::dropdown(array('right' => 'all'));
         echo "</td><td class='tab_bg_2 center'>" . self::getTypeName(1) . "</td><td>";
         Profile::dropdownUnder(array('value' => Profile::getDefault()));
         echo "</td><td class='tab_bg_2 center'>" . __('Recursive') . "</td><td>";
         Dropdown::showYesNo("is_recursive", 0);
         echo "</td><td class='tab_bg_2 center'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
     }
     $query = "SELECT DISTINCT `glpi_profiles`.`id`, `glpi_profiles`.`name`\n                FROM `glpi_profiles_users`\n                LEFT JOIN `glpi_profiles`\n                     ON (`glpi_profiles_users`.`profiles_id` = `glpi_profiles`.`id`)\n                LEFT JOIN `glpi_users` ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n                WHERE `glpi_profiles_users`.`entities_id` = '{$ID}'\n                     AND `glpi_users`.`is_deleted` = '0'";
     $result = $DB->query($query);
     $nb = $DB->numrows($result);
     echo "<div class='spaced'>";
     if ($canedit && $nb) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => array('purge' => _x('button', 'Delete permanently')));
         Html::showMassiveActions($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixehov'>";
     echo "<thead><tr>";
     echo "<th class='noHover' colspan='{$headerspan}'>";
     printf(__('%1$s (%2$s)'), _n('User', 'Users', Session::getPluralNumber()), __('D=Dynamic, R=Recursive'));
     echo "</th></tr></thead>";
     if ($nb) {
         Session::initNavigateListItems('User', sprintf(__('%1$s = %2$s'), Entity::getTypeName(1), $entity->getName()));
         while ($data = $DB->fetch_assoc($result)) {
             echo "<tbody><tr class='noHover'>";
             $reduce_header = 0;
             if ($canedit && $nb) {
                 echo "<th width='10'>";
                 echo Html::checkAllAsCheckbox("profile" . $data['id'] . "_{$rand}");
                 echo "</th>";
                 $reduce_header++;
             }
             echo "<th colspan='" . ($headerspan - $reduce_header) . "'>";
             printf(__('%1$s: %2$s'), __('Profile'), $data["name"]);
             echo "</th></tr></tbody>";
             echo "<tbody id='profile" . $data['id'] . "_{$rand}'>";
             $query = "SELECT `glpi_users`.*,\n                             `glpi_profiles_users`.`id` AS linkID,\n                             `glpi_profiles_users`.`is_recursive`,\n                             `glpi_profiles_users`.`is_dynamic`\n                      FROM `glpi_profiles_users`\n                      LEFT JOIN `glpi_users`\n                           ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n                      WHERE `glpi_profiles_users`.`entities_id` = '{$ID}'\n                            AND `glpi_users`.`is_deleted` = '0'\n                            AND `glpi_profiles_users`.`profiles_id` = '" . $data['id'] . "'\n                      ORDER BY `glpi_profiles_users`.`profiles_id`,\n                               `glpi_users`.`name`,\n                               `glpi_users`.`realname`,\n                               `glpi_users`.`firstname`";
             $result2 = $DB->query($query);
             if ($DB->numrows($result2) > 0) {
                 $i = 0;
                 while ($data2 = $DB->fetch_assoc($result2)) {
                     Session::addToNavigateListItems('User', $data2["id"]);
                     if ($i % $nb_per_line == 0) {
                         if ($i != 0) {
                             echo "</tr>";
                         }
                         echo "<tr class='tab_bg_1'>";
                     }
                     if ($canedit) {
                         echo "<td width='10'>";
                         Html::showMassiveActionCheckBox(__CLASS__, $data2["linkID"]);
                         echo "</td>";
                     }
                     $username = formatUserName($data2["id"], $data2["name"], $data2["realname"], $data2["firstname"], $canshowuser);
                     if ($data2["is_dynamic"] || $data2["is_recursive"]) {
                         $username = sprintf(__('%1$s %2$s'), $username, "<span class='b'>(");
                         if ($data2["is_dynamic"]) {
                             $username = sprintf(__('%1$s%2$s'), $username, __('D'));
                         }
                         if ($data2["is_dynamic"] && $data2["is_recursive"]) {
                             $username = sprintf(__('%1$s%2$s'), $username, ", ");
                         }
                         if ($data2["is_recursive"]) {
                             $username = sprintf(__('%1$s%2$s'), $username, __('R'));
                         }
                         $username = sprintf(__('%1$s%2$s'), $username, ")</span>");
                     }
                     echo "<td>" . $username . "</td>";
                     $i++;
                 }
                 while ($i % $nb_per_line != 0) {
                     echo "<td>&nbsp;</td>";
                     if ($canedit) {
                         echo "<td>&nbsp;</td>";
                     }
                     $i++;
                 }
                 echo "</tr>";
                 echo "</tbody>";
             } else {
                 echo "<tr colspan='{$headerspan}'>" . __('Item not found') . "</tr>";
             }
         }
     }
     echo "</table>";
     if ($canedit && $nb) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
 /**
  * Fetches a single property of the given object and returns its plain, unformatted value.
  * 
  * @param Entity $entity
  * @param type $id
  * @param type $propertyName
  * @param array $params
  * @return property value or NULL if not present
  */
 public function getObjectProperty(Entity $entity, $id, $propertyName, array $params)
 {
     $queryContext = new QueryContext($params, $entity);
     // Always include blobs
     $query = new QueryEntity($entity, $queryContext, Scope::parseValue(Scope::VALUE_P_ALL), $id);
     $query->setPropertyNames(array($propertyName));
     $mySQLi = $this->schema->getMySQLi();
     $queryString = $query->getQueryString();
     $queryResult = $mySQLi->query($queryString);
     if (!$queryResult) {
         throw new Exception("Error fetching property '{$propertyName}' of '" . $entity->getName() . "' - " . $mySQLi->error . "\n<!--\n{$queryString}\n-->");
     }
     $queryData = $queryResult->fetch_assoc();
     $output = NULL;
     if ($queryData) {
         $output = $queryData[$propertyName];
     }
     $queryResult->close();
     return $output;
 }
 public function getScope(Entity $entity, Scope $defaultScope)
 {
     if (array_key_exists($entity->getName(), $this->scopeMap)) {
         return $this->scopeMap[$entity->getName()];
     } else {
         return $defaultScope;
     }
 }
Exemplo n.º 16
0
 public function generateOrder($params)
 {
     global $DB;
     $ID = $params['id'];
     $template = $params['template'];
     $signature = $params['sign'];
     if ($template) {
         $config = array('PATH_TO_TMP' => GLPI_DOC_DIR . '/_tmp');
         $odf = new Odtphp\Odf(PLUGIN_ORDER_TEMPLATE_DIR . "{$template}", $config);
         $this->getFromDB($ID);
         if (file_exists(PLUGIN_ORDER_TEMPLATE_CUSTOM_DIR . "custom.php")) {
             include_once PLUGIN_ORDER_TEMPLATE_CUSTOM_DIR . "custom.php";
         }
         if (function_exists("plugin_order_getCustomFieldsForODT")) {
             plugin_order_getCustomFieldsForODT($ID, $template, $odf, $signature);
         } else {
             $PluginOrderOrder_Item = new PluginOrderOrder_Item();
             $PluginOrderReference_Supplier = new PluginOrderReference_Supplier();
             try {
                 $odf->setImage('logo', PLUGIN_ORDER_TEMPLATE_LOGO_DIR . '/logo.jpg');
             } catch (\Odtphp\Exceptions\OdfException $e) {
             }
             $values = array();
             $values['title_order'] = __("Order number", "order");
             $values['num_order'] = $this->fields["num_order"];
             $values['title_invoice_address'] = __("Invoice address", "order");
             $values['comment_order'] = $this->fields["comment"];
             $entity = new Entity();
             $entity->getFromDB($this->fields["entities_id"]);
             $town = '';
             if ($this->fields["entities_id"] != 0) {
                 $name_entity = $entity->fields["name"];
             } else {
                 $name_entity = __("Root entity");
             }
             $values['entity_name'] = $name_entity;
             if ($entity->getFromDB($this->fields["entities_id"])) {
                 $town = $entity->fields["town"];
                 $values['entity_address'] = $entity->fields["address"];
                 $values['entity_postcode'] = $entity->fields["postcode"];
                 $values['entity_town'] = $entity->fields["town"];
                 $values['entity_country'] = $entity->fields["country"];
             }
             $supplier = new Supplier();
             if ($supplier->getFromDB($this->fields["suppliers_id"])) {
                 $values['supplier_name'] = $supplier->fields["name"];
                 $values['supplier_address'] = $supplier->fields["address"];
                 $values['supplier_postcode'] = $supplier->fields["postcode"];
                 $values['supplier_town'] = $supplier->fields["town"];
                 $values['supplier_country'] = $supplier->fields["country"];
             }
             $location = new Location();
             if ($location->getFromDB($this->fields["locations_id"])) {
                 $values['title_delivery_address'] = __("Delivery address", "order");
                 $values['comment_delivery_address'] = $location->fields['comment'];
             }
             if ($town) {
                 $town = $town . ", ";
             }
             $order_date = Html::convDate($this->fields["order_date"]);
             $username = Html::clean(getUserName(Session::getLoginUserID()));
             $values['title_date_order'] = $town . __("The", "order") . " ";
             $values['date_order'] = $order_date;
             $values['title_sender'] = __("Issuer order", "order");
             $values['sender'] = $username;
             $values['title_budget'] = __("Budget");
             $budget = new Budget();
             if ($budget->getFromDB($this->fields["budgets_id"])) {
                 $values['budget'] = $budget->fields['name'];
             } else {
                 $values['budget'] = '';
             }
             $output = '';
             $contact = new Contact();
             if ($contact->getFromDB($this->fields["contacts_id"])) {
                 $output = formatUserName($contact->fields["id"], "", $contact->fields["name"], $contact->fields["firstname"]);
             }
             $values['title_recipient'] = __("Recipient", "order");
             $values['recipient'] = Html::clean($output);
             $values['nb'] = __("Quantity", "order");
             $values['title_item'] = __("Designation", "order");
             $values['title_ref'] = __("Reference");
             $values['HTPrice_item'] = __("Unit price", "order");
             $values['TVA_item'] = __("VAT", "order");
             $values['title_discount'] = __("Discount rate", "order");
             $values['HTPriceTotal_item'] = __("Sum tax free", "order");
             $values['ATIPriceTotal_item'] = __("Price ATI", "order");
             $listeArticles = array();
             $result = $PluginOrderOrder_Item->queryDetail($ID);
             $num = $DB->numrows($result);
             while ($data = $DB->fetch_array($result)) {
                 $quantity = $PluginOrderOrder_Item->getTotalQuantityByRefAndDiscount($ID, $data["id"], $data["price_taxfree"], $data["discount"]);
                 $listeArticles[] = array('quantity' => $quantity, 'ref' => utf8_decode($data["name"]), 'taxe' => Dropdown::getDropdownName(getTableForItemType("PluginOrderOrderTax"), $data["plugin_order_ordertaxes_id"]), 'refnumber' => $PluginOrderReference_Supplier->getReferenceCodeByReferenceAndSupplier($data["id"], $this->fields["suppliers_id"]), 'price_taxfree' => $data["price_taxfree"], 'discount' => $data["discount"], false, 0, 'price_discounted' => $data["price_discounted"] * $quantity, 'price_ati' => $data["price_ati"]);
             }
             $article = $odf->setSegment('articles');
             foreach ($listeArticles as $element) {
                 $article->nbA($element['quantity']);
                 $article->titleArticle($element['ref']);
                 $article->refArticle($element['refnumber']);
                 $article->TVAArticle($element['taxe']);
                 $article->HTPriceArticle(Html::clean(Html::formatNumber($element['price_taxfree'])));
                 if ($element['discount'] != 0) {
                     $article->discount(Html::clean(Html::formatNumber($element['discount'])) . " %");
                 } else {
                     $article->discount("");
                 }
                 $article->HTPriceTotalArticle(Html::clean(Html::formatNumber($element['price_discounted'])));
                 $total_TTC_Article = $element['price_discounted'] * (1 + $element['taxe'] / 100);
                 $article->ATIPriceTotalArticle(Html::clean(Html::formatNumber($total_TTC_Article)));
                 $article->merge();
             }
             $odf->mergeSegment($article);
             $prices = $PluginOrderOrder_Item->getAllPrices($ID);
             // total price (with postage)
             $postagewithTVA = $PluginOrderOrder_Item->getPricesATI($this->fields["port_price"], Dropdown::getDropdownName("glpi_plugin_order_ordertaxes", $this->fields["plugin_order_ordertaxes_id"]));
             $total_HT = $prices["priceHT"] + $this->fields["port_price"];
             $total_TVA = $prices["priceTVA"] + $postagewithTVA - $this->fields["port_price"];
             $total_TTC = $prices["priceTTC"] + $postagewithTVA;
             if ($signature) {
                 try {
                     $odf->setImage('sign', PLUGIN_ORDER_SIGNATURE_DIR . $signature);
                 } catch (\Odtphp\Exceptions\OdfException $e) {
                 }
             } else {
                 try {
                     $odf->setImage('sign', '../pics/nothing.gif');
                 } catch (\Odtphp\Exceptions\OdfException $e) {
                 }
             }
             $name = Dropdown::getDropdownName("glpi_plugin_order_orderpayments", $this->fields["plugin_order_orderpayments_id"]);
             $values['title_totalht'] = __("Price tax free", "order");
             $values['totalht'] = Html::clean(Html::formatNumber($prices['priceHT']));
             $values['title_port'] = __("Price tax free with postage", "order");
             $values['totalht_port_price'] = Html::clean(Html::formatNumber($total_HT));
             $values['title_price_port'] = __("Postage", "order");
             $values['price_port_tva'] = " (" . Html::clean(Dropdown::getDropdownName("glpi_plugin_order_ordertaxes", $this->fields["plugin_order_ordertaxes_id"])) . "%)";
             $values['port_price'] = Html::clean(Html::formatNumber($postagewithTVA));
             $values['title_tva'] = __("VAT", "order");
             $values['totaltva'] = Html::clean(Html::formatNumber($total_TVA));
             $values['title_totalttc'] = __("Price ATI", "order");
             $values['totalttc'] = Html::clean(Html::formatNumber($total_TTC));
             $values['title_money'] = __("€", "order");
             $values['title_sign'] = __("Signature of issuing order", "order");
             $values['title_conditions'] = __("Payment conditions", "order");
             $values['payment_conditions'] = $name;
             // Set variables in odt template
             foreach ($values as $field => $val) {
                 try {
                     $odf->setVars($field, $val, true, 'UTF-8');
                 } catch (\Odtphp\Exceptions\OdfException $e) {
                 }
             }
         }
         $message = "_";
         if (Session::isMultiEntitiesMode()) {
             $entity = new Entity();
             $entity->getFromDB($this->fields['entities_id']);
             $message .= $entity->getName();
         }
         $message .= "_" . $this->fields['num_order'] . "_";
         $message .= Html::convDateTime($_SESSION['glpi_currenttime']);
         $message = str_replace(" ", "_", $message);
         $outputfile = str_replace(".odt", $message . ".odt", $template);
         // We export the file
         $odf->exportAsAttachedFile($outputfile);
     }
 }
Exemplo n.º 17
0
 /**
  * Implement selectors like m, name, etc...
  */
 public static function checkSelectors(array $args, CommandSender $sender, Entity $item)
 {
     foreach ($args as $name => $value) {
         switch ($name) {
             case "m":
                 $mode = intval($value);
                 if ($mode === -1) {
                     break;
                 }
                 // what is the point of adding this (in PC) when they can just safely leave this out?
                 if ($item instanceof Player && $mode !== $item->getGamemode()) {
                     return false;
                 }
                 break;
             case "name":
                 if ($value[0] === "!") {
                     if (substr($value, 1) === strtolower($item->getName())) {
                         return false;
                     }
                 } else {
                     if ($value !== strtolower($item->getName())) {
                         return false;
                     }
                 }
                 break;
             case "w":
                 // Non standard
                 if ($value[0] === "!") {
                     if (substr($value, 1) === strtolower($item->getLevel()->getName())) {
                         return false;
                     }
                 } else {
                     if ($value !== strtolower($item->getLevel()->getName())) {
                         return false;
                     }
                 }
                 break;
             case "type":
                 if ($item instanceof Player) {
                     $type = "player";
                 } else {
                     $type = strtolower($item->getSaveId());
                 }
                 if ($value[0] === "!") {
                     if (substr($value, 1) === $type) {
                         return false;
                     }
                 } else {
                     if ($value !== $type) {
                         return false;
                     }
                 }
                 break;
                 // x,y,z
                 // r,rm
                 // c
                 // dx,dy,dz
                 // rx,rxm
                 // ry,rym
         }
     }
     return true;
 }
 function updateGenericServicesCatalogs($action = 'update')
 {
     global $DB;
     $entity = new Entity();
     $pmServicescatalog = new PluginMonitoringServicescatalog();
     $pmBusinessrulegroup = new PluginMonitoringBusinessrulegroup();
     $pmBusinessrulecomponent = new PluginMonitoringBusinessrule_component();
     $existingSCs = array();
     // Find existing instances of generic services catalog ...
     $a_SCs = $this->find("`name` LIKE '" . $this->getName() . "%'");
     foreach ($a_SCs as $a_SC) {
         // Toolbox::logInFile("pm", "SC : ".$a_SC['id'].", name : ".$a_SC['name'].", generic : ".$a_SC['is_generic']."\n");
         if ($a_SC['name'] == $this->getField('name')) {
             continue;
         }
         $existingSCs[$a_SC['name']] = $a_SC;
     }
     if ($action == 'delete') {
         foreach ($existingSCs as $name => $a_SC) {
             $pmServicescatalog->getFromDB($a_SC['id']);
             $pmServicescatalog->delete($pmServicescatalog->fields);
             // Toolbox::logInFile("pm", "Deleted : ".$a_SC['name']."\n");
             $pmBusinessrulecomponent = new PluginMonitoringBusinessrule_component();
             $pmBusinessrule = new PluginMonitoringBusinessrule();
             // Get business rules groups ...
             $a_BRgroups = $pmBusinessrulegroup->find("`plugin_monitoring_servicescatalogs_id`='" . $a_SC['id'] . "'");
             // Delete business groups components
             foreach ($a_BRgroups as $a_BRgroup) {
                 // Toolbox::logInFile("pm", "a_BRgroup : ".$a_BRgroup['id']."\n");
                 $a_brcomponents = $pmBusinessrulecomponent->find("`plugin_monitoring_businessrulegroups_id`='" . $a_BRgroup['id'] . "'");
                 foreach ($a_brcomponents as $a_brcomponent) {
                     // Toolbox::logInFile("pm", "a_brcomponent : ".$a_brcomponent['id']."\n");
                     $pmBusinessrulecomponent->getFromDB($a_brcomponent['id']);
                     $pmBusinessrulecomponent->delete($pmBusinessrulecomponent->fields);
                 }
             }
             // Delete business groups rules
             foreach ($a_BRgroups as $a_BRgroup) {
                 $a_brs = $pmBusinessrule->find("`plugin_monitoring_businessrulegroups_id`='" . $a_BRgroup['id'] . "'");
                 foreach ($a_brs as $a_br) {
                     // Toolbox::logInFile("pm", "a_br : ".$a_br['id']."\n");
                     $pmBusinessrulecomponent->getFromDB($a_brcomponent['id']);
                     $pmBusinessrulecomponent->delete($pmBusinessrulecomponent->fields);
                 }
             }
         }
         return;
     } else {
         foreach ($existingSCs as $name => $a_SC) {
             $pmServicescatalog->getFromDB($a_SC['id']);
             $pmBusinessrulegroup = new PluginMonitoringBusinessrulegroup();
             $pmBusinessrulecomponent = new PluginMonitoringBusinessrule_component();
             $pmBusinessrule = new PluginMonitoringBusinessrule();
             // Get business rules groups ...
             $a_BRgroups = $pmBusinessrulegroup->find("`plugin_monitoring_servicescatalogs_id`='" . $a_SC['id'] . "'");
             // Delete business groups components
             foreach ($a_BRgroups as $a_BRgroup) {
                 // Toolbox::logInFile("pm", "a_BRgroup : ".$a_BRgroup['id']."\n");
                 $a_brcomponents = $pmBusinessrulecomponent->find("`plugin_monitoring_businessrulegroups_id`='" . $a_BRgroup['id'] . "'");
                 foreach ($a_brcomponents as $a_brcomponent) {
                     // Toolbox::logInFile("pm", "a_brcomponent : ".$a_brcomponent['id']."\n");
                     $pmBusinessrulecomponent->getFromDB($a_brcomponent['id']);
                     $pmBusinessrulecomponent->delete($pmBusinessrulecomponent->fields);
                 }
             }
             // Delete business groups rules
             foreach ($a_BRgroups as $a_BRgroup) {
                 $a_brs = $pmBusinessrule->find("`plugin_monitoring_businessrulegroups_id`='" . $a_BRgroup['id'] . "'");
                 foreach ($a_brs as $a_br) {
                     // Toolbox::logInFile("pm", "a_br : ".$a_br['id']."\n");
                     $pmBusinessrulecomponent->getFromDB($a_brcomponent['id']);
                     $pmBusinessrulecomponent->delete($pmBusinessrulecomponent->fields);
                 }
             }
         }
     }
     // Find entities concerned ...
     $a_entitiesServices = $this->getGenericServicesEntities();
     foreach ($a_entitiesServices as $idEntity => $a_entityServices) {
         // New entity ... so it must exist a derivated SC !
         $entity->getFromDB($idEntity);
         // Toolbox::logInFile("pm", "Found entity : ".$idEntity." / ".$entity->getName()."\n");
         $scName = $this->getName() . " - " . $entity->getName();
         if (isset($existingSCs[$scName])) {
             // Update SC
             $pmServicescatalog->getFromDB($existingSCs[$scName]['id']);
             $pmServicescatalog->fields = $this->fields;
             unset($pmServicescatalog->fields['id']);
             $pmServicescatalog->fields['id'] = $existingSCs[$scName]['id'];
             $pmServicescatalog->fields['entities_id'] = $idEntity;
             $pmServicescatalog->fields['is_generic'] = 0;
             $pmServicescatalog->fields['name'] = $DB->escape($scName);
             $pmServicescatalog->update($pmServicescatalog->fields);
             /*            // Finish updating if needed ...
                         $a_BRgroups = $pmBusinessrulegroup->find("`plugin_monitoring_servicescatalogs_id`='".$this->fields['id']."'");
                         foreach ($a_BRgroups as $a_BRgroup) {
                            $pmBusinessrulegroup = $pmBusinessrulegroup->find("`plugin_monitoring_servicescatalogs_id`='".$a_SC['id']."' AND `name`='".$a_BRgroup['name']."'");
                            $pmBusinessrulegroup->fields = $a_BRgroup->fields;
                            unset($pmBusinessrulegroup->fields['id']);
                            $pmBusinessrulegroup->fields['plugin_monitoring_servicescatalogs_id'] = $pmServicescatalog->fields['id'];
                            $pmBusinessrulegroup->update($pmBusinessrulegroup->fields);
                         }
             */
             // Toolbox::logInFile("pm", "Updated : ".$scName."\n");
         } else {
             // Add SC
             $pmServicescatalog = new PluginMonitoringServicescatalog();
             $pmServicescatalog->getEmpty();
             $pmServicescatalog->fields = $this->fields;
             unset($pmServicescatalog->fields['id']);
             $pmServicescatalog->fields['entities_id'] = $idEntity;
             $pmServicescatalog->fields['is_recursive'] = 0;
             $pmServicescatalog->fields['is_generic'] = 0;
             $pmServicescatalog->fields['name'] = $DB->escape($scName);
             $pmServicescatalog->fields['plugin_monitoring_servicescatalogs_id'] = $this->fields['id'];
             $pmServicescatalog->add($pmServicescatalog->fields);
             /*
                         // Finish updating if needed ...
                         $a_BRgroups = $pmBusinessrulegroup->find("`plugin_monitoring_servicescatalogs_id`='".$this->fields['id']."'");
                         foreach ($a_BRgroups as $a_BRgroup) {
                            $ref = new PluginMonitoringBusinessrulegroup();
                            $ref->getFromDB($a_BRgroup['id']);
                            $pmBusinessrulegroup = new PluginMonitoringBusinessrulegroup();
                            $pmBusinessrulegroup->getEmpty();
                            $pmBusinessrulegroup->fields = $ref->fields;
                            unset($pmBusinessrulegroup->fields['id']);
                            $pmBusinessrulegroup->fields['plugin_monitoring_servicescatalogs_id'] = $pmServicescatalog->fields['id'];
                            $pmBusinessrulegroup->add($pmBusinessrulegroup->fields);
             
                            $a_brcomponents = $pmBusinessrulecomponent->find("`plugin_monitoring_businessrulegroups_id`='".$a_BRgroup['id']."'");
                            foreach ($a_brcomponents as $a_brcomponent) {
                               $ref = new PluginMonitoringBusinessrule_component();
                               $ref->getFromDB($a_brcomponent['id']);
                               $pmBusinessrule_component = new PluginMonitoringBusinessrule_component();
                               $pmBusinessrule_component->getEmpty();
                               $pmBusinessrule_component->fields = $ref->fields;
                               unset($pmBusinessrule_component->fields['id']);
                               $pmBusinessrule_component->fields['plugin_monitoring_businessrulegroups_id'] = $pmBusinessrulegroup->fields['id'];
                               $pmBusinessrule_component->add($pmBusinessrule_component->fields);
                            }
                         }
             */
             // Toolbox::logInFile("pm", "Added : ".$scName."\n");
         }
     }
 }
 private function generateRemove(Entity $entity)
 {
     $pk = $entity->getPrimaryKey()->getName();
     return "\tpublic function remove(\${$pk}) {\n" . "\t\t\$this->findByPrimaryKey(\${$pk});\n" . "\t\t\$this->db->updateQuery(\"DELETE FROM \".self::TABLE.\" WHERE {$pk}='\".addslashes(\${$pk}).\"'\");\n" . "\t\tparent::\$dbCache->resetEntity('{$entity->getName()}');\n" . "\t\tparent::\$dbCache->resetSingle(\"{$entity->getName()}\", \${$pk});\n" . "\t}\n\n";
 }
 function showContacts($itemtype, $items_id)
 {
     global $DB, $LANG, $CFG_GLPI;
     $this->addContact($itemtype, $items_id);
     $group = new Group();
     $user = new User();
     $rand = mt_rand();
     echo "<form method='post' name='contact_item_form{$rand}' id='contact_item_form{$rand}' action=\"" . $CFG_GLPI["root_doc"] . "/plugins/monitoring/front/contact_item.form.php\">";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     echo "<th>";
     echo $LANG['plugin_monitoring']['contact'][20];
     echo "</th>";
     echo "</tr>";
     echo "</table>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     echo "<th width='10'>&nbsp;</th>";
     echo "<th>" . $LANG['common'][35] . " - " . $LANG['common'][16] . "</th>";
     echo "<th colspan='3'></th>";
     echo "</tr>";
     $used = array();
     // Display groups first
     $query = "SELECT * FROM `" . $this->getTable() . "`\n         WHERE `items_id`='" . $items_id . "'\n            AND `itemtype`='" . $itemtype . "'\n            AND `groups_id` > 0";
     $result = $DB->query($query);
     while ($data = $DB->fetch_array($result)) {
         $group->getFromDB($data['groups_id']);
         echo "<tr>";
         echo "<td>";
         echo "<input type='checkbox' name='item[" . $data["id"] . "]' value='1'>";
         echo "</td>";
         echo "<td class='center'>";
         echo $group->getLink(1);
         echo "</td>";
         echo "<td colspan='3'>";
         echo "</td>";
         echo "</tr>";
     }
     echo "<tr>";
     echo "<th width='10'>&nbsp;</th>";
     echo "<th>" . $LANG['common'][34] . " - " . $LANG['common'][16] . "</th>";
     echo "<th>" . $LANG['entity'][0] . "</th>";
     echo "<th>" . $LANG['setup'][14] . "</th>";
     echo "<th>" . $LANG['help'][35] . "</th>";
     echo "</tr>";
     $entity = new Entity();
     $used = array();
     // Display Users
     $query = "SELECT * FROM `" . $this->getTable() . "`\n         WHERE `items_id`='" . $items_id . "'\n            AND `itemtype`='" . $itemtype . "'\n            AND `users_id` > 0";
     $result = $DB->query($query);
     while ($data = $DB->fetch_array($result)) {
         $user->getFromDB($data['users_id']);
         echo "<tr>";
         echo "<td>";
         echo "<input type='checkbox' name='item[" . $data["id"] . "]' value='1'>";
         echo "</td>";
         echo "<td class='center'>";
         echo $user->getLink(1);
         echo "</td>";
         $entity->getFromDB($data['entities_id']);
         echo "<td class='center'>";
         echo $entity->getName() . " <strong>(R)</strong>";
         echo "</td>";
         echo "<td class='center'>";
         echo $user->fields['email'];
         echo "</td>";
         echo "<td class='center'>";
         echo $user->fields['phone'];
         echo "</td>";
         echo "</tr>";
     }
     openArrowMassive("contact_item_form{$rand}", true);
     closeArrowMassive('deleteitem', $LANG['buttons'][6]);
     echo "</table>";
 }
 private function insertOrUpdate(Schema $schema, Entity $entity, $id, array $propertyValues, Audit $audit)
 {
     $mustInsert = $id == NULL;
     $mySQLi = $schema->getMySQLi();
     $entityName = $entity->getName();
     $stateIdColumnName = $entity->getStateIdColumnName();
     // Create a state object if the given entity supports states.
     $stateId = NULL;
     if ($stateIdColumnName != NULL) {
         $queryString = "INSERT INTO " . DbConstants::TABLE_STATE . " (id_created) VALUES(" . $audit->getId() . ")";
         $queryResult = $mySQLi->query($queryString);
         if (!$queryResult) {
             throw new Exception("Error creating state for new object of '{$entityName}'" . " - {$mySQLi->error}\n<!--\n{$queryString}\n-->");
         }
         $stateId = $mySQLi->insert_id;
         // Statefull entities must always be inserted.
         $mustInsert = TRUE;
         // If no id was given...
         if ($id == NULL) {
             // ...then use the (auto-incremented) stateId as id.
             $id = $stateId;
         }
     }
     // Prepare the input parameters for the insert-query.
     $columnNames = array();
     $types = '';
     $values = array();
     // Add the object-id if applicable.
     if ($entity->isObjectEntity()) {
         // Ensure that primary key properties are not specified explicitly.
         foreach ($propertyValues as $propertyName => $value) {
             if ($entity->getProperty($propertyName)->getKeyIndicator() == Property::KEY_PRIMARY) {
                 throw new Exception("Property '{$propertyName}' of '{$entityName}' is a primary key and cannot be changed.");
             }
         }
         // Add the object-id.
         $columnNames[] = $entity->getObjectIdColumnName();
         $types .= 'i';
         $values[] = $id;
     }
     // Add the state-info if applicable.
     if ($stateIdColumnName != NULL) {
         $columnNames[] = $stateIdColumnName;
         $types .= 'i';
         $values[] = $stateId;
     }
     $blobs = array();
     foreach ($propertyValues as $columnName => $value) {
         $property = $entity->getProperty($columnName);
         $columnNames[] = $property->getName();
         $typeIndicator = $property->getTypeIndicator();
         switch ($typeIndicator) {
             case Property::TYPE_TEXT:
             case Property::TYPE_TIMESTAMP:
                 $types .= 's';
                 break;
             case Property::TYPE_BINARY:
                 $types .= 'b';
                 $blobs[count($values)] = $value;
                 $value = NULL;
                 break;
             case Property::TYPE_DOUBLE:
                 $types .= 'd';
                 break;
             case Property::TYPE_INTEGER:
                 $types .= 'i';
                 break;
             default:
                 throw new Exception("Unknown type indicator '{$typeIndicator}'.");
         }
         $values[] = $value;
     }
     // Compose the query string...
     $queryString = NULL;
     if ($mustInsert) {
         $queryString = "INSERT INTO {$entityName} (" . implode(',', $columnNames) . ") VALUES(";
         for ($i = 0; $i < count($columnNames); $i++) {
             $queryString .= '?,';
         }
         // Remove the last comma.
         $queryString = substr($queryString, 0, strlen($queryString) - 1);
         $queryString .= ")";
     } else {
         $queryString = "UPDATE {$entityName} SET ";
         foreach ($columnNames as $columnName) {
             $queryString .= "{$columnName}=?,";
         }
         // Remove the last comma.
         $queryString = substr($queryString, 0, strlen($queryString) - 1);
         if ($entity->isObjectEntity()) {
             $queryString .= " WHERE " . $entity->getObjectIdColumnName() . " = " . $id;
         }
     }
     // ...and prepare the query.
     $stmt = $mySQLi->prepare($queryString);
     if ($stmt === FALSE) {
         throw new Exception("Error creating prepared statement to insert '{$entityName}' - " . "{$mySQLi->error}\n<!--\n{$queryString}\n-->");
     }
     // Don't throw exceptions before closing the prepared statement.
     $exception = NULL;
     // Fill-in the parameters.
     $bindParams = array(&$types);
     for ($i = 0; $i < count($values); $i++) {
         $bindParams[] =& $values[$i];
     }
     call_user_func_array(array($stmt, "bind_param"), $bindParams);
     foreach ($blobs as $index => $value) {
         $stmt->send_long_data($index, base64_decode($value));
     }
     // Execute the query.
     $queryResult = $stmt->execute();
     if (!$queryResult) {
         $formattedPropertyValues = array();
         foreach ($propertyValues as $columnName => $value) {
             $formattedPropertyValues[] = "{$columnName}={$value}";
         }
         $exception = new Exception("Error " . ($mustInsert ? 'inserting' : 'updating') . " object '{$entityName}' - {$mySQLi->error}\n<!-- " . implode(', ', $formattedPropertyValues) . " -->");
     } else {
         if ($id == NULL) {
             $id = $mySQLi->insert_id;
         }
     }
     // Close the prepared statement before throwing any exception.
     $stmt->close();
     if ($exception != NULL) {
         throw $exception;
     }
     return $id;
 }
Exemplo n.º 22
0
   function showContacts($itemtype, $items_id) {
      global $DB,$CFG_GLPI;

      $this->addContact($itemtype, $items_id);

      $group = new Group();
      $user  = new User();

      $rand = mt_rand();

      echo "<form method='post' name='contact_item_form$rand' id='contact_item_form$rand' action=\"".
                $CFG_GLPI["root_doc"]."/plugins/monitoring/front/contact_item.form.php\">";

      echo "<table class='tab_cadre_fixe'>";

      echo "<tr>";
      echo "<th>";
      echo __('Contacts', 'monitoring');
      echo "</th>";
      echo "</tr>";

      echo "</table>";

      echo "<table class='tab_cadre_fixe'>";

      echo "<tr>";
      echo "<th width='10'>&nbsp;</th>";
      echo "<th>".__('Group')." - ".__('Name')."</th>";
      echo "<th colspan='3'></th>";
      echo "</tr>";

      $used = array();
      // Display groups first
      $query = "SELECT * FROM `".$this->getTable()."`
         WHERE `items_id`='".$items_id."'
            AND `itemtype`='".$itemtype."'
            AND `groups_id` > 0";
      $result = $DB->query($query);
      while ($data=$DB->fetch_array($result)) {
         $group->getFromDB($data['groups_id']);

         echo "<tr>";
         echo "<td>";
         echo "<input type='checkbox' name='item[".$data["id"]."]' value='1'>";
         echo "</td>";
         echo "<td class='center'>";
         echo $group->getLink(1);
         echo "</td>";
         echo "<td colspan='3'>";

         echo "</td>";

         echo "</tr>";
      }

      echo "<tr>";
      echo "<th width='10'>&nbsp;</th>";
      echo "<th>".__('User')." - ".__('Name')."</th>";
      echo "<th>".__('Entity')."</th>";
      echo "<th>".__('Email address')."</th>";
      echo "<th>".__('Phone')."</th>";
      echo "</tr>";

      $entity = new Entity();
      $used = array();
      // Display Users
      $query = "SELECT * FROM `".$this->getTable()."`
         WHERE `items_id`='".$items_id."'
            AND `itemtype`='".$itemtype."'
            AND `users_id` > 0";
      $result = $DB->query($query);
      while ($data=$DB->fetch_array($result)) {
         $user->getFromDB($data['users_id']);

         echo "<tr>";
         echo "<td>";
         echo "<input type='checkbox' name='item[".$data["id"]."]' value='1'>";
         echo "</td>";
         echo "<td class='center'>";
         echo $user->getLink(1);
         echo "</td>";
         $entity->getFromDB($data['entities_id']);
         echo "<td class='center'>";
         echo $entity->getName()." <strong>(R)</strong>";
         echo "</td>";
         echo "<td class='center'>";
         $a_emails = UserEmail::getAllForUser($data['users_id']);
         $first = 0;
         foreach ($a_emails as $email) {
            if ($first == 0) {
               echo $email;
            }
            $first++;
         }
         echo "</td>";
         echo "<td class='center'>";
         echo $user->fields['phone'];
         echo "</td>";

         echo "</tr>";
      }

      Html::openArrowMassives("contact_item_form$rand", true);
      Html::closeArrowMassives(array('deleteitem' => _sx('button', 'Delete permanently')));
      Html::closeForm();
      echo "</table>";

   }
Exemplo n.º 23
0
 public function getName()
 {
     return $this->parent ? parent::getName() : null;
 }
 private function generateBaseServices(Entity $entity)
 {
     $name = $entity->getName();
     return "\tpublic function create{$name}(\$pk=0) {\n" . "\t\treturn \$this->getPersistence()->create(\$pk);\n" . "\t}\n\n" . "\tpublic function get{$name}(\$pk) {\n" . "\t\treturn \$this->getPersistence()->findByPrimaryKey(\$pk);\n" . "\t}\n\n" . "\tpublic function update{$name}({$name} \$object) {\n" . "\t\treturn \$this->getPersistence()->update(\$object);\n" . "\t}\n\n" . "\tpublic function delete{$name}(\$pk) {\n" . "\t\t\$this->getPersistence()->remove(\$pk);\n" . "\t}\n\n" . "\tpublic function get{$name}s(\$from=0, \$limit=9999999999) {\n" . "\t\treturn \$this->getPersistence()->findAll(\$from, \$limit);\n" . "\t}\n\n" . "\tpublic function count{$name}s() {\n" . "\t\treturn \$this->getPersistence()->count();\n" . "\t}\n\n" . "\tprivate function getPersistence() {\n" . "\t\treturn Singleton::create(\"{$name}Persistence\");\n" . "\t}\n\n";
 }
Exemplo n.º 25
0
 private function importEntities()
 {
     $file = Singleton::create("DOMXmlFactory")->fromFile("config/service.xml");
     $root = $file->getRootElement();
     $entityEls = $root->getChildren("entity");
     $this->entities = array();
     foreach ($entityEls as $entityEl) {
         $name = $entityEl->getAttribute("name");
         $table = $entityEl->getAttribute("table");
         $entity = new Entity($name, $table);
         // Insert properties
         foreach ($entityEl->getChildren("column") as $property) {
             $propertyName = $property->getAttribute("name");
             $type = $property->getAttribute("type");
             $size = $property->getAttribute("size");
             $entityName = $property->getAttribute("entity");
             $mappingTable = $property->getAttribute("mapping-table");
             $primary = $property->getAttribute("primary") == "true";
             $autoIncrement = $property->getAttribute("auto-increment") == "true";
             if ($primary) {
                 $entity->addPKProperty(new PrimaryKeyProperty($propertyName, $type, $size, $autoIncrement));
             } elseif ($type == "Object") {
                 $entity->addOneToOneProperty(new OneToOneProperty($propertyName, $entityName));
             } elseif ($type == "Collection" && !$mappingTable) {
                 $entity->addOneManyProperty(new OneToManyProperty($propertyName, $entityName));
             } elseif ($mappingTable) {
                 $entity->addManyToManyProperty(new ManyToManyProperty($propertyName, $entityName, $mappingTable));
             } else {
                 $entity->addProperty(new Property($propertyName, $type, $size));
             }
         }
         // Insert finders
         foreach ($entityEl->getChildren("finder") as $finderEl) {
             $finderName = $finderEl->getAttribute("name");
             $unique = $finderEl->getAttribute("unique");
             $cacheable = $finderEl->getAttribute("cacheable");
             $unique = $unique === "true";
             $cacheable = !($cacheable === "false");
             $finder = new Finder($entity, $finderName, $unique, $cacheable);
             foreach ($finderEl->getChildren("finder-column") as $fcEl) {
                 $name = $fcEl->getAttribute("name");
                 $comparator = $fcEl->getAttribute("comparator");
                 if (empty($comparator)) {
                     $comparator = "=";
                 }
                 $finder->addFinderColumn(new FinderColumn($name, $comparator));
             }
             $orderEls = $finderEl->getChildren("order");
             if ($orderEls->size() > 1) {
                 throw new ServiceBuilderException("Multiple order elements defined for finder {$finderName}");
             }
             if ($orderEls->size() == 1) {
                 $orderEl = $orderEls->getFirst();
                 foreach ($orderEl->getChildren("order-column") as $ocEl) {
                     $ocName = $ocEl->getAttribute("name");
                     $ocOrderBy = $ocEl->getAttribute("order-by");
                     $finder->addOrderCol(new OrderColumn($ocName, $ocOrderBy));
                 }
             }
             $entity->addFinder($finder);
         }
         // Insert order
         $orderEls = $entityEl->getChildren("order");
         if ($orderEls->size() > 1) {
             throw new ServiceBuilderException("Multiple order elements defined for entity {$entity->getName()}");
         }
         if ($orderEls->size() == 1) {
             $orderEl = $orderEls->get(0);
             foreach ($orderEl->getChildren("order-column") as $ocEl) {
                 $ocName = $ocEl->getAttribute("name");
                 $ocOrderBy = $ocEl->getAttribute("order-by");
                 $entity->addOrderCol(new OrderColumn($ocName, $ocOrderBy));
             }
         }
         $entity->validate();
         // Add entity
         $this->entities[$entity->getName()] = $entity;
     }
 }