示例#1
0
/**
 * Function updateNofiticatoinModel is used to update or delete notification details
 * @param  int  $delId  notification id to delete
 * @param  int  $userID  user id
 * @return void
 */
function updateNotificationModel($notificationID, $userID)
{
    global $wpdb;
    $getSubscriberID = $wpdb->get_var($wpdb->prepare('SELECT sub_id FROM ' . WVG_CHANNEL_NOTIFICATION . ' WHERE user_id=%d', $userID));
    $subscriberId = json_decode($getSubscriberID, true);
    if (in_array($notificationID, $subscriberId)) {
        $delkey = array_search($notificationID, $subscriberId);
        unset($subscriberId[$delkey]);
        if (!empty($subscriberId)) {
            $updatedId = json_encode($subscriberId);
            /** data hold query details */
            $data = array('sub_id' => $updatedId);
            /** where hold query condition */
            $where = array('user_id' => $userID);
            /** format hold data format */
            $format = array('%s');
            /** where format hold where data format */
            $whereFormat = array('%d');
            $wpdb->update(WVG_CHANNEL_NOTIFICATION, $data, $where, $format, $whereFormat);
        } else {
            deleteNotificationModel($userID);
        }
    } else {
        echo __('Unknown Error Occured', APPTHA_VGALLERY);
        exitAction('');
    }
}
 /**
  * Function to delete notification details.
  * This function is used to remove required user notification details.
  * @param   int  $userID   user id
  * @return  void
  */
 public function deleteNotification($userID)
 {
     $notificationID = isset($_POST['delId']) && $_POST['delId'] != '' ? intVal($_POST['delId']) : '';
     if (empty($notificationID)) {
         deleteNotificationModel($userID);
     } else {
         updateNotificationModel($notificationID, $userID);
     }
 }