You are here

function CourseObjectController::load in Course 7

Same name and namespace in other branches
  1. 7.2 includes/CourseObjectController.inc \CourseObjectController::load()

Fork of Entity API's "merge" functionality.

Merge the serialized field to the entity object.

Overrides EntityAPIController::load

File

includes/CourseObjectController.inc, line 49

Class

CourseObjectController

Code

function load($ids = array(), $conditions = array()) {
  $entities = parent::load($ids, $conditions);
  $base_table = $this->entityInfo['base table'];
  $schema = drupal_get_schema($base_table);
  foreach ($schema['fields'] as $field_name => $info) {
    if (!empty($info['serialize'])) {
      $serialized_field = $field_name;
    }
  }
  foreach ($entities as $courseObject) {
    if (isset($courseObject->{$serialized_field}) && is_array($courseObject->{$serialized_field})) {
      $reflect = new ReflectionClass($courseObject);
      foreach ($reflect
        ->getProperties(ReflectionProperty::IS_PRIVATE | ReflectionProperty::IS_PROTECTED) as $prop) {
        $props[$prop
          ->getName()] = $prop
          ->getName();
      }
      foreach ($courseObject->{$serialized_field} as $field => $value) {
        if (!isset($props[$field])) {
          $courseObject
            ->setOption($field, $value);
        }
      }
      unset($courseObject->{$serialized_field});
    }
  }
  return $entities;
}