SoftwareLicense::countForSoftware PHP Méthode

countForSoftware() static public méthode

Get number of licensesof a software
static public countForSoftware ( $softwares_id ) : number
$softwares_id software ID
Résultat number of licenses
    static function countForSoftware($softwares_id)
    {
        global $DB;
        $query = "SELECT `id`\n                FROM `glpi_softwarelicenses`\n                WHERE `softwares_id` = '{$softwares_id}'\n                      AND `number` = '-1' " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true);
        $result = $DB->query($query);
        if ($DB->numrows($result)) {
            // At least 1 unlimited license, means unlimited
            return -1;
        }
        $query = "SELECT SUM(`number`)\n                FROM `glpi_softwarelicenses`\n                WHERE `softwares_id` = '{$softwares_id}'\n                      AND `number` > '0' " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true);
        $result = $DB->query($query);
        $nb = $DB->result($result, 0, 0);
        return $nb ? $nb : 0;
    }

Usage Example

 /**
  * Show softwares candidates to be merged with the current
  *
  * @return nothing
  **/
 function showMergeCandidates()
 {
     global $DB, $CFG_GLPI;
     $ID = $this->getField('id');
     $this->check($ID, "w");
     $rand = mt_rand();
     echo "<div class='center'>";
     $sql = "SELECT `glpi_softwares`.`id`,\n                     `glpi_softwares`.`name`,\n                     `glpi_entities`.`completename` AS entity\n              FROM `glpi_softwares`\n              LEFT JOIN `glpi_entities` ON (`glpi_softwares`.`entities_id` = `glpi_entities`.`id`)\n              WHERE (`glpi_softwares`.`id` != '{$ID}'\n                     AND `glpi_softwares`.`name` = '" . addslashes($this->fields["name"]) . "'\n                     AND `glpi_softwares`.`is_deleted` = '0'\n                     AND `glpi_softwares`.`is_template` = '0' " . getEntitiesRestrictRequest('AND', 'glpi_softwares', 'entities_id', getSonsOf("glpi_entities", $this->fields["entities_id"]), false) . ")\n              ORDER BY `entity`";
     $req = $DB->request($sql);
     if ($nb = $req->numrows()) {
         $link = Toolbox::getItemTypeFormURL('Software');
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $paramsma = array('num_displayed' => $nb, 'specific_actions' => array('mergesoftware' => __('Merge')));
         Html::showMassiveActions(__CLASS__, $paramsma);
         echo "<table class='tab_cadre_fixehov'>";
         echo "<tr><th width='10'>";
         echo Html::checkAllAsCheckbox('mass' . __CLASS__ . $rand);
         echo "</th>";
         echo "<th>" . __('Name') . "</th>";
         echo "<th>" . __('Entity') . "</th>";
         echo "<th>" . _n('Installation', 'Installations', 2) . "</th>";
         echo "<th>" . _n('License', 'Licenses', 2) . "</th></tr>";
         foreach ($req as $data) {
             echo "<tr class='tab_bg_2'>";
             echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>";
             echo "<td><a href='" . $link . "?id=" . $data["id"] . "'>" . $data["name"] . "</a></td>";
             echo "<td>" . $data["entity"] . "</td>";
             echo "<td class='right'>" . Computer_SoftwareVersion::countForSoftware($data["id"]) . "</td>";
             echo "<td class='right'>" . SoftwareLicense::countForSoftware($data["id"]) . "</td></tr>\n";
         }
         echo "</table>\n";
         echo "<input type='hidden' name='id' value='{$ID}'>";
         $paramsma['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $paramsma);
         Html::closeForm();
     } else {
         _e('No item found');
     }
     echo "</div>";
 }
All Usage Examples Of SoftwareLicense::countForSoftware