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 
<?php
defined('C5_EXECUTE') or die("Access Denied.");

/**
 * @package Users
 * @author Andrew Embler <[email protected]>
 * @copyright  Copyright (c) 2003-2008 Concrete5. (http://www.concrete5.org)
 * @license    http://www.concrete5.org/license/     MIT License
 * @access private
 */
 
/** 
 * @access private
 */

class Concrete5_Model_GroupSearch extends DatabaseItemList {
    
    
    protected $itemsPerPage = 10;
    protected $minimumGroupID = REGISTERED_GROUP_ID;
    
    public function includeAllGroups() {
        $this->minimumGroupID = -1;
    }
    
    public function filterByKeywords($kw) {
        static $reverseLookup = array();
        $db = Loader::db();
        $locale = Localization::activeLocale();
        if(!array_key_exists($locale, $reverseLookup)) {
            $reverseLookup[$locale] = false;
            if((Localization::activeLocale() != 'en_US') || ENABLE_TRANSLATE_LOCALE_EN_US) {
                $limit = defined('GROUPNAME_REVERSELOOKUP_LIMIT') ? GROUPNAME_REVERSELOOKUP_LIMIT : 100;
                $count = $db->GetOne('select count(*) from Groups');
                if(($count > 0) && ($count <= $limit)) {
                    $reverseLookup[$locale] = array();
                    $rs = $db->Query('select gID, gName, gDescription from Groups');
                    while($row = $rs->FetchRow()) {
                        $reverseLookup[$locale][$row['gID']] = array('name' => tc('GroupName', $row['gName']), 'description' => tc('GroupDescription', $row['gDescription']));
                    }
                    $rs->Close();
                }
            }
        }
        if($reverseLookup[$locale]) {
            $foundIDs = array();
            foreach($reverseLookup[$locale] as $gID => $gTranslated) {
                if((stripos($gTranslated['name'], $kw) !== false) || (stripos($gTranslated['description'], $kw) !== false)) {
                    $foundIDs[] = $gID;
                }
            }
            if(count($foundIDs)) {
                $this->filter(false, '(Groups.gID in (' . implode(', ', $foundIDs) . '))');
                return;
            }
        }
        $this->filter(false, "(Groups.gName like " . $db->qstr('%' . $kw . '%') . " or Groups.gDescription like " . $db->qstr('%' . $kw . '%') . ")");
    }
    
    public function filterByAllowedPermission($pk) {
        $assignment = $pk->getMyAssignment();
        $r = $assignment->getGroupsAllowedPermission();
        $gIDs = array('-1');
        if ($r == 'C') {
            $gIDs = array_merge($assignment->getGroupsAllowedArray(), $gIDs);
            $this->filter('gID', $gIDs, 'in');
        }
    }
    
    public function updateItemsPerPage( $num ) {
        $this->itemsPerPage = $num;
    }
    
    function __construct() {
        $this->setQuery("select Groups.gID, Groups.gName, Groups.gDescription from Groups");
        $this->sortBy('gName', 'asc');
    }
    
    public function getPage() {
        $this->filter('gID', $this->minimumGroupID, '>');
        return parent::getPage();
    }
}