comanage-dev - [comanage-dev] r651 - registry/trunk/app/Controller
Subject: COmanage Developers List
List archive
- From:
- To:
- Subject: [comanage-dev] r651 - registry/trunk/app/Controller
- Date: Thu, 26 Dec 2013 13:38:34 -0500
Author: benno
Date: 2013-12-26 13:38:33 -0500 (Thu, 26 Dec 2013)
New Revision: 651
Modified:
registry/trunk/app/Controller/AppController.php
registry/trunk/app/Controller/HistoryRecordsController.php
registry/trunk/app/Controller/MVPAController.php
Log:
MVPA history records (CO-96)
Modified: registry/trunk/app/Controller/AppController.php
===================================================================
--- registry/trunk/app/Controller/AppController.php 2013-12-25 20:31:46
UTC (rev 650)
+++ registry/trunk/app/Controller/AppController.php 2013-12-26 18:38:33
UTC (rev 651)
@@ -344,8 +344,16 @@
} else {
// Generate the union of keys among old and new
- $attrs = array_unique(array_merge(array_keys($newdata[$model]),
array_keys($olddata[$model])));
+ $attrs = array();
+ if(!empty($newdata[$model]) && !empty($olddata[$model])) {
+ $attrs = array_unique(array_merge(array_keys($newdata[$model]),
array_keys($olddata[$model])));
+ } elseif(!empty($newdata[$model])) {
+ $attrs = array_keys($newdata[$model]);
+ } elseif(!empty($olddata[$model])) {
+ $attrs = array_keys($olddata[$model]);
+ }
+
foreach($attrs as $attr) {
// Skip some "housekeeping" keys
if($attr == 'id' || preg_match('/.*_id$/', $attr) || $attr ==
'created' || $attr == 'modified') {
@@ -381,7 +389,19 @@
// Treat name specially
$ftxt = _txt('fd.name.'.$attr);
} else {
- $ftxt = _txt('fd.'.$attr);
+ global $cm_texts, $cm_lang;
+
+ // Inflect the model name and see if fd.model.attr exists
+
+ $imodel = Inflector::underscore($model);
+
+ // XXX this isn't really an ideal way to see if a language key
exists
+ if(!empty($cm_texts[ $cm_lang ]['fd.' . $imodel . '.' . $attr]))
{
+ $ftxt = _txt('fd.' . $imodel . '.' . $attr);
+ } else {
+ // Otherwise see if the attribute by itself exists
+ $ftxt = _txt('fd.' . $attr);
+ }
}
if(isset($newval) && !isset($oldval)) {
Modified: registry/trunk/app/Controller/HistoryRecordsController.php
===================================================================
--- registry/trunk/app/Controller/HistoryRecordsController.php 2013-12-25
20:31:46 UTC (rev 650)
+++ registry/trunk/app/Controller/HistoryRecordsController.php 2013-12-26
18:38:33 UTC (rev 651)
@@ -39,7 +39,7 @@
public $paginate = array(
'limit' => 25,
'order' => array(
- 'created' => 'desc'
+ 'HistoryRecord.id' => 'desc'
),
'contain' => array(
'ActorCoPerson.PrimaryName',
@@ -79,6 +79,7 @@
// Note a join isn't needed here because paginate+contain is
already joining the right tables.
$args['OR']['CoPersonRole.cou_id'] =
array_keys($this->viewVars['permissions']['cous']);
+ $args['OR'][] = 'CoPersonRole.cou_id IS NULL';
$args['OR'][] = 'HistoryRecord.co_person_role_id IS NULL';
} else {
// This should catch the case where COUs aren't in use
@@ -105,6 +106,7 @@
// Note a join isn't needed here because paginate+contain is
already joining the right tables.
$args['OR']['CoPersonRole.cou_id'] =
array_keys($this->viewVars['permissions']['cous']);
+ $args['OR'][] = 'CoPersonRole.cou_id IS NULL';
$args['OR'][] = 'HistoryRecord.co_person_role_id IS NULL';
} else {
// This should catch the case where COUs aren't in use
Modified: registry/trunk/app/Controller/MVPAController.php
===================================================================
--- registry/trunk/app/Controller/MVPAController.php 2013-12-25 20:31:46
UTC (rev 650)
+++ registry/trunk/app/Controller/MVPAController.php 2013-12-26 18:38:33
UTC (rev 651)
@@ -76,4 +76,82 @@
$this->requires_co = false;
}
}
+
+ /**
+ * Generate history records for a transaction. This method is intended to
be
+ * overridden by model-specific controllers, and will be called from
within a
+ * try{} block so that HistoryRecord->record() may be called without
worrying
+ * about catching exceptions.
+ *
+ * @since COmanage Registry v0.9
+ * @param String Controller action causing the change
+ * @param Array Data provided as part of the action (for add/edit)
+ * @param Array Previous data (for delete/edit)
+ * @return boolean Whether the function completed successfully (which does
not necessarily imply history was recorded)
+ */
+
+ public function generateHistory($action, $newdata, $olddata) {
+ $req = $this->modelClass;
+ $model = $this->$req;
+
+ switch($action) {
+ case 'add':
+ case 'edit':
+ if(!empty($newdata[$req]['org_identity_id'])) {
+ $model->OrgIdentity->HistoryRecord->record(null,
+ null,
+
$newdata[$req]['org_identity_id'],
+
$this->Session->read('Auth.User.co_person_id'),
+
ActionEnum::OrgIdEditedManual,
+
$this->changesToString($newdata, $olddata, array($req)));
+ } elseif(!empty($newdata[$req]['co_person_role_id'])) {
+ // Map CO Person Role to CO Person
+ $copid = $model->CoPersonRole->field('co_person_id',
array('CoPersonRole.id' => $newdata[$req]['co_person_role_id']));
+
+ $model->CoPersonRole->HistoryRecord->record($copid,
+
$newdata[$req]['co_person_role_id'],
+ null,
+
$this->Session->read('Auth.User.co_person_id'),
+
ActionEnum::CoPersonEditedManual,
+
$this->changesToString($newdata, $olddata, array($req)));
+ } elseif(!empty($newdata[$req]['co_person_id'])) {
+
$model->CoPerson->HistoryRecord->record($newdata[$req]['co_person_id'],
+ null,
+ null,
+
$this->Session->read('Auth.User.co_person_id'),
+
ActionEnum::CoPersonEditedManual,
+
$this->changesToString($newdata, $olddata, array($req)));
+ }
+ break;
+ case 'delete':
+ if(!empty($olddata[$req]['org_identity_id'])) {
+ $model->OrgIdentity->HistoryRecord->record(null,
+ null,
+
$olddata[$req]['org_identity_id'],
+
$this->Session->read('Auth.User.co_person_id'),
+
ActionEnum::OrgIdEditedManual,
+
$this->changesToString($newdata, $olddata, array($req)));
+ } elseif(!empty($olddata[$req]['co_person_role_id'])) {
+ // Map CO Person Role to CO Person
+ $copid = $model->CoPersonRole->field('co_person_id',
array('CoPersonRole.id' => $olddata[$req]['co_person_role_id']));
+
+ $model->CoPersonRole->HistoryRecord->record($copid,
+
$olddata[$req]['co_person_role_id'],
+ null,
+
$this->Session->read('Auth.User.co_person_id'),
+
ActionEnum::CoPersonEditedManual,
+
$this->changesToString($newdata, $olddata, array($req)));
+ } elseif(!empty($olddata[$req]['co_person_id'])) {
+
$model->CoPerson->HistoryRecord->record($olddata[$req]['co_person_id'],
+ null,
+ null,
+
$this->Session->read('Auth.User.co_person_id'),
+
ActionEnum::CoPersonEditedManual,
+
$this->changesToString($newdata, $olddata, array($req)));
+ }
+ break;
+ }
+
+ return true;
+ }
}
- [comanage-dev] r651 - registry/trunk/app/Controller, svnlog, 12/26/2013
Archive powered by MHonArc 2.6.16.