Exemplo n.º 1
0
 /**
  * Return a list of comments
  *
  * @param string $contextlevel ('system, course, user', etc..)
  * @param int $instanceid
  * @param string $component the name of the component
  * @param int $itemid the item id
  * @param string $area comment area
  * @param int $page page number
  * @return array of comments and warnings
  * @since Moodle 2.9
  */
 public static function get_comments($contextlevel, $instanceid, $component, $itemid, $area = '', $page = 0)
 {
     $warnings = array();
     $arrayparams = array('contextlevel' => $contextlevel, 'instanceid' => $instanceid, 'component' => $component, 'itemid' => $itemid, 'area' => $area, 'page' => $page);
     $params = self::validate_parameters(self::get_comments_parameters(), $arrayparams);
     $context = self::get_context_from_params($params);
     self::validate_context($context);
     require_capability('moodle/comment:view', $context);
     $args = new stdClass();
     $args->context = $context;
     $args->area = $params['area'];
     $args->itemid = $params['itemid'];
     $args->component = $params['component'];
     $commentobject = new comment($args);
     $comments = $commentobject->get_comments($params['page']);
     // False means no permissions to see comments.
     if ($comments === false) {
         throw new moodle_exception('nopermissions', 'error', '', 'view comments');
     }
     foreach ($comments as $key => $comment) {
         list($comments[$key]->content, $comments[$key]->format) = external_format_text($comment->content, $comment->format, $context->id, $params['component'], '', 0);
     }
     $results = array('comments' => $comments, 'warnings' => $warnings);
     return $results;
 }
Exemplo n.º 2
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.º 3
0
 function util_get_comments_array($entity, $id, $options = array())
 {
     global $TPL;
     $current_user =& singleton("current_user");
     $rows = array();
     $new_rows = array();
     // Need to get timeSheet comments too for task comments
     if ($entity == "task") {
         $rows = comment::get_comments($entity, $id);
         has("time") and $rows2 = timeSheetItem::get_timeSheetItemComments($id);
         $rows or $rows = array();
         $rows2 or $rows2 = array();
         $rows = array_merge($rows, $rows2);
         if (is_array($rows)) {
             usort($rows, array("comment", "sort_task_comments_callback_func"));
         }
     } else {
         $rows = comment::get_comments($entity, $id);
     }
     $e = new $entity();
     $e->set_id($id);
     $e->select();
     $all_parties = $e->get_all_parties();
     foreach ((array) $rows as $v) {
         unset($children);
         foreach ((array) $v["children"] as $c) {
             $children[] = comment::get_one_comment_array($c, $all_parties);
         }
         $children and $v["children"] = $children;
         $new_rows[] = comment::get_one_comment_array($v, $all_parties);
     }
     return (array) $new_rows;
 }
Exemplo n.º 4
0
                    }
                }
            }
        }
        break;
    case 'delete':
        $result = $comment->delete($commentid);
        if ($result === true) {
            echo json_encode(array('client_id' => $client_id, 'commentid' => $commentid));
        } else {
            if ($result == COMMENT_ERROR_INSUFFICIENT_CAPS) {
                $err->error = get_string('nopermissiontoeditcomment');
                echo json_encode($err);
            } else {
                if ($result == COMMENT_ERROR_DB) {
                    $err->error = get_string('dbupdatefailed');
                    echo json_encode($err);
                }
            }
        }
        break;
    case 'get':
    default:
        $ret = array();
        $comments = $comment->get_comments($page);
        $ret['list'] = $comments;
        $ret['pagination'] = $comment->get_pagination($page);
        $ret['client_id'] = $client_id;
        echo json_encode($ret);
        exit;
}
Exemplo n.º 5
0
	case "quotes-authors-%author%-%quote_id%":
 		$quotes_temp = quote::get_quotes(array(
			"q_id" => $a_path[3]
		));
    $context["quotes"] = $quotes_temp;

		if (strlen($quotes_temp[0]["author_born_death"])>0)
		{
			$author_born_death = " (" . $quotes_temp[0]["author_born_death"] . ")";
		}
		$context["h1"] = $quotes_temp[0]["author_name"] . " " . $context["labels"]["quotes_clean"];
		$context["fake_h1"] = $quotes_temp[0]["author_name"] . $author_born_death;
		$context["profession"] = $quotes_temp[0]["author_profession_parsed"];
		$context["title"] = $quotes_temp[0]["author_name_wo_brackets"] . " " . $context["labels"]["quotes_clean"];
    $context["keywords"] = $smarty_q->tpl_vars['keywords']->value . ", " . tag::get_keywords_for_author_meta_description($a_path[2], $quotes_temp);
    $context["comments"] = comment::get_comments(array("quote_id"=>$a_path[3]));

    /*
		$quotes_temp = quote::get_quotes(array(
			"q_id" => $a_path[3]
		));
		$smarty_q->assign("quotes", $quotes_temp);
		if (strlen($quotes_temp[0]["author_born_death"])>0)
		{
			$author_born_death = " (" . $quotes_temp[0]["author_born_death"] . ")";
		}
		$smarty_q->assign("h1", $quotes_temp[0]["author_name"] . " " . _("quotes"));
		$smarty_q->assign("fake_h1", $quotes_temp[0]["author_name"] . $author_born_death);
		$smarty_q->assign("profession",  $quotes_temp[0]["author_profession_parsed"]);
		$smarty_q->assign ("title", $quotes_temp[0]["author_name_wo_brackets"] . " " . _("quotes"));
		$smarty_q->assign("googlead01_position", quote::get_googlead01_position($quotes_temp));