SmartChimpNewsletter::ShowOrHide()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 0
1
<?php
2
3
/*
4
 *@author: nicolaas [at] sunny side up . co . nz
5
 *
6
 **/
7
8
9
class SmartChimpNewsletter extends DataObject
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...
10
{
11
    public static $has_one = array(
12
        "Parent" => "SmartChimpSignupPage"
13
    );
14
15
    public static $db = array(
16
        "Hide" => "Boolean",
17
        "CampaignID" => "Varchar(30)",//id
18
        "Date" => "Datetime",//send_time
19
        "Title" => "Varchar(255)",//title
20
        "Subject" => "Varchar(255)",//title
21
        "PermaLink" => "Varchar(255)",//archive_url
22
        "WebID" => "Int", //web_id
23
        "Status" => "Varchar(20)", //should be sent!
24
        "TextContent" => "Text", //html
25
        "HTMLContent" => "HTMLText", //text
26
        "Done" => "Boolean"
27
    );
28
29
    
30
31
    public static $indexes = array(
32
        "CampaignID" => true
33
    );
34
35
    public static $casting = array(
36
        "DateNice" => "Text",
37
        "ShowOrHide" => "Text",
38
        "YearMonth" => "Int",
39
        "Month" => "Int",
40
        "Link" => "Text"
41
    );
42
43
    public function getYearMonth()
44
    {
45
        return $this->obj('Date')->format("F")." ".$this->obj('Date')->format("Y");
46
    }
47
48
    public function getDateNice()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
49
    {
50
        return $this->obj('Date')->Long();
51
    }
52
53
    public function ShowOrHide()
54
    {
55
        return $this->Hide ? "hide" : "show";
0 ignored issues
show
Documentation introduced by
The property Hide does not exist on object<SmartChimpNewsletter>. 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...
56
    }
57
58
    public function Link()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
59
    {
60
        return str_replace('&amp;', '&', $this->PermaLink);
0 ignored issues
show
Documentation introduced by
The property PermaLink does not exist on object<SmartChimpNewsletter>. 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...
61
    }
62
63
    public function requiredDefaultRecords()
64
    {
65
        parent::requiredDefaultRecords();
0 ignored issues
show
Bug introduced by
The method requiredDefaultRecords() does not exist on DataObject. Did you maybe mean requireDefaultRecords()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
66
    }
67
    public static $default_sort = "\"Date\" DESC";
68
    public static $defaults = array();//use fieldName => Default Value
69
    public static $searchable_fields = array("Title" => "PartialMatchFilter");
70
    public static $field_labels = array("Title" => "Title");
71
    public static $summary_fields = array("Title" => "Title", "DateNice" => "Date", "ShowOrHide" => "ShowOrHide");
72
    public static $singular_name = "MailChimp Newsletter";
73
    public static $plural_name = "MailChimp Newsletters";
74
75
    public static function clean_up_characters()
76
    {
77
        DB::query("UPDATE `SmartChimpNewsletter` SET `TextContent` = REPLACE(`TextContent`,'’','\'');");
78
        DB::query("UPDATE `SmartChimpNewsletter` SET `TextContent` = REPLACE(`TextContent`,'…','');");
79
        DB::query("UPDATE `SmartChimpNewsletter` SET `TextContent` = REPLACE(`TextContent`,'“','\"');");
80
        DB::query("UPDATE `SmartChimpNewsletter` SET `TextContent` = REPLACE(`TextContent`,'“','\"');");
81
        DB::query("UPDATE `SmartChimpNewsletter` SET `TextContent` = REPLACE(`TextContent`,'–','-');");
82
        DB::query("UPDATE `SmartChimpNewsletter` SET `TextContent` = REPLACE(`TextContent`,'�','\"');");
83
        DB::query("UPDATE `SmartChimpNewsletter` SET `TextContent` = REPLACE(`TextContent`,'� ','\"');");
84
    }
85
86
    public static $field_types = array(
87
        "CampaignID" => "TextField",//id
88
        "Date" => "TextField",//send_time
89
        "Title" => "TextField",//title
90
        "Subject" => "TextField",//title
91
        "PermaLink" => "TextField",//archive_url
92
        "WebID" => "NumericField", //web_id
93
        "Status" => "TextField", //should be sent!
94
        "TextContent" => "TextareaField", //html
95
        "HTMLContent" => "TextareaField", //text
96
        "Done" => "CheckboxField"
97
    );
98
}
99