mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-06-16 23:00:51 +03:00
Забыл файл в прошлом коммите - опросы
This commit is contained in:
parent
219a092c4a
commit
7c53f8e62e
150
application/classes/modules/poll/Poll.class.php
Normal file
150
application/classes/modules/poll/Poll.class.php
Normal file
|
@ -0,0 +1,150 @@
|
|||
<?php
|
||||
/**
|
||||
* LiveStreet CMS
|
||||
* Copyright © 2013 OOO "ЛС-СОФТ"
|
||||
*
|
||||
* ------------------------------------------------------
|
||||
*
|
||||
* Official site: www.livestreetcms.com
|
||||
* Contact e-mail: office@livestreetcms.com
|
||||
*
|
||||
* GNU General Public License, version 2:
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* ------------------------------------------------------
|
||||
*
|
||||
* @link http://www.livestreetcms.com
|
||||
* @copyright 2013 OOO "ЛС-СОФТ"
|
||||
* @author Maxim Mzhelskiy <rus.engine@gmail.com>
|
||||
*
|
||||
*/
|
||||
|
||||
class ModulePoll extends ModuleORM {
|
||||
|
||||
/**
|
||||
* Объект текущего пользователя
|
||||
*
|
||||
* @var ModuleUser_EntityUser|null
|
||||
*/
|
||||
protected $oUserCurrent;
|
||||
|
||||
protected $aTargetTypes=array(
|
||||
'topic'=>array(),
|
||||
);
|
||||
|
||||
/**
|
||||
* Инициализация
|
||||
*
|
||||
*/
|
||||
public function Init() {
|
||||
parent::Init();
|
||||
$this->oUserCurrent=$this->User_GetUserCurrent();
|
||||
}
|
||||
/**
|
||||
* Возвращает список типов объектов
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetTargetTypes() {
|
||||
return $this->aTargetTypes;
|
||||
}
|
||||
/**
|
||||
* Добавляет в разрешенные новый тип
|
||||
*
|
||||
* @param string $sTargetType Тип
|
||||
* @param array $aParams Параметры
|
||||
* @return bool
|
||||
*/
|
||||
public function AddTargetType($sTargetType,$aParams=array()) {
|
||||
if (!array_key_exists($sTargetType,$this->aTargetTypes)) {
|
||||
$this->aTargetTypes[$sTargetType]=$aParams;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Проверяет разрешен ли данный тип
|
||||
*
|
||||
* @param string $sTargetType Тип
|
||||
* @return bool
|
||||
*/
|
||||
public function IsAllowTargetType($sTargetType) {
|
||||
return in_array($sTargetType,array_keys($this->aTargetTypes));
|
||||
}
|
||||
/**
|
||||
* Возвращает парметры нужного типа
|
||||
*
|
||||
* @param string $sTargetType
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function GetTargetTypeParams($sTargetType) {
|
||||
if ($this->IsAllowTargetType($sTargetType)) {
|
||||
return $this->aTargetTypes[$sTargetType];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Проверка объекта target - владелец медиа
|
||||
*
|
||||
* @param string $sTargetType Тип
|
||||
* @param int $iTargetId ID владельца
|
||||
* @return bool
|
||||
*/
|
||||
public function CheckTarget($sTargetType,$iTargetId) {
|
||||
if (!$this->IsAllowTargetType($sTargetType)) {
|
||||
return false;
|
||||
}
|
||||
$sMethod = 'CheckTarget'.func_camelize($sTargetType);
|
||||
if (method_exists($this,$sMethod)) {
|
||||
return $this->$sMethod($iTargetId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Заменяет временный идентификатор на необходимый ID объекта
|
||||
*
|
||||
* @param string $sTargetType
|
||||
* @param string $sTargetId
|
||||
* @param null|string $sTargetTmp Если не задан, то берется их куки "poll_target_tmp_{$sTargetType}"
|
||||
*/
|
||||
public function ReplaceTargetTmpById($sTargetType,$sTargetId,$sTargetTmp=null) {
|
||||
$sCookieKey='poll_target_tmp_'.$sTargetType;
|
||||
if (is_null($sTargetTmp) and isset($_COOKIE[$sCookieKey])) {
|
||||
$sTargetTmp=$_COOKIE[$sCookieKey];
|
||||
setcookie($sCookieKey,null,-1,Config::Get('sys.cookie.path'),Config::Get('sys.cookie.host'));
|
||||
}
|
||||
if (is_string($sTargetTmp)) {
|
||||
$aPollItems=$this->Poll_GetPollItemsByTargetTmpAndTargetType($sTargetTmp,$sTargetType);
|
||||
foreach($aPollItems as $oPoll) {
|
||||
$oPoll->setTargetTmp(null);
|
||||
$oPoll->setTargetId($sTargetId);
|
||||
$oPoll->Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Проверка владельца с типом "topic"
|
||||
* Название метода формируется автоматически
|
||||
*
|
||||
* @param int $iTargetId ID владельца
|
||||
* @return bool
|
||||
*/
|
||||
public function CheckTargetTopic($iTargetId) {
|
||||
if ($oTopic=$this->Topic_GetTopicById($iTargetId)) {
|
||||
if (!$oTopicType=$this->Topic_GetTopicType($oTopic->getType()) or !$oTopicType->getParam('allow_poll')) {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Проверяем права на редактирование топика
|
||||
*/
|
||||
if ($this->ACL_IsAllowEditTopic($oTopic,$this->oUserCurrent)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue