SoftwareLicense::countForVersion PHP Method

countForVersion() static public method

Get number of bought licenses of a version
static public countForVersion ( $softwareversions_id, $entity = '' ) : number
$softwareversions_id version ID
$entity to search for licenses in (default = all active entities) (default '')
return number of installations
    static function countForVersion($softwareversions_id, $entity = '')
    {
        global $DB;
        $query = "SELECT COUNT(*)\n                FROM `glpi_softwarelicenses`\n                WHERE `softwareversions_id_buy` = '{$softwareversions_id}' " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', $entity);
        $result = $DB->query($query);
        if ($DB->numrows($result) != 0) {
            return $DB->result($result, 0, 0);
        }
        return 0;
    }

Usage Example

 /**
  * Print the Software / version form
  *
  * @param $ID Integer : Id of the version or the template to print
  * @param $options array
  *     - target form target
  *     - softwares_id ID of the software for add process
  *
  * @return true if displayed  false if item not found or not right to display
  *
  **/
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI, $LANG;
     $softwares_id = -1;
     if (isset($options['softwares_id'])) {
         $softwares_id = $options['softwares_id'];
     }
     if (!haveRight("software", "r")) {
         return false;
     }
     if ($ID > 0) {
         $this->check($ID, 'r');
     } else {
         $soft = new Software();
         $soft->getFromDB($softwares_id);
         // Create item
         $input = array('entities_id' => $soft->getEntityID(), 'is_recursive' => $soft->isRecursive());
         $this->check(-1, 'w', $input);
     }
     $this->showTabs($options);
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_1'><td>" . $LANG['help'][31] . "&nbsp;:</td>";
     echo "<td>";
     if ($ID > 0) {
         $softwares_id = $this->fields["softwares_id"];
     } else {
         echo "<input type='hidden' name='softwares_id' value='{$softwares_id}'>";
     }
     echo "<a href='software.form.php?id=" . $softwares_id . "'>" . Dropdown::getDropdownName("glpi_softwares", $softwares_id) . "</a>";
     echo "</td>";
     echo "<td rowspan='4' class='middle'>" . $LANG['common'][25] . "&nbsp;:</td>";
     echo "<td class='center middle' rowspan='4'>";
     echo "<textarea cols='45' rows='3' name='comment' >" . $this->fields["comment"];
     echo "</textarea></td></tr>\n";
     echo "<tr class='tab_bg_1'><td>" . $LANG['common'][16] . "&nbsp;:</td>";
     echo "<td>";
     autocompletionTextField($this, "name");
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'><td>" . $LANG['setup'][5] . "&nbsp;:</td><td>";
     Dropdown::show('OperatingSystem', array('value' => $this->fields["operatingsystems_id"]));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'><td>" . $LANG['state'][0] . "&nbsp;:</td><td>";
     Dropdown::show('State', array('value' => $this->fields["states_id"]));
     echo "</td></tr>\n";
     // Only count softwareversions_id_buy (don't care of softwareversions_id_use if no installation)
     if (SoftwareLicense::countForVersion($ID) > 0 || Computer_SoftwareVersion::countForVersion($ID) > 0) {
         $options['candel'] = false;
     }
     $this->showFormButtons($options);
     $this->addDivForTabs();
     return true;
 }
All Usage Examples Of SoftwareLicense::countForVersion