Skip to content

Commit

Permalink
added a button to the admin author form to initiate process of mergin…
Browse files Browse the repository at this point in the history
…g authors (#49)

also added the corresponding target action in the controller.
  • Loading branch information
Rija Menage committed Apr 2, 2018
1 parent 8f233dd commit 0a85cc2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
23 changes: 22 additions & 1 deletion protected/controllers/AdminAuthorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function accessRules()
{
return array(
array('allow', // admin only
'actions'=>array('admin','delete','index','view','create','update','prepareUserLink','linkUser','unlinkUser'),
'actions'=>array('admin','delete','index','view','create','update','prepareUserLink','prepareAuthorMerge','linkUser','unlinkUser'),
'roles'=>array('admin'),
),
array('deny', // deny all users
Expand Down Expand Up @@ -148,6 +148,27 @@ public function actionPrepareUserLink($user_id, $abort="no") {
}


/**
* Create a session to allow admin to search an author to link to the author
*/
public function actionPrepareAuthorMerge($origin_author_id, $abort="no") {
if( null != $origin_author_id && "no" == $abort ){
if (preg_match("/^\d+$/", $origin_author_id)) {
Yii::app()->session['merge_author'] = $origin_author_id;
Yii::log(__FUNCTION__."> new session var: merge_author = ". $origin_author_id, 'info');
}
$this->redirect(array('adminAuthor/admin'));
}
else if (null != $origin_author_id && "yes" == $abort) {
unset(Yii::app()->session['merge_author']);
Yii::log(__FUNCTION__."> unset session var: merge_author", 'info');
$this->redirect(array('user/view','id'=>$origin_author_id));
}
else {
Yii::log(__FUNCTION__."> There is a problem with parameters received", 'error');
}
}

public function actionLinkUser($id) {
$author = $this->loadModel($id);
if ( isset(Yii::app()->session['attach_user']) ) {
Expand Down
7 changes: 6 additions & 1 deletion protected/views/adminAuthor/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@
</div> */?>

<div class="pull-right">
<a href="/adminAuthor/admin" class="btn">Cancel</a>
<?php
echo CHtml::link('Merge with an author',
array('adminAuthor/prepareAuthorMerge', 'origin_author_id'=>$model->id),
array('class' => 'btn'));
?>
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',array('class'=>'btn')); ?>
<a href="/adminAuthor/admin" class="btn">Cancel</a>
</div>

<?php $this->endWidget(); ?>
Expand Down

0 comments on commit 0a85cc2

Please sign in to comment.