How to add a user to Limesurvey through RemoteControl 2? - json-rpc

Is there a way to add a user to Limesurvey through RemoteControl2-API? I would like to programmtically add users and surveys belonging to that user.

you can add a user using add_participants function of remote control API of limesurvey.
You can see how I used it my work:
// without composer this line can be used
include_once("../../lib/jsonrpcphp/JsonRPCClient.php");
//Get Session parameters
$myJSONRPCClient = new JsonRPCClient( LS_BASEURL );
$sessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD );
$aParticipantData = array(
'user'=>array('firstname'=>'Christopher',
'lastname'=>'hitchens',
'email'=>'christopher#example.com',
'language'=>'en',
'emailstatus'=>'ok'),
);
$added_user = $myJSONRPCClient->add_participants($sessionKey, $survey_id, $aParticipantData, 1);
$myJSONRPCClient->release_session_key($sessionKey );
You can use this code when user want to register for that survey.
It will be better if provide more info about problem.
you can get more information about this at this link: http://code.uoa.gr/p/limesurvey/test_scenarios.php

Related

Google Analytics Reporting API - Get Activity data via Client ID

I am trying to get user activity data via his client id using Google Analytics api. Take a look at the below image:
Now highlighted text is users client id, it could be user id too, and when I trying to get it via Google's playground, I get the correct response and activity data which is required, like:
and this is the response:
which is required and OK.
but I want this data via API, and have searched the web to get it, but nothing helped me.
Here is sample code Google showing i.e.
function getReport($analytics) {
// Replace with your view ID, for example XXXX.
$VIEW_ID = "<REPLACE_WITH_VIEW_ID>";
// Create the DateRange object.
$dateRange = new Google_Service_AnalyticsReporting_DateRange();
$dateRange->setStartDate("7daysAgo");
$dateRange->setEndDate("today");
// Create the Metrics object.
$sessions = new Google_Service_AnalyticsReporting_Metric();
$sessions->setExpression("ga:sessions");
$sessions->setAlias("sessions");
// Create the ReportRequest object.
$request = new Google_Service_AnalyticsReporting_ReportRequest();
$request->setViewId($VIEW_ID);
$request->setDateRanges($dateRange);
$request->setMetrics(array($sessions));
$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests( array( $request) );
return $analytics->reports->batchGet( $body );
}
I do found a class for adding user to request i.e.
$user = new Google_Service_AnalyticsReporting_User();
$user->setType("CLIENT_ID");
$user->setUserId("660467279.1539972080");
but this class Google_Service_AnalyticsReporting_ReportRequest which accepts conditions/filters for query does not have such method to accept user object.
How can I achieve this?
You should use this function: $analytics->userActivity->search().
$search = new Google_Service_AnalyticsReporting_SearchUserActivityRequest();
$search->setViewId($VIEW_ID); // Google Analytics View ID
$dateRange = new Google_Service_AnalyticsReporting_DateRange();
$dateRange->setStartDate("7daysAgo");
$dateRange->setEndDate("today");
$search->setDateRange($dateRange);
$user = new Google_Service_AnalyticsReporting_User();
$user->setType("USER_ID"); // or CLIENT_ID if you are not using custom USER ID views
$user->setUserId($user_id); // The actual user's ID as stored in your DB passed to GA
$search->setPageSize(10); // Number of results you want to pull
$search->setUser($user);
return $analytics->userActivity->search($search); // Perform the search query.
Alternatively you can also pass the params to search() like:
$params = [
'metrics' => //Your comma separated desired metrics
'dimmensions' => //Your comma separated custom dimmentions
]
return $analytics->userActivity->search($search, $params);

How to show records created by that users on index page in yii2?

I am using yii2 basic and implemented RBAC.
I have two roles admin and fieldofficer and created permissions and rules and assigned users. Now when admin logs in, on index page he should be able to see all records as well as his created records in grid.
Whereas when fieldofficer logs in, he should be able to see only his created records in index page.
How to accomplish this?
You need to pre-load the user's id into the Search Model. If security is an issue (ie: you don't want other user's to be able to bypass this no matter what), then you will need to detect if the user's id has been passed to the query, and force it back to the user you want (ie: the one logged in). In most situations, your going to need the extra security, and should.
Replace UserPlan with whatever your model is. Since you didn't post code, I have no clue what it is :)
Before: Original Index Example (as generated by Gii):
public function actionIndex()
{
$searchModel = new UserPlanSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
After: Locked to the currently logged in user:
public function actionIndex()
{
$searchModel = new UserPlanSearch();
$searchModel->user_id = Yii::$app->user->id;
// override (so users can't bypass)
$queryParams = Yii::$app->request->queryParams;
if ( isset($queryParams['UserPlan']['user_id']) ) {
$queryParams['UserPlan']['user_id'] = Yii::$app->user->id;
}
$dataProvider = $searchModel->search($queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
Also, you should post code when posting to StackOverflow unless you want a bunch of down votes. Just asking questions, is against the rules. They want to see what you have tried so far, and some code to go by.

how to unenroll user programmatically

i want to unenrol user from a course in moodle ,i want to know there is any in built function like
unenrol_user($userid,$courseid)
Try this
$instances = $DB->get_records('enrol', array('courseid' => $courseid));
foreach ($instances as $instance) {
$plugin = enrol_get_plugin($instance->enrol);
$plugin->unenrol_user($instance, $userid);
}
Moodle supports multiple enrollment methods (e.g. 'manual', 'guest', etc.,) via plugins. This loops through the enrollment methods configured for the course and tries to unenroll the user using each.
Library: lib/enrollib.php

AngularJS $resource creating new object instead of updating object

// Set up the $resource
$scope.Users = $resource("http://localhost/users/:id");
// Retrieve the user who has id=1
$scope.user = $scope.Users.get({ id : 1 }); // returns existing user
// Results
{"created_at":"2013-03-03T06:32:30Z","id":1,"name":"testing","updated_at":"2013-03-03T06:32:30Z"}
// Change this user's name
$scope.user.name = "New name";
// Attempt to save the change
$scope.user.$save();
// Results calls POST /users and not PUT /users/1
{"created_at":"2013-03-03T23:25:03Z","id":2,"name":"New name","updated_at":"2013-03-03T23:25:03Z"}
I would expect that this would result in a PUT to /users/1 with the changed attribute. But it's instead POST to /users and it creates a new user (with a new id along with the new name).
Is there something that I'm doing wrong?
AngularJS v1.0.5
you just need to tell the $resource, how he has to bind the route-parameter ":id" with the JSON Object:
$scope.Users = $resource("http://localhost/users/:id",{id:'#id'});
This should work,
regards
thanks for the answer. It worked in the end for me too.
As a side note, I was using .NET WEB API and my entity has an Id property (UPPER CASE "I").
The PUT and DELETE worked only after I used the following:
$scope.Users = $resource("http://localhost/users/:Id",{Id:'#Id'});
Hope it helps.

Cakephp 2.1 Facebook Connect And Auth

I'm using the below plugin in my app to get facebook connect working with auth.
https://github.com/webtechnick/CakePHP-Facebook-Plugin
The thing is I want to save user data into users table manually.
So I'm trying like this
public function beforeFacebookSave(){
//$this->Auth->autoRedirect = false;
debug($this->Connect->user('email'));
$this->Connect->authUser['User']['email'] = $this->Connect->user('email');
$this->Connect->authUser['User']['username'] = $this->Connect->user('username');
//Must return true or will not save.
$this->redirect(array('controller' => 'users', 'action' => 'beforefbsave', '?' => array('param1' => $this->Connect->user('email'))));
//return true;
}
The redirect is getting into a loop and getting an error
The page isn't redirecting properly
Is this a proper way or have follow some other method to get this done?
there is a documentation on page:
https://github.com/webtechnick/CakePHP-Facebook-Plugin
beforeFacebookSave handle the user to save into the users table. If returned false, creation is haulted.
//Add an email field to be saved along with creation.
function beforeFacebookSave(){
$this->Connect->authUser['User']['email'] = $this->Connect->user('email');
return true; //Must return true or will not save.
}
so if i were you i' d look on the next section:
beforeFacebookLogin Handle the user before logging the user into Auth.
function beforeFacebookLogin($user){
//Logic to happen before a facebook login
}
and instead of redirection use direct functions from your model.