KnowbaseItem::showRecentPopular PHP Method

showRecentPopular() static public method

Print out list recent or popular kb/faq
static public showRecentPopular ( $type ) : nothing
$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() && countElementsInTable('glpi_knowbaseitemtranslations') > 0) {
            $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>";
        }
    }

Usage Example

Beispiel #1
0
 /**
  * Show the knowbase search view
  **/
 static function showSearchView()
 {
     // Search a solution
     if (!isset($_GET["contains"]) && isset($_GET["itemtype"]) && isset($_GET["items_id"])) {
         if ($item = getItemForItemtype($_GET["itemtype"])) {
             if ($item->getFromDB($_GET["items_id"])) {
                 $_GET["contains"] = addslashes($item->getField('name'));
             }
         }
     }
     if (isset($_GET["contains"])) {
         $_SESSION['kbcontains'] = $_GET["contains"];
     } else {
         if (isset($_SESSION['kbcontains'])) {
             $_GET['contains'] = $_SESSION["kbcontains"];
         }
     }
     $ki = new KnowbaseItem();
     $ki->searchForm($_GET);
     if (!isset($_GET['contains']) || empty($_GET['contains'])) {
         echo "<div><table class='center-h' width='950px'><tr class='noHover'><td class='center top'>";
         KnowbaseItem::showRecentPopular("recent");
         echo "</td><td class='center top'>";
         KnowbaseItem::showRecentPopular("lastupdate");
         echo "</td><td class='center top'>";
         KnowbaseItem::showRecentPopular("popular");
         echo "</td></tr>";
         echo "</table></div>";
     } else {
         KnowbaseItem::showList($_GET, 'search');
     }
 }
All Usage Examples Of KnowbaseItem::showRecentPopular