Пример #1
0
    public function UpdateCounter($oTopic)
    {
        $sql = 'SELECT
					DISTINCT user_id
				FROM 
					' . Config::Get('db.table.topic_read') . '
				WHERE
					topic_id = ?d';
        $aUserId = $this->oDb->selectCol($sql, $oTopic->getId());
        $oUserCurrent = PluginLib_ModuleUser::GetUserCurrent();
        if (in_array($oUserCurrent->getId(), $aUserId)) {
            $iUsersRead = $oTopic->getCountUsersRead() + 1;
        } else {
            $iUsersRead = $oTopic->getCountUsersRead();
        }
        $sql = 'UPDATE ' . Config::Get('db.table.topic') . '
					SET
						topic_count_read = ?d,
						topic_count_unique_read = ?d,
						topic_count_users_read = ?d
					WHERE
						topic_id = ?d
				';
        if ($this->oDb->query($sql, $oTopic->getCountRead() + 1, count($aUserId), $iUsersRead, $oTopic->getId())) {
            return true;
        }
        return false;
    }
Пример #2
0
 public function Init()
 {
     parent::Init();
     //init all parent stuff
     $this->oMapperTopic = Engine::GetMapper('PluginMystuff_ModuleTopic');
     //this is essential, otherwise the default mapper is used, which we do not want
     $this->oMapperTopic->SetUserCurrent(PluginLib_ModuleUser::GetUserCurrent());
 }
Пример #3
0
 /**
  * Возвращает текущего пользователя. Если пользователь "аноним", то создаёт для него объект
  * с id = 0 и возвращает его.
  * 
  * @return	oUser		Результат проверки
  */
 public static function GetUserCurrent()
 {
     if (!self::$oUserCurrent) {
         $oEngine = Engine::getInstance();
         list($oModuleUser, $sModuleName, $sMethod) = $oEngine->GetModule('User_IsAuthorization');
         //Проверяем является находистя ли пользователь в системе
         if (!$oModuleUser->IsAuthorization()) {
             //Создаём анонима
             self::$oUserCurrent = Engine::GetEntity('User_User', array('user_id' => self::ANONIM_USER_ID, 'user_is_administrator' => false));
         } else {
             self::$oUserCurrent = $oModuleUser->GetUserCurrent();
         }
     }
     return self::$oUserCurrent;
 }
Пример #4
0
    public function getTopicIDsForMyStuff($oUser, $aFilter = array())
    {
        $sql = 'SELECT 
						user_to 
						FROM ' . Config::Get('db.table.friend') . ' 
						WHERE 
							user_from = ?d 
							AND (status_from = 1
							OR status_from   = 2)
					UNION 
					SELECT 
						user_from 
						FROM ' . Config::Get('db.table.friend') . '
						WHERE 
							user_to = ?d
							AND (status_to = 1
							OR status_to = 2)';
        //first, get a list of all my friends
        $friends = $this->oDb->selectCol($sql, $oUser->getId(), $oUser->getId());
        dump('My friends are: ' . print_r($friends, true));
        //now get a list of topics my friends commented
        $oUserCurrent = PluginLib_ModuleUser::GetUserCurrent();
        $sAccessWhere = !$oUserCurrent->isAdministrator() && PluginLib_ModulePlugin::IsPluginAvailable('accesstotopic') ? ' AND ' . PluginAccesstotopic_ModuleAccess::GetAccessWhereStatment($oUserCurrent->getId()) : ' ';
        $sDateWhere = '';
        if (isset($aFilter['more']['topic_add_date']) && isset($aFilter['less']['topic_add_date'])) {
            $sDateWhere = ' AND tc.created >= "' . mysql_real_escape_string($aFilter['more']['topic_add_date']) . '" AND ' . 'tc.created <= "' . mysql_real_escape_string($aFilter['less']['topic_add_date']) . '"';
        }
        $sql = 'SELECT
						tc.topic_id 
					FROM 
						' . Config::Get('plugin.mystuff.table.topic_commented') . ' as tc,
						' . Config::Get('db.table.topic') . ' as t
					WHERE
						tc.user_id IN (?a)
						AND
						tc.topic_id = t.topic_id
						' . $sDateWhere . '
						' . $sAccessWhere . '
					';
        if ($topics = $this->oDb->selectCol($sql, $friends)) {
            $topics = array_unique($topics);
            dump('My Stuff Topics are: ' . print_r($topics, true));
            return $topics;
        }
        //fallback
        return array();
    }
Пример #5
0
 /**
  * Список топиков по фильтру
  *
  * @param  array $aFilter
  * @return array
  */
 public function GetTopicsForBlogosphereByFilter($aFilter)
 {
     $aFilter['oUser'] = PluginLib_ModuleUser::GetUserCurrent();
     $aFilterConfig = $this->getFilterConfig($aFilter['filterType']);
     if (isset($aFilterConfig['function'])) {
         $sOutsideGetTopicsFunctionName = $aFilterConfig['function'];
         return $this->{$sOutsideGetTopicsFunctionName}($aFilter);
     } elseif (isset($aFilterConfig['type'])) {
         $sPrepareStandartFilterMethodName = $this->getFilterMethodName($aFilterConfig['type']);
         $aFilter = $this->{$sPrepareStandartFilterMethodName}($aFilter);
     }
     $s = serialize($aFilter);
     if (false === ($data = $this->Cache_Get("topic_filter_{$s}"))) {
         $data = $this->oMapperTopic->GetTopicsForBlogosphereByFilter($aFilter);
         $this->Cache_Set($data, "topic_filter_{$s}", array('topic_update', 'topic_new'), 60 * 60 * 24 * 3);
     }
     $data = $this->GetTopicsAdditionalData($data);
     return $data;
 }
Пример #6
0
    /**
     * Получаем массив id топиков удовлетворяющих фильтру
     * 
     * @param	array		параметры фильтра 'aUserFilter' array(
     * 												'more' => array('fieldName' => 'value'),
     * 												'less' => ...,
     * 												'in' => ...
     * 												...
     * 											),
     * 											'aTopicFilter' => (...)
     * @param	array		(поле=>направление для сортировки)
     * @param	array		параметры для браузера страниц ('iPage', 'iElementsPerPage')
     * @return	array		массив id
     */
    public function GetTopicsByFilters($aFilters, $aOrder, $aPaging)
    {
        if (isset($aFilters['aUserFilter'])) {
            $sUserWhere = PluginLib_ModuleMapper::BuildFilter($aFilters['aUserFilter'], 'u');
        } else {
            $sUserWhere = '';
        }
        if (isset($aFilters['aTopicFilter'])) {
            $sTopicWhere = PluginLib_ModuleMapper::BuildFilter($aFilters['aTopicFilter'], 't');
        } else {
            $sTopicWhere = '';
        }
        $oUserCurrent = PluginLib_ModuleUser::GetUserCurrent();
        if (!$oUserCurrent->isAdministrator() && PluginLib_ModulePlugin::IsPluginAvailable('accesstotopic')) {
            $sTopicWhere .= ' AND ' . PluginAccesstotopic_ModuleAccess::GetAccessWhereStatment($oUserCurrent->getId());
        }
        $sOrder = PluginLib_ModuleMapper::BuildOrder($aOrder, 't');
        $sLimit = PluginLib_ModuleMapper::BuildLimit($aPaging);
        $sql = 'SELECT 
						t.topic_id
					FROM 
						' . Config::Get('db.table.user') . ' as u,
						' . Config::Get('db.table.topic') . ' as t
					WHERE t.user_id = u.user_id
						' . $sUserWhere . '
						' . $sTopicWhere . '
						' . $sOrder . '
						' . $sLimit;
        $aTopics = array();
        if ($aRows = $this->oDb->select($sql)) {
            foreach ($aRows as $aTopic) {
                $aTopics[] = $aTopic['topic_id'];
            }
        }
        return $aTopics;
    }
Пример #7
0
 /**
  * Удаляем из полученных топиков те, к которым текущий пользователь не должен получить доступ.
  * @param	array		ассоциатвный массив результатов запроса и параметров.
  */
 protected function deleteTopicsWithoutNeccessaryAccess($aTopics)
 {
     if (!is_array($aTopics)) {
         return $aTopics;
     }
     $oUserCurrent = PluginLib_ModuleUser::GetUserCurrent();
     //Для админа никаких ограничений
     if ($oUserCurrent->isAdministrator()) {
         return $aTopics;
     }
     //Обходим все топики в выборке и принимаем решение оставлять ли каждый из них.
     $aNewResult = array();
     foreach ($aTopics as $oTopic) {
         if ($this->PluginAccesstotopic_ModuleAccess_CheckAccessToTopic($oUserCurrent, $oTopic)) {
             $aNewResult[$oTopic->getId()] = $oTopic;
         }
     }
     return $aNewResult;
 }
Пример #8
0
 private function checkUserRights($oBlog)
 {
     //получаем текущего юзера
     $oUserCurrent = PluginLib_ModuleUser::GetUserCurrent();
     //владелец блога может закреплять топики
     if ($oBlog->getOwnerId() == $oUserCurrent->getId()) {
         return true;
     }
     //администратор может закреплять топики
     if ($oUserCurrent->isAdministrator()) {
         return true;
     }
     //администратор блога может закреплять топики
     $aUsersObjs = $this->ModuleBlog_GetBlogUsersByBlogId($oBlog->getId());
     if (isset($aUsersObjs[$oUserCurrent->getId()])) {
         $oUserBlog = $aUsersObjs[$oUserCurrent->getId()];
         if ($oUserBlog->getIsAdministrator()) {
             return true;
         }
     }
     //в противном случае пользователь не может закреплять топики
     return false;
 }
Пример #9
0
    public function GetAllTopics($aFilter)
    {
        $oUserCurrent = PluginLib_ModuleUser::GetUserCurrent();
        $sAccessWhere = $oUserCurrent->isAdministrator() ? '' : ' AND ' . PluginAccesstotopic_ModuleAccess::GetAccessWhereStatment($oUserCurrent->getId());
        $sWhere = $this->buildFilter($aFilter);
        $sql = 'SELECT 
						t.topic_id
					FROM 
						' . Config::Get('db.table.topic') . ' as t,
						' . Config::Get('db.table.blog') . ' as b
					WHERE 
						1=1
						' . $sWhere . '
						' . $sAccessWhere . '
						AND
						t.blog_id=b.blog_id
					ORDER by t.topic_id desc';
        $aTopics = array();
        if ($aRows = $this->oDb->select($sql)) {
            foreach ($aRows as $aTopic) {
                $aTopics[] = $aTopic['topic_id'];
            }
        }
        return $aTopics;
    }