Advertisement
  1. Code
  2. PHP
  3. Yii

Building Your Startup: Meetings With Multiple Participants

Scroll to top
Read Time: 12 min
This post is part of a series called Building Your Startup With PHP.
Building Your Startup: Requesting Scheduling Changes
Building Your Startup: Completing Group Scheduling
Final product imageFinal product imageFinal product image
What You'll Be Creating

This tutorial is part of the Building Your Startup With PHP series on Envato Tuts+. In this series, I'm guiding you through launching a startup from concept to reality using my Meeting Planner app as a real-life example. Every step along the way, I'll release the Meeting Planner code as open-source examples you can learn from. I'll also address startup-related business issues as they arise.

Introduction to Group Meetings

Scheduling meetings with multiple participants was always part of my plan—but not part of the earliest Minimum Viable Product (MVP). The alpha release of Meeting Planner launched with only 1:1 scheduling. The goal of supporting group scheduling sat on the task list like Mount Everest to a climber aiming for the seven summits (and I'm not even an outdoor climber).

Multiple participant meetings are the most challenging to schedule and therefore valuable for the Meeting Planner product to offer. I was excited when the beta task list reached the point that I could begin work on this.

I've been planning, architecting and coding with group meetings in mind from nearly the beginning. I hoped that updating the site for this feature would not require significant UX changes or coding updates. It turned out to require a middle path, 7-10 days of very focused work and testing but no major re-architecting.

In fact, testing proved to be the most difficult aspect of building this feature. It also helped reveal shortcomings in earlier code. It's just that it's not easy... sending to multiple email addresses, checking that every one of them receives all the proper notifications but not the wrong notifications—and sees all the correct menu options throughout the site.

In today's tutorial, I'm going to cover enabling multiple participants, upgrading the UX for groups, appointing organizers, removing participants, and sorting date, time and place options by their popularity with participants. 

In the next tutorial, I'll describe the rest of the work: reviewing all the areas of the site affected by multiple participant meetings, handling and smartly displaying lists of recipients of various status, properly managing notifications and notification filtering for groups, and finally upgrading the recently launched request meeting changes feature.

Try Scheduling a Group Meeting

Please do schedule a group meeting today! Share your thoughts and feedback in the comments below. 

I do participate in the discussions, but you can also reach me @reifman on Twitter. I'm always open to new feature ideas for Meeting Planner as well as suggestions for future series episodes.

As a reminder, all the code for Meeting Planner is provided open source and written in the Yii2 Framework for PHP. If you'd like to learn more about Yii2, check out my parallel series Programming With Yii2. I've heard great things about Laravel, but Yii2 always meets my needs quickly and easily.

Looking Back

When I first designed the Meeting Planner scheduling interface, it showed the current availability of the other participant in its own column. And it was a bit confusing as there were disabled controls. 

Meeting Planner Startup Series - The old You Them Availability PanelMeeting Planner Startup Series - The old You Them Availability PanelMeeting Planner Startup Series - The old You Them Availability Panel

At the time, I worried about how would I make space for displaying the availability of groups.

Fortunately, when I rebuilt the UX for a better responsive experience, I replaced the participant availability column with a small text summary:

Meeting Planner Startup Series - The newer built for mobile responsive planning viewMeeting Planner Startup Series - The newer built for mobile responsive planning viewMeeting Planner Startup Series - The newer built for mobile responsive planning view

The text summary of availability would coincidentally work well for group meetings.

By redesigning for mobile first, I solved the most significant UX barrier to multiple participant meetings!

Coding for Group Meetings

Let's get started going through all the code and testing that multiple participant meetings required.

Enabling Multiple Participants

Meeting Planner Startup Series - Who Panel - Enabled Button for More ParticipantsMeeting Planner Startup Series - Who Panel - Enabled Button for More ParticipantsMeeting Planner Startup Series - Who Panel - Enabled Button for More Participants

The funniest aspect of group meetings is that activating them was straightforward. I just needed to turn off disabling of the plus icon button on the Who panel for meetings in the planning stage:

1
<div class="col-lg-2 col-md-2 col-xs-2">
2
      <div style="float:right;">
3
        <?= Html::a(Yii::t('frontend', ''), ['/participant/create', 'meeting_id' => $model->id], ['class' => 'btn btn-primary '.($model->status>=$model::STATUS_CONFIRMED?'disabled':'').' glyphicon glyphicon-plus']) ?>
4
      </div>
5
    </div>

Then, I began by creating a MEETING_LIMIT in the Participant model:

1
class Participant extends \yii\db\ActiveRecord
2
{
3
    ...
4
5
    const MEETING_LIMIT = 15;

It's used in ParticipantController::actionCreate() on submit:

1
 public function actionCreate($meeting_id)
2
 {
3
    if (!Participant::withinLimit($meeting_id)) {
4
       Yii::$app->getSession()->setFlash('error', Yii::t('frontend','Sorry, you have reached the maximum number of participants per meeting. Contact support if you need additional help or want to offer feedback.'));
5
       return $this->redirect(['/meeting/view', 'id' => $meeting_id]);
6
    }

Advancing the UX and Related Features

For a long time, I've wanted to allow meeting organizers to remove participants, places, and date times without cluttering the user interface. Similarly, I realized that there might be several commands to perform on participants.

After finding so much utility in the compact Bootstrap dropdown button in the Advanced Commands tutorial, I decided to use it for displaying meeting attendees:

Meeting Planner Startup Series - New Buttons and Dropdown Menu for Organizers Meeting Planner Startup Series - New Buttons and Dropdown Menu for Organizers Meeting Planner Startup Series - New Buttons and Dropdown Menu for Organizers

Organizers are denoted with a star. Attendees that have declined the meeting are displayed in orange. Attendees that organizers remove are displayed in red. 

Here's the code in my new partial /frontend/views/participant/_buttons.php:

1
<div class="btn-group btn-participant">
2
  <button type="button" class="btn btn-default btn-sm dropdown-toggle " data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
3
      <span class="glyphicon glyphicon-star red-star aria-hidden="true"></span>
4
    <?= MiscHelpers::getDisplayName($model->owner_id) ?>
5
    <span class="caret"></span>
6
  </button>
7
  <ul class="dropdown-menu">
8
      <li><?= Html::a(Yii::t('frontend','Send a message'),Url::to('mailto:'.$model->owner->email))?></li>
9
  </ul>
10
</div>

Anyone can now send a message to any participant (the meeting notes features is currently distributed to all meeting participants). 

Organizers see a deeper dropdown which allows them to anoint additional organizers, i.e. Make organizer. This is now a very cool feature. Organizers will receive more complete notifications and have more power throughout the planning phases. They can also Remove participants.

Building AJAX Features Into the Participant Buttons

I decided on a whim to AJAXify all these menu options. That turned out to require several complex hours of coding.

Here's the code that defines the initial button menu and prepares the JavaScript:

1
<?php
2
if (count($model->participants)>0) {
3
  foreach ($model->participants as $p) {
4
    if ($p->participant->id==Yii::$app->user->getId()) {
5
      continue;
6
    }
7
    $btn_color = 'btn-default';
8
    if ($p->status == Participant::STATUS_DECLINED) {
9
      $btn_color = 'btn-warning';
10
    } else if ($p->status == Participant::STATUS_REMOVED || $p->status == Participant::STATUS_DECLINED_REMOVED) {
11
      $btn_color = 'btn-danger';
12
    }
13
  ?>
14
  <div class="btn-group btn-participant">
15
    <button id="btn_<?= $p->id ?>" type="button" class="btn <?= $btn_color ?> btn-sm dropdown-toggle " data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
16
        <span id="star_<?= $p->id ?>" class="glyphicon glyphicon-star red-star <?= (!$p->isOrganizer())?'hidden':''?>" aria-hidden="true"></span>
17
      <?= MiscHelpers::getDisplayName($p->participant->id) ?>
18
      <span class="caret"></span>
19
    </button>
20
    <ul class="dropdown-menu">
21
        <li><?= Html::a(Yii::t('frontend','Send a message'),Url::to('mailto:'.$p->participant->email))?></li>
22
        <?php if ($model->isOrganizer()) {
23
          ?>
24
          <li role="separator" class="divider"></li>
25
            <li id="mo_<?= $p->id ?>" class="<?= ($p->isOrganizer())?'hidden':''?>"><?= Html::a(Yii::t('frontend','Make organizer'),'javascript:void(0);',['onclick' => "toggleOrganizer($p->id,true);return false;"]); ?></li>
26
            <li id="ro_<?= $p->id ?>" class="<?= (!$p->isOrganizer())?'hidden':''?>"><?= Html::a(Yii::t('frontend','Revoke organizer role'),'javascript:void(0);',['onclick' => "toggleOrganizer($p->id,false);return false;"]); ?></li>
27
          <li id="rp_<?= $p->id ?>" class="<?= ($p->status == Participant::STATUS_REMOVED || $p->status == Participant::STATUS_DECLINED_REMOVED)?'hidden':''?>"><?= Html::a(Yii::t('frontend','Remove participant'),'javascript:void(0);',['onclick' => "toggleParticipant($p->id,false,$p->status);return false;"]); ?></li>
28
          <li id="rstp_<?= $p->id ?>" class="<?= ($p->status != Participant::STATUS_REMOVED && $p->status != Participant::STATUS_DECLINED_REMOVED)?'hidden':''?>"><?= Html::a(Yii::t('frontend','Restore participant'),'javascript:void(0);',['onclick' => "toggleParticipant($p->id,true,$p->status);return false;"]); ?></li>
29
          <?php
30
          }
31
          ?>
32
    </ul>
33
  </div>

There are so many button states, colors and stars to update as changes are made interactively on a page that the code becomes fairly intricate. I added functions to the meeting.js JavaScript file for toggleOrganizer(), i.e. make/unset organizer, and toggleParticipant(), i.e. remove/restore participant as attendee.

1
function toggleOrganizer(id, val) {
2
  if (val === true) {
3
    arg2 = 1;
4
  } else {
5
    arg2 =0;
6
  }
7
  $.ajax({
8
     url: $('#url_prefix').val()+'/participant/toggleorganizer',
9
     data: {id: id, val: arg2},
10
     success: function(data) {
11
       if (data) {
12
         if (val===false) {
13
            $('#star_'+id).addClass("hidden");
14
            $('#ro_'+id).addClass("hidden");
15
            $('#mo_'+id).removeClass("hidden");
16
         } else {
17
           $('#star_'+id).removeClass("hidden");
18
           $('#ro_'+id).removeClass("hidden");
19
           $('#mo_'+id).addClass("hidden");
20
         }
21
       }
22
        return true;
23
     }
24
  });
25
}
26
27
function toggleParticipant(id, val, original_status) {
28
  if (val === true) {
29
    arg2 = 1;
30
  } else {
31
    arg2 =0;
32
  }
33
  $.ajax({
34
     url: $('#url_prefix').val()+'/participant/toggleparticipant',
35
     data: {id: id, val: arg2, original_status: original_status},
36
     success: function(data) {
37
       if (data) {
38
         if (val===false) {
39
            $('#rp_'+id).addClass("hidden");
40
            $('#rstp_'+id).removeClass("hidden");
41
            $('#btn_'+id).addClass("btn-danger");
42
            $('#btn_'+id).removeClass("btn-default");
43
         } else {
44
           $('#rp_'+id).removeClass("hidden");
45
           $('#rstp_'+id).addClass("hidden");
46
           if (original_status==100) {
47
             $('#btn_'+id).addClass("btn-warning");
48
             $('#btn_'+id).removeClass("btn-danger");
49
           } else {
50
             $('#btn_'+id).addClass("btn-default");
51
             $('#btn_'+id).removeClass("btn-danger");
52
           }
53
         }
54
       }
55
        return true;
56
     }
57
  });
58
}

These required accompanying JSON controller methods in ParticipantController.php to process the toggle requests and update the databases:

1
public function actionToggleorganizer($id,$val) {
2
  Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
3
  // change setting

4
  $p=Participant::findOne($id);
5
  if ($p->meeting->isOrganizer()) {
6
    $p->email = $p->participant->email;
7
    if ($val==1) {
8
      $p->participant_type=Participant::TYPE_ORGANIZER;
9
    } else {
10
      $p->participant_type=Participant::TYPE_DEFAULT;
11
    }
12
    $p->update();
13
    return true;
14
  } else {
15
    return false;
16
  }
17
18
}
19
20
public function actionToggleparticipant($id,$val) {
21
  Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
22
  // change setting

23
  $p=Participant::findOne($id);
24
  if ($p->meeting->isOrganizer()) {
25
    $p->email = $p->participant->email;
26
    if ($val==0) {
27
      if ($p->status == Participant::STATUS_DECLINED) {
28
          $p->status=Participant::STATUS_DECLINED_REMOVED;
29
      } else {
30
        $p->status=Participant::STATUS_REMOVED;
31
      }
32
    } else {
33
      if ($p->status == Participant::STATUS_DECLINED_REMOVED) {
34
          $p->status=Participant::STATUS_DECLINED;
35
      } else {
36
        $p->status=Participant::STATUS_DEFAULT;
37
      }
38
    }
39
    $p->update();
40
    return true;
41
  } else {
42
    return false;
43
  }
44
}

Activating the Accordion Feature on Panels

Meeting Planner Startup Series - Open and Closed Panels with Bootstrap Accordion FeatureMeeting Planner Startup Series - Open and Closed Panels with Bootstrap Accordion FeatureMeeting Planner Startup Series - Open and Closed Panels with Bootstrap Accordion Feature

At this time, I also realized that as meeting plans increased in complexity with more recipients and options, there would be more scrolling. I decided to implement the Bootstrap accordion feature for all the panels on our meeting view.

In other words, you can now click on a heading to collapse or open each and/or all of the panels.

Here are the changes to the partials for meeting place _panel.php:

1
<div class="panel panel-default">
2
  <!-- Default panel contents -->
3
  <div class="panel-heading" role="tab" id="headingWhere">
4
    <div class="row">
5
      <div class="col-lg-10 col-md-10 col-xs-10" ><h4 class="meeting-place">
6
      <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseWhere" aria-expanded="true" aria-controls="collapseWhere"><?= Yii::t('frontend','Where') ?></a>
7
      </h4><p>
8
        <div class="hint-text heading-pad">
9
        <?php if ($placeProvider->count<=1) { ?>
10
          <?= Yii::t('frontend','add places for participants or switch to \'virtual\'') ?>
11
      <?php } elseif ($placeProvider->count>1) { ?>
12
          <?= Yii::t('frontend','are listed places okay?&nbsp;') ?>
13
        <?php
14
          }
15
        ?>
16
...
17
<div id="collapseWhere" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingWhere">
18
    <div class="panel-body">
19
      <?php
20
        $style = ($model->switchVirtual==$model::SWITCH_VIRTUAL?'none':'block');
21
       ?>
22
      <div id ="meeting-place-list" style="display:<?php echo $style; ?>">
23
      <?php
24
       if ($placeProvider->count>0):
25
      ?>
26
      <table class="table">
27
        <?= ListView::widget([
28
               'dataProvider' => $placeProvider,
29
               'itemOptions' => ['class' => 'item'],
30
               'layout' => '{items}',
31
               'itemView' => '_list',
32
               'viewParams' => ['placeCount'=>$placeProvider->count,'isOwner'=>$isOwner,'participant_choose_place'=>$model->meetingSettings['participant_choose_place'],'whereStatus'=>$whereStatus],
33
           ]) ?>
34
      </table>
35
  

Note the settings above on the panel-heading and then the surrounding div for the later panel-body. These control the opening and collapsing of each panel.

This led to some small cosmetic problems such as unwanted padding around the list of items, which I'll need to clean up in the future.

Model Infrastructure for Group Meetings

While I'd been planning for multiple participants from nearly the beginning, there were some minor to modest infrastructure enhancements to support them.

While the MeetingTimeChoice and MeetingPlaceChoice models keep track of whether participants prefer specific date times and places, I wanted to track the overall availability for all participants at each date time and place. This would allow me to sort places and times by how popular they are—and show the most popular settings at the top of the panels.

First, I created a migration to add this to both models. It's infrequent that a migration of mine affects multiple models, which makes this one kind of special:

1
<?php
2
3
use yii\db\Schema;
4
use yii\db\Migration;
5
6
class m160824_235517_extend_meeting_place_and_time extends Migration
7
{
8
  public function up()
9
  {
10
    $tableOptions = null;
11
    if ($this->db->driverName === 'mysql') {
12
        $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
13
    }
14
    $this->addColumn('{{%meeting_time}}','availability',Schema::TYPE_SMALLINT.' NOT NULL DEFAULT 0');
15
    $this->addColumn('{{%meeting_place}}','availability',Schema::TYPE_SMALLINT.' NOT NULL DEFAULT 0');
16
  }
17
18
  public function down()
19
  {
20
    $this->dropColumn('{{%meeting_time}}','availability');
21
    $this->dropColumn('{{%meeting_place}}','availability');
22
  }
23
}

With this capacity, I was able to begin display possible meeting date times and places sorted by their popularity with participants, from MeetingController::actionView():

1
$timeProvider = new ActiveDataProvider([
2
            'query' => MeetingTime::find()->where(['meeting_id'=>$id]),
3
            'sort' => [
4
              'defaultOrder' => [
5
                'availability'=>SORT_DESC
6
              ]
7
            ],
8
        ]);
9
        $placeProvider = new ActiveDataProvider([
10
            'query' => MeetingPlace::find()->where(['meeting_id'=>$id]),
11
            'sort' => [
12
              'defaultOrder' => [
13
                'availability'=>SORT_DESC
14
              ]
15
            ],
16
        ]);

You can see this in action in the below planning screenshot:

Meeting Planner Startup Series - Sorted Date Times and Places By PopularityMeeting Planner Startup Series - Sorted Date Times and Places By PopularityMeeting Planner Startup Series - Sorted Date Times and Places By Popularity

To track whether participants are organizers and to allow for future opt-out of a specific meeting's notifications, I added this migration for the Participant table:

1
<?php
2
3
use yii\db\Schema;
4
use yii\db\Migration;
5
6
class m160825_074740_extend_participant_add_type extends Migration
7
{
8
  public function up()
9
  {
10
    $tableOptions = null;
11
    if ($this->db->driverName === 'mysql') {
12
        $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
13
    }
14
    $this->addColumn('{{%participant}}','participant_type',Schema::TYPE_SMALLINT.' NOT NULL DEFAULT 0');
15
    $this->addColumn('{{%participant}}','notify',Schema::TYPE_SMALLINT.' NOT NULL DEFAULT 0');
16
  }
17
18
  public function down()
19
  {
20
    $this->dropColumn('{{%participant}}','participant_type');
21
    $this->dropColumn('{{%participant}}','notify');
22
  }
23
}

I also added a number of constants in Participant.php to work with these properties:

1
class Participant extends \yii\db\ActiveRecord
2
{
3
    const TYPE_DEFAULT = 0;
4
    const TYPE_ORGANIZER = 10;
5
6
    const NOTIFY_ON = 0;
7
    const NOTIFY_OFF = 1;
8
9
    const STATUS_DEFAULT = 0;
10
    const STATUS_REMOVED = 90;
11
    const STATUS_DECLINED = 100;
12
    const STATUS_DECLINED_REMOVED = 110;

And I knew that it would be helpful to have some helper functions within the massive Meeting model. For example, IsOrganizer() tells me if the current viewer is a meeting organizer:

1
public function isOrganizer() {
2
      $user_id = Yii::$app->user->getId();
3
      if ($user_id == $this->owner_id) {
4
        return true;
5
      } else {
6
        foreach ($this->participants as $p) {
7
          if ($user_id == $p->participant_id) {
8
            if ($p->participant_type == Participant::TYPE_ORGANIZER) {
9
              return true;
10
            } else {
11
              return false;
12
            }
13
          }
14
      }
15
    }
16
    return false;
17
  }

Wait, There's More?

As you can see, there's a lot of ground to cover to build this feature. In the next episode, I'll cover the second half of development and testing required to launch multiple participant meetings: recipient strings, notifications, requests, and responding to requests.

If you haven't yet, go schedule your first meeting with Meeting Planner and try all this out. Please share your feedback in the comments below.

A tutorial on crowdfunding is also in the works, so please follow our WeFunder Meeting Planner page

You can also reach out to me @reifman. I'm always open to new feature ideas and topic suggestions for future tutorials.

Stay tuned for all of this and more upcoming tutorials by checking out the Building Your Startup With PHP series

Related Links

Advertisement
Did you find this post useful?
Want a weekly email summary?
Subscribe below and we’ll send you a weekly email summary of all new Code tutorials. Never miss out on learning about the next big thing.
Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.