From 652cc8d27b275009c4f7ded0312013c5326f406d Mon Sep 17 00:00:00 2001
From: Gunnar Wrobel
Date: Tue, 28 Apr 2009 22:53:51 +0200
Subject: [PATCH] Added a draft for the search view.
---
koward/app/controllers/ApplicationController.php | 4 +-
koward/app/views/Object/search.html.php | 40 +++++++++
koward/config/search.php | 15 ++++
koward/lib/Form/Search.php | 100 +++++++++++++++++++++++
4 files changed, 157 insertions(+), 2 deletions(-)
create mode 100644 koward/app/views/Object/search.html.php
create mode 100644 koward/config/search.php
create mode 100644 koward/lib/Form/Search.php
diff --git a/koward/app/controllers/ApplicationController.php b/koward/app/controllers/ApplicationController.php
index 55cfd478e..212890b23 100644
--- a/koward/app/controllers/ApplicationController.php
+++ b/koward/app/controllers/ApplicationController.php
@@ -30,11 +30,11 @@ class Koward_ApplicationController extends Horde_Controller_Base
_("_Objects"), 'user.png', $registry->getImageDir('horde'));
$menu->add($this->urlFor(array('controller' => 'object', 'action' => 'edit')),
_("_Add"), 'plus.png', $registry->getImageDir('horde'));
- $menu->add(Horde::applicationUrl('search'), _("_Search"), 'search.png', $registry->getImageDir('horde'));
+ $menu->add($this->urlFor(array('controller' => 'object', 'action' => 'search')),
+ _("_Search"), 'search.png', $registry->getImageDir('horde'));
$menu->add(Horde::applicationUrl('Queries'), _("_Queries"), 'query.png', $registry->getImageDir('koward'));
$menu->add($this->urlFor(array('controller' => 'check', 'action' => 'show')),
_("_Test"), 'problem.png', $registry->getImageDir('horde'));
-
return $menu;
}
}
diff --git a/koward/app/views/Object/search.html.php b/koward/app/views/Object/search.html.php
new file mode 100644
index 000000000..3059c8e50
--- /dev/null
+++ b/koward/app/views/Object/search.html.php
@@ -0,0 +1,40 @@
+= $this->renderPartial('header'); ?>
+= $this->renderPartial('menu'); ?>
+objectlist)): ?>
+ = $this->form->renderActive(new Horde_Form_Renderer(), $this->vars,
+ $this->post, 'post'); ?>
+
+
+
+
+ | getImageDir('horde')) ?> |
+ getImageDir('horde')) ?> |
+ attributes as $attribute => $info): ?>
+ = $info['title'] ?> |
+
+
+
+
+ objectlist as $dn => $info): ?>
+
+ |
+ = $info['edit_url'] ?>
+ |
+
+ = $info['delete_url'] ?>
+ |
+ attributes as $attribute => $ainfo): ?>
+
+
+ = $info['view_url'] . $this->escape($info[$attribute]) . ''; ?>
+
+ = $this->escape($info[$attribute]) ?>
+
+ |
+
+
+
+
+
+
+
diff --git a/koward/config/search.php b/koward/config/search.php
new file mode 100644
index 000000000..fb6264f6b
--- /dev/null
+++ b/koward/config/search.php
@@ -0,0 +1,15 @@
+ array(
+ 'givenName' => array(
+ 'label' => _("First Name"),
+ 'type' => 'text',
+ 'params' => array('regex' => '', 'size' => 40, 'maxlength' => 255)
+ ),
+ )
+);
+
+if (file_exists(dirname(__FILE__) . '/search.local.php')) {
+ require_once(dirname(__FILE__) . '/search.local.php');
+}
diff --git a/koward/lib/Form/Search.php b/koward/lib/Form/Search.php
new file mode 100644
index 000000000..7e8a8a70d
--- /dev/null
+++ b/koward/lib/Form/Search.php
@@ -0,0 +1,100 @@
+koward = &Koward_Koward::singleton();
+
+ $this->object = &$object;
+
+ parent::Horde_Form($vars);
+
+ $type = false;
+
+ $this->setButtons(_("Search"));
+ $this->_addFields($this->koward->search);
+ }
+
+
+ /**
+ * Sort fields for an object type
+ */
+ function _sortFields($a, $b)
+ {
+ if ($a['order'] == -1) {
+ return 1;
+ }
+ if ($b['order'] == -1) {
+ return -1;
+ }
+ if ($a['order'] == $b['order']) {
+ return 0;
+ }
+ return ($a['order'] < $b['order']) ? -1 : 1;
+ }
+
+ /**
+ * Set up the Horde_Form fields for the attributes of this object type.
+ */
+ function _addFields($config)
+ {
+ // Now run through and add the form variables.
+ $tabs = isset($config['tabs']) ? $config['tabs'] : array('' => $config['fields']);
+
+ foreach ($tabs as $tab => $tab_fields) {
+ if (!empty($tab)) {
+ $this->setSection($tab, $tab);
+ }
+ foreach ($tab_fields as $key => $field) {
+ if (!in_array($key, array_keys($config['fields']))) {
+ continue;
+ }
+ $attribute = $field;
+ $params = isset($attribute['params']) ? $attribute['params'] : array();
+ $desc = isset($attribute['desc']) ? $attribute['desc'] : null;
+
+ $v = &$this->addVariable($attribute['label'], 'object[' . $key . ']', $attribute['type'], $attribute['required'], null, $desc, $params);
+ }
+
+ if (isset($attribute['default'])) {
+ $v->setDefault($attribute['default']);
+ }
+ }
+ }
+
+ function &execute()
+ {
+ $this->getInfo($this->_vars, $info);
+ if (isset($info['object'])) {
+ $search_criteria = array();
+ foreach ($info['object'] as $key => $value) {
+ if (!empty($value)) {
+ $search_criteria[] = array('field' => $key,
+ 'op' => 'contains',
+ 'test' => $value);
+ }
+ }
+ $search_criteria = array('AND' => $search_criteria);
+ $criteria = array('AND' => array($search_criteria,
+ $this->koward->search['criteria']));
+ $filter = $this->koward->getServer()->searchQuery($criteria);
+ $params = array('scope' => 'sub',
+ 'attributes' => array('dn'));
+ return $this->koward->getServer()->search($filter, $params);
+ }
+ }
+}
--
2.11.0