query.class.inc.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. // Copyright (C) 2010-2012 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * Persistent class Event and derived
  20. * Application internal events
  21. * There is also a file log
  22. *
  23. * @copyright Copyright (C) 2010-2012 Combodo SARL
  24. * @license http://opensource.org/licenses/AGPL-3.0
  25. */
  26. abstract class Query extends cmdbAbstractObject
  27. {
  28. public static function Init()
  29. {
  30. $aParams = array
  31. (
  32. "category" => "core/cmdb,view_in_gui,application",
  33. "key_type" => "autoincrement",
  34. "name_attcode" => "name",
  35. "state_attcode" => "",
  36. "reconc_keys" => array(),
  37. "db_table" => "priv_query",
  38. "db_key_field" => "id",
  39. "db_finalclass_field" => "realclass",
  40. "display_template" => "",
  41. );
  42. MetaModel::Init_Params($aParams);
  43. //MetaModel::Init_InheritAttributes();
  44. MetaModel::Init_AddAttribute(new AttributeString("name", array("allowed_values"=>null, "sql"=>"name", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  45. MetaModel::Init_AddAttribute(new AttributeText("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  46. MetaModel::Init_AddAttribute(new AttributeString("fields", array("allowed_values"=>null, "sql"=>"fields", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  47. // Display lists
  48. MetaModel::Init_SetZListItems('details', array('name', 'description', 'fields')); // Attributes to be displayed for the complete details
  49. MetaModel::Init_SetZListItems('list', array('description')); // Attributes to be displayed for a list
  50. // Search criteria
  51. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  52. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  53. }
  54. }
  55. class QueryOQL extends Query
  56. {
  57. public static function Init()
  58. {
  59. $aParams = array
  60. (
  61. "category" => "core/cmdb,view_in_gui,application",
  62. "key_type" => "autoincrement",
  63. "name_attcode" => "name",
  64. "state_attcode" => "",
  65. "reconc_keys" => array(),
  66. "db_table" => "priv_query_oql",
  67. "db_key_field" => "id",
  68. "db_finalclass_field" => "",
  69. "display_template" => "",
  70. );
  71. MetaModel::Init_Params($aParams);
  72. MetaModel::Init_InheritAttributes();
  73. MetaModel::Init_AddAttribute(new AttributeOQL("oql", array("allowed_values"=>null, "sql"=>"oql", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  74. // Display lists
  75. MetaModel::Init_SetZListItems('details', array('name', 'description', 'oql', 'fields')); // Attributes to be displayed for the complete details
  76. MetaModel::Init_SetZListItems('list', array('description')); // Attributes to be displayed for a list
  77. // Search criteria
  78. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  79. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  80. }
  81. function DisplayBareProperties(WebPage $oPage, $bEditMode = false, $sPrefix = '', $aExtraParams = array())
  82. {
  83. parent::DisplayBareProperties($oPage, $bEditMode, $sPrefix, $aExtraParams);
  84. if (!$bEditMode)
  85. {
  86. $sUrl = utils::GetAbsoluteUrlAppRoot().'webservices/export.php?format=spreadsheet&login_mode=basic&query='.$this->GetKey();
  87. $sOql = $this->Get('oql');
  88. $oSearch = DBObjectSearch::FromOQL($sOql);
  89. $aParameters = $oSearch->GetQueryParams();
  90. foreach($aParameters as $sParam => $val)
  91. {
  92. $sUrl .= '&arg_'.$sParam.'=["'.$sParam.'"]';
  93. }
  94. $oPage->p(Dict::S('UI:Query:UrlForExcel').':<br/><textarea cols="80" rows="3" READONLY>'.$sUrl.'</textarea>');
  95. }
  96. }
  97. }
  98. ?>