/**
  * Constructs a DisplayBlock object from a DBObjectSet already in memory
  * @param $oSet DBObjectSet
  * @return DisplayBlock The DisplayBlock object, or null if the creation failed
  */
 public static function FromObjectSet(DBObjectSet $oSet, $sStyle, $aParams = array())
 {
     $oDummyFilter = new DBObjectSearch($oSet->GetClass());
     $aKeys = array();
     while ($oObject = $oSet->Fetch()) {
         $aKeys[] = $oObject->GetKey();
     }
     $oSet->Rewind();
     if (count($aKeys) > 0) {
         $oDummyFilter->AddCondition('id', $aKeys, 'IN');
     } else {
         $oDummyFilter->AddCondition('id', 0, '=');
     }
     $oBlock = new DisplayBlock($oDummyFilter, $sStyle, false, $aParams);
     // DisplayBlocks built this way are synchronous
     return $oBlock;
 }
 /**
  * Displays a list of objects, without any hyperlink (except for the object's details)
  * @param DBObjectSet $oSet The set of objects to display
  * @param Array $aZList The ZList (list of field codes) to use for the tabular display
  * @param String $sEmptyListMessage Message displayed whenever the list is empty
  * @return string The HTML text representing the list
  */
 public function DisplaySet($oSet, $aZList, $sEmptyListMessage = '')
 {
     if ($oSet->Count() > 0) {
         $sClass = $oSet->GetClass();
         if (is_subclass_of($sClass, 'cmdbAbstractObject')) {
             // Home-made and very limited display of an object set
             $sUniqueId = $sClass . $this->GetUniqueId();
             $this->add("<div id=\"{$sUniqueId}\">\n");
             // The id here MUST be the same as currentId, otherwise the pagination will be broken
             cmdbAbstractObject::DisplaySet($this, $oSet, array('currentId' => $sUniqueId, 'menu' => false, 'toolkit_menu' => false, 'zlist' => false, 'extra_fields' => implode(',', $aZList)));
             $this->add("</div>\n");
         } else {
             // Home-made and very limited display of an object set
             $aAttribs = array();
             $aValues = array();
             $aAttribs['key'] = array('label' => MetaModel::GetName($sClass), 'description' => '');
             foreach ($aZList as $sAttCode) {
                 $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
                 $aAttribs[$sAttCode] = array('label' => $oAttDef->GetLabel(), 'description' => $oAttDef->GetDescription());
             }
             while ($oObj = $oSet->Fetch()) {
                 $aRow = array();
                 $aRow['key'] = '<a href="./index.php?operation=details&class=' . get_class($oObj) . '&id=' . $oObj->GetKey() . '">' . $oObj->GetName() . '</a>';
                 $sHilightClass = $oObj->GetHilightClass();
                 if ($sHilightClass != '') {
                     $aRow['@class'] = $sHilightClass;
                 }
                 foreach ($aZList as $sAttCode) {
                     $aRow[$sAttCode] = $oObj->GetAsHTML($sAttCode);
                 }
                 $aValues[$oObj->GetKey()] = $aRow;
             }
             $this->table($aAttribs, $aValues);
         }
     } elseif (strlen($sEmptyListMessage) > 0) {
         $this->add($sEmptyListMessage);
     }
 }
 /**
  * Simplifed version of GetDisplaySet() with less "decoration" around the table (and no paging)
  * that fits better into a printed document (like a PDF or a printable view)
  * @param WebPage $oPage
  * @param DBObjectSet $oSet
  * @param hash $aExtraParams
  * @return string The HTML representation of the table
  */
 public static function GetDisplaySetForPrinting(WebPage $oPage, DBObjectSet $oSet, $aExtraParams = array())
 {
     $iListId = empty($aExtraParams['currentId']) ? $oPage->GetUniqueId() : $aExtraParams['currentId'];
     $sTableId = isset($aExtraParams['table_id']) ? $aExtraParams['table_id'] : null;
     $bViewLink = true;
     $sSelectMode = 'none';
     $iListId = $sTableId;
     $sClassAlias = $oSet->GetClassAlias();
     $sClassName = $oSet->GetClass();
     $sZListName = 'list';
     $aClassAliases = array($sClassAlias => $sClassName);
     $aList = cmdbAbstractObject::FlattenZList(MetaModel::GetZListItems($sClassName, $sZListName));
     $oDataTable = new PrintableDataTable($iListId, $oSet, $aClassAliases, $sTableId);
     $oSettings = DataTableSettings::GetDataModelSettings($aClassAliases, $bViewLink, array($sClassAlias => $aList));
     $oSettings->iDefaultPageSize = 0;
     $oSettings->aSortOrder = MetaModel::GetOrderByDefault($sClassName);
     return $oDataTable->Display($oPage, $oSettings, false, $sSelectMode, $bViewLink, $aExtraParams);
 }
Example #4
0
 function test_search()
 {
     echo "<h4>Two searches</h4>";
     $oFilterAllDevs = new DBObjectSearch("cmdbTeam");
     $oAllDevs = new DBObjectSet($oFilterAllDevs);
     echo "Found " . $oAllDevs->Count() . " items.</br>\n";
     while ($oDev = $oAllDevs->Fetch()) {
         $aValues = array();
         foreach (MetaModel::GetAttributesList($oAllDevs->GetClass()) as $sAttCode) {
             $aValues[] = MetaModel::GetLabel(get_class($oDev), $sAttCode) . " (" . MetaModel::GetDescription(get_class($oDev), $sAttCode) . ") = " . $oDev->GetAsHTML($sAttCode);
         }
         echo $oDev->GetKey() . " => " . implode(", ", $aValues) . "</br>\n";
     }
     // a second one
     $oMyFilter = new DBObjectSearch("cmdbContact");
     //$oMyFilter->AddCondition("name", "aii", "Finishes with");
     $oMyFilter->AddCondition("name", "aii");
     $this->search_and_show_list($oMyFilter);
 }