profileicons.json.php 1.96 KB
Newer Older
1 2 3 4 5 6
<?php
/**
 *
 * @package    mahara
 * @subpackage core
 * @author     Catalyst IT Ltd
7 8
 * @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.
9 10 11 12 13 14 15
 *
 */

define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');

16
$result = get_records_sql_array('SELECT a.id, a.title, a.note, (u.profileicon = a.id) AS isdefault,
17
        COUNT (DISTINCT aa.artefact) AS attachcount, COUNT(DISTINCT va.view) AS viewcount, COUNT(DISTINCT s.id) AS skincount, COUNT(DISTINCT fpa.id) AS postcount
18
    FROM {artefact} a
19 20
    LEFT OUTER JOIN {view_artefact} va ON va.artefact = a.id
    LEFT OUTER JOIN {artefact_attachment} aa ON aa.attachment = a.id
21
    LEFT OUTER JOIN {skin} s ON (s.bodybgimg = a.id OR s.viewbgimg = a.id)
22
    LEFT OUTER JOIN {interaction_forum_post_attachment} fpa ON fpa.attachment = a.id
23
    LEFT OUTER JOIN {usr} u ON (u.id = a.owner)
24 25
    WHERE artefacttype = \'profileicon\'
    AND a.owner = ?
26
    GROUP BY a.id, a.title, a.note, isdefault
27 28
    ORDER BY a.id', array($USER->get('id')));

29 30 31 32 33 34 35
if ($result) {
    foreach ($result as $r) {
        $r->default_str = get_string('setdefaultfor', 'artefact.file', ($r->title ? $r->title : $r->note));
        $r->delete_str = get_string('markfordeletionspecific', 'artefact.file', ($r->title ? $r->title : $r->note));
    }
}

36 37 38 39 40 41 42 43 44 45 46
$lastrow = array(
    'id'        => 0,
    'isdefault' => 't',
    'title'     => get_string('standardavatartitle', 'artefact.file'),
    'note'      => get_string('standardavatarnote', 'artefact.file')
);
$usersdefaulticon = record_exists_select('usr', 'profileicon IS NULL AND id = ?', array($USER->get('id')));
if (!$usersdefaulticon) {
    $lastrow['isdefault'] = 'f';
}
if (!$result) {
47 48
    $result = array();
}
49
$result[] = $lastrow;
50 51 52 53

$data['error'] = false;
$data['data'] = $result;
$data['count'] = ($result) ? count($result) : 0;
54
json_reply(false, $data);