- Removes unused method from the base model. Closes #511
This commit is contained in:
@@ -152,18 +152,6 @@ class Model extends \Sudzy\ValidModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static function filterSearchCustomFields($orm, $searchCriteria = array(), $searchCondition = 'AND', $searchSymbol = '=') {
|
|
||||||
$havingFields = array_filter(
|
|
||||||
array_map(function ($customField) use ($searchSymbol) {
|
|
||||||
return sprintf('`%s` %s ?', $customField['name'], $searchSymbol);
|
|
||||||
}, $searchCriteria)
|
|
||||||
);
|
|
||||||
$havingValues = array_map(function ($customField) use ($searchSymbol) {
|
|
||||||
return (strtolower($searchSymbol) === 'like') ? '%' . $customField['value'] . '%' : $customField['value'];
|
|
||||||
}, $searchCriteria);
|
|
||||||
return $orm->having_raw(implode(' ' . $searchCondition . ' ', $havingFields), array_values($havingValues));
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getPublished() {
|
static function getPublished() {
|
||||||
return static::whereNull('deleted_at');
|
return static::whereNull('deleted_at');
|
||||||
}
|
}
|
||||||
|
@@ -230,78 +230,6 @@ class NewsletterTest extends MailPoetTest {
|
|||||||
expect($newsletter->Event)->equals($association->value);
|
expect($newsletter->Event)->equals($association->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItCanFilterOptions() {
|
|
||||||
$newsletter_options = array(
|
|
||||||
array(
|
|
||||||
'name' => 'Event',
|
|
||||||
'newsletter_type' => 'welcome',
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'name' => 'List',
|
|
||||||
'newsletter_type' => 'welcome',
|
|
||||||
)
|
|
||||||
);
|
|
||||||
foreach ($newsletter_options as $data) {
|
|
||||||
$option_field = NewsletterOptionField::create();
|
|
||||||
$option_field->hydrate($data);
|
|
||||||
$option_field->save();
|
|
||||||
$createdOptionFields[] = $option_field->asArray();
|
|
||||||
}
|
|
||||||
$newsletter_options = array(
|
|
||||||
array(
|
|
||||||
'newsletter_id' => $this->newsletter->id,
|
|
||||||
'option_field_id' => $createdOptionFields[0]['id'],
|
|
||||||
'value' => 'list'
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'newsletter_id' => $this->newsletter->id,
|
|
||||||
'option_field_id' => $createdOptionFields[1]['id'],
|
|
||||||
'value' => '1'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
foreach($newsletter_options as $data) {
|
|
||||||
$association = NewsletterOption::create();
|
|
||||||
$association->hydrate($data);
|
|
||||||
$association->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
$newsletter = Newsletter::filter('filterWithOptions')
|
|
||||||
->filter('filterSearchCustomFields', array(
|
|
||||||
array(
|
|
||||||
'name' => 'Event',
|
|
||||||
'value' => 'list'
|
|
||||||
)
|
|
||||||
))
|
|
||||||
->findArray();
|
|
||||||
expect(empty($newsletter))->false();
|
|
||||||
$newsletter = Newsletter::filter('filterWithOptions')
|
|
||||||
->filter('filterSearchCustomFields', array(
|
|
||||||
array(
|
|
||||||
'name' => 'Event',
|
|
||||||
'value' => 'list'
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'name' => 'List',
|
|
||||||
'value' => '1'
|
|
||||||
)
|
|
||||||
))
|
|
||||||
->findArray();
|
|
||||||
expect(empty($newsletter))->false();
|
|
||||||
$newsletter = Newsletter::filter('filterWithOptions')
|
|
||||||
->filter('filterSearchCustomFields', array(
|
|
||||||
array(
|
|
||||||
'name' => 'Event',
|
|
||||||
'value' => 'list'
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'name' => 'List',
|
|
||||||
'value' => '2'
|
|
||||||
)
|
|
||||||
))
|
|
||||||
->findArray();
|
|
||||||
expect(empty($newsletter))->true();
|
|
||||||
}
|
|
||||||
|
|
||||||
function _after() {
|
function _after() {
|
||||||
ORM::raw_execute('TRUNCATE ' . NewsletterOption::$_table);
|
ORM::raw_execute('TRUNCATE ' . NewsletterOption::$_table);
|
||||||
ORM::raw_execute('TRUNCATE ' . Newsletter::$_table);
|
ORM::raw_execute('TRUNCATE ' . Newsletter::$_table);
|
||||||
|
@@ -138,125 +138,6 @@ class SubscriberTest extends MailPoetTest {
|
|||||||
expect($subscriber->DOB)->equals($association->value);
|
expect($subscriber->DOB)->equals($association->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItCanFilterCustomFields() {
|
|
||||||
$cf_city = CustomField::createOrUpdate(array(
|
|
||||||
'name' => 'City',
|
|
||||||
'type' => 'text'
|
|
||||||
));
|
|
||||||
|
|
||||||
SubscriberCustomField::createOrUpdate(array(
|
|
||||||
'subscriber_id' => $this->subscriber->id,
|
|
||||||
'custom_field_id' => $cf_city->id,
|
|
||||||
'value' => 'Paris'
|
|
||||||
));
|
|
||||||
|
|
||||||
$cf_country = CustomField::createOrUpdate(array(
|
|
||||||
'name' => 'Country',
|
|
||||||
'type' => 'text'
|
|
||||||
));
|
|
||||||
|
|
||||||
SubscriberCustomField::createOrUpdate(array(
|
|
||||||
'subscriber_id' => $this->subscriber->id,
|
|
||||||
'custom_field_id' => $cf_country->id,
|
|
||||||
'value' => 'France'
|
|
||||||
));
|
|
||||||
|
|
||||||
$subscriber = Subscriber::filter('filterWithCustomFields')
|
|
||||||
->filter('filterSearchCustomFields', array(
|
|
||||||
array(
|
|
||||||
'name' => 'City',
|
|
||||||
'value' => 'Paris'
|
|
||||||
)
|
|
||||||
))
|
|
||||||
->findArray();
|
|
||||||
expect(empty($subscriber))->false();
|
|
||||||
$subscriber = Subscriber::filter('filterWithCustomFields')
|
|
||||||
->filter('filterSearchCustomFields', array(
|
|
||||||
array(
|
|
||||||
'name' => 'City',
|
|
||||||
'value' => 'Paris'
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'name' => 'Country',
|
|
||||||
'value' => 'France'
|
|
||||||
)
|
|
||||||
))
|
|
||||||
->findArray();
|
|
||||||
expect(empty($subscriber))->false();
|
|
||||||
|
|
||||||
$subscriber = Subscriber::filter('filterWithCustomFields')
|
|
||||||
->filter('filterSearchCustomFields', array(
|
|
||||||
array(
|
|
||||||
'name' => 'City',
|
|
||||||
'value' => 'Paris'
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'name' => 'Country',
|
|
||||||
'value' => 'Russia'
|
|
||||||
)
|
|
||||||
), 'OR')
|
|
||||||
->findArray();
|
|
||||||
expect(empty($subscriber))->false();
|
|
||||||
|
|
||||||
$subscriber = Subscriber::filter('filterWithCustomFields')
|
|
||||||
->filter('filterSearchCustomFields', array(
|
|
||||||
array(
|
|
||||||
'name' => 'City',
|
|
||||||
'value' => 'is'
|
|
||||||
)
|
|
||||||
), 'AND', 'LIKE')
|
|
||||||
->findArray();
|
|
||||||
expect(empty($subscriber))->false();
|
|
||||||
|
|
||||||
$subscriber = Subscriber::filter('filterWithCustomFields')
|
|
||||||
->filter('filterSearchCustomFields', array(
|
|
||||||
array(
|
|
||||||
'name' => 'City',
|
|
||||||
'value' => 'Moscow'
|
|
||||||
)
|
|
||||||
))
|
|
||||||
->findArray();
|
|
||||||
expect(empty($subscriber))->true();
|
|
||||||
|
|
||||||
$subscriber = Subscriber::filter('filterWithCustomFields')
|
|
||||||
->filter('filterSearchCustomFields', array(
|
|
||||||
array(
|
|
||||||
'name' => 'City',
|
|
||||||
'value' => 'Paris'
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'name' => 'Country',
|
|
||||||
'value' => 'Russia'
|
|
||||||
)
|
|
||||||
))
|
|
||||||
->findArray();
|
|
||||||
expect(empty($subscriber))->true();
|
|
||||||
|
|
||||||
$subscriber = Subscriber::filter('filterWithCustomFields')
|
|
||||||
->filter('filterSearchCustomFields', array(
|
|
||||||
array(
|
|
||||||
'name' => 'City',
|
|
||||||
'value' => 'Moscow'
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'name' => 'Country',
|
|
||||||
'value' => 'Russia'
|
|
||||||
)
|
|
||||||
), 'OR')
|
|
||||||
->findArray();
|
|
||||||
expect(empty($subscriber))->true();
|
|
||||||
|
|
||||||
$subscriber = Subscriber::filter('filterWithCustomFields')
|
|
||||||
->filter('filterSearchCustomFields', array(
|
|
||||||
array(
|
|
||||||
'name' => 'City',
|
|
||||||
'value' => 'zz'
|
|
||||||
)
|
|
||||||
), 'AND', 'LIKE')
|
|
||||||
->findArray();
|
|
||||||
expect(empty($subscriber))->true();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testItCanCreateOrUpdate() {
|
function testItCanCreateOrUpdate() {
|
||||||
$data = array(
|
$data = array(
|
||||||
'email' => 'john.doe@mailpoet.com',
|
'email' => 'john.doe@mailpoet.com',
|
||||||
|
Reference in New Issue
Block a user