Add the ability to pass notes and log categories into farm_log_create() and farm_quantity_log_create().
This commit is contained in:
parent
369c0e2d5a
commit
6566d88e1f
|
@ -699,11 +699,15 @@ function farm_log_query($time = REQUEST_TIME, $done = TRUE, $single = TRUE) {
|
|||
* Boolean indicating whether or not the log is done.
|
||||
* @param array $assets
|
||||
* An array of assets to reference in the log.
|
||||
* @param string $notes
|
||||
* Notes to add to the log.
|
||||
* @param array $categories
|
||||
* An array of categories to add to the log.
|
||||
*
|
||||
* @return \Log
|
||||
* Returns a saved log entity.
|
||||
*/
|
||||
function farm_log_create($type, $name = '', $timestamp = REQUEST_TIME, $done = TRUE, $assets = array()) {
|
||||
function farm_log_create($type, $name = '', $timestamp = REQUEST_TIME, $done = TRUE, $assets = array(), $notes = '', $categories = array()) {
|
||||
|
||||
// Create a new log entity.
|
||||
$log = entity_create('log', array('type' => $type));
|
||||
|
@ -735,6 +739,40 @@ function farm_log_create($type, $name = '', $timestamp = REQUEST_TIME, $done = T
|
|||
}
|
||||
}
|
||||
|
||||
// Add the notes.
|
||||
if (!empty($notes)) {
|
||||
$log->field_farm_notes[LANGUAGE_NONE][0]['value'] = $notes;
|
||||
$log->field_farm_notes[LANGUAGE_NONE][0]['format'] = 'farm_format';
|
||||
}
|
||||
|
||||
// Add the categories.
|
||||
if (!empty($categories)) {
|
||||
foreach ($categories as $category) {
|
||||
|
||||
// Look up the category taxonomy term.
|
||||
$terms = taxonomy_get_term_by_name($category, 'farm_log_categories');
|
||||
|
||||
// If terms were found, use the first one.
|
||||
if (!empty($terms)) {
|
||||
$term = reset($terms);
|
||||
}
|
||||
|
||||
// If a term wasn't found, create it.
|
||||
else {
|
||||
$vocab = taxonomy_vocabulary_machine_name_load('farm_log_categories');
|
||||
$term = new stdClass();
|
||||
$term->name = check_plain($category);
|
||||
$term->vid = $vocab->vid;
|
||||
taxonomy_term_save($term);
|
||||
}
|
||||
|
||||
// Add the category to the log.
|
||||
$log->field_farm_log_category[LANGUAGE_NONE][] = array(
|
||||
'tid' => $term->tid,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Set the log owner to the currently authenticated user.
|
||||
global $user;
|
||||
$log->field_farm_log_owner[LANGUAGE_NONE][] = array(
|
||||
|
|
|
@ -205,14 +205,18 @@ function farm_quantity_log_asset_query($asset_id, $measure = NULL, $label = NULL
|
|||
* 'label' => 'Foo',
|
||||
* ),
|
||||
* );
|
||||
* @param string $notes
|
||||
* Notes to add to the log.
|
||||
* @param array $categories
|
||||
* An array of categories to add to the log.
|
||||
*
|
||||
* @return \Log
|
||||
* Returns a saved log entity.
|
||||
*/
|
||||
function farm_quantity_log_create($type, $name = '', $timestamp = REQUEST_TIME, $done = TRUE, $assets = array(), $measurements = array()) {
|
||||
function farm_quantity_log_create($type, $name = '', $timestamp = REQUEST_TIME, $done = TRUE, $assets = array(), $measurements = array(), $notes = '', $categories = array()) {
|
||||
|
||||
// Create a new log entity.
|
||||
$log = farm_log_create($type, $name, $timestamp, $done, $assets);
|
||||
$log = farm_log_create($type, $name, $timestamp, $done, $assets, $notes, $categories);
|
||||
|
||||
// Iterate through the measurements.
|
||||
foreach ($measurements as $measurement) {
|
||||
|
|
Loading…
Reference in New Issue