Exemplo n.º 1
0
                echo json_encode($result);
                die;
            }
        }
        break;
    case 'delete':
        $comment_record = $DB->get_record('comments', array('id' => $commentid));
        if ($manager->can_delete($commentid) || $comment_record->userid == $USER->id) {
            if ($manager->delete($commentid)) {
                $result = array('client_id' => $client_id, 'commentid' => $commentid);
                echo json_encode($result);
                die;
            }
        }
        break;
    case 'get':
    default:
        if ($manager->can_view()) {
            $comments = $manager->get_comments($page);
            $result = array('list' => $comments, 'count' => $manager->count(), 'pagination' => $manager->get_pagination($page), 'client_id' => $client_id);
            echo json_encode($result);
            die;
        }
        break;
}
if (!isloggedin()) {
    // tell user to log in to view comments
    echo json_encode(array('error' => 'require_login'));
}
// ignore request
die;
Exemplo n.º 2
0
 /**
  * Get comments created since a given time.
  *
  * @param  stdClass $course    course object
  * @param  stdClass $context   context object
  * @param  string $component   component name
  * @param  int $since          the time to check
  * @param  stdClass $cm        course module object
  * @return array list of comments db records since the given timelimit
  * @since Moodle 3.2
  */
 public function get_component_comments_since($course, $context, $component, $since, $cm = null)
 {
     global $DB;
     $commentssince = array();
     $where = 'contextid = ? AND component = ? AND timecreated > ?';
     $comments = $DB->get_records_select('comments', $where, array($context->id, $component, $since));
     // Check item by item if we have permissions.
     $managersviewstatus = array();
     foreach ($comments as $comment) {
         // Check if the manager for the item is cached.
         if (!isset($managersviewstatus[$comment->commentarea]) or !isset($managersviewstatus[$comment->commentarea][$comment->itemid])) {
             $args = new stdClass();
             $args->area = $comment->commentarea;
             $args->itemid = $comment->itemid;
             $args->context = $context;
             $args->course = $course;
             $args->client_id = 0;
             $args->component = $component;
             if (!empty($cm)) {
                 $args->cm = $cm;
             }
             $manager = new comment($args);
             $managersviewstatus[$comment->commentarea][$comment->itemid] = $manager->can_view();
         }
         if ($managersviewstatus[$comment->commentarea][$comment->itemid]) {
             $commentssince[$comment->id] = $comment;
         }
     }
     return $commentssince;
 }