Exemplo n.º 1
0
 /**
  * This function returns a list of the given blogs.
  *
  * @param User
  * @return array (count: integer, data: array)
  */
 public static function get_blog_list($limit, $offset, $institution = null, $group = null)
 {
     global $USER;
     $sql = "SELECT b.id, b.title, b.description, b.locked, COUNT(p.id) AS postcount\n                FROM {artefact} b LEFT JOIN {artefact} p ON (p.parent = b.id AND p.artefacttype = 'blogpost')\n                WHERE b.artefacttype = 'blog'";
     if ($institution) {
         $sql .= ' AND b.institution = ?';
         $values = array($institution);
         $count = (int) get_field('artefact', 'COUNT(*)', 'institution', $institution, 'artefacttype', 'blog');
     } else {
         if ($group) {
             $sql .= ' AND b.group = ?';
             $values = array($group);
             $count = (int) get_field('artefact', 'COUNT(*)', 'group', $group, 'artefacttype', 'blog');
         } else {
             $sql .= ' AND b.owner = ?';
             $values = array($USER->get('id'));
             $count = (int) get_field('artefact', 'COUNT(*)', 'owner', $USER->get('id'), 'artefacttype', 'blog');
         }
     }
     $sql .= " GROUP BY b.id, b.title, b.description, b.locked ORDER BY b.title";
     ($result = get_records_sql_array($sql, $values, $offset, $limit)) || ($result = array());
     foreach ($result as &$r) {
         if (!$r->locked) {
             $r->deleteform = ArtefactTypeBlog::delete_form($r->id, $r->title);
         }
     }
     return array($count, $result);
 }
Exemplo n.º 2
0
 * @package    mahara
 * @subpackage artefact-blog
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
 *
 */
define('INTERNAL', 1);
define('SECTION_PLUGINTYPE', 'artefact');
define('SECTION_PLUGINNAME', 'blog');
define('SECTION_PAGE', 'index');
require dirname(dirname(dirname(__FILE__))) . '/init.php';
safe_require('artefact', 'blog');
define('TITLE', get_string('blogs', 'artefact.blog'));
if ($delete = param_integer('delete', 0)) {
    ArtefactTypeBlog::delete_form($delete);
}
$blogs = (object) array('offset' => param_integer('offset', 0), 'limit' => param_integer('limit', 10), 'institution' => null, 'data' => false, 'pagination_js' => false);
$institutionname = null;
if ($institution = param_alphanum('institution', null)) {
    if ($institution == 'mahara') {
        $institutionname = $institution;
        if (!$USER->get('admin')) {
            throw new AccessDeniedException();
        }
        $institutiontitle = get_string('siteblogs', 'artefact.blog');
    } else {
        $s = institution_selector_for_page($institution, get_config('wwwroot') . 'artefact/blog/index.php');
        $institutionname = $s['institution'];
        if (!($USER->get('admin') || $USER->is_institutional_admin())) {
            throw new AccessDeniedException();
Exemplo n.º 3
0
 /**
  * This function returns a list of the given user's blogs.
  *
  * @param User
  * @return array (count: integer, data: array)
  */
 public static function get_blog_list($limit, $offset)
 {
     global $USER;
     ($result = get_records_sql_array("\n         SELECT b.id, b.title, b.description, b.locked, COUNT(p.id) AS postcount\n         FROM {artefact} b LEFT JOIN {artefact} p ON (p.parent = b.id AND p.artefacttype = 'blogpost')\n         WHERE b.owner = ? AND b.artefacttype = 'blog'\n         GROUP BY b.id, b.title, b.description, b.locked\n         ORDER BY b.title", array($USER->get('id')), $offset, $limit)) || ($result = array());
     foreach ($result as &$r) {
         if (!$r->locked) {
             $r->deleteform = ArtefactTypeBlog::delete_form($r->id, $r->title);
         }
     }
     $count = (int) get_field('artefact', 'COUNT(*)', 'owner', $USER->get('id'), 'artefacttype', 'blog');
     return array($count, $result);
 }