2019-07-17 20:08:50 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2019-07-17 20:31:04 +00:00
|
|
|
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
2019-07-17 20:08:50 +00:00
|
|
|
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
|
|
|
* @author Keyboard Monkey Ltd
|
|
|
|
* @since CommunityID 0.9
|
|
|
|
* @package CommunityID
|
|
|
|
* @packager Keyboard Monkeys
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
class Model_Sites extends Monkeys_Db_Table_Gateway
|
2019-07-17 20:08:50 +00:00
|
|
|
{
|
|
|
|
protected $_name = 'sites';
|
|
|
|
protected $_primary = 'id';
|
2019-07-17 20:16:19 +00:00
|
|
|
protected $_rowClass = 'Model_Site';
|
2019-07-17 20:08:50 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
private $_userSites = array();
|
|
|
|
|
|
|
|
public function deleteForUserSite(Users_Model_User $user, $site)
|
2019-07-17 20:08:50 +00:00
|
|
|
{
|
|
|
|
$where1 = $this->getAdapter()->quoteInto('user_id=?',$user->id);
|
|
|
|
$where2 = $this->getAdapter()->quoteInto('site=?', $site);
|
|
|
|
$this->delete("$where1 AND $where2");
|
|
|
|
}
|
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
public function getSites(Users_Model_User $user)
|
|
|
|
{
|
|
|
|
if (!isset($this->_userSites[$user->username])) {
|
|
|
|
$select = $this->select()
|
|
|
|
->where('user_id=?', $user->id);
|
|
|
|
|
|
|
|
$this->_userSites[$user->username] = $this->fetchAll($select);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->_userSites[$user->username];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get(Users_Model_User $user, $startIndex, $results)
|
2019-07-17 20:08:50 +00:00
|
|
|
{
|
|
|
|
$select = $this->select()
|
|
|
|
->where('user_id=?', $user->id);
|
|
|
|
|
|
|
|
if ($startIndex !== false && $results !== false) {
|
|
|
|
$select = $select->limit($results, $startIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->fetchAll($select);
|
|
|
|
}
|
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
public function getNumSites(Users_Model_User $user)
|
2019-07-17 20:08:50 +00:00
|
|
|
{
|
|
|
|
$sites = $this->get($user, false, false);
|
|
|
|
|
|
|
|
return count($sites);
|
|
|
|
}
|
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
public function isTrusted(Users_Model_User $user, $site)
|
2019-07-17 20:08:50 +00:00
|
|
|
{
|
2019-07-17 20:16:19 +00:00
|
|
|
foreach ($this->getSites($user) as $userSite) {
|
|
|
|
if ($userSite->site == $site && $userSite->trusted != 'b:0;') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2019-07-17 20:08:50 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isNeverTrusted(Users_Model_User $user, $site)
|
|
|
|
{
|
|
|
|
foreach ($this->getSites($user) as $userSite) {
|
|
|
|
if ($userSite->site == $site && $userSite->trusted == 'b:0;') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2019-07-17 20:08:50 +00:00
|
|
|
}
|
|
|
|
}
|