GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Coding-iOS/Coding_iOS/Models/ProjectTopic.m at master · DoomYang/Coding-iOS Expand file tree/ Copy pathProjectTopic.mMore file actions executable file ·226 lines (203 loc) · 6.35 KB / Copy pathProjectTopic.mFile metadata and controlsexecutable file ·226 lines (203 loc) · 6.35 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 // // ProjectTopic.m // Coding_iOS // // Created by 王 原闯 on 14-8-20. // Copyright (c) 2014年 Coding. All rights reserved. // #import "ProjectTopic.h" #import "Login.h" #import "ProjectTag.h" @implementation ProjectTopic - (instancetype)init { self = [super init]; if (self) { _propertyArrayMap = [NSDictionary dictionaryWithObjectsAndKeys: @"ProjectTag", @"labels", @"ProjectTopic", @"child_comments", @"User", @"up_vote_users", nil]; _page = [NSNumber numberWithInteger:1]; _pageSize = [NSNumber numberWithInteger:20]; _canLoadMore = YES; _isLoading = _willLoadMore = NO; _contentHeight = 1; _title = @""; _content = @""; _mdTitle = @""; _mdContent = @""; _labels = [[NSMutableArray alloc] initWithCapacity:3]; _mdLabels = [[NSMutableArray alloc] initWithCapacity:3]; } return self; } - (NSNumber *)is_up_voted{ if (!_is_up_voted) { _is_up_voted = @(NO); for (User *user in _up_vote_users) { if ([user.global_key isEqualToString:[Login curLoginUser].global_key]) { _is_up_voted = @(YES); break; } } } return _is_up_voted; } - (void)setContent:(NSString *)content{ if (_content != content) { _htmlMedia = [HtmlMedia htmlMediaWithString:content showType:MediaShowTypeNone]; _content = _htmlMedia.contentDisplay; } } + (ProjectTopic *)feedbackTopic { ProjectTopic *topic = [[ProjectTopic alloc] init]; topic.project = [Project project_FeedBack]; topic.project_id = topic.project.id; return topic; } + (ProjectTopic *)topicWithPro:(Project *)pro { ProjectTopic *topic = [[ProjectTopic alloc] init]; topic.owner = [Login curLoginUser]; topic.project = pro; topic.project_id = pro.id; return topic; } + (ProjectTopic *)topicWithId:(NSNumber *)topicId{ ProjectTopic *topic = [[ProjectTopic alloc] init]; topic.id = topicId; return topic; } - (User *)hasWatcher:(User *)watcher{ for (User *user in self.watchers) { if ([user.id isEqual:watcher.id]) { return user; } } return nil; } - (NSString *)toTopicPath { return [NSString stringWithFormat:@"api/topic/%d", self.id.intValue]; } - (NSDictionary *)toEditParams { NSMutableArray *tempAry = [NSMutableArray arrayWithCapacity:_mdLabels.count]; for (ProjectTag *lbl in _mdLabels) { [tempAry addObject:lbl.id]; } return @{@"title" : [_mdTitle aliasedString], @"content" : [_mdContent aliasedString], @"label" : tempAry}; } - (NSString *)toLabelPath { return [NSString stringWithFormat:@"api/user/%@/project/%@/topics/%d/labels", _project.owner_user_name, _project.name, self.id.intValue]; } - (NSDictionary *)toLabelParams { NSMutableArray *tempAry = [NSMutableArray arrayWithCapacity:_mdLabels.count]; for (ProjectTag *lbl in _mdLabels) { [tempAry addObject:lbl.id]; } return @{@"label_id" : tempAry}; } - (NSString *)toAddTopicPath { return [NSString stringWithFormat:@"api/project/%d/topic?parent=0", [self.project_id intValue]]; } - (NSDictionary *)toAddTopicParams { NSMutableArray *tempAry = [NSMutableArray arrayWithCapacity:_mdLabels.count]; for (ProjectTag *lbl in _mdLabels) { [tempAry addObject:lbl.id]; } return @{@"title" : [_mdTitle aliasedString], @"content" : [_mdContent aliasedString], @"label" : tempAry}; } - (NSString *)toCommentsPath { return [NSString stringWithFormat:@"api/topic/%d/comments", _id.intValue]; } - (NSDictionary *)toCommentsParams { return @{@"page" : (_willLoadMore? [NSNumber numberWithInteger:_page.integerValue +1] : [NSNumber numberWithInteger:1]), @"pageSize" : _pageSize}; } - (void)configWithComments:(ProjectTopics *)comments { self.page = comments.page; self.totalRow = comments.totalRow; self.totalPage = comments.totalPage; if (_willLoadMore) { [_comments.list addObjectsFromArray:comments.list]; } else { self.comments = comments; } _canLoadMore = (_page.integerValue < _totalPage.integerValue); } - (NSString *)toDoCommentPath { return [NSString stringWithFormat:@"api/project/%@/topic/%@/comment", _project_id, _id]; } - (void)configWithComment:(ProjectTopic *)comment andAnswer:(ProjectTopic *)answer { if (answer) { if (answer.child_comments) { [answer.child_comments addObject:comment]; answer.child_count = @(answer.child_count.integerValue + 1); }else{ answer.child_comments = @[comment].mutableCopy; answer.child_count = @1; } }else{ if (self.canLoadMore) { return; } if (self.comments && self.comments.list) { [self.comments.list addObject:comment]; }else{ self.comments = [[ProjectTopics alloc] init]; self.comments.list = [NSMutableArray arrayWithObject:comment]; } self.child_count = [NSNumber numberWithInteger:_child_count.intValue +1]; } } - (NSString *)toDeletePath { return [NSString stringWithFormat:@"api/topic/%d", self.id.intValue]; } - (BOOL)canEdit { return ([Login isLoginUserGlobalKey:self.owner.global_key] || // 讨论创建者 [Login isLoginUserGlobalKey:self.project.owner_user_name]);// 项目创建者 } - (NSInteger)commentsDisplayNum{ return MIN(_child_comments.count, 6); } - (void)change_is_up_voted{ _is_up_voted = @(!self.is_up_voted.boolValue); if (_is_up_voted.boolValue) {//原来没有,现在需要添加 if (!_up_vote_users) { _up_vote_users = @[].mutableCopy; } [_up_vote_users addObject:[Login curLoginUser]]; _up_vote_counts = @(_up_vote_counts.integerValue + 1); }else{//原来有,现在需要移除 User *meUser = nil; for (User *user in _up_vote_users) { if ([user.global_key isEqualToString:[Login curLoginUser].global_key]) { meUser = user; break; } } if (meUser) { [_up_vote_users removeObject:meUser]; _up_vote_counts = @(_up_vote_counts.integerValue - 1); } } } @end |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |