/** * Return wishlist of a user and its followers. * * @author Kuldeep Dangi <*****@*****.**> */ public function actionGetWishlist($id) { $userObj = new Users(); $userModel = $userObj->findByPk($id); $userFeedObj = new UserFeed(); if ($userModel) { $userFollowObj = new UserFollow(); $usersData = $userFollowObj->getUserFollowers($id); $users = array(); foreach ($usersData as $user) { $users[] = $user['id_user']; } $users[] = $id; $wishList = $userFeedObj->getUsersWishlist($users); $wishListCount = count($wishList); if ($wishListCount < 30) { $wishList = $userFeedObj->getTrendingWishlist(30 - $wishListCount); } } else { $wishList = $userFeedObj->getTrendingWishlist(); } $this->result['data'] = $wishList; $this->result['success'] = true; $this->sendResponse($this->result); }
public function AddFollow($userid, $roomid, $flag = '') { if (!$flag) { //room有这个直播的前提,先查询follow里是否已添加,是的话 $getRes = UserFollow::model()->find(array('condition' => 'userid=' . $userid . ' AND roomid=' . $roomid)); if (!$getRes) { $flag = 1; } } else { //room里没有这个直播,首次添加,用户直接保存。 $flag = 1; } if ($flag) { $newFollow = new UserFollow(); $newFollow->roomid = $roomid; $newFollow->userid = $userid; $newFollow->addtime = time(); $newFollow->save(); return '1'; //用户列表里新增该直播间 } else { return '2'; //用户列表里已添加该直播间。 } /* if($flag){ $newFollow=new UserFollow(); $newFollow->roomid=$roomid; $newFollow->userid=$userid; $newFollow->addtime=time(); $newFollow->save(); }else{ $getRes=UserFollow::model()->find(array('condition'=>'userid='.$userid.' AND roomid='.$roomid)); if($getRes){ return '1'; }else{ $newFollow=new UserFollow(); $newFollow->roomid=$roomid; $newFollow->userid=$userid; $newFollow->addtime=time(); $newFollow->save(); return '1'; } } */ }
/** * Executes the widgets */ public function run() { // Some member stats Yii::import('application.modules.mail.models.*'); $statsTotalUsers = User::model()->count(); $criteria = new CDbCriteria(); $criteria->group = 'user_id'; $criteria->condition = 'user_id IS NOT null'; $statsUserOnline = UserHttpSession::model()->count($criteria); $statsMessageEntries = 0; if (Yii::app()->moduleManager->isEnabled('mail')) { $statsMessageEntries = MessageEntry::model()->count(); } $statsUserFollow = UserFollow::model()->countByAttributes(array('object_model' => 'User')); // Render widgets view $this->render('memberStats', array('statsTotalUsers' => $statsTotalUsers, 'statsUserOnline' => $statsUserOnline, 'statsMessageEntries' => $statsMessageEntries, 'statsUserFollow' => $statsUserFollow)); }
/** * Returns the number of follows the owner object performed. * This is only affects User owner objects! * * @param string $objectModel HActiveRecord Classname to restrict Object Classes to (e.g. User) * @return int */ public function getFollowingCount($objectModel) { if (!class_exists($objectModel)) { throw new CException("Invalid objectModel parameter given!"); } return UserFollow::model()->countByAttributes(array('user_id' => $this->getOwner()->getPrimaryKey(), 'object_model' => $objectModel)); }
/** * Function set user information to the result * * @param int $userId * * @author Kuldeep Dangi <*****@*****.**> */ public function getUserInformation($userId) { $data = array('info' => array(), 'followers' => array(), 'following' => array(), 'notes' => array()); if (!empty($userId)) { $data['info'] = $this->loadModel($userId); if (empty($data['info'])) { $this->result['message'] = 'User does not exist.'; } else { $userFollowObj = new UserFollow(); $extentionObj = new Extensions(); $data['followers'] = $userFollowObj->getUserFollowers($userId); $data['following'] = $userFollowObj->getUserFollowing($userId); $data['notes'] = $extentionObj->getNotesByUsers($userId); $this->result['data'] = $data; $this->result['success'] = true; } } $this->sendResponse($this->result); }
public function follow() { // creates follow record between logged in user (follower) $follow_user_id = Input::get('follow_user_id'); $user = Auth::user(); $user_follow = UserFollow::where(function ($query) use($follow_user_id, $user) { $query->where('following_id', '=', $follow_user_id)->where('user_id', '=', $user->id); }); if ($user_follow->count()) { //UN-FOLLOW $user_follow->delete(); } else { //FOLLOW $user_follow = UserFollow::create(array('following_id' => $follow_user_id, 'user_id' => $user->id)); } //return Redirect::back(); }
/** * Before deletion of a Space */ protected function beforeDelete() { foreach (SpaceSetting::model()->findAllByAttributes(array('space_id' => $this->id)) as $spaceSetting) { $spaceSetting->delete(); } // Disable all enabled modules foreach ($this->getAvailableModules() as $moduleId => $module) { if ($this->isModuleEnabled($moduleId)) { $this->disableModule($moduleId); } } HSearch::getInstance()->deleteModel($this); $this->getProfileImage()->delete(); // Remove all Follwers UserFollow::model()->deleteAllByAttributes(array('object_id' => $this->id, 'object_model' => 'Space')); //Delete all memberships: //First select, then delete - done to make sure that SpaceMembership::beforeDelete() is triggered $spaceMemberships = SpaceMembership::model()->findAllByAttributes(array('space_id' => $this->id)); foreach ($spaceMemberships as $spaceMembership) { $spaceMembership->delete(); } UserInvite::model()->deleteAllByAttributes(array('space_invite_id' => $this->id)); // Delete all content objects of this space foreach (Content::model()->findAllByAttributes(array('space_id' => $this->id)) as $content) { $content->delete(); } // When this workspace is used in a group as default workspace, delete the link foreach (Group::model()->findAllByAttributes(array('space_id' => $this->id)) as $group) { $group->space_id = ""; $group->save(); } Wall::model()->deleteAllByAttributes(array('id' => $this->wall_id)); return parent::beforeDelete(); }
/** * Return all notes of a user + max purchased notes + max view notes. * * @author Kuldeep Dangi <*****@*****.**> */ public function actionGetUserNotes() { $model = new Extensions(); $maxPurchaseDocs = $model->getNotesWithMaxPurchase(20); $maxViewDocs = $model->getNotesWithMaxViews(20); $latestUpdated = $model->getNotesWithLatestUpdated(20); if (!empty($_GET['id'])) { $userFollower = new UserFollow(); $usersData = $userFollower->getUserFollowers($_GET['id']); $users = array(); array_map(create_function('$usersData', 'return $usersData["id_user"];'), $users); $users[] = $_GET['id']; $data = $model->getNotesByUsers($users, 10); $this->result['data'] = array_merge($data, $maxPurchaseDocs, $maxViewDocs); } else { //$this->result['data'] = array_merge($maxPurchaseDocs, $maxViewDocs); $this->result['data'] = array_merge($latestUpdated); } $this->result['success'] = true; $this->sendResponse($this->result); }
public function beforeDelete($event) { UserFollow::model()->deleteAllByAttributes(array('object_model' => get_class($this->getOwner()), 'object_id' => $this->getOwner()->getPrimaryKey())); return parent::beforeValidate($event); }
/** * Before Delete of a User * */ public function beforeDelete() { // We don't allow deletion of users who owns a space - validate that foreach (SpaceMembership::GetUserSpaces($this->id) as $workspace) { if ($workspace->isSpaceOwner($this->id)) { throw new Exception("Tried to delete a user which is owner of a space!"); } } UserSetting::model()->deleteAllByAttributes(array('user_id' => $this->id)); // Disable all enabled modules foreach ($this->getAvailableModules() as $moduleId => $module) { if ($this->isModuleEnabled($moduleId)) { $this->disableModule($moduleId); } } HSearch::getInstance()->deleteModel($this); // Delete user session UserHttpSession::model()->deleteAllByAttributes(array('user_id' => $this->id)); // Delete Profile Image $this->getProfileImage()->delete(); // Delete all pending invites UserInvite::model()->deleteAllByAttributes(array('user_originator_id' => $this->id)); UserFollow::model()->deleteAllByAttributes(array('user_id' => $this->id)); UserFollow::model()->deleteAllByAttributes(array('object_model' => 'User', 'object_id' => $this->id)); // Delete all group admin assignments GroupAdmin::model()->deleteAllByAttributes(array('user_id' => $this->id)); // Delete wall entries WallEntry::model()->deleteAllByAttributes(array('wall_id' => $this->wall_id)); // Delete user profile Profile::model()->deleteAllByAttributes(array('user_id' => $this->id)); // Deletes all content created by this user foreach (Content::model()->findAllByAttributes(array('user_id' => $this->id)) as $content) { $content->delete(); } foreach (Content::model()->findAllByAttributes(array('created_by' => $this->id)) as $content) { $content->delete(); } // Delete all passwords foreach (UserPassword::model()->findAllByAttributes(array('user_id' => $this->id)) as $password) { $password->delete(); } return parent::beforeDelete(); }