original_string: public static function update($tagcoll, $data) {
          global $DB;
          $defaulttagcollid = self::get_default();
          $allowedfields = array('name', 'searchable', 'customurl');
          if ($tagcoll->id == $defaulttagcollid) {
              $allowedfields = array('name');
          }
  
          $updatedata = array();
          $data = (array)$data;
          foreach ($allowedfields as $key) {
              if (array_key_exists($key, $data) && $data[$key] !== $tagcoll->$key) {
                  $updatedata[$key] = $data[$key];
              }
          }
  
          if (!$updatedata) {
              // Nothing to update.
              return false;
          }
  
          if (isset($updatedata['searchable'])) {
              $updatedata['searchable'] = (int)(bool)$updatedata['searchable'];
          }
          foreach ($updatedata as $key => $value) {
              $tagcoll->$key = $value;
          }
          $updatedata['id'] = $tagcoll->id;
          $DB->update_record('tag_coll', $updatedata);
  
          // Reset cache.
          cache::make('core', 'tags')->delete('tag_coll');
  
          \core\event\tag_collection_updated::create_from_record($tagcoll)->trigger();
  
          return true;
      }
code: public static function update($tagcoll, $data) {
          global $DB;
          $defaulttagcollid = self::get_default();
          $allowedfields = array('name', 'searchable', 'customurl');
          if ($tagcoll->id == $defaulttagcollid) {
              $allowedfields = array('name');
          }
  
          $updatedata = array();
          $data = (array)$data;
          foreach ($allowedfields as $key) {
              if (array_key_exists($key, $data) && $data[$key] !== $tagcoll->$key) {
                  $updatedata[$key] = $data[$key];
              }
          }
  
          if (!$updatedata) {
              // Nothing to update.
              return false;
          }
  
          if (isset($updatedata['searchable'])) {
              $updatedata['searchable'] = (int)(bool)$updatedata['searchable'];
          }
          foreach ($updatedata as $key => $value) {
              $tagcoll->$key = $value;
          }
          $updatedata['id'] = $tagcoll->id;
          $DB->update_record('tag_coll', $updatedata);
  
          // Reset cache.
          cache::make('core', 'tags')->delete('tag_coll');
  
          \core\event\tag_collection_updated::create_from_record($tagcoll)->trigger();
  
          return true;
      }
code_tokens: public static function update ( $ tagcoll , $ data ) { global $ DB ; $ defaulttagcollid = self :: get_default ( ) ; $ allowedfields = array ( 'name' , 'searchable' , 'customurl' ) ; if ( $ tagcoll -> id == $ defaulttagcollid ) { $ allowedfields = array ( 'name' ) ; } $ updatedata = array ( ) ; $ data = ( array ) $ data ; foreach ( $ allowedfields as $ key ) { if ( array_key_exists ( $ key , $ data ) && $ data [ $ key ] !== $ tagcoll -> $ key ) { $ updatedata [ $ key ] = $ data [ $ key ] ; } } if ( ! $ updatedata ) { // Nothing to update. return false ; } if ( isset ( $ updatedata [ 'searchable' ] ) ) { $ updatedata [ 'searchable' ] = ( int ) ( bool ) $ updatedata [ 'searchable' ] ; } foreach ( $ updatedata as $ key => $ value ) { $ tagcoll -> $ key = $ value ; } $ updatedata [ 'id' ] = $ tagcoll -> id ; $ DB -> update_record ( 'tag_coll' , $ updatedata ) ; // Reset cache. cache :: make ( 'core' , 'tags' ) -> delete ( 'tag_coll' ) ; \ core \ event \ tag_collection_updated :: create_from_record ( $ tagcoll ) -> trigger ( ) ; return true ; }
docstring: Updates the tag collection information
  
  @param stdClass $tagcoll existing record in DB table tag_coll
  @param stdClass $data data to update
  @return bool wether the record was updated
docstring_tokens: Updates the tag collection information