Contract::getSearchOptionsToAdd PHP Method

getSearchOptionsToAdd() static public method

static public getSearchOptionsToAdd ( )
    static function getSearchOptionsToAdd()
    {
        $tab = array();
        $tab['contract'] = self::getTypeName(Session::getPluralNumber());
        $joinparams = array('beforejoin' => array('table' => 'glpi_contracts_items', 'joinparams' => array('jointype' => 'itemtype_item')));
        $joinparamscost = array('jointype' => 'child', 'beforejoin' => array('table' => 'glpi_contracts', 'joinparams' => $joinparams));
        $tab[139]['table'] = 'glpi_contracts_items';
        $tab[139]['field'] = 'id';
        $tab[139]['name'] = _x('quantity', 'Number of contracts');
        $tab[139]['forcegroupby'] = true;
        $tab[139]['usehaving'] = true;
        $tab[139]['datatype'] = 'count';
        $tab[139]['massiveaction'] = false;
        $tab[139]['joinparams'] = array('jointype' => 'itemtype_item');
        $tab[29]['table'] = 'glpi_contracts';
        $tab[29]['field'] = 'name';
        $tab[29]['name'] = self::getTypeName(1);
        $tab[29]['forcegroupby'] = true;
        $tab[29]['datatype'] = 'itemlink';
        $tab[29]['massiveaction'] = false;
        $tab[29]['joinparams'] = $joinparams;
        $tab[30]['table'] = 'glpi_contracts';
        $tab[30]['field'] = 'num';
        $tab[30]['name'] = __('Contract number');
        $tab[30]['forcegroupby'] = true;
        $tab[30]['massiveaction'] = false;
        $tab[30]['joinparams'] = $joinparams;
        $tab[30]['datatype'] = 'string';
        $tab[129]['table'] = 'glpi_contracttypes';
        $tab[129]['field'] = 'name';
        $tab[129]['name'] = sprintf(__('%1$s - %2$s'), __('Contract'), __('Type'));
        $tab[129]['datatype'] = 'dropdown';
        $tab[129]['massiveaction'] = false;
        $tab[129]['joinparams'] = array('beforejoin' => array('table' => 'glpi_contracts', 'joinparams' => $joinparams));
        $tab[130]['table'] = 'glpi_contracts';
        $tab[130]['field'] = 'duration';
        $tab[130]['name'] = sprintf(__('%1$s - %2$s'), __('Contract'), __('Duration'));
        $tab[130]['datatype'] = 'number';
        $tab[130]['max'] = 120;
        $tab[130]['unit'] = 'month';
        $tab[130]['forcegroupby'] = true;
        $tab[130]['massiveaction'] = false;
        $tab[130]['joinparams'] = $joinparams;
        $tab[131]['table'] = 'glpi_contracts';
        $tab[131]['field'] = 'periodicity';
        //TRANS: %1$s is Contract, %2$s is field name
        $tab[131]['name'] = sprintf(__('%1$s - %2$s'), __('Contract'), __('Periodicity'));
        $tab[131]['forcegroupby'] = true;
        $tab[131]['massiveaction'] = false;
        $tab[131]['joinparams'] = $joinparams;
        $tab[131]['datatype'] = 'number';
        $tab[131]['min'] = 12;
        $tab[131]['max'] = 60;
        $tab[131]['step'] = 12;
        $tab[131]['toadd'] = array(0 => Dropdown::EMPTY_VALUE, 1 => sprintf(_n('%d month', '%d months', 1), 1), 2 => sprintf(_n('%d month', '%d months', 2), 2), 3 => sprintf(_n('%d month', '%d months', 3), 3), 6 => sprintf(_n('%d month', '%d months', 6), 6));
        $tab[131]['unit'] = 'month';
        $tab[132]['table'] = 'glpi_contracts';
        $tab[132]['field'] = 'begin_date';
        $tab[132]['name'] = sprintf(__('%1$s - %2$s'), __('Contract'), __('Start date'));
        $tab[132]['forcegroupby'] = true;
        $tab[132]['datatype'] = 'date';
        $tab[132]['massiveaction'] = false;
        $tab[132]['joinparams'] = $joinparams;
        $tab[133]['table'] = 'glpi_contracts';
        $tab[133]['field'] = 'accounting_number';
        $tab[133]['name'] = sprintf(__('%1$s - %2$s'), __('Contract'), __('Account number'));
        $tab[133]['forcegroupby'] = true;
        $tab[133]['massiveaction'] = false;
        $tab[133]['datatype'] = 'string';
        $tab[133]['joinparams'] = $joinparams;
        $tab[134]['table'] = 'glpi_contracts';
        $tab[134]['field'] = 'end_date';
        $tab[134]['name'] = sprintf(__('%1$s - %2$s'), __('Contract'), __('End date'));
        $tab[134]['forcegroupby'] = true;
        $tab[134]['datatype'] = 'date_delay';
        $tab[134]['datafields'][1] = 'begin_date';
        $tab[134]['datafields'][2] = 'duration';
        $tab[134]['searchunit'] = 'MONTH';
        $tab[134]['delayunit'] = 'MONTH';
        $tab[134]['massiveaction'] = false;
        $tab[134]['joinparams'] = $joinparams;
        $tab[135]['table'] = 'glpi_contracts';
        $tab[135]['field'] = 'notice';
        $tab[135]['name'] = sprintf(__('%1$s - %2$s'), __('Contract'), __('Notice'));
        $tab[135]['datatype'] = 'number';
        $tab[135]['max'] = 120;
        $tab[135]['unit'] = 'month';
        $tab[135]['forcegroupby'] = true;
        $tab[135]['massiveaction'] = false;
        $tab[135]['joinparams'] = $joinparams;
        $tab[136]['table'] = 'glpi_contractcosts';
        $tab[136]['field'] = 'totalcost';
        $tab[136]['name'] = sprintf(__('%1$s - %2$s'), __('Contract'), __('Cost'));
        $tab[136]['forcegroupby'] = true;
        $tab[136]['usehaving'] = true;
        $tab[136]['datatype'] = 'decimal';
        $tab[136]['massiveaction'] = false;
        $tab[136]['joinparams'] = $joinparamscost;
        $tab[136]['computation'] = "(SUM(TABLE.`cost`) / COUNT(TABLE.`id`)) * COUNT(DISTINCT TABLE.`id`)";
        $tab[137]['table'] = 'glpi_contracts';
        $tab[137]['field'] = 'billing';
        $tab[137]['name'] = sprintf(__('%1$s - %2$s'), __('Contract'), __('Invoice period'));
        $tab[137]['forcegroupby'] = true;
        $tab[137]['massiveaction'] = false;
        $tab[137]['joinparams'] = $joinparams;
        $tab[137]['datatype'] = 'number';
        $tab[137]['min'] = 12;
        $tab[137]['max'] = 60;
        $tab[137]['step'] = 12;
        $tab[137]['toadd'] = array(0 => Dropdown::EMPTY_VALUE, 1 => sprintf(_n('%d month', '%d months', 1), 1), 2 => sprintf(_n('%d month', '%d months', 2), 2), 3 => sprintf(_n('%d month', '%d months', 3), 3), 6 => sprintf(_n('%d month', '%d months', 6), 6));
        $tab[137]['unit'] = 'month';
        $tab[138]['table'] = 'glpi_contracts';
        $tab[138]['field'] = 'renewal';
        $tab[138]['name'] = sprintf(__('%1$s - %2$s'), __('Contract'), __('Renewal'));
        $tab[138]['forcegroupby'] = true;
        $tab[138]['massiveaction'] = false;
        $tab[138]['joinparams'] = $joinparams;
        $tab[138]['datatype'] = 'specific';
        return $tab;
    }

Usage Example

Example #1
0
 /**
  * Get the SEARCH_OPTION array
  *
  * @param $itemtype
  * @param $withplugins boolean get search options from plugins
  *
  * @return the reference to  array of search options for the given item type
  **/
 static function &getOptions($itemtype, $withplugins = true)
 {
     global $LANG, $CFG_GLPI;
     static $search = array();
     if (!isset($search[$itemtype])) {
         // standard type first
         if ($itemtype == 'States') {
             $search[$itemtype]['common'] = $LANG['common'][32];
             $search['States'][1]['table'] = 'state_types';
             $search['States'][1]['field'] = 'name';
             $search['States'][1]['name'] = $LANG['common'][16];
             $search['States'][1]['datatype'] = 'itemlink';
             $search['States'][1]['searchtype'] = 'contains';
             $search['States'][2]['table'] = 'state_types';
             $search['States'][2]['field'] = 'id';
             $search['States'][2]['name'] = $LANG['common'][2];
             $search['States'][2]['searchtype'] = 'contains';
             $search['States'][31]['table'] = 'glpi_states';
             $search['States'][31]['field'] = 'name';
             $search['States'][31]['name'] = $LANG['state'][0];
             $search['States'] += Location::getSearchOptionsToAdd();
             $search['States'][5]['table'] = 'state_types';
             $search['States'][5]['field'] = 'serial';
             $search['States'][5]['name'] = $LANG['common'][19];
             $search['States'][6]['table'] = 'state_types';
             $search['States'][6]['field'] = 'otherserial';
             $search['States'][6]['name'] = $LANG['common'][20];
             $search['States'][16]['table'] = 'state_types';
             $search['States'][16]['field'] = 'comment';
             $search['States'][16]['name'] = $LANG['common'][25];
             $search['States'][16]['datatype'] = 'text';
             $search['States'][70]['table'] = 'glpi_users';
             $search['States'][70]['field'] = 'name';
             $search['States'][70]['name'] = $LANG['common'][34];
             $search['States'][71]['table'] = 'glpi_groups';
             $search['States'][71]['field'] = 'name';
             $search['States'][71]['name'] = $LANG['common'][35];
             $search['States'][19]['table'] = 'state_types';
             $search['States'][19]['field'] = 'date_mod';
             $search['States'][19]['name'] = $LANG['common'][26];
             $search['States'][19]['datatype'] = 'datetime';
             $search['States'][19]['massiveaction'] = false;
             $search['States'][23]['table'] = 'glpi_manufacturers';
             $search['States'][23]['field'] = 'name';
             $search['States'][23]['name'] = $LANG['common'][5];
             $search['States'][24]['table'] = 'glpi_users';
             $search['States'][24]['field'] = 'name';
             $search['States'][24]['name'] = $LANG['common'][10];
             $search['States'][80]['table'] = 'glpi_entities';
             $search['States'][80]['field'] = 'completename';
             $search['States'][80]['name'] = $LANG['entity'][0];
         } else {
             if (class_exists($itemtype)) {
                 $item = new $itemtype();
                 $search[$itemtype] = $item->getSearchOptions();
             }
         }
         if (getLoginUserID() && in_array($itemtype, $CFG_GLPI["ticket_types"])) {
             $search[$itemtype]['tracking'] = $LANG['title'][24];
             $search[$itemtype][60]['table'] = 'glpi_tickets';
             $search[$itemtype][60]['linkfield'] = 'items_id';
             $search[$itemtype][60]['field'] = 'count';
             $search[$itemtype][60]['name'] = $LANG['stats'][13];
             $search[$itemtype][60]['forcegroupby'] = true;
             $search[$itemtype][60]['usehaving'] = true;
             $search[$itemtype][60]['datatype'] = 'number';
             $search[$itemtype][60]['massiveaction'] = false;
             $search[$itemtype][60]['joinparams'] = array('jointype' => "itemtype_item", 'condition' => getEntitiesRestrictRequest('AND', 'NEWTABLE'));
         }
         if (in_array($itemtype, $CFG_GLPI["networkport_types"])) {
             $search[$itemtype] += NetworkPort::getSearchOptionsToAdd($itemtype);
         }
         if (in_array($itemtype, $CFG_GLPI["contract_types"])) {
             $search[$itemtype] += Contract::getSearchOptionsToAdd();
         }
         if (in_array($itemtype, $CFG_GLPI["infocom_types"])) {
             $search[$itemtype] += Infocom::getSearchOptionsToAdd($itemtype);
         }
         if ($withplugins) {
             // Search options added by plugins
             $plugsearch = getPluginSearchOptions($itemtype);
             if (count($plugsearch)) {
                 $search[$itemtype] += array('plugins' => $LANG['common'][29]);
                 $search[$itemtype] += $plugsearch;
             }
         }
         // Complete linkfield if not define
         if ($itemtype === 'States') {
             $itemtable = 'states_types';
         } else {
             $itemtable = $item->getTable();
         }
         foreach ($search[$itemtype] as $key => $val) {
             // Compatibility before 0.80 : Force massive action to false if linkfield is empty :
             if (isset($val['linkfield']) && empty($val['linkfield'])) {
                 $search[$itemtype][$key]['massiveaction'] = false;
             }
             if (!isset($val['linkfield']) || empty($val['linkfield'])) {
                 if (strcmp($itemtable, $val['table']) == 0 && (!isset($val['joinparams']) || count($val['joinparams']) == 0)) {
                     $search[$itemtype][$key]['linkfield'] = $val['field'];
                 } else {
                     $search[$itemtype][$key]['linkfield'] = getForeignKeyFieldForTable($val['table']);
                 }
             }
             // Add default joinparams
             if (!isset($val['joinparams'])) {
                 $search[$itemtype][$key]['joinparams'] = array();
             }
         }
     }
     return $search[$itemtype];
 }
All Usage Examples Of Contract::getSearchOptionsToAdd