Skip to content

Commit

Permalink
Merge pull request #23 from codehaiku/1.3.3
Browse files Browse the repository at this point in the history
fixed error when bp notifications is disabled
  • Loading branch information
JosephGabito authored Jan 29, 2017
2 parents f095c4b + b2a8ea4 commit 21c8ef0
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 81 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
~Current Version:1.3.2~
~Current Version:1.3.3~

# Task Breaker

Expand Down
33 changes: 11 additions & 22 deletions controllers/tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ public function addTicket( $params = array() ) {
$args[ $key ] = $value;

}

}

$this->setTitle( $args['title'] )
->setDescription( $args['description'] )
->setMilestoneId( $args['milestone_id'] )
->setProjectId( $args['project_id'] )
->setUser( $args['user_id'] )
->setPriority( $args['priority'] )
->setAssignUsers( $args['user_id_collection'] );
->setDescription( $args['description'] )
->setMilestoneId( $args['milestone_id'] )
->setProjectId( $args['project_id'] )
->setUser( $args['user_id'] )
->setPriority( $args['priority'] )
->setAssignUsers( $args['user_id_collection'] );

if ( empty( $this->title ) || empty( $this->description ) ) {

Expand All @@ -51,7 +52,7 @@ public function addTicket( $params = array() ) {

}

public function deleteTicket( $id = 0, $project_id = 0 ) {
public function deleteTask( $id = 0, $project_id = 0 ) {

// delete the ticket
if ( 0 === $id ) {
Expand All @@ -66,7 +67,7 @@ public function deleteTicket( $id = 0, $project_id = 0 ) {

}

public function updateTicket( $id = 0, $args = array() ) {
public function updateTask( $id = 0, $args = array() ) {

// Make sure the current user is able to update the task.
if ( ! task_breaker_can_update_task( $args['project_id'] ) ) {
Expand All @@ -93,18 +94,6 @@ public function renderTasks( $args = array() ) {

}

public function renderTicketsByMilestone( $milestone_id = 0 ) {

return array();
}

public function renderTicketsByUser( $user_id = 0 ) {

return array();

}


public function completeTask( $task_id = 0, $user_id = 0 ) {

parent::prepare();
Expand All @@ -117,12 +106,12 @@ public function renewTask( $task_id = 0 ) {

parent::prepare();

return parent::renewTask( $task_id );
return parent::renewTask( absint( $task_id ) );
}

public function getPriority( $priority = 1 ) {

return parent::getPriority( $priority );
return parent::getPriority( absint( $priority ) );

}

Expand Down
43 changes: 21 additions & 22 deletions core/conditional-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ function task_breaker_current_user_is_member_of_group( $group_id = 0 ) {

}

/**
* Check if current user can access projects. Only group members can access
* the project
*
* @return boolean
*/
/**
* Check if current user can access projects. Only group members can access
* the project
*
* @return boolean
*/
function task_breaker_can_view_project( $project_id ) {

if ( ! is_user_logged_in() ) {
Expand All @@ -69,12 +69,12 @@ function task_breaker_can_view_project( $project_id ) {
return false;
}

/**
* Check if current user can add project to group. Only admin and
* moderators can add project to group.
*
* @return boolean
*/
/**
* Check if current user can add project to group. Only admin and
* moderators can add project to group.
*
* @return boolean
*/
function task_breaker_can_add_project_to_group( $group_id ) {

if ( ! is_user_logged_in() ) {
Expand All @@ -96,12 +96,12 @@ function task_breaker_can_add_project_to_group( $group_id ) {
return false;
}

/**
* Check if current user can edit project. Only admin and moderators can edit
* the projects.
*
* @return boolean
*/
/**
* Check if current user can edit project. Only admin and moderators can edit
* the projects.
*
* @return boolean
*/
function task_breaker_can_edit_project( $project_id = 0 ) {

if ( ! is_user_logged_in() ) {
Expand Down Expand Up @@ -165,8 +165,8 @@ function task_breaker_can_delete_project( $project_id = 0 ) {

}

// Tasks
// Check if current user can see tasks inside the project
// Tasks
// Check if current user can see tasks inside the project
function task_breaker_can_see_project_tasks( $project_id ) {

if ( ! is_user_logged_in() ) {
Expand Down Expand Up @@ -386,5 +386,4 @@ function task_breaker_is_project_group_public( $project_id = 0 ) {

return false;

}

}
15 changes: 13 additions & 2 deletions emails/class-buddypress-mail-register.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@

final class Task_Breaker_BP_Mail_Register {


public function __construct() {

// Register the new task email template.
add_action( 'bp_core_install_emails', array( $this, 'new_task_email_template' ) );

// Register our new email post type and template.
add_action( 'bp_core_install_emails', array( $this, 'new_task_comment_email_template', ) );
add_action( 'bp_core_install_emails', array( $this, 'new_task_comment_email_template' ) );

// Register the new task mailer.
add_action( 'tb_new_task', array( $this, 'tb_new_task' ), 10, 1);
Expand All @@ -31,6 +30,7 @@ public function __construct() {
add_action( 'bp_notification_settings', array( $this, 'tb_render_task_email_settings', ), 0 );

return $this;

}

function new_task_email_template() {
Expand Down Expand Up @@ -145,6 +145,12 @@ function new_task_comment_email_template() {
* @return void
*/
function tb_new_task( $task_object ) {

// Bail out if notifications are disabled or BP version does not support e-mail api.
if ( ! function_exists( 'bp_send_email' ) ) {
return;
}

// Add the tokens to parse in the email template.
$args = array(
'tokens' => array(
Expand Down Expand Up @@ -192,6 +198,11 @@ function tb_new_task( $task_object ) {
* @return void
*/
function tb_new_task_comment( $task_comment_object ) {

// Bail out if notifications are disabled or BP version does not support e-mail api.
if ( ! function_exists( 'bp_send_email' ) ) {
return;
}

// Add tokens to parse in email.
$args = array(
Expand Down
36 changes: 23 additions & 13 deletions models/tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,11 @@ public function fetch( $args = array() ) {
return array();
}

/**
* Saves the instance of new task in the database.
* @param array $args The arguments we need to pass in the save() method.
* @return boolean Returns true on success, otherwise false.
*/
public function save( $args = array() ) {

global $wpdb;
Expand Down Expand Up @@ -664,19 +669,24 @@ public function save( $args = array() ) {
// Send a notification to the assigned member.
$exploded_members = explode( ',', $this->group_members_assigned );

foreach ( (array) $exploded_members as $ua_id ) {

bp_notifications_add_notification(
array(
'user_id' => $ua_id,
'item_id' => $last_insert_id,
'secondary_item_id' => $this->user_id,
'component_name' => 'task_breaker_ua_notifications_name',
'component_action' => 'task_breaker_ua_action',
'date_notified' => bp_core_current_time(),
'is_new' => 1,
)
);
// Check if notification component is enabled.
if ( function_exists( 'bp_notifications_add_notification' ) ) {

foreach ( (array) $exploded_members as $ua_id ) {

bp_notifications_add_notification(
array(
'user_id' => $ua_id,
'item_id' => $last_insert_id,
'secondary_item_id' => $this->user_id,
'component_name' => 'task_breaker_ua_notifications_name',
'component_action' => 'task_breaker_ua_action',
'date_notified' => bp_core_current_time(),
'is_new' => 1,
)
);
}

}

// Send them ssome snazzy email!
Expand Down
4 changes: 2 additions & 2 deletions task-breaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: Task Breaker
* Description: A WordPress plug-in that will help you break some task!
* Version: 1.3.2
* Version: 1.3.3
* Author: Dunhakdis
* Author URI: http://dunhakdis.me
* Text Domain: task_breaker
Expand All @@ -22,7 +22,7 @@
exit();
}

define( 'TASK_BREAKER_VERSION', '1.3.2' );
define( 'TASK_BREAKER_VERSION', '1.3.3' );

define( 'TASK_BREAKER_PROJECT_LIMIT', 10 );

Expand Down
33 changes: 14 additions & 19 deletions transactions/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*/

// check if access directly
if ( ! defined( 'ABSPATH' ) ) { die();
if ( ! defined( 'ABSPATH' ) ) {
die();
}

$action = filter_input( INPUT_GET, 'action', FILTER_SANITIZE_STRING );
Expand All @@ -21,7 +22,6 @@
return;
}


// Format our page header when Unit Testing
if ( ! defined( 'WP_TESTS_DOMAIN' ) ) {

Expand Down Expand Up @@ -74,7 +74,6 @@ function task_breaker_transactions_callblack() {
}

$allowed_callbacks = array(

// Tickets/Tasks callbacks
'task_breaker_transaction_add_ticket',
'task_breaker_transaction_delete_ticket',
Expand Down Expand Up @@ -177,13 +176,12 @@ function task_breaker_transaction_delete_ticket() {
$ticket_id = (int) filter_input( INPUT_POST, 'id', FILTER_VALIDATE_INT );

$project_id = (int) filter_input( INPUT_POST, 'project_id', FILTER_VALIDATE_INT );
;

$task = new ThriveProjectTasksController();

$deleteTicket = $task->deleteTicket( $ticket_id, $project_id );
$deleteTask = $task->deleteTask( $ticket_id, $project_id );

if ( $deleteTicket ) {
if ( $deleteTask ) {

task_breaker_api_message(
array(
Expand Down Expand Up @@ -248,22 +246,19 @@ function task_breaker_transaction_fetch_task() {
$task = new ThriveProjectTasksController();

$args = array(
'project_id' => $project_id,
'id' => $task_id,
'page' => $page,
'priority' => $priority,
'search' => $search,
'show_completed' => $show_completed,
'orderby' => 'priority',
'order' => 'desc',
'echo' => 'no',
'project_id' => $project_id,
'id' => $task_id,
'page' => $page,
'priority' => $priority,
'search' => $search,
'show_completed' => $show_completed,
'orderby' => 'priority',
'order' => 'desc',
'echo' => 'no',
);

$task_collection = $task->renderTasks( $args );

// Push the ticket ID in the task_collection stack.
$task_collection->task_id = absint( $task_id );

if ( 0 === $task_id ) {

$task_id = null;
Expand Down Expand Up @@ -341,7 +336,7 @@ function task_breaker_transaction_edit_ticket() {
// Make sure the current user is able to update the task.
if ( task_breaker_can_update_task( $project_id ) ) {

if ( $task->updateTicket( $task_id, $args ) ) {
if ( $task->updateTask( $task_id, $args ) ) {

$json_response['message'] = 'success';

Expand Down

0 comments on commit 21c8ef0

Please sign in to comment.