Contract::getSuppliersNames PHP Method

getSuppliersNames() public method

Get the entreprise name for the contract
public getSuppliersNames ( ) : string
return string of names (HTML)
    function getSuppliersNames()
    {
        global $DB;
        $query = "SELECT `glpi_suppliers`.`id`\n                FROM `glpi_contracts_suppliers`,\n                     `glpi_suppliers`\n                WHERE `glpi_contracts_suppliers`.`suppliers_id` = `glpi_suppliers`.`id`\n                      AND `glpi_contracts_suppliers`.`contracts_id` = '" . $this->fields['id'] . "'";
        $result = $DB->query($query);
        $out = "";
        while ($data = $DB->fetch_assoc($result)) {
            $out .= Dropdown::getDropdownName("glpi_suppliers", $data['id']) . "<br>";
        }
        return $out;
    }

Usage Example

 static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item)
 {
     global $DB, $CFG_GLPIG;
     if (!Session::haveRight("contract", "r")) {
         return false;
     }
     $type = $item->getType();
     $ID = $item->getField('id');
     $con = new Contract();
     $query = "SELECT *\n                FROM `glpi_contracts_items`\n                WHERE `glpi_contracts_items`.`items_id` = '" . $ID . "'\n                      AND `glpi_contracts_items`.`itemtype` = '" . $type . "'";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = $j = 0;
     $pdf->setColumnsSize(100);
     if ($number > 0) {
         $pdf->displayTitle('<b>' . _N('Associated contract', 'Associated contracts', 2) . '</b>');
         $pdf->setColumnsSize(19, 19, 19, 16, 11, 16);
         $pdf->displayTitle(__('Name'), _x('phone', 'Number'), __('Contract type'), __('Supplier'), __('Start date'), __('Initial contract period'));
         $i++;
         while ($j < $number) {
             $cID = $DB->result($result, $j, "contracts_id");
             $assocID = $DB->result($result, $j, "id");
             if ($con->getFromDB($cID)) {
                 $pdf->displayLine(empty($con->fields["name"]) ? "(" . $con->fields["id"] . ")" : $con->fields["name"], $con->fields["num"], Html::clean(Dropdown::getDropdownName("glpi_contracttypes", $con->fields["contracttypes_id"])), str_replace("<br>", " ", $con->getSuppliersNames()), Html::convDate($con->fields["begin_date"]), sprintf(_n('%d month', '%d months', $con->fields["duration"]), $con->fields["duration"]));
             }
             $j++;
         }
     } else {
         $pdf->displayTitle("<b>" . __('No item found') . "</b>");
     }
     $pdf->displaySpace();
 }
All Usage Examples Of Contract::getSuppliersNames