예제 #1
0
파일: Dept.php 프로젝트: 3116246/haolinju
 public function setFriendByDept($deptid, $user = null)
 {
     //判断部门是否设置了自动好友
     $deptinfo = $this->getInfo($deptid);
     if ($deptinfo['friend'] != '1') {
         return;
     }
     $da = $this->conn_im;
     $friendLst = array();
     $success = true;
     $msg = "";
     if (!empty($user)) {
         $login_account = $user["login_account"];
         $fafa_jid = array(isset($user["fafa_jid"]) ? $user["fafa_jid"] : null);
         $staffMgr = new Staff($this->conn, $this->conn_im, $login_account, $this->container->get("logger"), $this->container);
         if (empty($fafa_jid)) {
             $user = $staffMgr->getInfo();
         }
         $friendLst = array(array("jid" => $user["fafa_jid"], "nick_name" => $user["nick_name"]));
     } else {
         $domain = $this->container->getParameter('edomain');
         $staffMgr = new Staff($this->conn, $this->conn_im, "admin@" . $domain, $this->container->get("logger"), $this->container);
         $sql = 'SELECT a.loginname jid,a.employeename nick_name FROM im_employee a where a.deptid=? and not exists(select jid from rosterdept where deptid=? and a.loginname=jid)';
         $ds = $da->GetData("t", $sql, array((string) $deptid, (string) $deptid));
         $friendLst = $ds["t"]["rows"];
     }
     $to_jid = array();
     $staffcount = count($friendLst);
     if ($staffcount == 0) {
         return array("success" => false, "message" => '该部门下没有人员,请进入子部门进行设置');
     }
     for ($i = 0; $i < $staffcount; $i++) {
         $fafa_jid = $friendLst[$i]["jid"];
         $nick_name = $friendLst[$i]["nick_name"];
         //判断是否已全部成为好友
         $sql = "SELECT a.loginname jid,a.employeename nick_name FROM im_employee a where a.deptid=? and not exists (select jid from rosterusers b where a.loginname=b.jid and b.username=? and b.subscription='B')";
         try {
             $ds_member = $da->GetData("member", $sql, array((string) $deptid, (string) $fafa_jid));
             if ($ds_member && count($ds_member["member"]["rows"] > 0)) {
                 if (!empty($user)) {
                     //如果是指定人员与部门人员成为好友,通知对象为部门中还未不是该人的帐号jid
                     for ($ic = 0; $ic < count($ds_member["member"]["rows"]); $ic++) {
                         array_push($to_jid, $ds_member["member"]["rows"][$ic]["jid"]);
                     }
                 }
                 $state = $staffMgr->DeptAddFriend($this->container, $deptid, $fafa_jid, $nick_name, $ds_member["member"]["rows"]);
             }
         } catch (\Exception $e) {
             $success = false;
             $msg = "设置部门人员互为好友出错!";
             $this->container->get("logger")->err($e->getMessage());
             return array("success" => $success, "message" => $msg);
         }
     }
     $to_jid = $this->getStaffJid($deptid);
     if (count($to_jid) > 0) {
         //获取在线帐号
         Utils::findonlinejid($da, $to_jid);
         //向成员发送出席
         $message = array('deptid' => $deptid);
         $msg = json_encode(Utils::WrapMessage('dept_friend', $message, array()));
         Utils::sendImPresence($fafa_jid, $to_jid, "dept_friend", $msg, $this->container, "", "", false, '', '0');
     }
     return array("success" => $success, "message" => $msg);
 }