KnowbaseItemTranslation::isKbTranslationActive PHP Method

isKbTranslationActive() static public method

Is kb item translation functionnality active
static public isKbTranslationActive ( ) : true
return true if active, false if not
    static function isKbTranslationActive()
    {
        global $CFG_GLPI;
        return $CFG_GLPI['translate_kb'];
    }

Usage Example

 /**
  * Print out list recent or popular kb/faq
  *
  * @param $type      type : recent / popular / not published
  *
  * @return nothing (display table)
  **/
 static function showRecentPopular($type)
 {
     global $DB, $CFG_GLPI;
     $faq = !Session::haveRight(self::$rightname, READ);
     if ($type == "recent") {
         $orderby = "ORDER BY `date` DESC";
         $title = __('Recent entries');
     } else {
         if ($type == 'lastupdate') {
             $orderby = "ORDER BY `date_mod` DESC";
             $title = __('Last updated entries');
         } else {
             $orderby = "ORDER BY `view` DESC";
             $title = __('Most popular questions');
         }
     }
     $faq_limit = "";
     $addselect = "";
     // Force all joins for not published to verify no visibility set
     $join = self::addVisibilityJoins(true);
     if (Session::getLoginUserID()) {
         $faq_limit .= "WHERE " . self::addVisibilityRestrict();
     } else {
         // Anonymous access
         if (Session::isMultiEntitiesMode()) {
             $faq_limit .= " WHERE (`glpi_entities_knowbaseitems`.`entities_id` = '0'\n                                   AND `glpi_entities_knowbaseitems`.`is_recursive` = '1')";
         } else {
             $faq_limit .= " WHERE 1";
         }
     }
     // Only published
     $faq_limit .= " AND (`glpi_entities_knowbaseitems`.`entities_id` IS NOT NULL\n                           OR `glpi_knowbaseitems_profiles`.`profiles_id` IS NOT NULL\n                           OR `glpi_groups_knowbaseitems`.`groups_id` IS NOT NULL\n                           OR `glpi_knowbaseitems_users`.`users_id` IS NOT NULL)";
     // Add visibility date
     $faq_limit .= " AND (`glpi_knowbaseitems`.`begin_date` IS NULL\n                           OR `glpi_knowbaseitems`.`begin_date` < NOW())\n                      AND (`glpi_knowbaseitems`.`end_date` IS NULL\n                           OR `glpi_knowbaseitems`.`end_date` > NOW()) ";
     if ($faq) {
         // FAQ
         $faq_limit .= " AND (`glpi_knowbaseitems`.`is_faq` = '1')";
     }
     if (KnowbaseItemTranslation::isKbTranslationActive()) {
         $join .= "LEFT JOIN `glpi_knowbaseitemtranslations`\n                     ON (`glpi_knowbaseitems`.`id` = `glpi_knowbaseitemtranslations`.`knowbaseitems_id`\n                           AND `glpi_knowbaseitemtranslations`.`language` = '" . $_SESSION['glpilanguage'] . "')";
         $addselect .= ", `glpi_knowbaseitemtranslations`.`name` AS transname,\n                          `glpi_knowbaseitemtranslations`.`answer` AS transanswer ";
     }
     $query = "SELECT DISTINCT `glpi_knowbaseitems`.* {$addselect}\n                FROM `glpi_knowbaseitems`\n                {$join}\n                {$faq_limit}\n                {$orderby}\n                LIMIT 10";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     if ($number > 0) {
         echo "<table class='tab_cadrehov'>";
         echo "<tr class='noHover'><th>" . $title . "</th></tr>";
         while ($data = $DB->fetch_assoc($result)) {
             $name = $data['name'];
             if (isset($data['transname']) && !empty($data['transname'])) {
                 $name = $data['transname'];
             }
             echo "<tr class='tab_bg_2'><td class='left'>";
             echo "<a " . ($data['is_faq'] ? " class='pubfaq' title='" . __("This item is part of the FAQ") . "' " : " class='knowbase' ") . " href=\"" . $CFG_GLPI["root_doc"] . "/front/knowbaseitem.form.php?id=" . $data["id"] . "\">" . Html::resume_text($name, 80) . "</a></td></tr>";
         }
         echo "</table>";
     }
 }