system/classes/Model.php
protected function _getAttributeData($name, $query = false, $loadMap = false, $record = false) 
    {
      ///////////////////////////////////////////////////////////////////////
      // -------------------------------------
      // If the model DB data is already set.
      // -------------------------------------
      // ADM allows fetching of only part of a model's data when fetching
      // a record. So we have to check if the data in question has been fetched
      // from the DB already or not. If it has been fetched, we have to check
      // if it's a placeholder for a related model (related models can be set
      // to boolean true, meaning we have to dynamically fetch the model)
      ///////////////////////////////////////////////////////////////////////
      if (isset($this->model_data[$name])) {
        return $this->_getAttributeDataWhenSet($name, $query, $loadMap, $record);
      }

      ///////////////////////////////////////////////////////////////////////
      // If the model DB data is defined, but not grabbed from the database,
      // then we need to dynamically fetch it.
      // OR, we need to return an empty collection or NULL
      // in the case of the attribute pointing to models.
      ///////////////////////////////////////////////////////////////////////
      if (isset($this->model_attributes[$name]) && !isset($this->model_dynamicOff)) {
        return $this->_getAttributeDataWhenUnset($name, $query, $loadMap, $record);
      }


      ///////////////////////////////////////////////////////////////////////
      // If there is a defined DATA property (non-DB related), return the data.
      ///////////////////////////////////////////////////////////////////////
      if (isset($this->data->{$name})) {
        $this->beforeGet($name); // Lifecycle callback
        $returnValue = $this->data->{$name};
        $this->afterGet($name, $returnValue); // Lifecycle callback
        return $returnValue;
      }


      ///////////////////////////////////////////////////////////////////////
      // If there is a defined property (non-DB related), return the data.
      ///////////////////////////////////////////////////////////////////////
      $class = get_class($this);
      if (property_exists($class, $name)) {
        $this->beforeGet($name); // Lifecycle callback
        $returnValue = $this->{$name};
        $this->afterGet($name, $returnValue); // Lifecycle callback
        return $returnValue;
      }


      ///////////////////////////////////////////////////////////////////////
      // IF NONE OF THE ABOVE WORKED BECAUSE TRANSLATION FROM 'ID' TO A CUSTOM ID NAME
      // NEEDS TO BE DONE:
      // If your DB id's aren't 'id', but instead something like "note_id",
      // but you always want to be able to refer to 'id' within a class.
      ///////////////////////////////////////////////////////////////////////
      if ($name == 'id' && property_exists($class, 'id_name')) {
        $this->beforeGet($this->id_name); // Lifecycle callback
        if (isset($this->model_data[$this->id_name])) {
          $returnValue = $this->model_data[$this->id_name];
        }
        else {
          $returnValue = $this->{$this->id_name};
        }
        $this->afterGet($this->id_name, $returnValue); // Lifecycle callback
        return $returnValue;
      }


      ///////////////////////////////////////////////////////////////////////
      // If this model extends another, and the data is present on the parent, return the data.
      ///////////////////////////////////////////////////////////////////////
      if (substr($name, 0, 6 ) != "model_" && $this->issetExtended($name)) {
        $this->beforeGet($name); // Lifecycle callback
        $returnValue = $this->getExtendedAttribute($name);
        $this->afterGet($name, $returnValue); // Lifecycle callback
        return $returnValue;
      }


      ///////////////////////////////////////////////////////////////////////
      // No matching property was found! Normally this will return null.
      // However, just-in-case the object has something special setup
      // in the beforeGet() callback, we need to double check that the property
      // still isn't set after that is called.
      ///////////////////////////////////////////////////////////////////////
      $this->beforeGet($name); // Lifecycle callback
      if (isset($this->{$name})) {
        $returnValue = $this->{$name};
      } else {
        $returnValue = null;
      }
      $this->afterGet($name, $returnValue); // Lifecycle callback
      return $returnValue;
    }
protected function _getAttributeData($name, $query = false, $loadMap = false, $record = false) 
    {
      ///////////////////////////////////////////////////////////////////////
      // -------------------------------------
      // If the model DB data is already set.
      // -------------------------------------
      // ADM allows fetching of only part of a model's data when fetching
      // a record. So we have to check if the data in question has been fetched
      // from the DB already or not. If it has been fetched, we have to check
      // if it's a placeholder for a related model (related models can be set
      // to boolean true, meaning we have to dynamically fetch the model)
      ///////////////////////////////////////////////////////////////////////
      if (isset($this->model_data[$name])) {
        return $this->_getAttributeDataWhenSet($name, $query, $loadMap, $record);
      }

      ///////////////////////////////////////////////////////////////////////
      // If the model DB data is defined, but not grabbed from the database,
      // then we need to dynamically fetch it.
      // OR, we need to return an empty collection or NULL
      // in the case of the attribute pointing to models.
      ///////////////////////////////////////////////////////////////////////
      if (isset($this->model_attributes[$name]) && !isset($this->model_dynamicOff)) {
        return $this->_getAttributeDataWhenUnset($name, $query, $loadMap, $record);
      }


      ///////////////////////////////////////////////////////////////////////
      // If there is a defined DATA property (non-DB related), return the data.
      ///////////////////////////////////////////////////////////////////////
      if (isset($this->data->{$name})) {
        $this->beforeGet($name); // Lifecycle callback
        $returnValue = $this->data->{$name};
        $this->afterGet($name, $returnValue); // Lifecycle callback
        return $returnValue;
      }


      ///////////////////////////////////////////////////////////////////////
      // If there is a defined property (non-DB related), return the data.
      ///////////////////////////////////////////////////////////////////////
      $class = get_class($this);
      if (property_exists($class, $name)) {
        $this->beforeGet($name); // Lifecycle callback
        $returnValue = $this->{$name};
        $this->afterGet($name, $returnValue); // Lifecycle callback
        return $returnValue;
      }


      ///////////////////////////////////////////////////////////////////////
      // IF NONE OF THE ABOVE WORKED BECAUSE TRANSLATION FROM 'ID' TO A CUSTOM ID NAME
      // NEEDS TO BE DONE:
      // If your DB id's aren't 'id', but instead something like "note_id",
      // but you always want to be able to refer to 'id' within a class.
      ///////////////////////////////////////////////////////////////////////
      if ($name == 'id' && property_exists($class, 'id_name')) {
        $this->beforeGet($this->id_name); // Lifecycle callback
        if (isset($this->model_data[$this->id_name])) {
          $returnValue = $this->model_data[$this->id_name];
        }
        else {
          $returnValue = $this->{$this->id_name};
        }
        $this->afterGet($this->id_name, $returnValue); // Lifecycle callback
        return $returnValue;
      }


      ///////////////////////////////////////////////////////////////////////
      // If this model extends another, and the data is present on the parent, return the data.
      ///////////////////////////////////////////////////////////////////////
      if (substr($name, 0, 6 ) != "model_" && $this->issetExtended($name)) {
        $this->beforeGet($name); // Lifecycle callback
        $returnValue = $this->getExtendedAttribute($name);
        $this->afterGet($name, $returnValue); // Lifecycle callback
        return $returnValue;
      }


      ///////////////////////////////////////////////////////////////////////
      // No matching property was found! Normally this will return null.
      // However, just-in-case the object has something special setup
      // in the beforeGet() callback, we need to double check that the property
      // still isn't set after that is called.
      ///////////////////////////////////////////////////////////////////////
      $this->beforeGet($name); // Lifecycle callback
      if (isset($this->{$name})) {
        $returnValue = $this->{$name};
      } else {
        $returnValue = null;
      }
      $this->afterGet($name, $returnValue); // Lifecycle callback
      return $returnValue;
    }
Returns the appropriate value for some data on this model

@param $name string The name of the data to be retrieved.
@return mixed