comanage-dev - [comanage-dev] r283 - in registry/trunk/app: Controller Model View/CoPeople View/CoPeople/json View/CoPeople/xml View/CoPetitions
Subject: COmanage Developers List
List archive
[comanage-dev] r283 - in registry/trunk/app: Controller Model View/CoPeople View/CoPeople/json View/CoPeople/xml View/CoPetitions
Chronological Thread
- From:
- To:
- Subject: [comanage-dev] r283 - in registry/trunk/app: Controller Model View/CoPeople View/CoPeople/json View/CoPeople/xml View/CoPetitions
- Date: Sun, 15 Apr 2012 00:09:27 -0400
Author: benno
Date: 2012-04-15 00:09:27 -0400 (Sun, 15 Apr 2012)
New Revision: 283
Added:
registry/trunk/app/View/CoPeople/json/match.ctp
registry/trunk/app/View/CoPeople/match.ctp
registry/trunk/app/View/CoPeople/xml/match.ctp
Modified:
registry/trunk/app/Controller/CoPeopleController.php
registry/trunk/app/Controller/CoPetitionsController.php
registry/trunk/app/Model/CoPerson.php
registry/trunk/app/View/CoPetitions/fields.inc
Log:
Initial real-time reconciliation/match for CO-186
Modified: registry/trunk/app/Controller/CoPeopleController.php
===================================================================
--- registry/trunk/app/Controller/CoPeopleController.php 2012-04-13
06:05:25 UTC (rev 282)
+++ registry/trunk/app/Controller/CoPeopleController.php 2012-04-15
04:09:27 UTC (rev 283)
@@ -261,6 +261,25 @@
}
/**
+ * Obtain all CO People, or perform a match
+ *
+ * @since COmanage Registry v0.5
+ */
+
+ public function index() {
+ // We need to check if we're being asked to do a match via the REST API,
and
+ // if so dispatch it. Otherwise, just invoke the standard behavior.
+
+ if($this->restful
+ && (isset($this->request->query['given'])
+ || isset($this->request->query['family']))) {
+ $this->match();
+ } else {
+ parent::index();
+ }
+ }
+
+ /**
* Invite the person identified by the Org Identity to a CO.
* - precondition: orgidentity and co set in $this->request->params
* - postcondition: $co_people set
@@ -345,6 +364,10 @@
// View all existing CO People (or a COU's worth)?
$p['index'] = ($cmr['cmadmin'] || $cmr['coadmin'] ||
!empty($cmr['couadmin']));
+ // Match against existing CO People?
+ // Note this same permission exists in CO Petitions
+ $p['match'] = ($cmr['cmadmin'] || $cmr['coadmin'] ||
!empty($cmr['couadmin']));
+
// View an existing CO Person?
$p['view'] = ($cmr['cmadmin'] || $cmr['coadmin'] ||
!empty($cmr['couadmin']) || $self);
@@ -408,6 +431,42 @@
$this->set('permissions', $p);
return($p[$this->action]);
}
+
+ /**
+ * Perform a match against existing records.
+ *
+ * @since COmanage Registry v0.5
+ */
+
+ function match() {
+ $criteria['Name.given'] = "";
+ $criteria['Name.family'] = "";
+
+ if($this->restful) {
+ if(isset($this->request->query['given'])) {
+ $criteria['Name.given'] = $this->request->query['given'];
+ }
+ if(isset($this->request->query['family'])) {
+ $criteria['Name.family'] = $this->request->query['family'];
+ }
+
+ // XXX We didn't validate CO ID exists here. (This is normally done by
+ // StandardController.)
+
+ $this->set('co_people',
+
$this->convertResponse($this->CoPerson->match($this->request->query['coid'],
+ $criteria)));
+ } else {
+ if(isset($this->params['named']['given'])) {
+ $criteria['Name.given'] = $this->params['named']['given'];
+ }
+ if(isset($this->params['named']['family'])) {
+ $criteria['Name.family'] = $this->params['named']['family'];
+ }
+
+ $this->set('matches',
$this->CoPerson->match($this->cur_co['Co']['id'], $criteria));
+ }
+ }
/**
* Perform a redirect back to the controller's default view.
Modified: registry/trunk/app/Controller/CoPetitionsController.php
===================================================================
--- registry/trunk/app/Controller/CoPetitionsController.php 2012-04-13
06:05:25 UTC (rev 282)
+++ registry/trunk/app/Controller/CoPetitionsController.php 2012-04-15
04:09:27 UTC (rev 283)
@@ -714,6 +714,10 @@
// Edit an existing CO Petition?
$p['edit'] = ($cmr['cmadmin'] || $cmr['coadmin'] ||
!empty($cmr['couadmin']));
+ // Match against existing CO People?
+ // Note this same permission exists in CO People
+ $p['match'] = ($cmr['cmadmin'] || $cmr['coadmin'] ||
!empty($cmr['couadmin']));
+
// View all existing CO Petitions?
$p['index'] = ($cmr['cmadmin'] || $cmr['coadmin'] ||
!empty($cmr['couadmin']));
Modified: registry/trunk/app/Model/CoPerson.php
===================================================================
--- registry/trunk/app/Model/CoPerson.php 2012-04-13 06:05:25 UTC (rev
282)
+++ registry/trunk/app/Model/CoPerson.php 2012-04-15 04:09:27 UTC (rev
283)
@@ -117,6 +117,38 @@
);
/**
+ * Attempt to match existing records based on the provided criteria.
+ *
+ * @since COmanage Registry v0.5
+ * @param integer Identifier of CO
+ * @param Array Hash of field name + search pattern pairs
+ * @return Array CO Person records of matching individuals
+ */
+
+ public function match($coId, $criteria) {
+ // XXX For now, we only support Name. That's not the right long term
design.
+
+ // We need to have at least one non-trivial condition
+ if((!isset($criteria['Name.given']) || strlen($criteria['Name.given']) <
3)
+ && (!isset($criteria['Name.family']) ||
strlen($criteria['Name.family']) < 3)) {
+ return(array());
+ }
+
+ // To perform case insensitive searching, we convert everything to
lowercase
+ if(isset($criteria['Name.given'])) {
+ $args['conditions']['LOWER(Name.given) LIKE'] =
strtolower($criteria['Name.given']) . '%';
+ }
+ if(isset($criteria['Name.family'])) {
+ $args['conditions']['LOWER(Name.family) LIKE'] =
strtolower($criteria['Name.family']) . '%';
+ }
+ $args['conditions']['CoPerson.co_id'] = $coId;
+ $args['contain'][] = 'Name';
+ $args['contain'][] = 'CoPersonRole';
+
+ return($this->find('all', $args));
+ }
+
+ /**
* Determine if an org identity is already associated with a CO.
*
* @since COmanage Registry v0.3
Property changes on: registry/trunk/app/View/CoPeople/json/match.ctp
___________________________________________________________________
Added: svn:special
+ *
Property changes on: registry/trunk/app/View/CoPeople/xml/match.ctp
___________________________________________________________________
Added: svn:special
+ *
Modified: registry/trunk/app/View/CoPetitions/fields.inc
===================================================================
--- registry/trunk/app/View/CoPetitions/fields.inc 2012-04-13 06:05:25
UTC (rev 282)
+++ registry/trunk/app/View/CoPetitions/fields.inc 2012-04-15 04:09:27
UTC (rev 283)
@@ -22,6 +22,23 @@
* @version $Id$
*/
-->
+<script type="text/javascript">
+$(document).ready(function() {
+ $("input.matchable").keyup(function(event) {
+ if(event.which != 13) {
+ // 13 is enter/return... don't search on form submit
+ // XXX Don't hardcode fields here, or /registry prefix
+ $.ajax({
+ url: '/registry/co_people/match/co:<?php print $cur_co['Co']['id'];
?>'
+ + '/given:' +
document.getElementById('EnrolleeCoPersonNameGiven').value
+ + '/family:' +
document.getElementById('EnrolleeCoPersonNameFamily').value
+ }).done(function(data) {
+ $('div#results').html(data);
+ });
+ }
+ });
+});
+</script>
<?php
// Determine if fields are editable
@@ -154,6 +171,9 @@
<h2 class="ui-state-default"><?php print _txt('fd.attrs.pet'); ?></h2>
+<div>
+ <div style="float:left;width:65%">
+
<table id="<?php print $this->action; ?>_co_petition_attrs"
class="ui-widget">
<tbody>
<?php foreach ($co_enrollment_attributes as $ea): ?>
@@ -225,7 +245,15 @@
break;
default:
// Use default field
- print $this->Form->input($fieldName);
+ if($permissions['match']
+ && ($fieldName == 'EnrolleeCoPerson.Name.given'
+ || $fieldName == 'EnrolleeCoPerson.Name.family')) {
+ # XXX Temp hack to enable real-time query. This should
+ # instead be enabled for fields with an appropriate flag.
+ print $this->Form->input($fieldName, array('class' =>
'matchable'));
+ } else {
+ print $this->Form->input($fieldName);
+ }
break;
}
@@ -266,6 +294,14 @@
</tbody>
</table>
+ </div>
+</div>
+
+<div>
+ <div style="float:right;width:35%" id="results">
+ </div>
+</div>
+
<?php if($this->action != 'add'): ?>
<h2 class="ui-state-default"><?php print _txt('fd.history.pt'); ?></h2>
- [comanage-dev] r283 - in registry/trunk/app: Controller Model View/CoPeople View/CoPeople/json View/CoPeople/xml View/CoPetitions, svnlog, 04/15/2012
Archive powered by MHonArc 2.6.16.