mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-06-26 11:40:48 +03:00
Функционал заметки о пользователе
This commit is contained in:
parent
a3d2ad4ed3
commit
ccd13f5ec9
|
@ -44,6 +44,8 @@ class ActionProfile extends Action {
|
|||
$this->AddEvent('ajaxfriendadd', 'EventAjaxFriendAdd');
|
||||
$this->AddEvent('ajaxfrienddelete', 'EventAjaxFriendDelete');
|
||||
$this->AddEvent('ajaxfriendaccept', 'EventAjaxFriendAccept');
|
||||
$this->AddEvent('ajax-note-save', 'EventAjaxNoteSave');
|
||||
$this->AddEvent('ajax-note-remove', 'EventAjaxNoteRemove');
|
||||
|
||||
$this->AddEventPreg('/^.+$/i','/^(whois)?$/i','EventWhois');
|
||||
$this->AddEventPreg('/^.+$/i','/^wall$/i','/^$/i','EventWall');
|
||||
|
@ -184,6 +186,12 @@ class ActionProfile extends Action {
|
|||
* Получаем список контактов
|
||||
*/
|
||||
$aUserFields = $this->User_getUserFieldsValues($this->oUserProfile->getId());
|
||||
/**
|
||||
* Заметка текущего пользователя о юзере
|
||||
*/
|
||||
if ($this->oUserCurrent) {
|
||||
$this->Viewer_Assign('oUserNote',$this->User_GetUserNote($this->oUserProfile->getId(),$this->oUserCurrent->getId()));
|
||||
}
|
||||
/**
|
||||
* Вызов хуков
|
||||
*/
|
||||
|
@ -359,6 +367,64 @@ class ActionProfile extends Action {
|
|||
$this->Viewer_AssignAjax('iCountWallReturn',count($aWall['collection']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Сохраняет заметку о пользователе
|
||||
*/
|
||||
public function EventAjaxNoteSave() {
|
||||
$this->Viewer_SetResponseAjax('json');
|
||||
if (!$this->oUserCurrent) {
|
||||
return parent::EventNotFound();
|
||||
}
|
||||
|
||||
/**
|
||||
* Создаем заметку и проводим валидацию
|
||||
*/
|
||||
$oNote=Engine::GetEntity('ModuleUser_EntityNote');
|
||||
$oNote->setTargetUserId(getRequest('iUserId'));
|
||||
$oNote->setUserId($this->oUserCurrent->getId());
|
||||
$oNote->setText(getRequest('text'));
|
||||
|
||||
if ($oNote->_Validate()) {
|
||||
/**
|
||||
* Экранируем текст и добавляем запись в БД
|
||||
*/
|
||||
$oNote->setText(htmlspecialchars($oNote->getText()));
|
||||
if ($this->User_SaveNote($oNote)) {
|
||||
$this->Viewer_AssignAjax('sText',$oNote->getText());
|
||||
} else {
|
||||
$this->Message_AddError($this->Lang_Get('user_note_save_error'),$this->Lang_Get('error'));
|
||||
}
|
||||
} else {
|
||||
/**
|
||||
* Пробегаем по ошибкам валидации
|
||||
*/
|
||||
foreach($oNote->_getValidateErrors() as $sField=>$aErros) {
|
||||
foreach($aErros as $sError) {
|
||||
$this->Message_AddError($sError,$this->Lang_Get('error'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Удаляет заметку о пользователе
|
||||
*/
|
||||
public function EventAjaxNoteRemove() {
|
||||
$this->Viewer_SetResponseAjax('json');
|
||||
if (!$this->oUserCurrent) {
|
||||
return parent::EventNotFound();
|
||||
}
|
||||
|
||||
if (!($oUserTarget=$this->User_GetUserById(getRequest('iUserId')))) {
|
||||
return parent::EventNotFound();
|
||||
}
|
||||
if (!($oNote=$this->User_GetUserNote($oUserTarget->getId(),$this->oUserCurrent->getId()))) {
|
||||
return parent::EventNotFound();
|
||||
}
|
||||
$this->User_DeleteUserNoteById($oNote->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавление пользователя в друзья, по отправленной заявке
|
||||
*/
|
||||
|
|
|
@ -1310,5 +1310,88 @@ class ModuleUser extends Module {
|
|||
public function DeleteUserFieldValues($iUserId,$aType=null) {
|
||||
return $this->oMapper->DeleteUserFieldValues($iUserId,$aType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает список заметок пользователя
|
||||
*
|
||||
* @param $iUserId
|
||||
* @param $iCurrPage
|
||||
* @param $iPerPage
|
||||
* @return array
|
||||
*/
|
||||
public function GetUserNotesByUserId($iUserId,$iCurrPage,$iPerPage) {
|
||||
$aResult=$this->oMapper->GetUserNotesByUserId($iUserId,$iCount,$iCurrPage,$iPerPage);
|
||||
/**
|
||||
* Цепляем пользователей
|
||||
*/
|
||||
$aUserId=array();
|
||||
foreach($aResult as $oNote) {
|
||||
$aUserId[]=$oNote->getTargetUserId();
|
||||
}
|
||||
$aUsers=$this->GetUsersAdditionalData($aUserId,array());
|
||||
foreach($aResult as $oNote) {
|
||||
if (isset($aUsers[$oNote->getTargetUserId()])) {
|
||||
$oNote->setTargetUser($aUsers[$oNote->getTargetUserId()]);
|
||||
} else {
|
||||
$oNote->setTargetUser(Engine::GetEntity('User')); // пустого пользователя во избеания ошибок, т.к. пользователь всегда должен быть
|
||||
}
|
||||
}
|
||||
return array('collection'=>$aResult,'count'=>$iCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращет заметку по автору и пользователю
|
||||
*
|
||||
* @param $iTargetUserId
|
||||
* @param $iUserId
|
||||
* @return ModuleUser_EntityNote
|
||||
*/
|
||||
public function GetUserNote($iTargetUserId,$iUserId) {
|
||||
return $this->oMapper->GetUserNote($iTargetUserId,$iUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Врзвращает заметку по ID
|
||||
*
|
||||
* @param $iId
|
||||
* @return ModuleUser_EntityNote
|
||||
*/
|
||||
public function GetUserNoteById($iId) {
|
||||
return $this->oMapper->GetUserNoteById($iId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Удаляет заметку по ID
|
||||
*
|
||||
* @param $iId
|
||||
* @return bool
|
||||
*/
|
||||
public function DeleteUserNoteById($iId) {
|
||||
return $this->oMapper->DeleteUserNoteById($iId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Сохраняет заметку в БД, если ее нет то создает новую
|
||||
*
|
||||
* @param $oNote
|
||||
* @return bool|ModuleUser_EntityNote
|
||||
*/
|
||||
public function SaveNote($oNote) {
|
||||
if (!$oNote->getDateAdd()) {
|
||||
$oNote->setDateAdd(date("Y-m-d H:i:s"));
|
||||
}
|
||||
|
||||
if ($oNoteOld=$this->GetUserNote($oNote->getTargetUserId(),$oNote->getUserId()) ) {
|
||||
$oNoteOld->setText($oNote->getText());
|
||||
$this->oMapper->UpdateUserNote($oNoteOld);
|
||||
return $oNoteOld;
|
||||
} else {
|
||||
if ($iId=$this->oMapper->AddUserNote($oNote)) {
|
||||
$oNote->setId($iId);
|
||||
return $oNote;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
?>
|
46
classes/modules/user/entity/Note.entity.class.php
Normal file
46
classes/modules/user/entity/Note.entity.class.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
/*-------------------------------------------------------
|
||||
*
|
||||
* LiveStreet Engine Social Networking
|
||||
* Copyright © 2008 Mzhelskiy Maxim
|
||||
*
|
||||
*--------------------------------------------------------
|
||||
*
|
||||
* Official site: www.livestreet.ru
|
||||
* Contact e-mail: rus.engine@gmail.com
|
||||
*
|
||||
* GNU General Public License, version 2:
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
---------------------------------------------------------
|
||||
*/
|
||||
|
||||
class ModuleUser_EntityNote extends Entity {
|
||||
|
||||
/**
|
||||
* Определяем правила валидации
|
||||
*/
|
||||
protected $aValidateRules=array(
|
||||
array('target_user_id','target'),
|
||||
);
|
||||
|
||||
public function Init() {
|
||||
parent::Init();
|
||||
$this->aValidateRules[]=array('text','string','max'=>Config::Get('module.user.usernote_text_max'),'min'=>1,'allowEmpty'=>false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Валидация пользователя
|
||||
*
|
||||
* @param $sValue
|
||||
* @param $aParams
|
||||
* @return bool
|
||||
*/
|
||||
public function ValidateTarget($sValue,$aParams) {
|
||||
if ($oUserTarget=$this->User_GetUserById($sValue) and $this->getUserId()!=$oUserTarget->getId()) {
|
||||
return true;
|
||||
}
|
||||
return $this->Lang_Get('user_note_target_error');
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -934,5 +934,64 @@ class ModuleUser_MapperUser extends Mapper {
|
|||
)';
|
||||
return $this->oDb->query($sql,$iUserId,(is_null($aType) or !count($aType)) ? DBSIMPLE_SKIP : $aType);
|
||||
}
|
||||
|
||||
|
||||
public function GetUserNotesByUserId($iUserId,&$iCount,$iCurrPage,$iPerPage) {
|
||||
$sql = "
|
||||
SELECT *
|
||||
FROM
|
||||
".Config::Get('db.table.user_note')."
|
||||
WHERE
|
||||
user_id = ?d
|
||||
ORDER BY id DESC
|
||||
LIMIT ?d, ?d ";
|
||||
$aReturn=array();
|
||||
if ($aRows=$this->oDb->selectPage($iCount,$sql,$iUserId,($iCurrPage-1)*$iPerPage, $iPerPage)) {
|
||||
foreach ($aRows as $aRow) {
|
||||
$aReturn[]=Engine::GetEntity('ModuleUser_EntityNote',$aRow);
|
||||
}
|
||||
}
|
||||
return $aReturn;
|
||||
}
|
||||
|
||||
public function GetUserNote($iTargetUserId,$iUserId) {
|
||||
$sql = "SELECT * FROM ".Config::Get('db.table.user_note')." WHERE target_user_id = ?d and user_id = ?d ";
|
||||
if ($aRow=$this->oDb->selectRow($sql,$iTargetUserId,$iUserId)) {
|
||||
return Engine::GetEntity('ModuleUser_EntityNote',$aRow);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function GetUserNoteById($iId) {
|
||||
$sql = "SELECT * FROM ".Config::Get('db.table.user_note')." WHERE id = ?d ";
|
||||
if ($aRow=$this->oDb->selectRow($sql,$iId)) {
|
||||
return Engine::GetEntity('ModuleUser_EntityNote',$aRow);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function DeleteUserNoteById($iId) {
|
||||
$sql = "DELETE FROM ".Config::Get('db.table.user_note')." WHERE id = ?d ";
|
||||
return $this->oDb->query($sql,$iId);
|
||||
}
|
||||
|
||||
public function AddUserNote($oNote) {
|
||||
$sql = "INSERT INTO ".Config::Get('db.table.user_note')." SET ?a ";
|
||||
if ($iId=$this->oDb->query($sql,$oNote->_getData())) {
|
||||
return $iId;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function UpdateUserNote($oNote) {
|
||||
$sql = "UPDATE ".Config::Get('db.table.user_note')."
|
||||
SET
|
||||
text = ?
|
||||
WHERE id = ?d
|
||||
";
|
||||
return $this->oDb->query($sql,$oNote->getText(),
|
||||
$oNote->getId());
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -177,6 +177,7 @@ $config['module']['user']['avatar_size'] = array(64,48,24,0); // Список р
|
|||
$config['module']['user']['login']['min_size'] = 3; // Минимальное количество символов в логине
|
||||
$config['module']['user']['login']['max_size'] = 30; // Максимальное количество символов в логине
|
||||
$config['module']['user']['time_active'] = 60*60*24*7; // Число секунд с момента последнего посещения пользователем сайта, в течение которых он считается активным
|
||||
$config['module']['user']['usernote_text_max'] = 250; // Максимальный размер заметки о пользователе
|
||||
// Модуль Comment
|
||||
$config['module']['comment']['per_page'] = 20; // Число комментариев на одну страницу(это касается только полного списка комментариев прямого эфира)
|
||||
$config['module']['comment']['bad'] = -5; // Рейтинг комментария, начиная с которого он будет скрыт
|
||||
|
@ -324,7 +325,8 @@ $config['db']['table']['user_field'] = '___db.table.prefix___user_field
|
|||
$config['db']['table']['user_field_value'] = '___db.table.prefix___user_field_value';
|
||||
$config['db']['table']['topic_photo'] = '___db.table.prefix___topic_photo';
|
||||
$config['db']['table']['subscribe'] = '___db.table.prefix___subscribe';
|
||||
$config['db']['table']['wall'] = '___db.table.prefix___wall';
|
||||
$config['db']['table']['wall'] = '___db.table.prefix___wall';
|
||||
$config['db']['table']['user_note'] = '___db.table.prefix___user_note';
|
||||
|
||||
$config['db']['tables']['engine'] = 'InnoDB'; // InnoDB или MyISAM
|
||||
/**
|
||||
|
@ -500,6 +502,7 @@ $config['head']['default']['js'] = array(
|
|||
"___path.root.engine_lib___/internal/template/js/poll.js",
|
||||
"___path.root.engine_lib___/internal/template/js/subscribe.js",
|
||||
"___path.root.engine_lib___/internal/template/js/wall.js",
|
||||
"___path.root.engine_lib___/internal/template/js/usernote.js",
|
||||
"___path.root.engine_lib___/internal/template/js/comments.js",
|
||||
"___path.root.engine_lib___/internal/template/js/blog.js",
|
||||
"___path.root.engine_lib___/internal/template/js/friend.js",
|
||||
|
|
69
engine/lib/internal/template/js/usernote.js
Normal file
69
engine/lib/internal/template/js/usernote.js
Normal file
|
@ -0,0 +1,69 @@
|
|||
var ls = ls || {};
|
||||
|
||||
ls.usernote =( function ($) {
|
||||
|
||||
this.sText='';
|
||||
|
||||
this.showForm = function(sText) {
|
||||
$('#usernote-button-add').hide();
|
||||
$('#usernote-note').hide();
|
||||
$('#usernote-form').show();
|
||||
if (this.sText) {
|
||||
$('#usernote-form-text').html(this.sText);
|
||||
} else {
|
||||
$('#usernote-form-text').val('');
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
this.hideForm = function() {
|
||||
$('#usernote-form').hide();
|
||||
if (this.sText) {
|
||||
this.showNote();
|
||||
} else {
|
||||
$('#usernote-button-add').show();
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
this.save = function(iUserId) {
|
||||
var url = aRouter['profile']+'ajax-note-save/';
|
||||
var params = {iUserId: iUserId, text: $('#usernote-form-text').val()};
|
||||
'*saveBefore*'; '*/saveBefore*';
|
||||
ls.ajax(url, params, function(result) {
|
||||
if (result.bStateError) {
|
||||
ls.msg.error(null, result.sMsg);
|
||||
} else {
|
||||
this.sText=result.sText;
|
||||
this.showNote();
|
||||
ls.hook.run('ls_usernote_save_after',[params, result]);
|
||||
}
|
||||
}.bind(this));
|
||||
return false;
|
||||
};
|
||||
|
||||
this.showNote = function() {
|
||||
$('#usernote-form').hide();
|
||||
$('#usernote-note').show();
|
||||
$('#usernote-note-text').html(this.sText);
|
||||
};
|
||||
|
||||
this.remove = function(iUserId) {
|
||||
var url = aRouter['profile']+'ajax-note-remove/';
|
||||
var params = {iUserId: iUserId};
|
||||
'*saveBefore*'; '*/saveBefore*';
|
||||
ls.ajax(url, params, function(result) {
|
||||
if (result.bStateError) {
|
||||
ls.msg.error(null, result.sMsg);
|
||||
} else {
|
||||
$('#usernote-note').hide();
|
||||
$('#usernote-button-add').show();
|
||||
this.sText='';
|
||||
ls.hook.run('ls_usernote_remove_after',[params, result]);
|
||||
}
|
||||
}.bind(this));
|
||||
return false;
|
||||
};
|
||||
|
||||
return this;
|
||||
}).call(ls.usernote || {},jQuery);
|
|
@ -44,4 +44,16 @@ CREATE TABLE IF NOT EXISTS `prefix_wall` (
|
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
ALTER TABLE `prefix_user_field` ADD `type` VARCHAR( 50 ) NOT NULL AFTER `id` ,
|
||||
ADD INDEX ( `type` );
|
||||
ADD INDEX ( `type` );
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `prefix_user_note` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`target_user_id` int(11) NOT NULL,
|
||||
`user_id` int(11) NOT NULL,
|
||||
`text` text NOT NULL,
|
||||
`date_add` datetime NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `user_id` (`user_id`),
|
||||
KEY `target_user_id` (`target_user_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
@ -531,6 +531,16 @@ return array(
|
|||
'user_field_error_add_no_name' => 'You must specify the name of the field',
|
||||
'user_field_error_add_no_title' => 'You must specify a title field',
|
||||
'user_field_error_name_exists' => 'Field with that name already exists',
|
||||
/**
|
||||
* Note fro user
|
||||
*/
|
||||
'user_note_form_edit' => 'Edit',
|
||||
'user_note_form_delete' => 'Remove',
|
||||
'user_note_form_save' => 'Save',
|
||||
'user_note_form_cancel' => 'Cancel',
|
||||
'user_note_add' => 'Add note',
|
||||
'user_note_save_error' => 'Error on save',
|
||||
'user_note_target_error' => 'Bad user for note',
|
||||
/**
|
||||
* Wall
|
||||
*/
|
||||
|
|
|
@ -531,6 +531,16 @@ return array(
|
|||
'user_field_error_add_no_name' => 'Необходимо указать название поля',
|
||||
'user_field_error_add_no_title' => 'Необходимо указать заголовок поля',
|
||||
'user_field_error_name_exists' => 'Поле с таким именем уже существует',
|
||||
/**
|
||||
* Заметка пользователя
|
||||
*/
|
||||
'user_note_form_edit' => 'Редактировать',
|
||||
'user_note_form_delete' => 'Удалить',
|
||||
'user_note_form_save' => 'Сохранить',
|
||||
'user_note_form_cancel' => 'Отмена',
|
||||
'user_note_add' => 'Написать заметку',
|
||||
'user_note_save_error' => 'Ошибка сохранения заметки',
|
||||
'user_note_target_error' => 'Неверный пользователь для заметки',
|
||||
/**
|
||||
* Стена
|
||||
*/
|
||||
|
|
|
@ -225,4 +225,29 @@
|
|||
</table>
|
||||
|
||||
|
||||
{if $oUserCurrent && $oUserCurrent->getId()!=$oUserProfile->getId()}
|
||||
{if $oUserNote}
|
||||
<script type="text/javascript">
|
||||
ls.usernote.sText={json var=$oUserNote->getText()};
|
||||
</script>
|
||||
{/if}
|
||||
|
||||
<div id="usernote-note" {if !$oUserNote}style="display:none;"{/if}>
|
||||
<div id="usernote-note-text">
|
||||
{if $oUserNote}
|
||||
{$oUserNote->getText()}
|
||||
{/if}
|
||||
</div>
|
||||
<a href="#" onclick="return ls.usernote.showForm();">{$aLang.user_note_form_edit}</a>
|
||||
<a href="#" onclick="return ls.usernote.remove({$oUserProfile->getId()});">{$aLang.user_note_form_delete}</a>
|
||||
</div>
|
||||
<div id="usernote-form" style="display:none;">
|
||||
<textarea rows="4" cols="20" id="usernote-form-text"></textarea><br/>
|
||||
<button onclick="return ls.usernote.save({$oUserProfile->getId()});">{$aLang.user_note_form_save}</button>
|
||||
<button onclick="return ls.usernote.hideForm();">{$aLang.user_note_form_cancel}</button>
|
||||
</div>
|
||||
<a href="#" onclick="return ls.usernote.showForm();" id="usernote-button-add" {if $oUserNote}style="display:none;"{/if}>{$aLang.user_note_add}</a>
|
||||
{/if}
|
||||
|
||||
|
||||
{include file='footer.tpl'}
|
Loading…
Reference in a new issue