OrderStepFeedback::myDescription()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 *
5
 * 1 July bough
6
 * +10 days start sending
7
 * +20 days stop sending
8
 * SO
9
 * on 11 July
10
 * 1 July + 10 < Now
11
 * 1 July + 20 > Now
12
 *
13
 */
14
15
16
/**
17
 *
18
 * 1 July bought
19
 * +10 days start sending
20
 * +20 days stop sending
21
 * SO
22
 * on 11 July
23
 * 1 July + 10 < Now
24
 * 1 July + 20 > Now
25
 *
26
 */
27
28
29
class OrderStepFeedback extends OrderStep
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
30
{
31
    private static $verbose = false;
0 ignored issues
show
Unused Code introduced by
The property $verbose is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
32
33
    /**
34
     * @var String
35
     */
36
    protected $emailClassName = "OrderStepFeedback_Email";
37
38
    private static $db = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
39
        'SendFeedbackEmail' => 'Boolean',
40
        'MinDays' => 'Int',
41
        'MaxDays' => 'Int',
42
        'MessageAfterProductsList' => 'HTMLText',
43
        'LinkText' => 'Varchar'
44
    );
45
46
    private static $defaults = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $defaults is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
47
        'CustomerCanEdit' => 0,
48
        'CustomerCanCancel' => 0,
49
        'CustomerCanPay' => 0,
50
        'Name' => 'Get Feedback',
51
        'Code' => 'FEEDBACK',
52
        "ShowAsInProcessOrder" => true,
53
        "HideStepFromCustomer" => true,
54
        'SendFeedbackEmail' => true,
55
        'MinDays' => 10,
56
        'MaxDays' => 20
57
    );
58
59
60
    public function getCMSFields()
61
    {
62
        $fields = parent::getCMSFields();
63
        $fields->addFieldsToTab(
64
            'Root.CustomerMessage',
65
            array(
66
                CheckboxField::create('SendFeedbackEmail', 'Send feedback email to customer?'),
67
                $minDaysField = NumericField::create('MinDays', "<strong>Min Days</strong> before sending"),
68
                $maxDaysField = NumericField::create('MaxDays', "<strong>Max Days</strong> before sending")
69
            ),
70
            "EmailSubject"
71
        );
72
        $minDaysField->setRightTitle('What is the <strong>mininum number of days to wait after completing an order</strong> before this email should be sent?');
73
        $maxDaysField->setRightTitle(
74
            '
75
            What is the <strong>maxinum number of days to wait after completing an order</strong> before this email should be sent?<br>
76
            <strong>If set to zero, this step will be ignored.</strong>'
77
        );
78
        $fields->addFieldsToTab(
79
            'Root.CustomerMessage',
80
            array(
81
                HTMLEditorField::create(
82
                    'MessageAfterProductsList',
83
                    _t('OrderStepFeedback.MESSAGEAFTERPRODUCTSLIST', 'Message After Products List')
84
                )->setRightTitle(
85
                    'Optional message displayed after the list of products'
86
                )->setRows(3),
87
                TextField::create(
88
                    'LinkText',
89
                    _t('OrderStepFeedback.BUTTONTEXT', 'Link Text')
90
                )->setRightTitle('This is the text displayed on the "order again" link/button')
91
            )
92
        );
93
        if ($this->MinDays) {
0 ignored issues
show
Documentation introduced by
The property MinDays does not exist on object<OrderStepFeedback>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
94
            $fields->replaceField(
95
                'DeferTimeInSeconds',
96
                $fields->dataFieldByName('DeferTimeInSeconds')->performReadonlyTransformation()
97
            );
98
        }
99
        return $fields;
100
    }
101
102
    public function initStep(Order $order)
103
    {
104
        if ($this->SendFeedbackEmail) {
0 ignored issues
show
Documentation introduced by
The property SendFeedbackEmail does not exist on object<OrderStepFeedback>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
105
            Config::inst()->update("OrderStep", "number_of_days_to_send_update_email", $this->MaxDays);
0 ignored issues
show
Documentation introduced by
The property MaxDays does not exist on object<OrderStepFeedback>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
106
        }
107
        return true;
108
    }
109
110
    public function doStep(Order $order)
111
    {
112
        //ignore altogether?
113
        if ($this->SendFeedbackEmail) {
0 ignored issues
show
Documentation introduced by
The property SendFeedbackEmail does not exist on object<OrderStepFeedback>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
114
            // too late to send
115
            if ($this->isExpiredFeedbackStep($order)) {
116
                if ($this->Config()->get("verbose")) {
117
                    DB::alteration_message(" - Time to send feedback is expired");
118
                }
119
                return true;
120
            }
121
            //is now the right time to send?
122
            elseif ($this->isReadyToGo($order)) {
123
                $subject = $this->EmailSubject;
0 ignored issues
show
Documentation introduced by
The property EmailSubject does not exist on object<OrderStepFeedback>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
124
                $message = $this->CustomerMessage;
0 ignored issues
show
Documentation introduced by
The property CustomerMessage does not exist on object<OrderStepFeedback>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
125
                if ($this->hasBeenSent($order, false)) {
126
                    if ($this->Config()->get("verbose")) {
127
                        DB::alteration_message(" - already sent!");
128
                    }
129
                    return true; //do nothing
130
                } else {
131
                    if ($this->Config()->get("verbose")) {
132
                        DB::alteration_message(" - Sending it now!");
133
                    }
134
                    return $order->sendEmail(
135
                        $this->getEmailClassName(),
136
                        $subject,
137
                        $message,
138
                        $resend = false,
139
                        $adminOnlyOrToEmail = false
140
                    );
141
                }
142
            }
143
            //wait until later....
144
            else {
145
                if ($this->Config()->get("verbose")) {
146
                    DB::alteration_message(" - We need to wait until minimum number of days.");
147
                }
148
                return false;
149
            }
150
        } else {
151
            return true;
152
        }
153
    }
154
155
    /**
156
     * can continue if emails has been sent or if there is no need to send a receipt.
157
     * @param DataObject $order Order
158
     * @return DataObject | Null - DataObject = next OrderStep
0 ignored issues
show
Documentation introduced by
Should the return type not be OrderStep|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
159
     **/
160
    public function nextStep(Order $order)
161
    {
162
        if (
163
            ! $this->SendFeedbackEmail ||
0 ignored issues
show
Documentation introduced by
The property SendFeedbackEmail does not exist on object<OrderStepFeedback>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
164
             $this->hasBeenSent($order, false) ||
165
             $this->isExpiredFeedbackStep($order)
166
        ) {
167
            if ($this->Config()->get("verbose")) {
168
                DB::alteration_message(" - Moving to next step");
169
            }
170
            return parent::nextStep($order);
171
        }
172
        if ($this->Config()->get("verbose")) {
173
            DB::alteration_message(" - no next step: has not been sent");
174
        }
175
        return null;
176
    }
177
178
    /**
179
     * For some ordersteps this returns true...
180
     * @return Boolean
181
     **/
182
    protected function hasCustomerMessage()
183
    {
184
        return true;
185
    }
186
187
    /**
188
     * Explains the current order step.
189
     * @return String
190
     */
191
    protected function myDescription()
192
    {
193
        return "The customer is sent a feedback request email.";
194
    }
195
196
    /**
197
     * returns true if the Minimum number of days is met....
198
     * @param Order
199
     * @return Boolean
200
     */
201
    protected function isReadyToGo(Order $order)
202
    {
203
        if ($this->MinDays) {
0 ignored issues
show
Documentation introduced by
The property MinDays does not exist on object<OrderStepFeedback>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
204
            $log = $order->SubmissionLog();
205
            if ($log) {
206
                $createdTS = strtotime($log->Created);
207
                $nowTS = strtotime('now');
208
                $startSendingTS = strtotime("+{$this->MinDays} days", $createdTS);
0 ignored issues
show
Documentation introduced by
The property MinDays does not exist on object<OrderStepFeedback>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
209
                //current TS = 10
210
                //order TS = 8
211
                //add 4 days: 12
212
                //thus if 12 <= now then go for it (start point in time has passed)
213
                if ($this->Config()->get("verbose")) {
214
                    DB::alteration_message("Time comparison: Start Sending TS: ".$startSendingTS." current TS: ".$nowTS.". If SSTS > NowTS then Go for it.");
215
                }
216
                return ($startSendingTS <= $nowTS) ? true : false;
217
            } else {
218
                user_error("can not find order log for ".$order->ID);
219
                return false;
220
            }
221
        } else {
222
            //send immediately
223
            return true;
224
        }
225
    }
226
227
    /**
228
     * returns true if it is too late to send the feedback step
229
     * @param Order
230
     * @return Boolean
231
     */
232
    protected function isExpiredFeedbackStep(Order $order)
233
    {
234
        if ($this->MaxDays) {
0 ignored issues
show
Documentation introduced by
The property MaxDays does not exist on object<OrderStepFeedback>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
235
            $log = $order->SubmissionLog();
236
            if ($log) {
237
                $createdTS = strtotime($log->Created);
238
                $nowTS = strtotime('now');
239
                $stopSendingTS = strtotime("+{$this->MaxDays} days", $createdTS);
0 ignored issues
show
Documentation introduced by
The property MaxDays does not exist on object<OrderStepFeedback>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
240
                return ($stopSendingTS < $nowTS) ? true : false;
241
            } else {
242
                user_error("can not find order log for ".$order->ID);
243
                return false;
244
            }
245
        } else {
246
            return true;
247
        }
248
    }
249
250
    public function hasBeenSent(Order $order, $checkDateOfOrder = true)
251
    {
252
        return OrderEmailRecord::get()->filter(
253
            array(
254
                "OrderEmailRecord.OrderID" => $order->ID,
255
                "OrderEmailRecord.OrderStepID" => $this->ID,
256
                "OrderEmailRecord.Result" => 1
257
            )
258
        )->count() ? true : false;
259
    }
260
261
262
    /**
263
     * Event handler called before writing to the database.
264
     */
265
    public function onBeforeWrite()
266
    {
267
        parent::onBeforeWrite();
268
        $deferTime = $this->MinDays * 86400;
0 ignored issues
show
Documentation introduced by
The property MinDays does not exist on object<OrderStepFeedback>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
269
        if ($this->DeferTimeInSeconds < $deferTime) {
0 ignored issues
show
Documentation introduced by
The property DeferTimeInSeconds does not exist on object<OrderStepFeedback>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
270
            $this->DeferTimeInSeconds = $deferTime;
0 ignored issues
show
Documentation introduced by
The property DeferTimeInSeconds does not exist on object<OrderStepFeedback>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
271
        }
272
    }
273
}
274