Skip to content

Commit

Permalink
add GDPR for je
Browse files Browse the repository at this point in the history
  • Loading branch information
Ngo Hoang committed Jun 6, 2018
1 parent 48710ad commit a057db8
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 2 deletions.
152 changes: 152 additions & 0 deletions app/controllers/backend/je-gdpr-controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?php
/**
* Author: Hoang Ngo
*/

class JE_GDPR_Controller {
public function __construct() {
add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'register_plugin_exporter' ), 10 );
add_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_plugin_eraser' ), 10 );
}

public function register_plugin_eraser( $erasers ) {
$erasers['appointments'] = array(
'eraser_friendly_name' => __( "Jobs & Experts", je()->domain ),
'callback' => array( $this, 'plugin_eraser' ),
);

return $erasers;
}

public function register_plugin_exporter( $exporters ) {
$exporters['job_plus'] = array(
'exporter_friendly_name' => __( "Jobs & Experts", je()->domain ),
'callback' => array( $this, 'plugin_exporter' ),
);

return $exporters;
}

public function plugin_eraser( $email, $page = 1 ) {
$jobs = JE_Job_Model::model()->find_by_attributes( array(
'contact_email' => $email
) );

$experts = JE_Expert_Model::model()->find_by_attributes( array(
'contact_email' => $email
) );

if ( count( $jobs ) ) {
foreach ( $jobs as $job ) {
$job->delete();
}
}
if ( count( $experts ) ) {
foreach ( $experts as $expert ) {
$expert->delete();
}
}

return array(
'items_removed' => count( $jobs ) + count( $experts ),
'items_retained' => false, // we will remove all
'messages' => array(),
'done' => true,
);
}

public function plugin_exporter( $email, $page = 1 ) {
$jobs = JE_Job_Model::model()->find_by_attributes( array(
'contact_email' => $email
) );

$experts = JE_Expert_Model::model()->find_by_attributes( array(
'contact_email' => $email
) );

$export_items = array();
if ( count( $jobs ) ) {
foreach ( $jobs as $job ) {
$item = array(
'group_id' => 'je-jobs',
'group_label' => __( "Jobs & Experts - Jobs Info", je()->domain ),
'item_id' => 'je-job-' . $job->ID,
'data' => array(
array(
'name' => __( 'Job Name', je()->domain ),
'value' => $job->job_title,
),
array(
'name' => __( 'Email', je()->domain ),
'value' => $job->contact_email,
),
array(
'name' => __( 'Budget', je()->domain ),
'value' => $job->render_prices( true ),
),
array(
'name' => __( 'Open For', je()->domain ),
'value' => $job->get_due_day(),
),
array(
'name' => __( 'Status', je()->domain ),
'value' => $job->get_status(),
)
),
);
$export_items[] = $item;
}
}
if ( count( $experts ) ) {
foreach ( $experts as $expert ) {
$socials = explode( ',', $expert->social );
$socials_text = array();
foreach ( $socials as $social ) {
$model = Social_Wall_Model::model()->get_one( $social, $expert->id );
if ( is_object( $model ) ) {
$socials_text[] = $model->name . ':' . $model->value;
}
}
$item = array(
'group_id' => 'je-experts',
'group_label' => __( "Jobs & Experts - Experts Info", je()->domain ),
'item_id' => 'je-expert-' . $expert->ID,
'data' => array(
array(
'name' => __( 'Expert Name', je()->domain ),
'value' => $expert->first_name . ' ' . $expert->last_name,
),
array(
'name' => __( 'Email', je()->domain ),
'value' => $expert->contact_email,
),
array(
'name' => __( 'Company', je()->domain ),
'value' => $expert->company,
),
array(
'name' => __( 'Company URL', je()->domain ),
'value' => $expert->company_url,
),
array(
'name' => __( 'Location', je()->domain ),
'value' => $expert->get_location(),
),
array(
'name' => __( 'Social', je()->domain ),
'value' => implode( '<br/>', $socials_text ),
)
),
);
$export_items[] = $item;
}
}

$export = array(
'data' => $export_items,
'done' => true,
);

return $export;
}
}
10 changes: 8 additions & 2 deletions app/models/je-job-model.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class JE_Job_Model extends IG_Post_Model {
public $budget;
public $contact_email;
public $dead_line;
public $job_img;
public $job_img;
public $open_for;
public $portfolios;
public $status;
Expand Down Expand Up @@ -53,7 +53,7 @@ class JE_Job_Model extends IG_Post_Model {
'key' => '_ct_jbp_job_Due',
'map' => 'dead_line'
),
array(
array(
'type' => 'meta',
'key' => '_ct_jbp_job_img',
'map' => 'job_img'
Expand Down Expand Up @@ -162,6 +162,7 @@ public function get_price() {
public function render_prices( $return = '' ) {
$prices = $this->get_price();
$currency = je()->settings()->currency;
ob_start();
if ( is_array( $prices ) ) {
?>
<?php if ( empty( $return ) ): ?>
Expand All @@ -176,6 +177,11 @@ public function render_prices( $return = '' ) {
<?php echo JobsExperts_Helper::format_currency( $currency, $this->budget ) ?>
<?php
}
$content = ob_get_clean();
if ( $return == true ) {
return $content;
}
echo $content;
}

public function get_due_day() {
Expand Down
2 changes: 2 additions & 0 deletions jobs-experts.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ function dispatch() {
$landing = new JE_Landing_Shortcode_Controller();
$shared = new JE_Shared_Controller();

//GDPR
new JE_GDPR_Controller();
//load addon
//load add on
$addons = $this->settings()->plugins;
Expand Down

0 comments on commit a057db8

Please sign in to comment.