You are here

function editor_note_get_notes in Editor Notes 7

Returns array of notes per entity revision.

Parameters

string $entity_type: The type of the entity.

object $entity: The entity object.

array $field: The field data about an individual field.

bool $id_only: Determines whether to return an array of note ids instead of fully loaded notes.

Return value

array An associative array, or an empty array if there is no result set.

6 calls to editor_note_get_notes()
editor_note_add_note in ./editor_note.module
Ajax callback for 'Add note' button in 'editor_note_field_widget_form'.
editor_note_confirm_edit_form_update in ./editor_note.pages.inc
Submit callback for 'Update' button in 'editor_note_confirm_edit_form'.
editor_note_confirm_remove_form_remove in ./editor_note.pages.inc
Submit callback for 'Remove' button in 'editor_note_confirm_remove_form'.
editor_note_field_formatter_view in ./editor_note.module
Implements hook_field_formatter_view().
editor_note_field_load in ./editor_note.module
Implements hook_field_load().

... See full list

File

./editor_note.module, line 1100
Main functionality for Editor Notes module.

Code

function editor_note_get_notes($entity_type, $entity, array $field, $id_only = FALSE) {
  list($entity_id, $revision_id, $bundle) = entity_extract_ids($entity_type, $entity);
  if (!isset($revision_id)) {
    $revision_id = $entity_id;
  }
  $notes_display_mode = isset($field['settings']['notes_display_mode']) ? $field['settings']['notes_display_mode'] : 'per_revision';
  $query = db_select('editor_note', 'en');
  $query
    ->condition('en.entity_type', $entity_type, '=')
    ->condition('en.entity_id', $entity_id, '=')
    ->condition('en.bundle', $bundle, '=')
    ->condition('en.field_name', $field['field_name'], '=')
    ->orderBy('en.changed', $field['settings']['order']);
  if ($notes_display_mode == 'per_revision') {
    $query
      ->condition('en.revision_id', $revision_id, '=');
  }
  if ($id_only) {
    $ids = $query
      ->fields('en', array(
      'id',
    ))
      ->execute()
      ->fetchAllKeyed(0, 0);
    return array_values($ids);
  }
  $columns = array(
    'id',
    'note',
    'entity_type',
    'bundle',
    'field_name',
    'entity_id',
    'revision_id',
    'uid',
    'created',
    'changed',
    'text_format',
  );
  $query
    ->fields('en', $columns);
  if ($field['settings']['limit'] > 0) {
    if ($field['settings']['pager']['enabled']) {
      $query = $query
        ->extend('PagerDefault');
      $query
        ->limit($field['settings']['limit']);
    }
    else {
      $query
        ->range(0, $field['settings']['limit']);
    }
  }
  return $query
    ->execute()
    ->fetchAllAssoc('id');
}