public static function addComment($issueGuid, $comment, $userId)
 {
     global $wpdb;
     $postId = $wpdb->get_var($wpdb->prepare("SELECT post_id\n            FROM {$wpdb->postmeta}\n            WHERE meta_key = 'guid' AND meta_value = %s", $issueGuid));
     if (isset($postId) && $postId != '') {
         $issue = get_post($postId);
         $authorized = false;
         $user = get_user_by('id', $userId);
         $options = BIMBCFManagement::getOptions();
         $assignedTo = get_post_meta($issue->ID, 'assigned_to', true);
         if ($issue->post_author == $userId || $user->user_email == $assignedTo) {
             $authorized = true;
         }
         $uri = get_post_meta($issue->ID, '_bimsie_uri', true);
         $poids = get_post_meta($issue->ID, 'poid');
         // We have not published this issue and it is not assigned to us
         // Check if we have access to at least one of its project(s)
         if (!$authorized) {
             foreach ($poids as $poid) {
                 $project = BIMsie::getProject($uri, $poid, $userId);
                 if ($project) {
                     $authorized = true;
                     break;
                 }
             }
         }
         if ($issue->post_type == $options['bcf_issue_post_type'] && $authorized) {
             if (!isset($comment['VerbalStatus'])) {
                 $comment['VerbalStatus'] = '';
             }
             if (!isset($comment['Status'])) {
                 $comment['Status'] = '';
             }
             if (!isset($comment['Date'])) {
                 $comment['Date'] = date('Y-m-d\\TH:i:sP');
             }
             if (!isset($comment['Author'])) {
                 $comment['Author'] = $user->user_email;
             }
             if (!isset($comment['Comment'])) {
                 $comment['Comment'] = '';
             }
             if (!isset($comment['Topic'])) {
                 $comment['Topic'] = array();
             }
             if (!isset($comment['ModifiedDate'])) {
                 $comment['ModifiedDate'] = date('Y-m-d\\TH:i:sP');
             }
             if (!isset($comment['Priority'])) {
                 $comment['Priority'] = '';
             }
             $topicStatuses = explode(',', $options['topic_statuses']);
             $priorities = explode(',', $options['priorities']);
             $markup = get_post_meta($postId, 'markup', true);
             if (!in_array($comment['VerbalStatus'], $topicStatuses)) {
                 $comment['VerbalStatus'] = isset($topicStatuses[0]) ? $topicStatuses[0] : '';
             }
             if (!in_array($comment['Priority'], $priorities)) {
                 $comment['Priority'] = isset($priorities[0]) ? $priorities[0] : '';
             }
             $markup['Comment'][] = $comment;
             update_post_meta($issue->ID, 'markup', $markup);
             $commentData = array('comment_post_ID' => $issue->ID, 'comment_author' => $comment['Author'], 'comment_author_email' => $comment['Author'], 'comment_author_url' => '', 'comment_content' => $comment['Comment'], 'comment_type' => '', 'comment_parent' => 0, 'user_id' => $userId, 'comment_author_IP' => '127.0.0.1', 'comment_agent' => 'BCF API', 'comment_date' => $comment['Date'], 'comment_approved' => 1);
             $commentData['comment_content'] = $commentData['comment_content'] . "\n" . __('Status', 'bim-bcf-management') . ': ' . $comment['Status'];
             $commentData['comment_content'] = $commentData['comment_content'] . "\n" . __('VerbalStatus', 'bim-bcf-management') . ': ' . $comment['VerbalStatus'];
             $commentData['comment_content'] = $commentData['comment_content'] . "\n" . __('Priority', 'bim-bcf-management') . ': ' . $comment['Priority'];
             wp_insert_comment($commentData);
             return BIMBCFManagement::getJSONFromIssue($issue);
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Example #2
0
 public static function getRevision($uri, $poid, $roid, $userId = -1)
 {
     $server = BIMsie::getServerByUri($uri, $userId);
     if ($server === false) {
         return false;
     } else {
         $userId = $userId == -1 ? get_current_user_id() : $userId;
         $bimsieCache = BIMsie::getCacheByUri($uri, $userId);
         if ($bimsieCache === false || !isset($bimsieCache['projects'][$poid])) {
             $project = BIMsie::getProject($uri, $poid, $userId);
             if ($project) {
                 $bimsieCache = BIMsie::getCacheByUri($uri, $userId);
                 if (isset($server['token']) && isset($server['tokenValid']) && $server['tokenValid'] > time()) {
                     $revisions = BIMsie::request($server['uri'], $server['token'], 'Bimsie1ServiceInterface', 'getAllRevisionsOfProject', array('poid' => $poid));
                     $error = BIMsie::getErrorMessage($revisions);
                     if ($error === false && isset($revisions) && isset($revisions->response) && isset($revisions->response->result)) {
                         $revisions = $revisions->response->result;
                         $bimsieCache['projects'][$poid]->revisions = array();
                         foreach ($revisions as $revision) {
                             $revision->dateString = date('d-m-Y H:i', $revision->date * 0.001);
                             $revision->name = $revision->dateString . ' - ' . $revision->comment;
                             $bimsieCache['projects'][$poid]->revisions[$revision->oid] = $revision;
                         }
                         BIMsie::updateCache($bimsieCache, $userId);
                         if (isset($bimsieCache['projects'][$poid]->revisions[$roid])) {
                             return $bimsieCache['projects'][$poid]->revisions[$roid];
                         } else {
                             return false;
                         }
                     } else {
                         return false;
                     }
                 } else {
                     return false;
                 }
             } else {
                 return false;
             }
         } elseif (isset($bimsieCache['projects']) && isset($bimsieCache['projects'][$poid]) && isset($bimsieCache['projects'][$poid]->revisions) && isset($bimsieCache['projects'][$poid]->revisions[$roid])) {
             return $bimsieCache['projects'][$poid]->revisions[$roid];
         } else {
             if (!isset($bimsieCache['projects'][$poid]->revisions) || !isset($bimsieCache['projects'][$poid]->revisions[$roid])) {
                 if (isset($server['token']) && isset($server['tokenValid']) && $server['tokenValid'] > time()) {
                     $revisions = BIMsie::request($server['uri'], $server['token'], 'Bimsie1ServiceInterface', 'getAllRevisionsOfProject', array('poid' => $poid));
                     $error = BIMsie::getErrorMessage($revisions);
                     if ($error === false && isset($revisions) && isset($revisions->response) && isset($revisions->response->result)) {
                         $revisions = $revisions->response->result;
                         $bimsieCache['projects'][$poid]->revisions = array();
                         foreach ($revisions as $revision) {
                             $revision->dateString = date('d-m-Y H:i', $revision->date * 0.001);
                             $revision->name = $revision->dateString . ' - ' . $revision->comment;
                             $bimsieCache['projects'][$poid]->revisions[$revision->oid] = $revision;
                         }
                         BIMsie::updateCache($bimsieCache, $userId);
                         if (isset($bimsieCache['projects'][$poid]->revisions[$roid])) {
                             return $bimsieCache['projects'][$poid]->revisions[$roid];
                         } else {
                             return false;
                         }
                     } else {
                         return false;
                     }
                 } else {
                     return false;
                 }
             } else {
                 return false;
             }
         }
     }
 }