2015-07-21 15:18:16 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Import;
|
|
|
|
|
|
|
|
use Icinga\Module\Director\Web\Form\QuickForm;
|
|
|
|
use Icinga\Module\Director\Web\Hook\ImportSourceHook;
|
|
|
|
use Icinga\Data\Db\DbConnection;
|
|
|
|
use Icinga\Web\Form;
|
|
|
|
|
|
|
|
class ImportSourceSql extends ImportSourceHook
|
|
|
|
{
|
|
|
|
protected $db;
|
|
|
|
|
|
|
|
public function fetchData()
|
|
|
|
{
|
|
|
|
return $this->db()->fetchAll($this->settings['query']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function listColumns()
|
|
|
|
{
|
|
|
|
return array_keys((array) current($this->fetchData()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function addSettingsFormFields(QuickForm $form)
|
|
|
|
{
|
|
|
|
$form->addElement('text', 'resource', array(
|
2015-07-22 19:18:42 +02:00
|
|
|
'label' => 'Resource name',
|
2015-07-21 15:18:16 +02:00
|
|
|
'required' => true,
|
|
|
|
));
|
2015-07-22 11:36:43 +02:00
|
|
|
$form->addElement('textarea', 'query', array(
|
2015-07-21 15:18:16 +02:00
|
|
|
'label' => 'DB Query',
|
|
|
|
'required' => true,
|
|
|
|
));
|
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function db()
|
|
|
|
{
|
|
|
|
if ($this->db === null) {
|
|
|
|
$this->db = DbConnection::fromResourceName($this->settings['resource'])->getDbAdapter();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->db;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|