original_string: public function get_lineitem($courseid, $itemid, $typeid) {
          global $DB, $CFG;
  
          require_once($CFG->libdir . '/gradelib.php');
          $lineitem = \grade_item::fetch(array('id' => $itemid));
          if ($lineitem) {
              $gbs = $this->find_ltiservice_gradebookservice_for_lineitem($itemid);
              if (!$gbs) {
                  // We will need to check if the activity related belongs to our tool proxy.
                  $ltiactivity = $DB->get_record('lti', array('id' => $lineitem->iteminstance));
                  if (($ltiactivity) && (isset($ltiactivity->typeid))) {
                      if ($ltiactivity->typeid != 0) {
                          $tool = $DB->get_record('lti_types', array('id' => $ltiactivity->typeid));
                      } else {
                          $tool = lti_get_tool_by_url_match($ltiactivity->toolurl, $courseid);
                          if (!$tool) {
                              $tool = lti_get_tool_by_url_match($ltiactivity->securetoolurl, $courseid);
                          }
                      }
                      if (is_null($typeid)) {
                          if (!(($tool) && ($this->get_tool_proxy()->id == $tool->toolproxyid))) {
                              return false;
                          }
                      } else {
                          if (!(($tool) && ($tool->id == $typeid))) {
                              return false;
                          }
                      }
                  } else {
                      return false;
                  }
              }
          }
          return $lineitem;
      }
code: public function get_lineitem($courseid, $itemid, $typeid) {
          global $DB, $CFG;
  
          require_once($CFG->libdir . '/gradelib.php');
          $lineitem = \grade_item::fetch(array('id' => $itemid));
          if ($lineitem) {
              $gbs = $this->find_ltiservice_gradebookservice_for_lineitem($itemid);
              if (!$gbs) {
                  // We will need to check if the activity related belongs to our tool proxy.
                  $ltiactivity = $DB->get_record('lti', array('id' => $lineitem->iteminstance));
                  if (($ltiactivity) && (isset($ltiactivity->typeid))) {
                      if ($ltiactivity->typeid != 0) {
                          $tool = $DB->get_record('lti_types', array('id' => $ltiactivity->typeid));
                      } else {
                          $tool = lti_get_tool_by_url_match($ltiactivity->toolurl, $courseid);
                          if (!$tool) {
                              $tool = lti_get_tool_by_url_match($ltiactivity->securetoolurl, $courseid);
                          }
                      }
                      if (is_null($typeid)) {
                          if (!(($tool) && ($this->get_tool_proxy()->id == $tool->toolproxyid))) {
                              return false;
                          }
                      } else {
                          if (!(($tool) && ($tool->id == $typeid))) {
                              return false;
                          }
                      }
                  } else {
                      return false;
                  }
              }
          }
          return $lineitem;
      }
code_tokens: public function get_lineitem ( $ courseid , $ itemid , $ typeid ) { global $ DB , $ CFG ; require_once ( $ CFG -> libdir . '/gradelib.php' ) ; $ lineitem = \ grade_item :: fetch ( array ( 'id' => $ itemid ) ) ; if ( $ lineitem ) { $ gbs = $ this -> find_ltiservice_gradebookservice_for_lineitem ( $ itemid ) ; if ( ! $ gbs ) { // We will need to check if the activity related belongs to our tool proxy. $ ltiactivity = $ DB -> get_record ( 'lti' , array ( 'id' => $ lineitem -> iteminstance ) ) ; if ( ( $ ltiactivity ) && ( isset ( $ ltiactivity -> typeid ) ) ) { if ( $ ltiactivity -> typeid != 0 ) { $ tool = $ DB -> get_record ( 'lti_types' , array ( 'id' => $ ltiactivity -> typeid ) ) ; } else { $ tool = lti_get_tool_by_url_match ( $ ltiactivity -> toolurl , $ courseid ) ; if ( ! $ tool ) { $ tool = lti_get_tool_by_url_match ( $ ltiactivity -> securetoolurl , $ courseid ) ; } } if ( is_null ( $ typeid ) ) { if ( ! ( ( $ tool ) && ( $ this -> get_tool_proxy ( ) -> id == $ tool -> toolproxyid ) ) ) { return false ; } } else { if ( ! ( ( $ tool ) && ( $ tool -> id == $ typeid ) ) ) { return false ; } } } else { return false ; } } } return $ lineitem ; }
docstring: Fetch a lineitem instance.
  
  Returns the lineitem instance if found, otherwise false.
  
  @param string $courseid ID of course
  @param string $itemid ID of lineitem
  @param string $typeid
  
  @return \ltiservice_gradebookservices\local\resources\lineitem|bool
docstring_tokens: Fetch a lineitem instance .