public function saveSendList(SendMessageData $message, $memberId)
 {
     $send = new MessageSendList();
     $send->setSendMessageData($message);
     $send->setMemberId($memberId);
     $send->save();
 }
コード例 #2
0
 public function saveSendList(SendMessageData $message)
 {
     $send_member_id = $this->getValue('send_member_id');
     $send = Doctrine::getTable('MessageSendList')->getMessageByReferences($send_member_id, $message->getId());
     if (!$send) {
         $send = new MessageSendList();
         $send->setSendMessageData($message);
         $send->setMemberId($send_member_id);
         $send->save();
     }
 }
コード例 #3
0
 protected function executeTransaction($conn, $arguments = array(), $options = array())
 {
     $members = Doctrine::getTable('Member')->findAll(Doctrine::HYDRATE_ARRAY);
     $memberIds = array_map(create_function('$m', 'return (int)$m[\'id\'];'), $members);
     foreach ($memberIds as $id) {
         for ($i = 0; $i < $options['number']; ++$i) {
             $sendTo = self::fetchRandomMemberId($id, $memberIds);
             $mes = new SendMessageData();
             $mes->setMemberId($id);
             $mes->setSubject('subject');
             $mes->setBody('body');
             $mes->setIsSend(true);
             $mes->setMessageTypeId(1);
             $mes->save();
             $mes->free();
             $messageSendList = new MessageSendList();
             $messageSendList->setMemberId($sendTo);
             $messageSendList->setSendMessageData($mes);
             $messageSendList->save();
             $messageSendList->free();
             $this->logSection('send message', sprintf("%s - %s", $id, $sendTo));
         }
     }
 }
コード例 #4
0
 /**
  * send message
  *
  * Available options:
  *
  *  * type      : The message type   (default: 'message')
  *  * identifier: The identifier of foreign table (default: 0)
  *  * is_read   : A default value of is_read flag (default: false)
  *  * fromMember: The message sender (default: my member object)
  *
  * @param mixed   $toMembers  a Member instance or array of Member instance
  * @param string  $subject    a subject of the message
  * @param string  $body       a body of the message
  * @param array   $options    options
  * @return SendMessageData
  */
 public static function sendMessage($toMembers, $subject, $body, $options = array())
 {
     $options = array_merge(array('type' => 'message', 'identifier' => 0, 'is_read' => false), $options);
     if ($toMembers instanceof Member) {
         $toMembers = array($toMembers);
     } elseif (!is_array($toMembers)) {
         throw new InvalidArgumentException();
     }
     $sendMessageData = new SendMessageData();
     if (!isset($options['fromMember'])) {
         $options['fromMember'] = sfContext::getInstance()->getUser()->getMember();
     }
     $sendMessageData->setMember($options['fromMember']);
     $sendMessageData->setSubject($subject);
     $sendMessageData->setBody($body);
     $sendMessageData->setForeignId($options['identifier']);
     $sendMessageData->setMessageType(Doctrine::getTable('MessageType')->getMessageTypeIdByName($options['type']));
     $sendMessageData->setIsSend(1);
     foreach ($toMembers as $member) {
         $send = new MessageSendList();
         $send->setSendMessageData($sendMessageData);
         $send->setMember($member);
         $send->setIsRead($options['is_read']);
         $send->save();
     }
     return $sendMessageData;
 }
コード例 #5
0
  protected function execute($arguments = array(), $options = array())
  {
    $databaseManager = new sfDatabaseManager($this->configuration);
    $this->conn = $databaseManager->getDatabase('doctrine')->getDoctrineConnection();

    $sql = 'SELECT id FROM member WHERE is_active != 0';
    $where = array();
    if ( $options['min'] && $options['max']  && $options['min'] <= $options['max'])
    {
        $sql .= ' AND id BETWEEN ? AND ?';
        $where = array(intval($options['min']),intval($options['max']));
    }
    $memberIds = $this->conn->fetchColumn($sql, $where);

    $sql = 'SELECT max(id) FROM member WHERE is_active != 0';
    $maxmemberId = $this->conn->fetchOne($sql);

    foreach ($memberIds as $id)
    {
      for ($i=0; $i<$options['number']; ++$i)
      {
        // 送り先は、id1~存在する最大のidからランダムに選出
        $sendTo = rand(1,$maxmemberId);
        $mes = new SendMessageData();
        $mes->setMemberId($id);
        $mes->setSubject('subject');
        $mes->setBody('body');

        // 一定割合で下書き
        $rate = $options['draftrate'];
        if ($rate != 0 && rand(1,100) <= $rate )
        {
          $mes->setIsSend(false);
        } else {
          $mes->setIsSend(true);
        }
        $mes->setMessageTypeId(1);
        $mes->save();

        $messageSendList = new MessageSendList();
        $messageSendList->setMemberId($sendTo);
        $messageSendList->setSendMessageData($mes);
        $messageSendList->save();

        $mesid = $mes->getId();
        $messageSendListid = $messageSendList->getId();

        $mes->free();
        $messageSendList->free();

        $this->logSection('send message', sprintf("%s - %s", $id, $sendTo));

        // 同時にあしあとをつける
        if ($options['footprint'] > 0)
        {
          $r_date = date('Y-m-d');
          for ($j=0 ; $j < $options['footprint'] ; ++$j) { 
              $ashi = new Ashiato();
              $ashi->setMemberIdFrom($id);
              $ashi->setMemberIdTo($sendTo);
              $ashi->setRDate($r_date);
              $ashi->save();
          }
          $ashi->free();
        }

        // 一定割合でゴミ箱へ
        $rate = $options['dustrate'];
        if ($rate != 0 && rand(1,100) <= $rate )
        {
            // 送信者がゴミ箱
            $deleted_message = new DeletedMessage();
            $deleted_message->setMemberId($id);
            $deleted_message->setMessageSendListId($messageSendListid);
            $deleted_message->save();

            // 受信者がゴミ箱
            $rec_deleted_message = new DeletedMessage();
            $rec_deleted_message->setMemberId($sendTo);
            $rec_deleted_message->setMessageId($mesid);
            $rec_deleted_message->save();

            $deleted_message->free();
            $rec_deleted_message->free();

            $this->logSection('delete message', sprintf("%s - %s", $id, $sendTo));
        }

      }
    }
  }