Set plan trial

@param  boolean  $enable
@param  int  $days
@param  boolean  $hold_setup_fee
@return $this
181193
public function setTrial($enable = false, $days = null, $hold_setup_fee = false)
    {
        $this->data->trial = new stdClass;
        $this->data->trial->enabled = (boolean) $enable;
        $this->data->trial->days = $days;
        $this->data->trial->hold_setup_fee = (boolean) $hold_setup_fee;

        return $this;
    }
892644
function start_trial( $plan_name = false ) {
            $this->_logger->entrance();

            // Alias.
            $oops_text = $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...';

            if ( $this->is_trial() ) {
                // Already in trial mode.
                $this->_admin_notices->add(
                    sprintf( $this->get_text_inline( 'You are already running the %s in a trial mode.', 'in-trial-mode' ), $this->_module_type ),
                    $oops_text,
                    'error'
                );

                return false;
            }

            if ( $this->_site->is_trial_utilized() ) {
                // Trial was already utilized.
                $this->_admin_notices->add(
                    $this->get_text_inline( 'You already utilized a trial before.', 'trial-utilized' ),
                    $oops_text,
                    'error'
                );

                return false;
            }

            if ( false !== $plan_name ) {
                $plan = $this->get_plan_by_name( $plan_name );

                if ( false === $plan ) {
                    // Plan doesn't exist.
                    $this->_admin_notices->add(
                        sprintf( $this->get_text_inline( 'Plan %s do not exist, therefore, can\'t start a trial.', 'trial-plan-x-not-exist' ), $plan_name ),
                        $oops_text,
                        'error'
                    );

                    return false;
                }

                if ( ! $plan->has_trial() ) {
                    // Plan doesn't exist.
                    $this->_admin_notices->add(
                        sprintf( $this->get_text_inline( 'Plan %s does not support a trial period.', 'plan-x-no-trial' ), $plan_name ),
                        $oops_text,
                        'error'
                    );

                    return false;
                }
            } else {
                if ( ! $this->has_trial_plan() ) {
                    // None of the plans have a trial.
                    $this->_admin_notices->add(
                        sprintf( $this->get_text_inline( 'None of the %s\'s plans supports a trial period.', 'no-trials' ), $this->_module_type ),
                        $oops_text,
                        'error'
                    );

                    return false;
                }

                $plans_with_trial = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );

                $plan = $plans_with_trial[0];
            }

            $api  = $this->get_api_site_scope();
            $plan = $api->call( "plans/{$plan->id}/trials.json", 'post' );

            if ( ! $this->is_api_result_entity( $plan ) ) {
                // Some API error while trying to start the trial.
                $this->_admin_notices->add(
                    sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type )
                    . ' ' . var_export( $plan, true ),
                    $oops_text,
                    'error'
                );

                return false;
            }

            // Sync license.
            $this->_sync_license();

            return $this->is_trial();
        }
369207
public function setByMonthDay($day)
    {
        if (!is_integer($day) || $day > 31 || $day < -31 || $day === 0) {
            throw new InvalidArgumentException('Invalid value for BYMONTHDAY');
        }

        $this->byMonthDay = $day;

        $this->canUseBySetPos = true;

        return $this;
    }
126103
public function setEnable($enable)
    {
        $properties = $this->getProperty();
        $properties['enable'] = (boolean) $enable;
        $this->getConfig()->setSection('bundle', $properties, true);

        return $this;
    }
879960
public function addDays($days)
    {
        $days = (int) $days;
        $interval = new DateInterval('P' . abs($days) . 'D');

        if ($days < 0) {
            $interval->invert = 1;
        }

        return $this->add($interval);
    }
548794
public function setDispatchStep(string $step, $enable)
    {
        switch ($step) {
            case self::RENDER_VIEW     : $this->renderView     = (bool) $enable; break;
            case self::RENDER_LAYOUT   : $this->renderLayout   = (bool) $enable; break;
            case self::RENDER_RESPONSE : $this->renderResponse = (bool) $enable; break;
            default : throw new ArchException('Dispatch step not found');
        }
        return $this;
    }
1319985
public function allow($roles, $actions, $allow = true, $descriptions = null, $categories = null)
    {
        $this->setAuthorization($roles, $actions, $allow);

        return $this->save($descriptions, $categories);
    }
109216
public function setExpires(int $days)
    {
        $this->expires_days = $days;

        $time = strtotime('+ ' . $this->expires_days . ' days');

        $this->expires_datetime = date('Y-m-d H:i:s', $time);
        $this->expires_timestamp = $time;
    }
1031682
protected function modifyDays($amount, $invert = false)
        {
            $interval = new \DateInterval("P{$amount}D");

            $this->modifyFromInterval($interval, $invert);

            return $this;
        }
980045
public function setDateActivation($date_activation){
        if(!$this->setModified('date_activation', $date_activation)->isModified()){
            return $this;
        }
        $this->date_activation = $date_activation;

        return $this;
    }
324690
public function setDayExcluded($day, $exclude)
    {
        DateBuilder::validateDayOfMonth($day);

        $days = $this->getValue('excludeDays', []);

        if ($exclude) {
            if (false === array_search($day, $days, true)) {
                $days[] = $day;
                sort($days, SORT_NUMERIC);
            }
        } else {
            if (false !== $index = array_search($day, $days, true)) {
                unset($days[$index]);
                $days = array_values($days);
            }
        }

        $this->setValue('excludeDays', $days);
    }
1263905
public void setShowMonthItem(boolean enable) {
        if(enable && !showMonthItem) {
            // create the in 1 month item
            final Calendar date = Calendar.getInstance();
            date.add(Calendar.MONTH, 1);
            addAdapterItem(new DateItem(formatDate(date), date, R.id.date_month));
        }
        else if(!enable && showMonthItem) {
            removeAdapterItemById(R.id.date_month);
        }
        showMonthItem = enable;
    }
1136032
public function addDay($day)
    {
        $available = array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun');

        foreach ((array) $day as $value) {
            // only accept valid values
            if ( ! in_array($value, $available)) {
                throw new InvalidArgumentException('Day must be a valid value: '.implode(', ', $available));
            }

            $this->days[] = $value;
        }

        return $this;
    }
573056
public void setShowPastItems(boolean enable) {
        if(enable && !showPastItems) {
            // first reset the minimum date if necessary:
            if(getMinDate() != null && compareCalendarDates(getMinDate(), Calendar.getInstance()) == 0)
                setMinDate(null);

            // create the yesterday and last Monday item:
            final Resources res = getResources();
            final Calendar date = Calendar.getInstance();
            // yesterday:
            date.add(Calendar.DAY_OF_YEAR, -1);
            insertAdapterItem(new DateItem(res.getString(R.string.date_yesterday), date, R.id.date_yesterday), 0);
            // last weekday item:
            date.add(Calendar.DAY_OF_YEAR, -6);
            int weekday = date.get(Calendar.DAY_OF_WEEK);
            insertAdapterItem(new DateItem(getWeekDay(weekday, R.string.date_last_weekday),
                    date, R.id.date_last_week), 0);
        }
        else if(!enable && showPastItems) {
            // delete the yesterday and last weekday items:
            removeAdapterItemById(R.id.date_last_week);
            removeAdapterItemById(R.id.date_yesterday);

            // we set the minimum date to today as we don't allow past items
            setMinDate(Calendar.getInstance());
        }
        showPastItems = enable;
    }
573209
public function set($setting, $value)
    {
        switch ($setting) {
            case 'optionsTemplate':
            case 'commandsTemplate':
            case 'usageTemplate':
                call_user_func([$this, 'set' . ucfirst($setting)], $value);
                break;
            default:
                $this->settings[$setting] = $value;
                break;
        }

        return $this;
    }
695310
public function setEnableSessionStrictPolicies(string $enable_session_strict_policies = "F") : CNabuDataObject
    {
        if ($enable_session_strict_policies === null) {
            throw new ENabuCoreException(
                    ENabuCoreException::ERROR_NULL_VALUE_NOT_ALLOWED_IN,
                    array("\$enable_session_strict_policies")
            );
        }
        $this->setValue('nb_site_enable_session_strict_policies', $enable_session_strict_policies);
        
        return $this;
    }
1224295
public function enable($enable = true)
    {
        if (! is_bool($enable)) {
            throw new InvalidArgumentException("enable must be a boolean. [$enable] given.");
        }

        $this->enabled = $enable;

        return $this;
    }