From f008eb9f07ac87b066b337fc364ef6b3cd80bfe6 Mon Sep 17 00:00:00 2001 From: iglocska Date: Tue, 19 Mar 2013 11:54:14 +0100 Subject: [PATCH] Search for attributes by organisation - New search functionality on request - restrict attributes by organisation - Also, attributes in the list attributes and search attributes result pages, that belong to the user's organisation will have a red event ID --- app/Controller/AttributesController.php | 12 +++++++++++- app/View/Attributes/index.ctp | 7 ++++++- app/View/Attributes/search.ctp | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/Controller/AttributesController.php b/app/Controller/AttributesController.php index 3100da983..436a7afaf 100755 --- a/app/Controller/AttributesController.php +++ b/app/Controller/AttributesController.php @@ -742,6 +742,7 @@ class AttributesController extends AppController { if ($this->request->is('post') && ($this->request->here == $fullAddress)) { $keyword = $this->request->data['Attribute']['keyword']; $keyword2 = $this->request->data['Attribute']['keyword2']; + $org = $this->request->data['Attribute']['org']; $type = $this->request->data['Attribute']['type']; $category = $this->request->data['Attribute']['category']; $this->set('keywordSearch', $keyword); @@ -752,6 +753,8 @@ class AttributesController extends AppController { $this->set('categorySearch', $category); // search the db $conditions = array(); + + // search on the value field if (isset($keyword)) { $keywordArray = preg_split("/\r\n|\n|\r/", $keyword); $i = 1; @@ -774,6 +777,8 @@ class AttributesController extends AppController { } } } + + // event IDs to be excluded if (isset($keyword2)) { $keywordArray2 = preg_split("/\r\n|\n|\r/", $keyword2); $i = 1; @@ -802,13 +807,18 @@ class AttributesController extends AppController { if ($category != 'ALL') { $conditions['Attribute.category ='] = $category; } + // organisation search field + if (isset($org) && $org != '') { + $org = trim($org); + $this->set('orgSearch', $org); + $conditions['Event.orgc ='] = $org; + } $this->Attribute->recursive = 0; $this->paginate = array( 'limit' => 60, 'maxLimit' => 9999, // LATER we will bump here on a problem once we have more than 9999 attributes? 'conditions' => $conditions ); - if ('true' == Configure::read('CyDefSIG.private')) { if (!$this->_IsSiteAdmin()) { // merge in private conditions diff --git a/app/View/Attributes/index.ctp b/app/View/Attributes/index.ctp index eafd2d328..4009bc1f7 100755 --- a/app/View/Attributes/index.ctp +++ b/app/View/Attributes/index.ctp @@ -7,6 +7,7 @@ if ($isSearch == 1) { if ($keywordSearch2 != null) echo " excluding the events \"" . h($keywordSearch2) . "\""; if ($categorySearch != "ALL") echo " of category \"" . h($categorySearch) . "\""; if ($typeSearch != "ALL") echo " of type \"" . h($typeSearch) . "\""; + if (isset($orgSearch) && $orgSearch != '' && $orgSearch != null) echo " created by the organisation \"" . h($orgSearch) . "\""; echo ":"; } ?> @@ -27,7 +28,11 @@ foreach ($attributes as $attribute): diff --git a/app/View/Attributes/search.ctp b/app/View/Attributes/search.ctp index 0107bbae0..1ab55c79c 100755 --- a/app/View/Attributes/search.ctp +++ b/app/View/Attributes/search.ctp @@ -5,6 +5,7 @@ Form->input('keyword', array('type' => 'textarea', 'label' => 'Containing the following expressions')); echo $this->Form->input('keyword2', array('type' => 'textarea', 'label' => 'Excluding the following events')); + echo $this->Form->input('org', array('type' => 'text', 'label' => 'From the following organisation')); echo $this->Form->input('type', array('between' => $this->Html->div('forminfo', '', array('id' => 'AttributeTypeDiv')))); echo $this->Form->input('category', array('between' => $this->Html->div('forminfo', '', array('id' => 'AttributeCategoryDiv')))); ?>
"; - echo $this->Html->link($attribute['Event']['id'], array('controller' => 'events', 'action' => 'view', $attribute['Event']['id'])); + if ($attribute['Event']['orgc'] == $me['org']) { + echo $this->Html->link($attribute['Event']['id'], array('controller' => 'events', 'action' => 'view', $attribute['Event']['id']), array('class' => 'SameOrgLink')); + } else { + echo $this->Html->link($attribute['Event']['id'], array('controller' => 'events', 'action' => 'view', $attribute['Event']['id'])); + } $currentCount++; ?>