Example #1
0
 /**
  * Get collections which have been explicitly shared to a group and are
  * not owned by the group
  * @param integer $limit
  * @param integer $offset
  * @param integer $groupid
  * @param boolean $membersonly Only return collections owned by members of the gorup
  * @param array $sort Columns to sort by (defaults to (title, id) if empty)
  * @return array of collections
  */
 public static function get_sharedcollections_data($limit = 10, $offset = 0, $groupid, $membersonly = false, $sort = null)
 {
     global $USER;
     $userid = $USER->get('id');
     require_once get_config('libroot') . 'group.php';
     if (!group_user_access($groupid)) {
         throw new AccessDeniedException(get_string('accessdenied', 'error'));
     }
     $from = '
         FROM {collection} c
             INNER JOIN {collection_view} cv ON (cv.collection = c.id)
             INNER JOIN {view_access} a ON (a.view = cv.view)
             INNER JOIN {view} v ON (cv.view = v.id)
             INNER JOIN {group_member} m ON (a.group = m.group AND (a.role = m.role OR a.role IS NULL)) ';
     $where = ' WHERE
             a.group = ?
             AND m.member = ?
             AND (c.group IS NULL OR c.group != ?)
             AND (a.startdate <= CURRENT_TIMESTAMP OR a.startdate IS NULL)
             AND (a.stopdate > CURRENT_TIMESTAMP OR a.stopdate IS NULL)
             AND (v.startdate <= CURRENT_TIMESTAMP OR v.startdate IS NULL)
             AND (v.stopdate > CURRENT_TIMESTAMP OR v.stopdate IS NULL)
     ';
     $ph = array($groupid, $userid, $groupid);
     if ($membersonly) {
         $from .= ' INNER JOIN {group_member} m2 ON m2.member = c.owner ';
         $where .= ' AND m2.group = ? ';
         $ph[] = $groupid;
     }
     $count = count_records_sql('SELECT COUNT(DISTINCT c.id) ' . $from . $where, $ph);
     $select = 'SELECT DISTINCT c.id, c.name, c.description, c.owner, c.group, c.institution, c.ctime, c.mtime';
     $orderby = ' ORDER BY ';
     if (is_array($sort)) {
         foreach ($sort as $sortitem) {
             $select .= ", {$sortitem['column']}";
             $orderby .= " {$sortitem['column']}";
             if (!empty($sortitem['desc'])) {
                 $orderby .= " DESC";
             }
         }
         $orderby .= ', c.id';
     } else {
         $orderby = ' ORDER BY c.name, c.id';
     }
     $collectiondata = get_records_sql_assoc($select . $from . $where . $orderby, $ph, $offset, $limit);
     if ($collectiondata) {
         View::get_extra_collection_info($collectiondata);
     } else {
         $collectiondata = array();
     }
     return (object) array('data' => array_values($collectiondata), 'count' => $count, 'limit' => $limit, 'offset' => $offset);
 }
Example #2
0
 /**
  * Get collections which have been explicitly shared to a group and are
  * not owned by the group
  * @param $limit, $offset for pagination
  * @param $groupid
  * @return array of collections
  */
 public static function get_sharedcollections_data($limit = 10, $offset = 0, $groupid)
 {
     global $USER;
     $userid = $USER->get('id');
     require_once get_config('libroot') . 'group.php';
     if (!group_user_access($groupid)) {
         throw new AccessDeniedException(get_string('accessdenied', 'error'));
     }
     $from = '
         FROM {collection} c
             INNER JOIN {collection_view} cv ON (cv.collection = c.id)
             INNER JOIN {view_access} a ON (a.view = cv.view)
             INNER JOIN {group_member} m ON (a.group = m.group AND (a.role = m.role OR a.role IS NULL))
         WHERE a.group = ? AND m.member = ? AND (c.group IS NULL OR c.group != ?)';
     $ph = array($groupid, $userid, $groupid);
     $count = count_records_sql('SELECT COUNT(DISTINCT c.id) ' . $from, $ph);
     $collectiondata = get_records_sql_assoc('
         SELECT DISTINCT c.id,c.name,c.description,c.owner,c.group,c.institution ' . $from . '
         ORDER BY c.name, c.id', $ph, $offset, $limit);
     if ($collectiondata) {
         View::get_extra_collection_info($collectiondata);
     } else {
         $collectiondata = array();
     }
     return (object) array('data' => array_values($collectiondata), 'count' => $count, 'limit' => $limit, 'offset' => $offset);
 }