query.class.inc.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Persistent class Event and derived
  18. * Application internal events
  19. * There is also a file log
  20. *
  21. * @author Erwan Taloc <erwan.taloc@combodo.com>
  22. * @author Romain Quetiez <romain.quetiez@combodo.com>
  23. * @author Denis Flaven <denis.flaven@combodo.com>
  24. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  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",
  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. // Display lists
  47. MetaModel::Init_SetZListItems('details', array('name', 'description')); // Attributes to be displayed for the complete details
  48. MetaModel::Init_SetZListItems('list', array('description')); // Attributes to be displayed for a list
  49. // Search criteria
  50. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  51. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  52. }
  53. }
  54. class QueryOQL extends Query
  55. {
  56. public static function Init()
  57. {
  58. $aParams = array
  59. (
  60. "category" => "core/cmdb,view_in_gui",
  61. "key_type" => "autoincrement",
  62. "name_attcode" => "name",
  63. "state_attcode" => "",
  64. "reconc_keys" => array(),
  65. "db_table" => "priv_query_oql",
  66. "db_key_field" => "id",
  67. "db_finalclass_field" => "",
  68. "display_template" => "",
  69. );
  70. MetaModel::Init_Params($aParams);
  71. MetaModel::Init_InheritAttributes();
  72. MetaModel::Init_AddAttribute(new AttributeOQL("oql", array("allowed_values"=>null, "sql"=>"oql", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  73. // Display lists
  74. MetaModel::Init_SetZListItems('details', array('name', 'description', 'oql')); // Attributes to be displayed for the complete details
  75. MetaModel::Init_SetZListItems('list', array('description')); // Attributes to be displayed for a list
  76. // Search criteria
  77. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  78. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  79. }
  80. function DisplayBareProperties(WebPage $oPage, $bEditMode = false, $sPrefix = '', $aExtraParams = array())
  81. {
  82. parent::DisplayBareProperties($oPage, $bEditMode, $sPrefix, $aExtraParams);
  83. if (!$bEditMode)
  84. {
  85. $sUrl = utils::GetAbsoluteUrlAppRoot().'webservices/export.php?format=spreadsheet&login_mode=basic&query='.$this->GetKey();
  86. $sOql = $this->Get('oql');
  87. $oSearch = DBObjectSearch::FromOQL($sOql);
  88. $aParameters = $oSearch->GetQueryParams();
  89. foreach($aParameters as $sParam => $val)
  90. {
  91. $sUrl .= '&arg_'.$sParam.'=["'.$sParam.'"]';
  92. }
  93. $oPage->p(Dict::S('UI:Query:UrlForExcel').':<br/><textarea cols="80" rows="3" READONLY>'.$sUrl.'</textarea>');
  94. }
  95. }
  96. }
  97. ?>