Import all ratings.

@return bool
513684
public function Import()
    {
        $cacheDirectoryPath = $this->getCacheUtil()->getCacheDirectory();
        $xmlFileOrData = null;
        if (null !== $cacheDirectoryPath) {
            $cacheFilePath = $cacheDirectoryPath.'ShopAuskunftAPI_data.xml';
            $this->downloadXml($cacheFilePath);
            if (file_exists($cacheFilePath)) {
                $xmlFileOrData = $cacheFilePath;
            }
        }
        if (null === $xmlFileOrData) {
            $xmlFileOrData = $this->fieldRatingUrl;
        }

        /**
         * streamer will only process elements with tag "rating" in element with tag "ratinglist".
         */
        $xmlStreamer = new ShopauskunftXmlStreamer($xmlFileOrData, 16384, 'ratinglist', null, 'rating');
        $xmlStreamer->setRatingServiceId($this->id);
        $xmlStreamer->parse();

        return $this->UpdateMainScroeValue();
    }
998327
public function Index() {
      $this->Permission('Garden.Import'); // This permission doesn't exist, so only users with Admin == '1' will succeed.
      $Timer = new Gdn_Timer();

      // Determine the current step.
      $this->Form = new Gdn_Form();
      $Imp = new ImportModel();
      $Imp->LoadState();

      // Search for the list of acceptable imports.
      $ImportPaths = array();
      $ExistingPaths = SafeGlob(PATH_UPLOADS.'/export*', array('gz', 'txt'));
      $ExistingPaths2 = SafeGlob(PATH_UPLOADS.'/porter/export*', array('gz'));
      $ExistingPaths = array_merge($ExistingPaths, $ExistingPaths2);
      foreach ($ExistingPaths as $Path)
         $ImportPaths[$Path] = basename($Path);
      // Add the database as a path.
      $ImportPaths = array_merge(array('db:' => T('This Database')), $ImportPaths);

      if($Imp->CurrentStep < 1) {
         // Check to see if there is a file.
         $ImportPath = C('Garden.Import.ImportPath');
         $Validation = new Gdn_Validation();


         if (strcasecmp(Gdn::Request()->RequestMethod(), 'post') == 0) {
            $Upload = new Gdn_Upload();
            $Validation = new Gdn_Validation();
            if (count($ImportPaths) > 0)
               $Validation->ApplyRule('PathSelect', 'Required', T('You must select a file to import.'));

            if (count($ImportPaths) == 0 || $this->Form->GetFormValue('PathSelect') == 'NEW')
               $TmpFile = $Upload->ValidateUpload('ImportFile', FALSE);
            else
               $TmpFile = '';

            if ($TmpFile) {
               $Filename = $_FILES['ImportFile']['name'];
               $Extension = pathinfo($Filename, PATHINFO_EXTENSION);
               $TargetFolder = PATH_ROOT . DS . 'uploads' . DS . 'import';
               if(!file_exists($TargetFolder)) {
                  mkdir($TargetFolder, 0777, TRUE);
               }
               $ImportPath = $Upload->GenerateTargetName(PATH_ROOT . DS . 'uploads' . DS . 'import', $Extension);
               $Upload->SaveAs($TmpFile, $ImportPath);
               $Imp->ImportPath = $ImportPath;
               $this->Form->SetFormValue('PathSelect', $ImportPath);

               $UploadedFiles = GetValue('UploadedFiles', $Imp->Data);
               $UploadedFiles[$ImportPath] = basename($Filename);
               $Imp->Data['UploadedFiles'] = $UploadedFiles;
            } elseif (($PathSelect = $this->Form->GetFormValue('PathSelect'))) {
               if ($PathSelect == 'NEW')
                  $Validation->AddValidationResult('ImportFile', 'ValidateRequired');
               else
                  $Imp->ImportPath = $PathSelect;
            } elseif (!$Imp->ImportPath && count($ImportPaths) == 0) {
               // There was no file uploaded this request or before.
               $Validation->AddValidationResult('ImportFile', $Upload->Exception);
            }

            // Validate the overwrite.
            if(TRUE || strcasecmp($this->Form->GetFormValue('Overwrite'), 'Overwrite') == 0) {
               if (!StringBeginsWith($this->Form->GetFormValue('PathSelect'), 'Db:', TRUE)) {
                  $Validation->ApplyRule('Email', 'Required');
                  if (!$this->Form->GetFormValue('UseCurrentPassword'))
                     $Validation->ApplyRule('Password', 'Required');
               }
            }

            if ($Validation->Validate($this->Form->FormValues())) {
               $this->Form->SetFormValue('Overwrite', 'overwrite');
               $Imp->FromPost($this->Form->FormValues());
               $this->View = 'Info';
            } else {
               $this->Form->SetValidationResults($Validation->Results());
            }
         } else {
            $this->Form->SetFormValue('PathSelect', $Imp->ImportPath);
         }
         $Imp->SaveState();
      } else {
         $this->SetData('Steps', $Imp->Steps());
         $this->View = 'Info';
      }

      if (!StringBeginsWith($Imp->ImportPath, 'db:') && !file_exists($Imp->ImportPath))
         $Imp->DeleteState();

      try {
         $UploadedFiles = GetValue('UploadedFiles', $Imp->Data, array());
         $ImportPaths = array_merge($ImportPaths, $UploadedFiles);
         $this->SetData('ImportPaths', $ImportPaths);
         $this->SetData('Header', $Imp->GetImportHeader());
         $this->SetData('Stats', GetValue('Stats', $Imp->Data, array()));
         $this->SetData('GenerateSQL', GetValue('GenerateSQL', $Imp->Data));
         $this->SetData('ImportPath', $Imp->ImportPath);
         $this->SetData('OriginalFilename', GetValue('OriginalFilename', $Imp->Data));
         $this->SetData('CurrentStep', $Imp->CurrentStep);
         $this->SetData('LoadSpeedWarning', $Imp->LoadTableType(FALSE) == 'LoadTableWithInsert');
      } catch(Gdn_UserException $Ex) {
         $this->Form->AddError($Ex);
         $Imp->SaveState();
         $this->View = 'Index';
      }
      $this->Render();
   }
63262
public function currentRun()
	{
		if (!$this->_currentRun)
		{
			$this->_currentRun = $this->runs()
				->whereEquals('import_id', $this->get('id'))
				->ordered()
				->row();
		}

		return $this->_currentRun;
	}
1034345
public function importFromCore() {
		if (!empty($this->request->query['reset'])) {
			$this->Languages->truncate();
		}
		//$languages = $this->Languages->iso3ToIso2();
		$languages = $this->Languages->catalog();
		$count = 0;
		$errors = [];
		foreach ($languages as $language) {
			if (!($code = $this->Languages->iso3ToIso2($language['localeFallback']))) {
				$code = '';
			}
			$data = [
				'name' => $language,
				'ori_name' => $language,
				'code' => $code,
				'locale' => $language['locale'],
				'locale_fallback' => $language['localeFallback'],
				'direction' => $language['direction']
			];
			$language = $this->Languages->newEntity($data);
			if ($this->Languages->save($language)) {
				$count++;
			} else {
				$errors[] = ['data' => $language, 'errors' => $this->Languages->validationErrors];
			}
		}

		$this->Flash->success($count . ' of ' . count($languages) . ' ' . __('languages added'));

		$errorMessage = [];
		foreach ($errors as $error) {
			$errorMessage[] = $error['data'] . ' (' . returns($error['errors']) . ')';
		}
		$this->Flash->warning(__('not added') . ' ' . implode(', ', $errorMessage));
		return $this->redirect(['action' => 'index']);
	}
891101
public function hasCompleteExportIgnores()
    {
        $expectedExportIgnores = $this->collectExpectedExportIgnores();

        if ($expectedExportIgnores === [] || $this->hasGitattributesFile() === false) {
            return false;
        }

        $actualExportIgnores = $this->getPresentExportIgnores();

        if ($this->isStrictAlignmentCamparisonEnabled()) {
            $expectedExportIgnores = $this->getAlignedExportIgnoreArtifacts(
                $expectedExportIgnores
            );
        }

        return array_values($expectedExportIgnores) === array_values($actualExportIgnores);
    }
273299
public function importAction()
	{
		$cntl = $this->createAdmin();

		if( ( $html = $cntl->import() ) == '' ) {
			return $this->setPsrResponse( $cntl->getView()->response() );
		}

		$this->view->assign( 'content', $html );
	}
644807
protected function UpdateMainScroeValue()
    {
        $bRet = false;
        $sQuery = " SELECT AVG( `score` ) AS main_score FROM `pkg_shop_rating_service_rating` WHERE `pkg_shop_rating_service_id` = '".$this->id."' ";
        $rs = MySqlLegacySupport::getInstance()->query($sQuery);
        if ($rs) {
            $oAVG = MySqlLegacySupport::getInstance()->fetch_object($rs);
        }

        //Update value
        if ($oAVG->main_score > 0) {
            $sQuery = "UPDATE pkg_shop_rating_service SET current_rating = '".$oAVG->main_score."', current_rating_date = NOW() WHERE id = '".$this->id."' ";
            MySqlLegacySupport::getInstance()->query($sQuery);
            $bRet = $oAVG->main_score;
        }

        return $bRet;
    }
953191
public function addRating(Rating $rating): bool
    {
        $response = $this->parent->performAPICall(
            'put',
            'user/ratings/'.$rating->getRatingType().'/'.$rating->ratingItemId.'/'.$rating->rating
        );
        return $response->getStatusCode() === 200;
    }
639172
public function import()
    {
        switch ($this->serviceGroupType) {
            case ServiceTypeGroups::DATABASE:
                $header = $this->getHeader();
                if ($this->createDbTableFromHeader($header)) {
                    try {
                        $this->importData();

                        return true;
                    } catch (\Exception $e) {
                        $this->revert();

                        throw $e;
                    }
                }
                break;
            default:
                throw new BadRequestException(
                    'Importing resource(s) to service type group [' . $this->serviceGroupType . '] ' .
                    'is not currently supported.'
                );
        }
    }
827510
public function getReviews()
    {
        if ($this->_aReviews === null) {
            $this->_aReviews = false;
            if ($oObject = $this->_getActiveObject()) {
                $this->_aReviews = $oObject->getReviews();
            }
        }

        return $this->_aReviews;
    }
479790
public static function add_rating_returns() {

        return new external_single_structure(
            array(
                'success' => new external_value(PARAM_BOOL, 'Whether the rate was successfully created'),
                'aggregate' => new external_value(PARAM_TEXT, 'New aggregate', VALUE_OPTIONAL),
                'count' => new external_value(PARAM_INT, 'Ratings count', VALUE_OPTIONAL),
                'itemid' => new external_value(PARAM_INT, 'Rating item id', VALUE_OPTIONAL),
                'warnings'  => new external_warnings(),
            )
        );
    }
1104434
public function import_calculated($question) {

        // Get common parts.
        $qo = $this->import_headers($question);

        // Header parts particular to calculated.
        $qo->qtype = 'calculated';
        $qo->synchronize = $this->getpath($question, array('#', 'synchronize', 0, '#'), 0);
        $single = $this->getpath($question, array('#', 'single', 0, '#'), 'true');
        $qo->single = $this->trans_single($single);
        $shuffleanswers = $this->getpath($question, array('#', 'shuffleanswers', 0, '#'), 'false');
        $qo->answernumbering = $this->getpath($question,
                array('#', 'answernumbering', 0, '#'), 'abc');
        $qo->shuffleanswers = $this->trans_single($shuffleanswers);

        $this->import_combined_feedback($qo, $question);

        $qo->unitgradingtype = $this->getpath($question,
                array('#', 'unitgradingtype', 0, '#'), 0);
        $qo->unitpenalty = $this->getpath($question, array('#', 'unitpenalty', 0, '#'), null);
        $qo->showunits = $this->getpath($question, array('#', 'showunits', 0, '#'), 0);
        $qo->unitsleft = $this->getpath($question, array('#', 'unitsleft', 0, '#'), 0);
        $qo->instructions = $this->getpath($question,
                array('#', 'instructions', 0, '#', 'text', 0, '#'), '', true);
        if (!empty($instructions)) {
            $qo->instructions = $this->import_text_with_files($instructions,
                    array('0'), '', $this->get_format($qo->questiontextformat));
        }

        // Get answers array.
        $answers = $question['#']['answer'];
        $qo->answer = array();
        $qo->feedback = array();
        $qo->fraction = array();
        $qo->tolerance = array();
        $qo->tolerancetype = array();
        $qo->correctanswerformat = array();
        $qo->correctanswerlength = array();
        $qo->feedback = array();
        foreach ($answers as $answer) {
            $ans = $this->import_answer($answer, true, $this->get_format($qo->questiontextformat));
            // Answer outside of <text> is deprecated.
            if (empty($ans->answer['text'])) {
                $ans->answer['text'] = '*';
            }
            $qo->answer[] = $ans->answer['text'];
            $qo->feedback[] = $ans->feedback;
            $qo->tolerance[] = $answer['#']['tolerance'][0]['#'];
            // Fraction as a tag is deprecated.
            if (!empty($answer['#']['fraction'][0]['#'])) {
                $qo->fraction[] = $answer['#']['fraction'][0]['#'];
            } else {
                $qo->fraction[] = $answer['@']['fraction'] / 100;
            }
            $qo->tolerancetype[] = $answer['#']['tolerancetype'][0]['#'];
            $qo->correctanswerformat[] = $answer['#']['correctanswerformat'][0]['#'];
            $qo->correctanswerlength[] = $answer['#']['correctanswerlength'][0]['#'];
        }
        // Get units array.
        $qo->unit = array();
        if (isset($question['#']['units'][0]['#']['unit'])) {
            $units = $question['#']['units'][0]['#']['unit'];
            $qo->multiplier = array();
            foreach ($units as $unit) {
                $qo->multiplier[] = $unit['#']['multiplier'][0]['#'];
                $qo->unit[] = $unit['#']['unit_name'][0]['#'];
            }
        }
        $instructions = $this->getpath($question, array('#', 'instructions'), array());
        if (!empty($instructions)) {
            $qo->instructions = $this->import_text_with_files($instructions,
                    array('0'), '', $this->get_format($qo->questiontextformat));
        }

        if (is_null($qo->unitpenalty)) {
            // Set a good default, depending on whether there are any units defined.
            if (empty($qo->unit)) {
                $qo->showunits = 3; // This is qtype_numerical::UNITNONE, but we cannot refer to that constant here.
            } else {
                $qo->showunits = 0; // This is qtype_numerical::UNITOPTIONAL, but we cannot refer to that constant here.
            }
        }

        $datasets = $question['#']['dataset_definitions'][0]['#']['dataset_definition'];
        $qo->dataset = array();
        $qo->datasetindex= 0;
        foreach ($datasets as $dataset) {
            $qo->datasetindex++;
            $qo->dataset[$qo->datasetindex] = new stdClass();
            $qo->dataset[$qo->datasetindex]->status =
                    $this->import_text($dataset['#']['status'][0]['#']['text']);
            $qo->dataset[$qo->datasetindex]->name =
                    $this->import_text($dataset['#']['name'][0]['#']['text']);
            $qo->dataset[$qo->datasetindex]->type =
                    $dataset['#']['type'][0]['#'];
            $qo->dataset[$qo->datasetindex]->distribution =
                    $this->import_text($dataset['#']['distribution'][0]['#']['text']);
            $qo->dataset[$qo->datasetindex]->max =
                    $this->import_text($dataset['#']['maximum'][0]['#']['text']);
            $qo->dataset[$qo->datasetindex]->min =
                    $this->import_text($dataset['#']['minimum'][0]['#']['text']);
            $qo->dataset[$qo->datasetindex]->length =
                    $this->import_text($dataset['#']['decimals'][0]['#']['text']);
            $qo->dataset[$qo->datasetindex]->distribution =
                    $this->import_text($dataset['#']['distribution'][0]['#']['text']);
            $qo->dataset[$qo->datasetindex]->itemcount = $dataset['#']['itemcount'][0]['#'];
            $qo->dataset[$qo->datasetindex]->datasetitem = array();
            $qo->dataset[$qo->datasetindex]->itemindex = 0;
            $qo->dataset[$qo->datasetindex]->number_of_items = $this->getpath($dataset,
                    array('#', 'number_of_items', 0, '#'), 0);
            $datasetitems = $this->getpath($dataset,
                    array('#', 'dataset_items', 0, '#', 'dataset_item'), array());
            foreach ($datasetitems as $datasetitem) {
                $qo->dataset[$qo->datasetindex]->itemindex++;
                $qo->dataset[$qo->datasetindex]->datasetitem[
                        $qo->dataset[$qo->datasetindex]->itemindex] = new stdClass();
                $qo->dataset[$qo->datasetindex]->datasetitem[
                        $qo->dataset[$qo->datasetindex]->itemindex]->itemnumber =
                                $datasetitem['#']['number'][0]['#'];
                $qo->dataset[$qo->datasetindex]->datasetitem[
                        $qo->dataset[$qo->datasetindex]->itemindex]->value =
                                $datasetitem['#']['value'][0]['#'];
            }
        }

        $this->import_hints($qo, $question, false, false, $this->get_format($qo->questiontextformat));

        return $qo;
    }
179997
public function init() {
        if ($this->csvreader == null) {
            $this->csvreader = new csv_import_reader($this->importid, 'assignfeedback_offline');
        }
        $this->csvreader->init();

        $columns = $this->csvreader->get_columns();

        $strgrade = get_string('grade');
        $strid = get_string('recordid', 'assign');
        $strmodified = get_string('lastmodifiedgrade', 'assign');

        foreach ($this->assignment->get_feedback_plugins() as $plugin) {
            if ($plugin->is_enabled() && $plugin->is_visible()) {
                foreach ($plugin->get_editor_fields() as $field => $description) {
                    $this->feedbackcolumnindexes[$description] = array('plugin'=>$plugin,
                                                                       'field'=>$field,
                                                                       'description'=>$description);
                }
            }
        }

        if ($columns) {
            foreach ($columns as $index => $column) {
                if (isset($this->feedbackcolumnindexes[$column])) {
                    $this->feedbackcolumnindexes[$column]['index'] = $index;
                }
                if ($column == $strgrade) {
                    $this->gradeindex = $index;
                }
                if ($column == $strid) {
                    $this->idindex = $index;
                }
                if ($column == $strmodified) {
                    $this->modifiedindex = $index;
                }
            }
        }

        if ($this->idindex < 0 || $this->gradeindex < 0 || $this->modifiedindex < 0) {
            return false;
        }

        $groupmode = groups_get_activity_groupmode($this->assignment->get_course_module());
        // All users.
        $groupid = 0;
        $groupname = '';
        if ($groupmode) {
            $groupid = groups_get_activity_group($this->assignment->get_course_module(), true);
            $groupname = groups_get_group_name($groupid).'-';
        }
        $this->validusers = $this->assignment->list_participants($groupid, false);
        return true;
    }
783372
public function installMigration()
    {
        $name = $this->getParsedNameInput();

        $migrationDir = base_path() . '/database/migrations/';
        $migrationName = 'create_' . str_plural(snake_case($name)) .'_table.php';
        $migrationStub = new SplFileInfo(__DIR__ . '/../stubs/Model/migration.stub');

        $files = $this->files->allFiles($migrationDir);

        foreach ($files as $file) {
            if(str_contains($file->getFilename(), $migrationName)) {
                $this->putFile($file->getPathname(), $migrationStub);

                return true;
            }
        }

        $path = $migrationDir . date('Y_m_d_His') . '_' . $migrationName;
        $this->putFile($path, $migrationStub);

        return true;
    }
216104
public function import_from_client() {
        if(!Permission::check('ADMIN')) {
            Security::permissionFailure($this);
            return;
        }
        
        $form=$this->ImportFromClientForm();
        if(Session::get('reloadOnImportDialogClose')) {
            Requirements::javascript(CB_DIR.'/javascript/CodeBank.ImportDialog.js');
            Session::clear('reloadOnImportDialogClose');
        }
        
        return $this->customise(array(
                                    'Content'=>' ',
                                    'Form'=>$form
                                ))->renderWith('CMSDialog');
    }
1342740
protected function import(&$out)
    {
        $s = $this->seek();
        if (!$this->literal('@import')) {
            return false;
        }

        // @import "something.css" media;
        // @import url("something.css") media;
        // @import url(something.css) media;

        if ($this->propertyValue($value)) {
            $out = array('import', $value);

            return true;
        }
    }
913756
public function data()
    {
        $ratings = RatingTotalModel::with([
            'rateable' => function ($query) {
                $query->with(['ratings', 'ratingTotal'])->select(['id', 'title', 'slug']);
            }])->get();

        $ratings = $ratings->filter(function ($value, $key) {
            return isset($value->rateable);
        });

        $resource = (new RatingTransformer())->transformCollection($ratings);

        return DataTables::of(collect($this->serializeToArray($resource)))
            ->rawColumns(['actions'])
            ->make();
    }