Set the Goal for the MemberCampaign.

@return bool
438906
public function defineGoal() {
    /**
     * To test generate Members, create MemberCampaign record and run code in /devel/php
     *
     * $entity = \Drupal\openy_campaign\Entity\MemberCampaign::load(1);
     * $entity->defineGoal();
     *
     * Needs actual data in order to proceed.
     */

    /** @var \Drupal\node\Entity\Node $campaign Current campaign */
    $campaign = $this->getCampaign();

    // Get all enabled activities list.
    $activitiesOptions = openy_campaign_get_enabled_activities($campaign);

    // For disabled Visits Goal activity.
    if (!in_array('field_prgf_activity_visits', $activitiesOptions)) {
      $this->setGoal(0);
      return TRUE;
    }

    $current = new \DateTime();
    $from = new \DateTime($campaign->field_goal_check_ins_start_date->value);
    $to = new \DateTime($campaign->field_goal_check_ins_end_date->value);

    // We should not call CRM for the future date.
    if ($current < $to) {
      $to = $current;
    }

    $member = $this->getMember();

    /** @var $client \Drupal\openy_campaign\CRMClientInterface */
    $client = \Drupal::getContainer()->get('openy_campaign.client_factory')->getClient();
    // Get total visits from CRM.
    $results = $client->getVisitCountByDate($member->getPersonifyId(), $from, $to);

    $visitsNumber = $results->TotalVisits;

    // Visits goal will be between these 2 values.
    $maxVisitsGoal = $campaign->field_limit_visits_goal->value;
    $minVisitsGoal = $campaign->field_min_visits_goal->value;

    $weeksSpan = ceil($from->diff($to)->days / 7);

    $calculatedGoal = ceil(2 * $visitsNumber / $weeksSpan) + 1;
    $visitsGoal = max($minVisitsGoal, $calculatedGoal);

    $goal = min($visitsGoal, $maxVisitsGoal);

    $this->setGoal($goal);

    return TRUE;
  }
1073272
protected function setWhere()
    {
        $foreign = $this->getForeignKey();

        $this->query->where($foreign, '=', $this->parent->getKey());

        return $this;
    }
1134468
protected function doExecute()
    {
        $paths = $this->getArgument(0);

        $paths = Arr::toArray($paths);

        if ($paths === []) {
            $p = $this->getOption('p');

            $dir = ConsoleHelper::getAllPackagesResolver()->getPackage($p)->getDir();

            $paths = [
                $dir . '/routing.yml',
                $dir . '/Resources/routing/**/*.yml'
            ];
        }

        $files = [];

        foreach ($paths as $path) {
            $files[] = \Windwalker\glob($path);
        }

        $files = array_merge(...$files);

        foreach ($files as $file) {
            $this->convert($file);
        }

        return true;
    }
1013663
private function setLimit()
    {
        if (isset($this->requestParams['start']) && -1 != $this->requestParams['length']) {
            $this->qb->setFirstResult($this->requestParams['start'])->setMaxResults($this->requestParams['length']);
        }

        return $this;
    }
936802
public function beginTransaction(): bool
    {
        if(!$this->inTransaction())
        {
            $result = $this->instance->beginTransaction();
            if(!$result)
            {
                return $result;
            }
        }
        $this->exec('SAVEPOINT P' . $this->getTransactionLevels());
        $this->__tBeginTransaction();
        return true;
    }
1062226
public function setCreditPointsForInviter()
    {
        $blSet = false;
        $iPoints = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('dPointsForInvitation');
        if ($iPoints) {
            $iNewPoints = $this->oxuser__oxpoints->value + $iPoints;
            $this->oxuser__oxpoints = new Field($iNewPoints, Field::T_RAW);
            $blSet = $this->save();
        }

        return $blSet;
    }
622985
public static function incrementStep()
    {
        if (self::isLastStep()) {
            return;
        }
        $next = self::classNameNumber() + 1;
        if ($next == 1) {
            $next++;
        }
        return self::setCurrentStep($next);
    }
1155198
public function setTargetfile()
	{
		//set the upload_path_relative
		$this->upload_path_relative = $this->upload_path . $this->target_file_name;

		//set the full target file path
		$this->target_file = $this->target_dir . $this->target_file_name;

		return $this;

	}
66983
public function setRequirements()
    {
        if (!isset($this->options['requirements']) || $this->options['requirements'] === null) {
            return $this;
        }

        $requirements = $this->options['requirements'];

        if (!is_array($requirements)) {
            $requirements = [$requirements];
        }

        foreach ($requirements as $constraint) {
            $this->requirements[] = $constraint;
        }

        unset($this->options['requirements']);

        return $this;
    }
1221781
public function main()
    {
        $this->info('Task: assign all users to the default group');
        $this->hr();

        // Read default group from configuration
        $groupName = (string)Configure::read('Groups.defaultGroup');
        if (empty($groupName)) {
            $this->warn("Default group is not configured.  Nothing to do.");

            return true;
        }

        /**
         * @var \Groups\Model\Table\GroupsTable $table
         */
        $table = TableRegistry::get('Groups.Groups');
        /**
         * Get default group entity.
         *
         * @var \Cake\Datasource\EntityInterface|null
         */
        $group = $table->find()
            ->where(['name' => $groupName])
            ->enableHydration(true)
            ->first();
        if (null === $group) {
            $this->warn("Default group [$groupName] does not exist.  Nothing to do.");

            return true;
        }

        // Get all user IDs
        $users = $table->Users->find('all', [
            'fields' => ['id'],
        ])->toArray();
        if (empty($users)) {
            $this->abort("No users found in the system.  Something is terribly wrong!");
        }

        // Assign all users to the group
        $result = $table->Users->replaceLinks($group, $users);
        if (!$result) {
            $this->abort("Failed to add all users to group [$groupName].");
        }

        $this->success("All users are now assigned to group [$groupName].");
    }
1035388
public function setGroup()
    {
        // set group position if exist

        $group = [];

        foreach ($this->data['group'] as $table => $params) {

            $params = array_flip($params);

            if (empty($params) === false) {

                foreach ($params as $field) {
                    $group[] = $table . '.' . $field;
                }
            }
        }
        $this->builder->groupBy($group);

        return null;
    }
189081
protected function setSearchCriteriaFromPost()
    {
        $this->initSearchCriteria();

        foreach ($this->aCriteria as $sIndex => $mValue) {
            $this->aCriteria[$sIndex] = $this->app['request']->request->get($sIndex, $mValue);
        }
    }
1047206
public function commit() : bool
    {
        return $this->isConnected() && $this->getConnection()->inTransaction() && $this->getConnection()->commit();
    }
126773
final public function setEnvironmentValue()
    {
        /**
         * Env file existence is verified in the controller.
         */
        $this->config()->setEnv(trim((string)file_get_contents($this->projectPath . '.env')));

        return true;
    }
1314961
public function persist()
    {
        try {
            return $this
                ->collectCloverXml()
                ->collectGitInfo()
                ->collectEnvVars()
                ->dumpJsonFile()
                ->send();
        } catch (\PhpCoveralls\Bundle\CoverallsBundle\Entity\Exception\RequirementsNotSatisfiedException $e) {
            $this->logger->error(sprintf('%s', $e->getHelpMessage()));

            return false;
        } catch (\Exception $e) {
            $this->logger->error(sprintf("%s\n\n%s", $e->getMessage(), $e->getTraceAsString()));

            return false;
        }
    }
43256
public function setDone() {
        $migration = $this->getMigration();
        if ($migration['state']) {
            return true; //alredy done
        }
        $this->db()->update($this->table, array('state' => true), array('id' => $migration['id']));
    }
945368
private function setCCI()
    {
        $cci = $this->mailable->get('_cci');

        if (!is_null($cci)) {
            foreach ($cci as $mail) {
                $this->message->setBcc($mail);
            }
        }
    }