original_string: public function matchLocation($name, $organizationId, $create = true)
      {
          $cacheId = __CLASS__ . '_' . __FUNCTION__;
          $matches = $this->cache->load($cacheId);
  
          if (! $matches) {
              $matches = array();
              $select     = $this->db->select();
              $select->from('gems__locations')
                      ->order('glo_name');
  
              $result = $this->db->fetchAll($select);
              foreach ($result as $row) {
                  foreach (explode('|', $row['glo_match_to']) as $match) {
                      foreach (explode(':', trim($row['glo_organizations'], ':')) as $subOrg) {
                          $matches[$match][$subOrg] = $row;
                      }
                  }
              }
              $this->cache->save($matches, $cacheId, array('locations'));
          }
  
          if (isset($matches[$name])) {
              if ($organizationId) {
                  if (isset($matches[$name][$organizationId])) {
                      return $matches[$name][$organizationId];
                  }
                  // Not in this organization, if we create we update the record
              } else {
                  // Return the first location among the organizations
                  return reset($matches[$name]);
              }
          } else {
              $matches[$name] = null;
          }
  
          if (! $create) {
              return null;
          }
  
          $result = $this->addLocation($name, $organizationId, $matches[$name]);
  
          return $result;
      }
code: public function matchLocation($name, $organizationId, $create = true)
      {
          $cacheId = __CLASS__ . '_' . __FUNCTION__;
          $matches = $this->cache->load($cacheId);
  
          if (! $matches) {
              $matches = array();
              $select     = $this->db->select();
              $select->from('gems__locations')
                      ->order('glo_name');
  
              $result = $this->db->fetchAll($select);
              foreach ($result as $row) {
                  foreach (explode('|', $row['glo_match_to']) as $match) {
                      foreach (explode(':', trim($row['glo_organizations'], ':')) as $subOrg) {
                          $matches[$match][$subOrg] = $row;
                      }
                  }
              }
              $this->cache->save($matches, $cacheId, array('locations'));
          }
  
          if (isset($matches[$name])) {
              if ($organizationId) {
                  if (isset($matches[$name][$organizationId])) {
                      return $matches[$name][$organizationId];
                  }
                  // Not in this organization, if we create we update the record
              } else {
                  // Return the first location among the organizations
                  return reset($matches[$name]);
              }
          } else {
              $matches[$name] = null;
          }
  
          if (! $create) {
              return null;
          }
  
          $result = $this->addLocation($name, $organizationId, $matches[$name]);
  
          return $result;
      }
code_tokens: public function matchLocation ( $ name , $ organizationId , $ create = true ) { $ cacheId = __CLASS__ . '_' . __FUNCTION__ ; $ matches = $ this -> cache -> load ( $ cacheId ) ; if ( ! $ matches ) { $ matches = array ( ) ; $ select = $ this -> db -> select ( ) ; $ select -> from ( 'gems__locations' ) -> order ( 'glo_name' ) ; $ result = $ this -> db -> fetchAll ( $ select ) ; foreach ( $ result as $ row ) { foreach ( explode ( '|' , $ row [ 'glo_match_to' ] ) as $ match ) { foreach ( explode ( ':' , trim ( $ row [ 'glo_organizations' ] , ':' ) ) as $ subOrg ) { $ matches [ $ match ] [ $ subOrg ] = $ row ; } } } $ this -> cache -> save ( $ matches , $ cacheId , array ( 'locations' ) ) ; } if ( isset ( $ matches [ $ name ] ) ) { if ( $ organizationId ) { if ( isset ( $ matches [ $ name ] [ $ organizationId ] ) ) { return $ matches [ $ name ] [ $ organizationId ] ; } // Not in this organization, if we create we update the record } else { // Return the first location among the organizations return reset ( $ matches [ $ name ] ) ; } } else { $ matches [ $ name ] = null ; } if ( ! $ create ) { return null ; } $ result = $ this -> addLocation ( $ name , $ organizationId , $ matches [ $ name ] ) ; return $ result ; }
docstring: Find a location for the name and organization.
  
  @param string $name The name to match against
  @param int $organizationId Organization id
  @param boolean $create Create a match when it does not exist
  @return array location
docstring_tokens: Find a location for the name and organization .