original_string: public function findTemplate(HTML_QuickForm2_Node $element, $default = '{element}')
      {
          if (!empty($this->templatesForId[$element->getId()])) {
              return $this->templatesForId[$element->getId()];
          }
          $class          = strtolower(get_class($element));
          $groupId        = end($this->groupId);
          $elementClasses = array();
          do {
              if (empty($groupId) && !empty($this->templatesForClass[$class])) {
                  return $this->templatesForClass[$class];
              }
              $elementClasses[$class] = true;
          } while ($class = strtolower(get_parent_class($class)));
  
          if (!empty($groupId)) {
              if (!empty($this->elementTemplatesForGroupId[$groupId])) {
                  while (list($elClass) = each($elementClasses)) {
                      if (!empty($this->elementTemplatesForGroupId[$groupId][$elClass])) {
                          return $this->elementTemplatesForGroupId[$groupId][$elClass];
                      }
                  }
              }
  
              $group = $element->getContainer();
              $grClass = strtolower(get_class($group));
              do {
                  if (!empty($this->elementTemplatesForGroupClass[$grClass])) {
                      reset($elementClasses);
                      while (list($elClass) = each($elementClasses)) {
                          if (!empty($this->elementTemplatesForGroupClass[$grClass][$elClass])) {
                              return $this->elementTemplatesForGroupClass[$grClass][$elClass];
                          }
                      }
                  }
              } while ($grClass = strtolower(get_parent_class($grClass)));
          }
          return $default;
      }
code: public function findTemplate(HTML_QuickForm2_Node $element, $default = '{element}')
      {
          if (!empty($this->templatesForId[$element->getId()])) {
              return $this->templatesForId[$element->getId()];
          }
          $class          = strtolower(get_class($element));
          $groupId        = end($this->groupId);
          $elementClasses = array();
          do {
              if (empty($groupId) && !empty($this->templatesForClass[$class])) {
                  return $this->templatesForClass[$class];
              }
              $elementClasses[$class] = true;
          } while ($class = strtolower(get_parent_class($class)));
  
          if (!empty($groupId)) {
              if (!empty($this->elementTemplatesForGroupId[$groupId])) {
                  while (list($elClass) = each($elementClasses)) {
                      if (!empty($this->elementTemplatesForGroupId[$groupId][$elClass])) {
                          return $this->elementTemplatesForGroupId[$groupId][$elClass];
                      }
                  }
              }
  
              $group = $element->getContainer();
              $grClass = strtolower(get_class($group));
              do {
                  if (!empty($this->elementTemplatesForGroupClass[$grClass])) {
                      reset($elementClasses);
                      while (list($elClass) = each($elementClasses)) {
                          if (!empty($this->elementTemplatesForGroupClass[$grClass][$elClass])) {
                              return $this->elementTemplatesForGroupClass[$grClass][$elClass];
                          }
                      }
                  }
              } while ($grClass = strtolower(get_parent_class($grClass)));
          }
          return $default;
      }
code_tokens: public function findTemplate ( HTML_QuickForm2_Node $ element , $ default = '{element}' ) { if ( ! empty ( $ this -> templatesForId [ $ element -> getId ( ) ] ) ) { return $ this -> templatesForId [ $ element -> getId ( ) ] ; } $ class = strtolower ( get_class ( $ element ) ) ; $ groupId = end ( $ this -> groupId ) ; $ elementClasses = array ( ) ; do { if ( empty ( $ groupId ) && ! empty ( $ this -> templatesForClass [ $ class ] ) ) { return $ this -> templatesForClass [ $ class ] ; } $ elementClasses [ $ class ] = true ; } while ( $ class = strtolower ( get_parent_class ( $ class ) ) ) ; if ( ! empty ( $ groupId ) ) { if ( ! empty ( $ this -> elementTemplatesForGroupId [ $ groupId ] ) ) { while ( list ( $ elClass ) = each ( $ elementClasses ) ) { if ( ! empty ( $ this -> elementTemplatesForGroupId [ $ groupId ] [ $ elClass ] ) ) { return $ this -> elementTemplatesForGroupId [ $ groupId ] [ $ elClass ] ; } } } $ group = $ element -> getContainer ( ) ; $ grClass = strtolower ( get_class ( $ group ) ) ; do { if ( ! empty ( $ this -> elementTemplatesForGroupClass [ $ grClass ] ) ) { reset ( $ elementClasses ) ; while ( list ( $ elClass ) = each ( $ elementClasses ) ) { if ( ! empty ( $ this -> elementTemplatesForGroupClass [ $ grClass ] [ $ elClass ] ) ) { return $ this -> elementTemplatesForGroupClass [ $ grClass ] [ $ elClass ] ; } } } } while ( $ grClass = strtolower ( get_parent_class ( $ grClass ) ) ) ; } return $ default ; }
docstring: Finds a proper template for the element
  
  Templates are scanned in a predefined order. First, if a template was
  set for a specific element by id, it is returned, no matter if the
  element belongs to a group. If the element does not belong to a group,
  we try to match a template using the element class.
  But, if the element belongs to a group, templates are first looked up
  using the containing group id, then using the containing group class.
  When no template is found, the provided default template is returned.
  
  @param    HTML_QuickForm2_Node    Element being rendered
  @param    string                  Default template to use if not found
  @return   string  Template
docstring_tokens: Finds a proper template for the element