コード例 #1
0
ファイル: GroupLink.php プロジェクト: ph7pal/wedding
 /**
  * 查找某人是否在团队中
  */
 public static function findRelation($uid, $gid)
 {
     if (!$uid || !$gid) {
         return false;
     }
     $info = GroupLink::model()->find('uid=:uid AND groupid=:gid', array(':uid' => $uid, ':gid' => $gid));
     if (!$info) {
         return false;
     }
     return $info;
 }
コード例 #2
0
ファイル: GroupController.php プロジェクト: ph7pal/wedding
 public function actionCreate()
 {
     $model = new WeddingGroup();
     if (isset($_POST['WeddingGroup'])) {
         $model->attributes = $_POST['WeddingGroup'];
         if ($model->save()) {
             //谁创建谁默认属于本团队成员
             $glinkAttr = array('groupid' => $model->id, 'uid' => $this->uid, 'isAdmin' => 1);
             $glModel = new GroupLink();
             $glModel->attributes = $glinkAttr;
             $glModel->save();
             //相关标签
             $tags = $_POST['tagnames'];
             $tags = !empty($tags) ? array_unique(array_filter($tags)) : array();
             $tagids = array();
             if (!empty($tags)) {
                 foreach ($tags as $str) {
                     $_tmp = explode('-', $str);
                     if ($_tmp[1] > 0) {
                         //添加对应关系
                         if (Tags::addRelation($_tmp[1], $model->id, 'wgroup')) {
                             $tagids[] = $_tmp[1];
                         }
                     } else {
                         //查找是否有对应话题
                         $_tagid = Tags::findAndAdd($_tmp[0], 'wgroup', $model->id);
                         if ($_tagid) {
                             $tagids[] = $_tagid;
                         }
                     }
                 }
                 $tagids = !empty($tagids) ? array_unique(array_filter($tagids)) : array();
             }
             $tagStr = join(',', $tagids);
             WeddingGroup::model()->updateByPk($model->id, array('tagids' => $tagStr));
             $this->redirect(array('group/view', 'id' => $model->id));
         }
     }
     //未认证用户不能创建团队
     if (!$this->userInfo['creditStatus']) {
         $this->message(0, '请完善资料并提交个人认证', Yii::app()->createurl('users/config', array('type' => 'info')));
     } else {
         //todo,创建的团队数量限制
     }
     //获取所有受推荐地区
     $topAreas = Area::getTops(0);
     $areas = CHtml::listData($topAreas, 'id', 'title');
     $suggestTags = Tags::getTops('posts');
     $data = array('model' => $model, 'areas' => $areas, 'suggestTags' => $suggestTags);
     $this->render('create', $data);
 }
コード例 #3
0
ファイル: AjaxController.php プロジェクト: ph7pal/wedding
 public function actionJoinGroup()
 {
     self::checkLogin();
     $uid = zmf::uid();
     $groupid = zmf::filterInput(Yii::app()->request->getParam('gid'));
     if (zmf::actionLimit('joinGroup', $groupid)) {
         $this->jsonOutPut(0, '操作太频繁,请稍后再试');
     }
     if (!$groupid || !is_numeric($groupid)) {
         $this->jsonOutPut(0, '加入失败');
     }
     $groupInfo = WeddingGroup::model()->findByPk($groupid);
     if (!$groupInfo) {
         $this->jsonOutPut(0, '您所查看的页面不存在');
     } elseif ($groupInfo['status'] == Posts::STATUS_STAYCHECK) {
         $this->jsonOutPut(0, '该团队暂未通过认证');
     }
     $reInfo = GroupLink::findRelation($uid, $groupid);
     if ($reInfo) {
         //已存在则退出
         if (GroupLink::model()->deleteByPk($reInfo['id'])) {
             $this->jsonOutPut(4, '已退出');
         } else {
             $this->jsonOutPut(0, '退出失败');
         }
     } else {
         $attr = array('groupid' => $groupid, 'uid' => $uid);
         if (GroupLink::add($attr)) {
             $this->jsonOutPut(3, '已加入');
         } else {
             $this->jsonOutPut(0, '加入失败');
         }
     }
 }