public function add($user_follow, $user_followed, $type) { $check = Relationship::model()->findAllByAttributes(array('user_id_1' => $user_follow, 'user_id_2' => $user_followed)); $check_2 = Relationship::model()->findAllByAttributes(array('user_id_2' => $user_follow, 'user_id_1' => $user_followed)); $check_3 = Follow::model()->findByAttributes(array('user_follow' => $user_follow, 'user_followed' => $user_followed)); if ($check || $check_2 || $check_3 || $user_followed == Yii::app()->session['user_id']) { return FALSE; } $model = new Follow(); $model->user_follow = $user_follow; $model->user_followed = $user_followed; $model->created_at = time(); $model->update_at = time(); $model->type = $type; $user_follow_data = User::model()->findByPk($user_follow); $user_followed_data = User::model()->findByPk($user_followed); if ($user_follow != Yii::app()->session['user_id']) { $arr_noti = array('user_id' => $user_follow, 'content' => "{$user_follow_data->username} vừa theo dõi bạn", 'type' => 'follow', 'recipient_id' => $user_followed_data->id, 'url' => Yii::app()->createAbsoulteUrl('user/profile', array('user_id' => $user_follow_data->id, 'ref' => 'noti'))); Notifications::model()->add($arr_noti); } if ($model->save(FALSE)) { return TRUE; } return FALSE; }
public function getNotification($user_id, $limit, $offset) { $criteria = new CDbCriteria(); $criteria->limit = $limit; $criteria->offset = $offset; $criteria->condition = "user_id = {$user_id}"; return $data = Notifications::model()->findAll($criteria); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = Notifications::model()->findByPk((int) $id); if ($model === null) { throw new CHttpException(404, Yii::t('site', '404_Error')); } return $model; }
public function afterDelete() { parent::afterDelete(); $shared = Shared::model()->findAllByAttributes(array('cam_id' => $this->id)); foreach ($shared as $s) { Notifications::model()->deleteAllByAttributes(array('shared_id' => $s->id, 'status' => 1)); $s->delete(); } Sessions::model()->deleteAllByAttributes(array('real_id' => $this->id)); Sessions::model()->deleteAllByAttributes(array('real_id' => $this->id . '_low')); return true; }
public function markAllNotificationAsSeen() { $flag = TRUE; $notis = Notifications::model()->findAllByAttributes(array('is_read' => 0)); foreach ($notis as $noti) { $noti->is_read = 2; if (!$noti->save(FALSE)) { $flag = FALSE; } } return $flag; }
public function addComment($user_id, $post_id, $content) { $model = new Comments(); $model->post_id = $post_id; $model->created_by = $user_id; $model->updated_at = time(); $model->comment_content = $content; $model->status = 1; $model->created_at = time(); $model->updated_at = time(); $model->save(FALSE); $post = Posts::model()->findByPk($post_id); $post->post_comment_count++; $user = User::model()->findByPk($model->created_by); $user_commented = User::model()->findByPk($post->user_id); if ($user_commented) { if ($user->id != $post->user_id) { $users_have_commented = $this->getListUserCommentedOnPost($post_id); if ($users_have_commented) { foreach ($users_have_commented as $item) { if ($user_id != $item->created_by && $post->user_id != $item->created_by) { $arr_noti_others = array('user_id' => $user->id, 'content' => "{$user->username} cũng đã bình luận bài viết của {$user_commented->username}", 'type' => 'comment_also', 'recipient_id' => $item->created_by, 'url' => Yii::app()->createAbsoluteUrl('post/viewPost', array('post_id' => $post_id, array('ref' => 'noti')))); Notifications::model()->add($arr_noti_others); } } } $arr_noti = array('user_id' => $user->id, 'content' => "{$user->username} vừa bình luận bài viết của bạn", 'type' => 'comment', 'recipient_id' => $user_commented->id, 'url' => Yii::app()->createAbsoluteUrl('post/viewPost', array('post_id' => $post_id, array('ref' => 'noti')))); Notifications::model()->add($arr_noti); } else { $users_have_commented = $this->getListUserCommentedOnPost($post_id); if ($users_have_commented) { foreach ($users_have_commented as $item) { if ($user_id != $item->created_by) { $arr_noti_others = array('user_id' => $user->id, 'content' => "{$user->username} cũng đã bình luận bài viết của họ", 'type' => 'comment_also', 'recipient_id' => $item->created_by, 'url' => Yii::app()->createAbsoluteUrl('post/viewPost', array('post_id' => $post_id, array('ref' => 'noti')))); Notifications::model()->add($arr_noti_others); } } } } } if ($model->save(FALSE) && $post->save(FALSE)) { $returnArr = array(); $returnArr['created_by'] = $model->created_by; $returnArr['username'] = $user->username; $returnArr['photo'] = StringHelper::generateUrlImage($user->photo); $returnArr['created_at'] = Util::time_elapsed_string($model->created_at); $returnArr['comment_content'] = $model->comment_content; return $returnArr; } return FALSE; }
/** * Load model of a Notification. * * @author Kuldeep Dangi <*****@*****.**> */ public function loadModel($id) { $model = Notifications::model()->findByPk($id); return $model; }
/** * @inheritdoc */ public function send($message, $category = null, $object_pk = null, $subject_pk = null, $notification = null) { $by_email = false; $notifications = null; $subscriptions = NfyDbSubscription::model()->current()->withQueue($this->id)->matchingCategory($category)->findAll(); if($message == null && !empty($notification)){ $notifications = Notifications::model()->findByPk($notification); if($notifications){ $message = $notifications->body; } if(empty($message)){ $success = false; } else { $queueMessage = $this->createNotification($message, $notifications->id, $object_pk, $subject_pk); } } else { $queueMessage = $this->createMessage($message, $object_pk, $subject_pk); } if ($this->beforeSend($queueMessage) !== true) { Yii::log(Yii::t('NfyModule.app', "Not sending message '{msg}' to queue {queue_label}.", array('{msg}' => $queueMessage->body, '{queue_label}' => $this->label)), CLogger::LEVEL_INFO, 'nfy'); return; } $success = true; $trx = $queueMessage->getDbConnection()->getCurrentTransaction() !== null ? null : $queueMessage->getDbConnection()->beginTransaction(); if (!$queueMessage->save()) { Yii::log(Yii::t('NfyModule.app', "Failed to save message '{msg}' in queue {queue_label}.", array('{msg}' => $queueMessage->body, '{queue_label}' => $this->label)), CLogger::LEVEL_ERROR, 'nfy'); return false; } if(!empty($subscriptions)){ foreach ($subscriptions as $subscription) { $simple = true; $subscriptionMessage = clone $queueMessage; $subscriptionMessage->subscription_id = $subscription->id; $subscriptionMessage->message_id = $queueMessage->id; if ($this->beforeSendSubscription($subscriptionMessage, $subscription->subscriber_id) !== true) { continue; } if($notifications){ $user_notification = UserNotification::model()->find('user_id=:user_id and notification_id=:notification_id',array(':user_id'=>$subscription->subscriber_id,':notification_id'=>$notification)); if($user_notification && $user_notification->by_email == true){ if(!$this->sendMessageByEmail($queueMessage, $subscription)) { Yii::log(Yii::t('NfyModule.app', "Failed to send message '{msg}' by email in queue {queue_label} for the subscription {subscription_id}.", array( '{msg}' => $queueMessage->body, '{queue_label}' => $this->label, '{subscription_id}' => $subscription->id, )), CLogger::LEVEL_ERROR, 'nfy'); $success = false; } } if($notifications->available == false){ // not send simple notification $simple = false; } } if ($simple == false) { continue; } if (!$subscriptionMessage->save()) { Yii::log(Yii::t('NfyModule.app', "Failed to save message '{msg}' in queue {queue_label} for the subscription {subscription_id}.", array( '{msg}' => $queueMessage->body, '{queue_label}' => $this->label, '{subscription_id}' => $subscription->id, )), CLogger::LEVEL_ERROR, 'nfy'); $success = false; } $this->afterSendSubscription($subscriptionMessage, $subscription->subscriber_id); } } $this->afterSend($queueMessage); if ($trx !== null) { $trx->commit(); } Yii::log(Yii::t('NfyModule.app', "Sent message '{msg}' to queue {queue_label}.", array('{msg}' => $queueMessage->body, '{queue_label}' => $this->label)), CLogger::LEVEL_INFO, 'nfy'); return $success; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param string $id the identifier of the model to be loaded */ public function loadModel($id) { $model = Notifications::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, Yii::t('http_status', 404)); } return $model; }
if ($("#form-changepassword").valid()) { return true } else { return false } }', 'success' => "function(html) {\n\t\t\t\t\t\t\t\t if (html.indexOf('{')==0) {\n\t\t\t\t\t\t\t\t \tvar obj = jQuery.parseJSON(html);\n\t\t\t\t\t\t\t\t \tvar mes = '';\n\t\t\t\t\t\t\t\t \tif(obj.UserChangePassword_oldPassword)\n\t\t\t\t\t\t\t\t \t\tmes = mes + obj.UserChangePassword_oldPassword + '<br>';\n\t\t\t\t\t\t\t\t \tif(obj.UserChangePassword_password)\n\t\t\t\t\t\t\t\t \t\tmes = mes + obj.UserChangePassword_password + '<br>';\n\t\t\t\t\t\t\t\t \tif(obj.UserChangePassword_verifyPassword)\n\t\t\t\t\t\t\t\t \t\tmes = mes + obj.UserChangePassword_verifyPassword + '<br>';\n\t\t\t\t\t\t\t\t \$.growl.error({ message: mes});\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t\t else {\n\t\t\t\t\t\t\t\t \t \$.growl.notice({ message: '" . Yii::t('site', 'Password saved successfully') . "' });\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t\t}", 'error' => "function(jqXHR, textStatus, errorThrown) {\n\t\t\t\t\t\t\t\t \$.growl.error({ message: textStatus +' '+errorThrown});\n\t\t\t\t\t\t\t\t}"), array('encode' => false, 'class' => 'btn btn-primary pull-right')); ?> </div> </div> <?php $this->endWidget(); ?> </div> <div class="panel-footer"> <div class="form-group no-margin tab-content-padding"> <?php // echo CHtml::link(Yii::t('site', 'Delete account'),Yii::app()->createUrl('/users/admin/default/delete',array('id'=>$user->id)), array('class'=>'pull-left', 'title'=>Yii::t('site', 'Delete account'), 'confirm' => Yii::t('site','Do you really want to delete account? Recovery will not be available.'))); ?> </div> </div> </div> </div> </div> <?php $src = $themeUrl . '/img/avatars/male.png'; $availableNotifications = CHtml::listData(Notifications::model()->findAll(array('condition' => 'available_email=:available', 'params' => array(':available' => true), 'order' => 'id')), 'id', 'form_title'); $availableNotificationsArray = array(); if (!empty($availableNotifications)) { foreach ($availableNotifications as $key => $value) { $availableNotificationsArray[] = array('value' => $key, 'text' => $value); } } $setArray = CJSON::encode($availableNotificationsArray); $scriptDd = "\n\$(document).ready(function(){\n\n\n\nvar dropzone = new Dropzone('#profileAvatarAdd', {\n\t // Prevents Dropzone from uploading dropped files immediately\n\t\tautoProcessQueue: true,\n\t\turl: '" . Yii::app()->createUrl('/users/admin/default/addavatar', array('id' => $user->id)) . "',\n\t\tmaxFilesize: 5,\n\t\tparamName: 'qqfile',\n\t\tthumbnailWidth: 160,\n thumbnailHeight: 160,\n\t\tparams: {\n '" . $csrfTokenName . "': '" . $csrfToken . "'\n },\n previewsContainer : '#profilePreviewAvatar',\n}).on('addedfile', function(file) {\n \n}).on('success', function(file) {\n\t\tvar src = \$('#profilePreviewAvatar .dz-preview:last .dz-details img').attr('src');\n\t//\t\$('.page-settings .profile-photo').css('width','auto');\n\t\t\$('.my-avatar').attr('src', src);\n\t//\tvar url = src.replace(/^data:image\\/[^;]/, 'data:application/octet-stream');\n //\t\tlocation.href = url;\n\t\t\n});\n\$('#profileAvatarDelete').on('click', function(e){\n\te.preventDefault();\n \$.ajax({\n\t\t\t\ttype: 'POST',\n\t\t\t\turl: '" . Yii::app()->createUrl('/users/admin/default/unlink', array('id' => $user->id)) . "',\n\t\t\t\tdata: { '" . $csrfTokenName . "': '" . $csrfToken . "'},\n\t\t}).done(function(data){\n\t\t\t\t\n\t\t\t\t\$('.my-avatar').attr('src', '" . $src . "');\n\t\t\t\tdropzone.removeAllFiles();\n\t\t});\n})\n\$('#bs-x-editable-notifications').editable({\n\t\t//limit: 3,\n\t\ttype:'checklist',\n\t\tsource: " . $setArray . ",\n\t\temptytext: '" . Yii::t('site', 'None') . "',\n\t\tdisplay: function(value, sourceData) {\n\t\t //display checklist as comma-separated values\n\t\t var html = [],\n\t\t checked = \$.fn.editableutils.itemsByValue(value, sourceData);\n\t\t if(checked.length) {\n\t\t \t\$.each(checked, function(i, v) { \n\t\t \t\thtml.push('<span class=\"selNotifsEmail\">'+\$.fn.editableutils.escape(v.text)+ '</span>'); \n\t\t \t});\n\t\t \t\$(this).html(html.join(', '));\n\t\n\t\t } else {\n\t\t \t\$(this).empty();\n\t\t }\n\t\t },\n\t\t\n\t params: function(params) {\n\t\t //originally params contain pk, name and value\n\t\t params." . $csrfTokenName . " = '" . $csrfToken . "';\n\t\t return params;\n\t\t },\n\t\t'url': '" . Yii::app()->createUrl('/users/admin/default/updateEmailNotification', array('id' => $user->id)) . "'\n\t});\n});\n"; Yii::app()->clientScript->registerScript("selScript", $scriptDd, CClientScript::POS_END);
public function actionLogs($type) { if ($type == 'system') { $logs = Notifications::model()->findAllByAttributes(array('creator_id' => 0), array('order' => 'time DESC')); } else { $logs = Notifications::model()->findAll(array('condition' => 'creator_id > 0', 'order' => 'time DESC')); } $this->render('logs/index', array('type' => $type, 'logs' => $logs)); }
public function addLikeNotification($from, $post_id, $to) { $user_from = User::model()->findByPk($from); // $user_to = User::model()->findByPk($to); if ($from != Yii::app()->session['user_id']) { $arr_noti = array('user_id' => $from, 'content' => "{$user_from->username} vừa thích bài post của bạn", 'type' => 'like', 'recipient_id' => $to, 'url' => Yii::app()->createAbsoluteUrl('post/viewPost', array('post_id' => $post_id, array('ref' => 'noti')))); Notifications::model()->add($arr_noti); // var_dump($res); die; } }
public function actionMarkSeen() { $request = Yii::app()->request; try { $noti_id = StringHelper::filterString($request->getPost('noti_id')); $data = Notifications::model()->markSeen($noti_id); ResponseHelper::JsonReturnSuccess($data, "Success"); } catch (Exception $ex) { var_dump($ex->getMessage()); } }