original_string: public function setValue($value) {
          global $DB;
          $values = (array) $value;
          $ids = array();
  
          foreach ($values as $onevalue) {
              if (!empty($onevalue) && (!$this->optionExists($onevalue)) &&
                      ($onevalue !== '_qf__force_multiselect_submission')) {
                  array_push($ids, $onevalue);
              }
          }
  
          if (empty($ids)) {
              return $this->setSelected(array());
          }
  
          // Logic here is simulating API.
          $toselect = array();
          list($insql, $inparams) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED, 'param');
          $frameworks = competency_framework::get_records_select("id $insql", $inparams, 'shortname');
          foreach ($frameworks as $framework) {
              if (!has_any_capability(array('moodle/competency:competencyview', 'moodle/competency:competencymanage'),
                      $framework->get_context())) {
                  continue;
              } else if ($this->onlyvisible && !$framework->get('visible')) {
                  continue;
              }
              $this->addOption($framework->get('shortname') . ' ' . $framework->get('idnumber'), $framework->get('id'));
              array_push($toselect, $framework->get('id'));
          }
  
          return $this->setSelected($toselect);
      }
code: public function setValue($value) {
          global $DB;
          $values = (array) $value;
          $ids = array();
  
          foreach ($values as $onevalue) {
              if (!empty($onevalue) && (!$this->optionExists($onevalue)) &&
                      ($onevalue !== '_qf__force_multiselect_submission')) {
                  array_push($ids, $onevalue);
              }
          }
  
          if (empty($ids)) {
              return $this->setSelected(array());
          }
  
          // Logic here is simulating API.
          $toselect = array();
          list($insql, $inparams) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED, 'param');
          $frameworks = competency_framework::get_records_select("id $insql", $inparams, 'shortname');
          foreach ($frameworks as $framework) {
              if (!has_any_capability(array('moodle/competency:competencyview', 'moodle/competency:competencymanage'),
                      $framework->get_context())) {
                  continue;
              } else if ($this->onlyvisible && !$framework->get('visible')) {
                  continue;
              }
              $this->addOption($framework->get('shortname') . ' ' . $framework->get('idnumber'), $framework->get('id'));
              array_push($toselect, $framework->get('id'));
          }
  
          return $this->setSelected($toselect);
      }
code_tokens: public function setValue ( $ value ) { global $ DB ; $ values = ( array ) $ value ; $ ids = array ( ) ; foreach ( $ values as $ onevalue ) { if ( ! empty ( $ onevalue ) && ( ! $ this -> optionExists ( $ onevalue ) ) && ( $ onevalue !== '_qf__force_multiselect_submission' ) ) { array_push ( $ ids , $ onevalue ) ; } } if ( empty ( $ ids ) ) { return $ this -> setSelected ( array ( ) ) ; } // Logic here is simulating API. $ toselect = array ( ) ; list ( $ insql , $ inparams ) = $ DB -> get_in_or_equal ( $ ids , SQL_PARAMS_NAMED , 'param' ) ; $ frameworks = competency_framework :: get_records_select ( "id $insql" , $ inparams , 'shortname' ) ; foreach ( $ frameworks as $ framework ) { if ( ! has_any_capability ( array ( 'moodle/competency:competencyview' , 'moodle/competency:competencymanage' ) , $ framework -> get_context ( ) ) ) { continue ; } else if ( $ this -> onlyvisible && ! $ framework -> get ( 'visible' ) ) { continue ; } $ this -> addOption ( $ framework -> get ( 'shortname' ) . ' ' . $ framework -> get ( 'idnumber' ) , $ framework -> get ( 'id' ) ) ; array_push ( $ toselect , $ framework -> get ( 'id' ) ) ; } return $ this -> setSelected ( $ toselect ) ; }
docstring: Set the value of this element.
  
  @param  string|array $value The value to set.
  @return boolean
docstring_tokens: Set the value of this element .