Skip to content

Commit

Permalink
updates api change
Browse files Browse the repository at this point in the history
  • Loading branch information
techjewel committed Oct 13, 2020
1 parent c7d60fc commit a4018eb
Show file tree
Hide file tree
Showing 70 changed files with 1,539 additions and 1,029 deletions.
22 changes: 19 additions & 3 deletions app/Api/Classes/Contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace FluentCrm\App\Api\Classes;

use FluentCrm\App\models\Subscriber;
use FluentCrm\App\Models\CustomContactField;
use FluentCrm\App\Models\Subscriber;
use FluentCrm\Includes\Helpers\Arr;

class Contacts
{
Expand Down Expand Up @@ -36,9 +38,23 @@ public function getContactByUserId($userId)
return Subscriber::where('user_id', $userId)->first();
}

public function createOrUpdate($data)
public function createOrUpdate($data, $forceUpdate = false, $deleteOtherValues = false, $sync = false)
{
return $this->instance->updateOrCreate($data);
if(!isset($data['custom_fields'])) {
$customFieldKeys = [];
$customFields = (new CustomContactField)->getGlobalFields()['fields'];
foreach ($customFields as $field) {
$customFieldKeys[] = $field['slug'];
}
if ($customFieldKeys) {
$customFieldsData = Arr::only($data, $customFieldKeys);
if ($customFields) {
$data['custom_fields'] = (new CustomContactField)->formatCustomFieldValues($customFieldsData);
}
}
}

return $this->instance->updateOrCreate($data, $forceUpdate = false, $deleteOtherValues = false, $sync = false);
}

public function getCurrentContact()
Expand Down
33 changes: 32 additions & 1 deletion app/Api/Classes/Lists.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace FluentCrm\App\Api\Classes;

use FluentCrm\App\models\Lists as CrmLists;
use FluentCrm\App\Models\Lists as CrmLists;

class Lists
{
Expand All @@ -26,6 +26,37 @@ public function getInstance()
return $this->instance;
}

public function importBulk($lists)
{
$newLists = [];
foreach ($lists as $list) {
if (!$list['title']) {
continue;
}

if(empty($list['slug'])) {
$list['slug'] = sanitize_title($list['title'], 'display');
} else {
$list['slug'] = sanitize_title($list['slug'], 'display');
}

$list['slug'] = sanitize_text_field($list['slug']);

$list = \FluentCrm\App\Models\Lists::updateOrCreate(
[
'slug' => $list['slug'],
'title' => sanitize_text_field($list['title'])
],
['slug' => $list['slug']]
);
do_action('fluentcrm_list_created', $list->id);

$newLists[] = $list;
}

return $newLists;
}

public function __call($method, $params)
{
if (in_array($method, $this->allowedInstanceMethods)) {
Expand Down
35 changes: 34 additions & 1 deletion app/Api/Classes/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace FluentCrm\App\Api\Classes;

use FluentCrm\App\models\Tag;
use FluentCrm\App\Models\Tag;

class Tags
{
Expand All @@ -16,6 +16,39 @@ class Tags
'paginate'
];


public function importBulk($tags)
{
$newTags = [];
foreach ($tags as $tag) {
if (!$tag['title']) {
continue;
}

if(empty($tag['slug'])) {
$tag['slug'] = sanitize_title($tag['title'], 'display');
} else {
$tag['slug'] = sanitize_title($tag['slug'], 'display');
}

$tag['slug'] = sanitize_text_field($tag['slug']);

$tag = \FluentCrm\App\Models\Tag::updateOrCreate(
[
'slug' => $tag['slug'],
'title' => sanitize_text_field($tag['title'])
],
['slug' => $tag['slug']]
);
do_action('fluentcrm_list_created', $tag->id);

$newTags[] = $tag;
}

return $newTags;
}


public function __construct(Tag $instance)
{
$this->instance = $instance;
Expand Down
4 changes: 2 additions & 2 deletions app/Api/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

return [
'contacts' => 'FluentCrm\App\Api\Classes\Contacts',
'tags' => 'FluentCrm\App\Api\Classes\Tags',
'lists' => 'FluentCrm\App\Api\Classes\Lists',
'tags' => 'FluentCrm\App\Api\Classes\Tags',
'lists' => 'FluentCrm\App\Api\Classes\Lists',
];
12 changes: 10 additions & 2 deletions app/Functions/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,17 @@ function fluentcrm_update_option($optionName, $value)

}

function fluentcrm_get_campaign_meta($objectId, $key)
function fluentcrm_get_campaign_meta($objectId, $key, $returnValue = false)
{
return fluentcrm_get_meta($objectId, 'FluentCrm\App\Models\Campaign', $key);
$item = fluentcrm_get_meta($objectId, 'FluentCrm\App\Models\Campaign', $key);
if($returnValue) {
if($item) {
return $item->value;
}
return false;
}

return $item;
}

function fluentcrm_update_campaign_meta($objectId, $key, $value)
Expand Down
2 changes: 1 addition & 1 deletion app/Hooks/Handlers/AdminBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AdminBar
{
public function init()
{
if (!current_user_can('manage_options')) {
if (!current_user_can('manage_options') || !is_admin()) {
return;
}

Expand Down
45 changes: 27 additions & 18 deletions app/Hooks/Handlers/AdminMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class AdminMenu
{
public $version = '1.0.1';
public $version = FLUENTCRM_PLUGIN_VERSION;

public function init()
{
Expand All @@ -23,8 +23,8 @@ public function addMenu()
{
$permission = 'manage_options';
add_menu_page(
__('FluentCRM', 'fluentcrm'),
__('FluentCRM', 'fluentcrm'),
__('FluentCRM', 'fluent-crm'),
__('FluentCRM', 'fluent-crm'),
$permission,
'fluentcrm-admin',
array($this, 'render'),
Expand Down Expand Up @@ -70,8 +70,8 @@ public function addMenu()

add_submenu_page(
'fluentcrm-admin',
__('Funnels', 'fluentform'),
__('Funnels', 'fluentform'),
__('Automations', 'fluentform'),
__('Automations', 'fluentform'),
$permission,
'fluentcrm-admin#/funnels',
array($this, 'render')
Expand Down Expand Up @@ -106,75 +106,84 @@ public function render()
$menuItems = [
[
'key' => 'dashboard',
'label' => __('Dashboard', 'fluentcrm'),
'label' => __('Dashboard', 'fluent-crm'),
'permalink' => $urlBase
],
[
'key' => 'contacts',
'label' => __('Contacts', 'fluentcrm'),
'label' => __('Contacts', 'fluent-crm'),
'permalink' => $urlBase . 'subscribers',
'sub_items' => [
[
'key' => 'all_contacts',
'label' => __('All Contacts', 'fluentcrm'),
'label' => __('All Contacts', 'fluent-crm'),
'permalink' => $urlBase . 'subscribers'
],
[
'key' => 'lists',
'label' => __('Lists', 'fluentcrm'),
'label' => __('Lists', 'fluent-crm'),
'permalink' => $urlBase . 'contact-groups/lists'
],
[
'key' => 'tags',
'label' => __('Tags', 'fluentcrm'),
'label' => __('Tags', 'fluent-crm'),
'permalink' => $urlBase . 'contact-groups/tags'
],
[
'key' => 'dynamic_segments',
'label' => __('Segments', 'fluentcrm'),
'label' => __('Segments', 'fluent-crm'),
'permalink' => $urlBase . 'contact-groups/dynamic-segments'
]
]
],
[
'key' => 'campaigns',
'label' => __('Email Campaigns', 'fluentcrm'),
'label' => __('Email Campaigns', 'fluent-crm'),
'permalink' => $urlBase . 'email/campaigns',
'sub_items' => [
[
'key' => 'all_campaigns',
'label' => __('All Campaigns', 'fluentcrm'),
'label' => __('All Campaigns', 'fluent-crm'),
'permalink' => $urlBase . 'email/campaigns'
],
[
'key' => 'email_sequences',
'label' => __('Email Sequences', 'fluentcrm'),
'label' => __('Email Sequences', 'fluent-crm'),
'permalink' => $urlBase . 'email/sequences'
],
[
'key' => 'email_templates',
'label' => __('Email Templates', 'fluentcrm'),
'label' => __('Email Templates', 'fluent-crm'),
'permalink' => $urlBase . 'email/templates'
]
]
],
[
'key' => 'forms',
'label' => __('Forms', 'fluentcrm'),
'label' => __('Forms', 'fluent-crm'),
'permalink' => $urlBase . 'forms'
],
[
'key' => 'funnels',
'label' => __('Funnels', 'fluentcrm'),
'label' => __('Automations', 'fluent-crm'),
'permalink' => $urlBase . 'funnels'
],
[
'key' => 'settings',
'label' => __('Settings', 'fluentcrm'),
'label' => __('Settings', 'fluent-crm'),
'permalink' => $urlBase . 'settings'
]
];

if(!defined('FLUENTCAMPAIGN')) {
$menuItems[] = [
'key' => 'get_pro',
'label' => 'Get Pro',
'permalink' => 'https://fluentcrm.com',
'class' => 'pro_link'
];
}

$app['view']->render('admin.menu_page', [
'menuItems' => $menuItems,
'logo' => FLUENTCRM_PLUGIN_URL . 'assets/images/fluentcrm-logo.svg',
Expand Down
10 changes: 7 additions & 3 deletions app/Hooks/Handlers/AutoSubscribeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class AutoSubscribeHandler
public function userRegistrationHandler($userId)
{
$settings = (new AutoSubscribe())->getRegistrationSettings();

if (Arr::get($settings, 'status') != 'yes') {
return;
}
Expand All @@ -29,11 +30,14 @@ public function userRegistrationHandler($userId)

if($isDoubleOptin) {
$subscriberData['status'] = 'pending';
} else {
$subscriberData['status'] = 'subscribed';
}


$contact = FunnelHelper::createOrUpdateContact($subscriberData);

if($contact->status = 'pending') {
if($contact->status == 'pending') {
$contact->sendDoubleOptinEmail();
}
}
Expand Down Expand Up @@ -61,7 +65,7 @@ public function addSubscribeCheckbox($buttonHtml)

$label = Arr::get($settings, 'checkbox_label');
if(!$label) {
$label = __('Subscribe to newsletter', 'fluentcrm');
$label = __('Subscribe to newsletter', 'fluent-crm');
}

$checkedTag = '';
Expand Down Expand Up @@ -116,7 +120,7 @@ public function handleCommentPost($commentId, $isApproved, $commentData)

$contact = FunnelHelper::createOrUpdateContact($subscriberData);

if($contact->status = 'pending') {
if($contact->status == 'pending') {
$contact->sendDoubleOptinEmail();
}

Expand Down
Loading

0 comments on commit a4018eb

Please sign in to comment.