This is the API documentation for concrete5 version 5.6 and earlier. View Current API Documentation
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 
<?php
defined('C5_EXECUTE') or die("Access Denied.");
/**
 * Bundles groups together into different sets.
 * @package Users
 * @author Andrew Embler <[email protected]>
 * @category Concrete
 * @copyright  Copyright (c) 2003-2008 Concrete5. (http://www.concrete5.org)
 * @license    http://www.concrete5.org/license/     MIT License
 *
 */

class Concrete5_Model_GroupSet extends Object {
    
    public static function getList() {
        $db = Loader::db();
        $r = $db->Execute('select gsID from GroupSets order by gsName asc');
        $list = array();
        while ($row = $r->FetchRow()) {
            $list[] = GroupSet::getByID($row['gsID']);
        }
        return $list;
    }   

    public static function getByID($gsID) {
        $db = Loader::db();
        $row = $db->GetRow('select gsID, pkgID, gsName from GroupSets where gsID = ?', array($gsID));
        if (isset($row['gsID'])) {
            $gs = new GroupSet();
            $gs->setPropertiesFromArray($row);
            return $gs;
        }
    }

    public static function getByName($gsName) {
        $db = Loader::db();
        $row = $db->GetRow('select gsID, pkgID, gsName from GroupSets where gsName = ?', array($gsName));
        if (isset($row['gsID'])) {
            $gs = new GroupSet();
            $gs->setPropertiesFromArray($row);
            return $gs;
        }
    }  

    public static function getListByPackage($pkg) {
        $db = Loader::db();
        $list = array();
        $r = $db->Execute('select gsID from GroupSets where pkgID = ? order by gsID asc', array($pkg->getPackageID()));
        while ($row = $r->FetchRow()) {
            $list[] = GroupSet::getByID($row['gsID']);
        }
        $r->Close();
        return $list;
    }
    
    public function getGroupSetID() {return $this->gsID;}
    public function getGroupSetName() {return $this->gsName;}
    public function getPackageID() {return $this->pkgID;}

    /** Returns the display name for this group set (localized and escaped accordingly to $format)
    * @param string $format = 'html'
    *   Escape the result in html format (if $format is 'html').
    *   If $format is 'text' or any other value, the display name won't be escaped.
    * @return string
    */
    public function getGroupSetDisplayName($format = 'html') {
        $value = tc('GroupSetName', $this->getGroupSetName());
        switch($format) {
            case 'html':
                return h($value);
            case 'text':
            default:
                return $value;
        }
    }

    public function updateGroupSetName($gsName) {
        $this->gsName = $gsName;
        $db = Loader::db();
        $db->Execute("update GroupSets set gsName = ? where gsID = ?", array($gsName, $this->gsID));
    }

    public function addGroup(Group $g) {
        $db = Loader::db();
        $no = $db->GetOne("select count(gID) from GroupSetGroups where gID = ? and gsID = ?", array($g->getGroupID(), $this->getGroupSetID()));
        if ($no < 1) {
            $db->Execute('insert into GroupSetGroups (gsID, gID) values (?, ?)', array($this->getGroupSetID(), $g->getGroupID()));
        }
    }

    public static function add($gsName, $pkg = false) {
        $db = Loader::db();
        $pkgID = 0;
        if (is_object($pkg)) {
            $pkgID = $pkg->getPackageID();
        }
        $db->Execute('insert into GroupSets (gsName, pkgID) values (?,?)', array($gsName, $pkgID));
        $id = $db->Insert_ID();
        $gs = GroupSet::getByID($id);
        return $gs;
    }

    public function clearGroups() {
        $db = Loader::db();
        $db->Execute('delete from GroupSetGroups where gsID = ?', array($this->gsID));
    }

    public function getGroups() {
        $db = Loader::db();
        $r = $db->Execute('select gID from GroupSetGroups where gsID = ? order by gID asc', $this->getGroupSetId());
        $groups = array();
        while ($row = $r->FetchRow()) {
            $g = Group::getByID($row['gID']);
            if (is_object($g)) {
                $groups[] = $g;
            }
        }
        return $groups;     
    }
    
    public function contains(Group $g) {
        $db = Loader::db();
        $r = $db->GetOne('select count(gID) from GroupSetGroups where gsID = ? and gID = ?', array($this->getGroupSetID(), $g->getGroupID()));
        return $r > 0;
    }   
    
    public function delete() {
        $db = Loader::db();
        $db->Execute('delete from GroupSets where gsID = ?', array($this->getGroupSetID()));
        $db->Execute('delete from GroupSetGroups where gsID = ?', array($this->getGroupSetID()));
    }
    
    public function removeGroup(Group $g) {
        $db = Loader::db();
        $db->Execute('delete from GroupSetGroups where gsID = ? and gID = ?', array($this->getGroupSetID(), $g->getGroupID()));
    }
        
}