original_string: public function get_owning_activity() {
          global $DB;
  
          // Set some defaults.
          $result = new stdClass();
          $result->id = 0;
  
          if (empty($this->instance->parentcontextid)) {
              return $result;
          }
          $parentcontext = context::instance_by_id($this->instance->parentcontextid);
          if ($parentcontext->contextlevel != CONTEXT_MODULE) {
              return $result;
          }
          $cm = get_coursemodule_from_id($this->page->cm->modname, $parentcontext->instanceid);
          if (!$cm) {
              return $result;
          }
          // Get the grade_items id.
          $rec = $DB->get_record('grade_items', array('iteminstance' => $cm->instance, 'itemmodule' => $this->page->cm->modname));
          if (!$rec) {
              return $result;
          }
          // See if it is a gradable activity.
          if (($rec->gradetype != GRADE_TYPE_VALUE) && ($rec->gradetype != GRADE_TYPE_SCALE)) {
              return $result;
          }
          return $rec;
      }
code: public function get_owning_activity() {
          global $DB;
  
          // Set some defaults.
          $result = new stdClass();
          $result->id = 0;
  
          if (empty($this->instance->parentcontextid)) {
              return $result;
          }
          $parentcontext = context::instance_by_id($this->instance->parentcontextid);
          if ($parentcontext->contextlevel != CONTEXT_MODULE) {
              return $result;
          }
          $cm = get_coursemodule_from_id($this->page->cm->modname, $parentcontext->instanceid);
          if (!$cm) {
              return $result;
          }
          // Get the grade_items id.
          $rec = $DB->get_record('grade_items', array('iteminstance' => $cm->instance, 'itemmodule' => $this->page->cm->modname));
          if (!$rec) {
              return $result;
          }
          // See if it is a gradable activity.
          if (($rec->gradetype != GRADE_TYPE_VALUE) && ($rec->gradetype != GRADE_TYPE_SCALE)) {
              return $result;
          }
          return $rec;
      }
code_tokens: public function get_owning_activity ( ) { global $ DB ; // Set some defaults. $ result = new stdClass ( ) ; $ result -> id = 0 ; if ( empty ( $ this -> instance -> parentcontextid ) ) { return $ result ; } $ parentcontext = context :: instance_by_id ( $ this -> instance -> parentcontextid ) ; if ( $ parentcontext -> contextlevel != CONTEXT_MODULE ) { return $ result ; } $ cm = get_coursemodule_from_id ( $ this -> page -> cm -> modname , $ parentcontext -> instanceid ) ; if ( ! $ cm ) { return $ result ; } // Get the grade_items id. $ rec = $ DB -> get_record ( 'grade_items' , array ( 'iteminstance' => $ cm -> instance , 'itemmodule' => $ this -> page -> cm -> modname ) ) ; if ( ! $ rec ) { return $ result ; } // See if it is a gradable activity. if ( ( $ rec -> gradetype != GRADE_TYPE_VALUE ) && ( $ rec -> gradetype != GRADE_TYPE_SCALE ) ) { return $ result ; } return $ rec ; }
docstring: If this block belongs to a activity context, then return that activity's id.
  Otherwise, return 0.
  @return stdclass the activity record.
docstring_tokens: If this block belongs to a activity context then return that activity s id . Otherwise return 0 .