I am new to moodle ,currently i am working on questionnaire module, in which we create questionnaire for courses(created by teacher , which are viewed by student on course detailed page there they will answer ) . now i want to know which user created that questionnaire (i.e userid ). I have been searching for while but didnt found any answer.
If the questionnaire table has a createdby field, then you can use that, otherwise, you'll have to do a search through the logs table like this:
// You'll need to get the right coursemoduleid first from the course_modules table
$cmid = 27;
$conditions = array('module' => 'questionnaire',
'coursemoduleid' => $cmid,
'action' => 'add');
$creationrecord = $DB->get_record('log', $conditions);
$creator = $creationrecord->userid;
Related
I have a problem with my Laravel crud application for Registrations.
There are these tables: Registration, ExtraRegistration (with a registration_id, extra_id and extraoptions_id),
Extra and ExtraOptions (with the Extra_id).
In the RegistrationController when i add a Registration it makes a new record in the ExtraRegistration with the extraoptions_id and the extra_id. the extra_id is the name of the option and the extraoptions_id is the id of the option you selected.
But now, when you click on edit a record, it shows all the information. the problem is that when you change the extraoption, it makes another record, and not change the select.
And when you have edited something and you look at it again, it still shows the option before you edited it.
RegistrationController
$options = Extra::where("exa_form_id", $distance->asd_form_id)->get();
foreach($options as $option){
$input_name = "option_" . $option->exa_id;
$input_option = $request->$input_name;
if(!is_null($input_option)){
$input_name_extra = "extraoptions_" . $option->exa_id;
$input_option_extra = $request->$input_name_extra;
$registrationextra = new ExtraRegistration();
$registrationextra->iea_registration_id = $registration->isg_id;
$registrationextra->iea_extra_id = $input_option;
$registrationextra->iea_extraoption_id = $input_option_extra;
$registrationextra->iea_price = $option->exa_price;
$registrationextra->save();
}
}
$registration->isg_options = $input_option;
$registration->isg_option_extra_id = $input_option_extra;
I want a check before it makes a new ExtraRegistration. that it only makes a new registration if the registration_id with that extra_id doesn't already exists. (Not 100% sure though).
Thanks in advance!
you make a new object of ExtraRegistration so its always make a new entry for update first get object of those id after that update
check the below link
https://laravel.com/docs/5.8/eloquent#updates
This happens because you're creating a new ExtraRegistration record:
$registrationextra = new ExtraRegistration();
If you want to update it, you need to find the related $registrationextra for your $options, and then update them (assuming you have relations set up):
$registrationextra = ExtraRegistration::where('options_id', $option->id);
$registrationextra->update([
'your_fields' => value
// etc...
]);
If you want to check if ExtraRegistration exists, and depending on that, create or update it, you can do something like this:
$registrationextra = App\ExtraRegistration::updateOrCreate(
['your_fields' => 'value'],
);
You can read more on official documentation.
I am new to Grocery CRUD.
I am impressed by how much time saver this library is and i want to thank all great developers who worked on this project.
i have a small problem with showing the date field in the table. when i press the edit button , it's shown in the edit and view pages.
but it doesn't appear in the table.
Even if i create the record myself from the add record button, it's saved successfully but not shown in the table.
i have checked many things like the default format of the date in the library.
$config['grocery_crud_date_format'] = 'sql-date';
I tried different web browsers
this is my table and how i update the date and save it to the DB:
$datestring = "%Y-%m-%d";
$time = time();
$data = array(
'Attendence_date_daily' => mdate($datestring, $time),
'Check_in_time' => null,
'Check_out_time' => null,
'Attendence_status' => null,
'Employee_comment' =>null,
'Deducted_today' => 0,
'user_id' => $row->id
);
this is how i created the table
public function edit_daily_record()
{
$crud = new grocery_CRUD();
$crud->columns('daily_record_id','Attendance_date_daily','Check_in_time','Check_out_time','Attendence_status','Employee_comment','Deducted_Today','user_id');
$crud->set_table('daily_attendence_record');
$crud->display_as('Attendance_date_daily','Date')
->display_as('user_id','Employee');
$crud->set_subject('daily record');
$crud->set_relation('user_id','users','username');
$output = $crud->render();
$this->_example_output($output);
}
where 'Attendance_date_daily' is of type date in mysql DB . All fields are shown correctly except this date
'daily_record_id' is auto increment PK
'user_id' is a FK
can you please help me with this problem?
image 1
image 2
I solved this with the help of Mr. Paul Savostin
one of the Advanced members in Grocery CRUD Advance members.
the issue is a simple typo.
the name of the filed in the database is different than the controller by one letter.
this shows how can a letter change the whole code!
/* In moodle **/
Like we obtain user id using $USER->id dynamically who is logged in ,how can we obtain the quiz id of which the user is currently playing ? is there any option like $QUIZ->id or something else ?.Please help
In theory, if its been set up correctly, you can get the course module from the $PAGE object.
$cm = $PAGE->cm
Then grab the quiz record from the $cm object
$quiz = $DB->get_record('quiz', array('id' => $cm->instance));
I have an app that I'm trying to write where users can view the photos that have been uploaded to an event's wall. I've managed to write a PHP script that gives me the photos and their URL's but I can't see how to get the event id that a photo has been posted against (so that each picture can be associated with the date of the event and therefore only show the appropriate ones when a user clicks on a calendar).
$event_id_name = 'actor_id'; //changed each attempt to something from the Facebook 'stream' table
$fql = array(
"permsQuery"=>"SELECT user_events, create_event FROM permissions WHERE uid = me()",
"query1"=>"SELECT eid FROM event_member WHERE uid = me()",
"query2"=>"SELECT name,start_time, eid FROM event WHERE eid IN (SELECT eid FROM #query1)",
"query3"=> 'SELECT attachment, '.$event_id_name.' FROM stream WHERE source_id IN (SELECT eid FROM #query1)',
"userQuery"=>"SELECT first_name FROM user WHERE uid = me()",
);
$ret_obj = $facebook->api(array('method' => 'fql.multiquery',
'access_token' => $access_token,
'scope' => $required_permissions,
'queries' => $fql,
));
//get the index of the query in the returned sets
//Yes, I'm sure there's an easier way of doing this! :)
$x = 0;
while ($x < count($ret_obj))
{
if ($ret_obj[$x]['name'] == 'query3') {$returnedPostIndex = $x;}
$x++;
}
//for debugging, just throw out the array elements in an relatively easy format
$x = 0;
while ($x < count($ret_obj[$returnedPostIndex][$results_set]))
{
print_r ($ret_obj[$returnedPostIndex][$results_set][$x][$event_id_name]);
print_r (' : ');
print_r (count($ret_obj[$returnedPostIndex][$results_set][$x]['attachment']['media']));
print_r (', ');
$x++;
}
So using the above code, I get a line of text on my web page which has the column content and then the count of photos that were uploaded for each post on all the events for a user. The problem is that I'm hoping that
$ret_obj[$returnedPostIndex][$results_set][$x][$event_id_name]
will return the event id but I don't seem to get that at all. The result (when looking at the actor_id column) is:
694382034 : 8, 694382034 : 2, 694382034 : 1, 694382034 : 1,
Which shows, correctly, that there are a total of 12 photos posted over 4 posts, but I know that they're spread over 2 events so clearly actor_id isn't the event's id.
Reading this I expected the 'actor_id' to be
The ID of the user, page, group, or event that published the post
I'm assuming that I'm approaching this from completely the wrong direction but am stuck now, so can someone please tell me how to access an individual photograph's associated event id?
So I did eventually approach from a different angle: I just take the eid's of the events and store them then lazy fetch the pictures assigned to those eid's when required.
The documentation for Netsuite is quite lacking, they cover the basics and then let you loose to explore. Anyone without a vast knowledge of PHP trying to use their php toolkit would be on their knees begging for mercy.
At any point throughout this whole project it's been trail and error and trying to make sense out of everything until stuff started to work.
I'm stumped on assigning custom fields to sales orders, I know it has to be an object of an object of an object in order for it to tier down the xml for the soap to take over but what with what with what?
I have some code I worked that is getting somewhere but it is complaining it's not the right RecordRef type. If anyone worked with Netsuite and feels my pain please lend me your knowledge before I pull out all my hair.
Thanks in advance.
Code:
$customFields = array('internalId' => 'custbody_new_die_yn','value' => array('name' => 'custbody_new_die_yn','internalId' => 'NO'));
$customObject = new nsComplexObject("SelectCustomFieldRef");
$customObject->setFields($customFields);
$salesOrderFields = array(
'entity' => new nsRecordRef(array('internalId' => $userId)),
'paymentMethod' => array('internalId' => 8),
'ccNumber' => 4111111111111111,
'ccExpireDate' => date("c", mktime(0,0,0,11,1,2011)),
'ccName' => 'Test Testerson',
'itemList' => array(
'item' => array(
'item' => array('internalId' => 5963),
'quantity' => 5
)
),
'department' => new nsRecordRef(array('internalId' => 1)),
'class' => new nsRecordRef(array('internalId' => 47)),
'customFieldList' => $customObject
);
I am not familiar using PHP with Netsuite but I have done a good amount of c#/.net Netsuite work. As Craig mentioned I find it much easier using a language such c#/.net with a Visual Studio generated interface to figure out what is available in the Netsuite SuiteTalk web service API.
There is a fair amount of documentation around this stuff in the NetSuite Help Center - by no means everythign you will need but a good start. Netsuite Help Center
Check out the SuiteFlex/SuiteTalk (Web Services) section specifically this page on Ids & References.
Using Internal Ids, External Ids, and References
With that said I will try to help with a .net example & explanation of adding a custom field to a Sales Order.
Here are a few examples of adding different CustomFieldRefs:
//A list object to store all the customFieldRefs
List<CustomFieldRef> oCustomFieldRefList = new List<CustomFieldRef>();
//List or Record Type reference
SelectCustomFieldRef custbody_XXX_freight_terms = new SelectCustomFieldRef();
custbody_XXX_freight_terms.internalId = "custbody_XXX_freight_terms";
ListOrRecordRef oFreightTermsRecordRef = new ListOrRecordRef();
oFreightTermsRecordRef.internalId = <internalId of specific record in Netsuite>;
//See the References link above for more info on this - trying to figure out typeId caused me a lot of pain.
oFreightTermsRecordRef.typeId = <internalId of the List Record Type in Netsuite>;
custbody_XXX_freight_terms.value = oFreightTermsRecordRef;
oCustomFieldRefList.Add(custbody_XXX_freight_terms);
//Freeform text sorta field
StringCustomFieldRef objStringCustomFieldRef = new StringCustomFieldRef();
objStringCustomFieldRef.internalId = "custbody_XXX_tracking_link";
objStringCustomFieldRef.value = "StringValue";
oCustomFieldRefList.Add(objStringCustomFieldRef);
//Checkbox field type
BooleanCustomFieldRef custbody_XXX_if_fulfilled = new BooleanCustomFieldRef();
custbody_XXX_if_fulfilled.internalId = "custbody_XXX_if_fulfilled";
custbody_XXX_if_fulfilled.value = true;
oCustomFieldRefList.Add(custbody_XXX_if_fulfilled);
//By far the most complicated example a multi-select list referencing other records in Netsuite
MultiSelectCustomFieldRef custrecord_XXX_transaction_link = new MultiSelectCustomFieldRef();
//internal id of field you are updating
custrecord_XXX_transaction_link.internalId = "custrecord_XXX_transaction_link";
List<ListOrRecordRef> oListOrRecordRefList = new List<ListOrRecordRef>();
ListOrRecordRef oListOrRecordRefItemFulfillment = new ListOrRecordRef();
oListOrRecordRefItemFulfillment.name = "Item Fulfillment";
oListOrRecordRefItemFulfillment.internalId = <ItemFulfillmentInternalId>;
//Item Fulfillment is record type (Transaction -30) - this is from the above Reference links
oListOrRecordRefItemFulfillment.typeId = "-30";
oListOrRecordRefList.Add(oListOrRecordRefItemFulfillment);
ListOrRecordRef oListOrRecordRefSalesOrder = new ListOrRecordRef();
oListOrRecordRefSalesOrder.name = "Sales Order";
oListOrRecordRefSalesOrder.internalId = <SalesOrderInternalId>;
//Sales Order is record type (Transaction -30) - this is from the above Reference links
oListOrRecordRefSalesOrder.typeId = "-30";
oListOrRecordRefList.Add(oListOrRecordRefSalesOrder);
//Add array of all the ListOrRecordRefs to the MultiSelectCustomFieldRef
custrecord_XXX_transaction_link.value = oListOrRecordRefList.ToArray();
oCustomFieldRefList.Add(custrecord_XXX_transaction_link);
//And then add all these to the Custom Record List (Array) on the Sales Order Record
objSalesOrder.customFieldList = oCustomFieldRefList.ToArray();
From what I can tell in your above example I think your issue is with the ListOrRecordRef typeId. Its hard to tell from your example what typeId you are referencing but if you can figure that out and set the TypeId on your SelectCustomFieldRef I think that should fix your issue.
The Custom Field Ref Internal ID is the reference ID on the record you are trying to update. This can be found in the Transaction Body fields for that record within Netsuite.
The Internal ID for the ListOrRecordRef is the internal ID for the actual list item or record that you want to attach to the previously mentioned record
The typeID for the ListOrRecordRef is the internal ID for the custom list/record. This is the parent ID for the previous internal ID, and is not inherently tied to the original record.