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;
  }
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;
  }
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 ; }
Set the Goal for the MemberCampaign.

@return bool
Set the Goal for the MemberCampaign .