Advertisement
  1. Code
  2. PHP
  3. Yii

Building Your Startup: Approaching Major Feature Enhancements

Scroll to top
16 min read
This post is part of a series called Building Your Startup With PHP.
Building Your Startup: Securing an API
Using Faker to Generate Filler Data for Automated Testing
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.

How to Approach Major Feature Updates

These days I'm most often working to add small incremental improvements to Meeting Planner. The basics work pretty well, and I'm trying to gradually improve the application based on my vision and people's feedback. Sometimes, my vision is for a bigger change, and that can be harder now that the codebase has grown so much.

In today's tutorial, I'm going to talk about ways to think about making bigger changes to an existing codebase. Specifically, I'll walk you through the impacts of adding the ability for meeting participants to collaboratively brainstorm and decide on activities, i.e. what we should do when we meet up.

If you haven't yet, do try to schedule a meeting, and now you can also schedule an activity. It will help you understand as you go through the tutorial.

Before we begin, please remember to share your comments and feedback below. I monitor them, and you can also reach me on Twitter @lookahead_io. I'm especially interested if you want to suggest new features or topics for future tutorials.

As a reminder, all of the code for Meeting Planner is written in the Yii2 Framework for PHP. If you'd like to learn more about Yii2, check out our parallel series Programming With Yii2.

The Activity Planning Feature

Building Startups - Approaching Major Features - Planning an Activity pageBuilding Startups - Approaching Major Features - Planning an Activity pageBuilding Startups - Approaching Major Features - Planning an Activity page

Basically, Meeting Planner and Simple Planner are designed to make scheduling as easy as it can be. You propose a few times and places and share it with one more people for them to weigh in on the options. Then, you decide together, and Meeting Planner keeps track with calendar entries, reminders and simple ways to make adjustments after the fact.

As an example, here's a video of scheduling for groups:

I wanted to expand the scheduling support provided for times and places to the concept of activities. For example, when planning a meetup with your friends, you're essentially asking, should we go to the movies, go dancing or snowboarding.

In other words, I wanted to create a panel like the one for times shown below but for activities: 

Building Startups - Approaching Major Features - The Older Plan a Time PanelBuilding Startups - Approaching Major Features - The Older Plan a Time PanelBuilding Startups - Approaching Major Features - The Older Plan a Time Panel

The MVC architecture and my code naming scheme are very similar between meeting times and places, so building activities seemed pretty simple on the surface. However, the decision to do so had wide ramifications.

Scoping the Changes

It's important when adding a big feature to think both about where the code will need to change and also all the places in your application that may be affected to think through the impacts.

Customer-Facing Impacts

From the design side, I thought about how activities will affect the customer-facing service:

  • It will change organizing a meeting to allow a new type, an activity-driven event. There will be an additional panel on the planning page.
  • The activity panel will need to be designed to allow people to choose from defaults or to customize and add their own, e.g. backcountry skiing instead of just skiing, "Go see Star Wars Rogue One" instead of just "Go see a movie."
  • Email invitations will need to include space to list activity options.
  • Calendar events will want to integrate the chosen activity with the subject of the meetup.
  • Organizers may want to send some activity ideas to a friend or a group without having chosen a place, so I need to allow this. Currently, the system doesn't let you send an invitation until there's at least one time and place suggested.
  • If someone requests a change to a meeting, the support for change requests will have to be expanded to support activities.

These were most of the basics. Now, let's think about the code.

Code Impacts

Source Code Branching

Frequently, it's helpful to branch your own code in GitHub so you can work on the new feature apart from the stable production-level codebase. This allows you to return and fix bugs or make smaller incremental changes while working on a major change. The GitHub folks are stricter in a way that makes definite sense for teams:

There's only one rule: anything in the master branch is always deployable.

Since there's just one of me and I'm pretty good at managing my codebase, I am a bit more laissez faire about this rule.

But branching code is also useful for reviewing code changes when you're ready for testing. I'll share a demonstration of this at the end of today's tutorial.

Replicating Common Code

There will be two types of meetings now: those based around only dates and times and those around activities, dates, and times. So the meeting model needs to adapt.

For times and places, there are specifically the models MeetingTime and MeetingPlace as well as models for the preferences for these with participants, called MeetingTimeChoices and MeetingPlaceChoices. You can read more about building this in Building Your Startup With PHP: Scheduling Availability and Choices.

So adding activities would essentially require duplicating these, creating MeetingActivity and MeetingActivityChoices and their accompany controllers, models, views, JavaScript and Ajax and database migrations.

Account and Meeting Settings

Also, organizers have the preference of various account settings and per meeting settings for whether participants can suggest and choose the final activity.

Email Templates

Adding activities also affected email templates for invitations and completed meetings.

Event History and Logs

Since every change to a meeting is logged, each activity option and change also needed to be logged.

Other Miscellaneous Areas

The .ics Calendar file should be changed to include the activity. Ultimately, the API would need to be updated—and even the statistics for the administrative dashboard.

While it seemed simple up front, adding activities actually required a lot of new code and testing.

Coding Highlights

While there's too much new code to cover in one tutorial, let's go through highlighted aspects from some of the concepts above.

Database Migrations

First, I created the database migrations. Earlier I spoke of replicating code with feature aspects in common. Here's an example of the MeetingActivity migration vs. the older MeetingTime table migration:

1
<?php
2
use yii\db\Schema;
3
use yii\db\Migration;
4
5
class m161202_020757_create_meeting_activity_table extends Migration
6
{
7
  public function up()
8
  {
9
      $tableOptions = null;
10
      if ($this->db->driverName === 'mysql') {
11
          $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
12
      }
13
14
      $this->createTable('{{%meeting_activity}}', [
15
          'id' => Schema::TYPE_PK,
16
          'meeting_id' => Schema::TYPE_INTEGER.' NOT NULL',
17
          'activity' => Schema::TYPE_STRING.' NOT NULL',          
18
          'suggested_by' => Schema::TYPE_BIGINT.' NOT NULL',
19
          'status' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 0',
20
          'availability' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 0',
21
          'created_at' => Schema::TYPE_INTEGER . ' NOT NULL',
22
          'updated_at' => Schema::TYPE_INTEGER . ' NOT NULL',
23
      ], $tableOptions);
24
      $this->addForeignKey('fk_meeting_activity_meeting', '{{%meeting_activity}}', 'meeting_id', '{{%meeting}}', 'id', 'CASCADE', 'CASCADE');
25
      $this->addForeignKey('fk_activity_suggested_by', '{{%meeting_activity}}', 'suggested_by', '{{%user}}', 'id', 'CASCADE', 'CASCADE');
26
27
  }
28
29
  public function down()
30
  {
31
    $this->dropForeignKey('fk_activity_suggested_by', '{{%meeting_activity}}');
32
    $this->dropForeignKey('fk_meeting_activity_meeting', '{{%meeting_activity}}');
33
      $this->dropTable('{{%meeting_activity}}');
34
  }
35
}

Here's MeetingTime's migration, and you can see the similarities:

1
<?php
2
3
use yii\db\Schema;
4
use yii\db\Migration;
5
6
class m141025_215833_create_meeting_time_table 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
15
      $this->createTable('{{%meeting_time}}', [
16
          'id' => Schema::TYPE_PK,
17
          'meeting_id' => Schema::TYPE_INTEGER.' NOT NULL',
18
          'start' => Schema::TYPE_INTEGER.' NOT NULL',
19
          'suggested_by' => Schema::TYPE_BIGINT.' NOT NULL',
20
          'status' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 0',
21
          'created_at' => Schema::TYPE_INTEGER . ' NOT NULL',
22
          'updated_at' => Schema::TYPE_INTEGER . ' NOT NULL',
23
      ], $tableOptions);
24
      $this->addForeignKey('fk_meeting_time_meeting', '{{%meeting_time}}', 'meeting_id', '{{%meeting}}', 'id', 'CASCADE', 'CASCADE');
25
      $this->addForeignKey('fk_participant_suggested_by', '{{%meeting_time}}', 'suggested_by', '{{%user}}', 'id', 'CASCADE', 'CASCADE');      
26
      
27
  }
28
29
  public function down()
30
  {
31
    $this->dropForeignKey('fk_participant_suggested_by', '{{%meeting_time}}');
32
    $this->dropForeignKey('fk_meeting_time_meeting', '{{%meeting_time}}');
33
      $this->dropTable('{{%meeting_time}}');
34
  }
35
}

 Ultimately, I needed five for the following new tables:

  1. m161202_020757_create_meeting_activity_table
  2. m161202_021355_create_meeting_activity_choice_table, for storing the availability preferences of each meeting participant for each activity
  3. m161202_024352_extend_meeting_setting_table_for_activities for a particular meeting's settings for adding or choosing activities
  4. m161202_024403_extend_user_setting_table_for_activities for the account's default settings
  5. m161203_010030_extend_meeting_table_for_activities and for adding is_activity to denote the property of a meeting with or without an activity 
1
$ ./yii migrate/up
2
Yii Migration Tool (based on Yii v2.0.10)
3
4
Total 5 new migrations to be applied:
5
    m161202_020757_create_meeting_activity_table
6
	m161202_021355_create_meeting_activity_choice_table
7
	m161202_024352_extend_meeting_setting_table_for_activities
8
	m161202_024403_extend_user_setting_table_for_activities
9
	m161203_010030_extend_meeting_table_for_activities
10
11
Apply the above migrations? (yes|no) [no]:yes
12
*** applying m161202_020757_create_meeting_activity_table
13
    > create table {{%meeting_activity}} ... done (time: 0.032s)
14
    > add foreign key fk_meeting_activity_meeting: {{%meeting_activity}} (meeting_id) references {{%meeting}} (id) ... done (time: 0.023s)
15
    > add foreign key fk_activity_suggested_by: {{%meeting_activity}} (suggested_by) references {{%user}} (id) ... done (time: 0.006s)
16
*** applied m161202_020757_create_meeting_activity_table (time: 0.071s)
17
18
*** applying m161202_021355_create_meeting_activity_choice_table
19
    > create table {{%meeting_activity_choice}} ... done (time: 0.002s)
20
    > add foreign key fk_mac_meeting_activity: {{%meeting_activity_choice}} (meeting_activity_id) references {{%meeting_activity}} (id) ... done (time: 0.006s)
21
    > add foreign key fk_mac_user_id: {{%meeting_activity_choice}} (user_id) references {{%user}} (id) ... done (time: 0.004s)
22
*** applied m161202_021355_create_meeting_activity_choice_table (time: 0.016s)
23
24
*** applying m161202_024352_extend_meeting_setting_table_for_activities
25
    > add column participant_add_activity smallint NOT NULL DEFAULT 0 to table {{%meeting_setting}} ... done (time: 0.013s)
26
    > add column participant_choose_activity smallint NOT NULL DEFAULT 0 to table {{%meeting_setting}} ... done (time: 0.019s)
27
*** applied m161202_024352_extend_meeting_setting_table_for_activities (time: 0.034s)
28
29
*** applying m161202_024403_extend_user_setting_table_for_activities
30
    > add column participant_add_activity smallint NOT NULL to table {{%user_setting}} ... done (time: 0.024s)
31
    > add column participant_choose_activity smallint NOT NULL to table {{%user_setting}} ... done (time: 0.027s)
32
*** applied m161202_024403_extend_user_setting_table_for_activities (time: 0.055s)
33
34
*** applying m161203_010030_extend_meeting_table_for_activities
35
      > add column is_activity smallint NOT NULL to table {{%meeting}} ... done (time: 0.019s)
36
*** applied m161203_010030_extend_meeting_table_for_activities (time: 0.022s)
37
38
39
5 migrations were applied.
40
41
Migrated up successfully.

Building the MVC Framework for Activities

Building Startups - Approaching Major Features - The Gii Scaffolding MenuBuilding Startups - Approaching Major Features - The Gii Scaffolding MenuBuilding Startups - Approaching Major Features - The Gii Scaffolding Menu

I used Yii's Gii scaffolding capability to create the model, controller, and initial views. I've covered migrations and Gii earlier in the series.

JavaScript and jQuery Changes

There were also substantial additions to the JavaScript and jQuery used, especially now that interacting with planning elements for a meeting is done with Ajax, without refreshing the page.

Here, for example, is the code loop to see if a meeting time is chosen:

1
// respond to change in meeting_time

2
$(document).on("click", '[id^=btn_mt_]', function(event) {
3
  current_id = $(this).attr('id');
4
  $(this).addClass("btn-primary");
5
  $(this).removeClass("btn-default");
6
  $('[id^=btn_mt_]').each(function(index) {
7
    if ($(this).attr('id')!=current_id) {
8
      $(this).addClass("btn-default");
9
      $(this).removeClass("btn-primary");
10
    }
11
  });
12
  $.ajax({
13
     url: $('#url_prefix').val()+'/meeting-time/choose',
14
     data: {id:   $('#meeting_id').val(), 'val': current_id},
15
     success: function(data) {
16
       displayNotifier('choosetime');
17
       refreshSend();
18
       refreshFinalize();
19
       return true;
20
     }
21
  });
22
});

By using a common naming scheme, writing the code for activities was replicable from this:

1
// respond to change in meeting_activity

2
$(document).on("click", '[id^=btn_ma_]', function(event) {
3
  current_id = $(this).attr('id');
4
  $(this).addClass("btn-primary");
5
  $(this).removeClass("btn-default");
6
  $('[id^=btn_ma_]').each(function(index) {
7
    if ($(this).attr('id')!=current_id) {
8
      $(this).addClass("btn-default");
9
      $(this).removeClass("btn-primary");
10
    }
11
  });
12
  $.ajax({
13
     url: $('#url_prefix').val()+'/meeting-activity/choose',
14
     data: {id:   $('#meeting_id').val(), 'val': current_id},
15
     success: function(data) {
16
       displayNotifier('chooseactivity');
17
       refreshSend();
18
       refreshFinalize();
19
       return true;
20
     }
21
  });
22
});

Other functions, such as those that display responses to the user, simply needed to be extended for activities:

1
function displayNotifier(mode) {
2
    if (notifierOkay) {
3
      if (mode == 'time') {
4
        $('#notifierTime').show();
5
      } else if (mode == 'place') {
6
         $('#notifierPlace').show();
7
       } else if (mode == 'chooseplace') {
8
          $('#notifierChoosePlace').show();
9
        } else if (mode == 'choosetime') {
10
           $('#notifierChooseTime').show();
11
     } else if (mode == 'activity') {
12
        $('#notifierPlace').show();
13
      } else if (mode == 'chooseactivity') {
14
         $('#notifierChooseActivity').show();
15
     } else {
16
        alert("We\'ll automatically notify the organizer when you're done making changes.");
17
      }
18
      notifierOkay=false;
19
    }
20
  }

Even with a feature so reflective in qualities as existing features, the additions of new code were extensive. Here's more of the JavaScript, for example. This code covers a lot more of the interactive ajax functionality of meeting times on the planning page:

1
function showActivity() {
2
  if ($('#addActivity').hasClass( "hidden")) {
3
    $('#addActivity').removeClass("hidden");
4
    $('.activity-form').removeClass("hidden");
5
  } else {
6
    $('#addActivity').addClass("hidden");
7
    $('.activity-form').addClass("hidden");
8
  }
9
};
10
11
function cancelActivity() {
12
  $('#addActivity').addClass("hidden");
13
  $('.activity-form').addClass("hidden");
14
}
15
16
function addActivity(id) {
17
    activity = $('#meeting_activity').val();
18
    // ajax submit subject and message

19
    $.ajax({
20
       url: $('#url_prefix').val()+'/meeting-activity/add',
21
       data: {
22
         id: id,
23
        activity: encodeURIComponent(activity),
24
      },
25
       success: function(data) {
26
         $('#meeting_activity').val('');
27
         loadActivityChoices(id);
28
         insertActivity(id);
29
         displayAlert('activityMessage','activityMsg1');
30
         return true;
31
       }
32
    });
33
    $('#addActivity').addClass('hidden');
34
  }
35
36
  function insertActivity(id) {
37
    $.ajax({
38
     url: $('#url_prefix').val()+'/meeting-activity/insertactivity',
39
     data: {
40
       id: id,
41
      },
42
      type: 'GET',
43
     success: function(data) {
44
      $("#meeting-activity-list").html(data).removeClass('hidden');
45
        $("input[name='meeting-activity-choice']").map(function(){
46
          //$(this).bootstrapSwitch();

47
          $(this).bootstrapSwitch('onText','<i class="glyphicon glyphicon-thumbs-up"></i>&nbsp;yes');
48
          $(this).bootstrapSwitch('offText','<i class="glyphicon glyphicon-thumbs-down"></i>&nbsp;no');
49
          $(this).bootstrapSwitch('onColor','success');
50
          $(this).bootstrapSwitch('offColor','danger');
51
          $(this).bootstrapSwitch('handleWidth',50);
52
          $(this).bootstrapSwitch('labelWidth',1);
53
          $(this).bootstrapSwitch('size','small');
54
        });
55
     },
56
   });
57
   refreshSend();
58
   refreshFinalize();
59
  }
60
61
function getActivities(id) {
62
  $.ajax({
63
   url: $('#url_prefix').val()+'/meeting-activity/getactivity',
64
   data: {
65
     id: id,
66
    },
67
    type: 'GET',
68
   success: function(data) {
69
     $('#meeting-activity-list').html(data);
70
   },
71
 });
72
}

Framework Additions

Certainly, there were models, controllers and views that had to be added. Here's an excerpt from the MeetingActivity.php model which lists a number of default activities the user can quickly typeahead to use:

1
<?php
2
namespace frontend\models;
3
4
use Yii;
5
use yii\db\ActiveRecord;
6
use common\components\MiscHelpers;
7
use frontend\models\Participant;
8
9
/**

10
 * This is the model class for table "{{%meeting_activity}}".

11
 *

12
 * @property integer $id

13
 * @property integer $meeting_id

14
 * @property string $activity

15
 * @property integer $availability

16
 * @property integer $suggested_by

17
 * @property integer $status

18
 * @property integer $created_at

19
 * @property integer $updated_at

20
 *

21
 * @property User $suggestedBy

22
 * @property Meeting $meeting

23
 * @property MeetingActivityChoice[] $meetingActivityChoices

24
 */
25
class MeetingActivity extends \yii\db\ActiveRecord
26
{
27
  const STATUS_SUGGESTED =0;
28
  const STATUS_SELECTED =10; // the chosen date time

29
  const STATUS_REMOVED =20;
30
31
  const MEETING_LIMIT = 7;
32
33
  public $url_prefix;
34
    /**

35
     * @inheritdoc

36
     */
37
    public static function tableName()
38
    {
39
        return '{{%meeting_activity}}';
40
    }
41
42
43
    public function behaviors()
44
    {
45
        return [
46
            /*[

47
                'class' => SluggableBehavior::className(),

48
                'attribute' => 'name',

49
                'immutable' => true,

50
                'ensureUnique'=>true,

51
            ],*/
52
            'timestamp' => [
53
                'class' => 'yii\behaviors\TimestampBehavior',
54
                'attributes' => [
55
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
56
                    ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
57
                ],
58
            ],
59
        ];
60
    }
61
    /**

62
     * @inheritdoc

63
     */
64
    public function rules()
65
    {
66
        return [
67
            [['meeting_id', 'activity', 'suggested_by',], 'required'],
68
            [['meeting_id', 'suggested_by', 'status', 'created_at', 'updated_at'], 'integer'],
69
            [['activity'], 'string', 'max' => 255],
70
            [['suggested_by'], 'exist', 'skipOnError' => true, 'targetClass' => \common\models\User::className(), 'targetAttribute' => ['suggested_by' => 'id']],
71
            [['meeting_id'], 'exist', 'skipOnError' => true, 'targetClass' => Meeting::className(), 'targetAttribute' => ['meeting_id' => 'id']],
72
        ];
73
    }
74
75
    public static function defaultActivityList() {
76
      $activities = [
77
        Yii::t('frontend','Bachelor party'),
78
        Yii::t('frontend','Birthday party'),
79
        Yii::t('frontend','Breakfast'),
80
        Yii::t('frontend','Brunch'),
81
        Yii::t('frontend','Coffee, Tea, Juice Bar, et al.'),
82
        Yii::t('frontend','Concert'),
83
        Yii::t('frontend','Counseling'),
84
        Yii::t('frontend','Cycling'),
85
        Yii::t('frontend','Dessert'),
86
        Yii::t('frontend','Dinner'),
87
        Yii::t('frontend','Dog walking'),
88
        Yii::t('frontend','Drinks'),
89
        Yii::t('frontend','Dancing'),
90
        Yii::t('frontend','Bar'),
91
        Yii::t('frontend','Movies'),
92
        Yii::t('frontend','Happy hour'),
93
        Yii::t('frontend','Hiking'),
94
        Yii::t('frontend','Lunch'),
95
        Yii::t('frontend','Meditation'),
96
        Yii::t('frontend','Netflix and chill'),
97
        Yii::t('frontend','Party'),
98
        Yii::t('frontend','Protest'),
99
        Yii::t('frontend','Theater'),        
100
        Yii::t('frontend','Play board games'),
101
        Yii::t('frontend','Play scrabble'),
102
        Yii::t('frontend','Play video games'),
103
        Yii::t('frontend','Running'),
104
        Yii::t('frontend','Shopping'),
105
        Yii::t('frontend','Skiing'),
106
        Yii::t('frontend','Snowboarding'),
107
        Yii::t('frontend','Snowshoeing'),
108
        Yii::t('frontend','Stand up comedy'),
109
        Yii::t('frontend','Walking'),
110
        Yii::t('frontend','Watch movies'),
111
        Yii::t('frontend','Watch sports'),
112
        Yii::t('frontend','Volunteer'),
113
        Yii::t('frontend','Yoga'),
114
      ];
115
      return $activities;
116
    }
Building Startups - Approaching Major Features - Activity Typeahead ListBuilding Startups - Approaching Major Features - Activity Typeahead ListBuilding Startups - Approaching Major Features - Activity Typeahead List

And here's an excerpt of the /frontend/views/activity/_form.php with the TypeaheadBasic widget using the above defaultActivityList():

1
<?php
2
$activities=MeetingActivity::defaultActivityList();
3
echo $form->field($model, 'activity')->label(Yii::t('frontend','Suggest an activity'))->widget(TypeaheadBasic::classname(), [
4
'data' => $activities,
5
'options' => ['placeholder' => Yii::t('frontend','enter your suggestions'),
6
'id'=>'meeting_activity',
7
  //'class'=>'input-large form-control'
8
],
9
'pluginOptions' => ['highlight'=>true],
10
]);
11
?>

But there are numerous changes to the code outside of common framework needs. Here's the Meeting.php model's canSend(), the function that determines whether the user is allowed to send an invitation for a meeting. It determines if a meeting's met the minimum requirements for sending, such as having a time and activity or time and place.

Below, you can see how a new section had to be added for activities:

1
public function canSend($sender_id) {
2
  // check if an invite can be sent

3
  // req: a participant, at least one place, at least one time

4
  $cntPlaces = 0;
5
  foreach($this->meetingPlaces as $mp) {
6
    if ($mp->status!=MeetingPlace::STATUS_REMOVED) {
7
      $cntPlaces+=1;
8
    }
9
  }
10
  $cntTimes = 0;
11
  foreach($this->meetingTimes as $mt) {
12
    if ($mt->status!=MeetingTime::STATUS_REMOVED) {
13
      $cntTimes+=1;
14
    }
15
  }
16
  $cntActivities =0; // for either type of meeting

17
  if ($this->is_activity==Meeting::IS_ACTIVITY) {
18
    foreach($this->meetingActivities as $ma) {
19
      if ($ma->status!=MeetingActivity::STATUS_REMOVED) {
20
        $cntActivities+=1;
21
      }
22
    }
23
  }
24
  if ($this->owner_id == $sender_id
25
   && count($this->participants)>0
26
   && ($cntPlaces>0 || $this->isVirtual() || ($this->is_activity == Meeting::IS_ACTIVITY && $cntActivities>0))
27
   && $cntTimes>0
28
   && ($this->is_activity == Meeting::NOT_ACTIVITY || ($this->is_activity == Meeting::IS_ACTIVITY && $cntActivities>0))
29
   ) {
30
    $this->isReadyToSend = true;
31
  } else {
32
    $this->isReadyToSend = false;
33
  }
34
  return $this->isReadyToSend;
35
 }

Email Templates

Updating the email layouts required a tiny bit of thinking about design and how best to present activities in meeting invitations and confirmations. Here's a sample of the updated email invitation:

Building Startups - Approaching Major Features - Email Invitation ThemeBuilding Startups - Approaching Major Features - Email Invitation ThemeBuilding Startups - Approaching Major Features - Email Invitation Theme

Essentially, if a meeting has an activity, then the invitation includes a wide row above times and places, again replicating a lot of the existing code for times and places:

1
<?php if ($is_activity==Meeting::IS_ACTIVITY) {?>
2
<tr>
3
<td style="color:#777; font-family:Helvetica, Arial, sans-serif; font-size:14px; line-height:21px; text-align:center; border-collapse:collapse; padding:8px 20px; width:280px" align="center" width="280">
4
<table cellspacing="0" cellpadding="0" width="100%" style="border-collapse:separate">
5
  <tr>
6
    <td style="color:#777; font-family:Helvetica, Arial, sans-serif; font-size:14px; line-height:21px; text-align:center; border-collapse:collapse; background-color:#fff; border:1px solid #ccc; border-radius:5px; padding:12px 15px 15px; width:498px" align="center" bgcolor="#ffffff" width="498">
7
      <table cellpadding="0" cellspacing="0" width="100%" style="border-collapse:collapse">
8
        <tr>
9
          <td style="color:#777; font-family:Helvetica, Arial, sans-serif; font-size:14px; line-height:21px; text-align:left; border-collapse:collapse" align="left">
10
            <span style="color:#4d4d4d; font-size:18px; font-weight:700; line-height:1.3; padding:5px 0">Possible Activities</span><br>
11
            <?php
12
              foreach($activities as $activity) {
13
                ?>
14
                    <?php echo $activity->activity; ?><br />
15
                    <?php
16
                  }
17
              ?>
18
              <br />
19
              <?php
20
              if ($meetingSettings->participant_add_activity) { ?>
21
              <?php echo HTML::a(Yii::t('frontend','suggest an activity'),$links['addactivity']); ?><br />
22
              <?php
23
              }
24
              ?>
25
          </td>
26
        </tr>
27
      </table>
28
    </td>
29
  </tr>
30
</table>
31
</td>
32
</tr>
33
<?php } ?>

Reflecting on the Changes

Ultimately, the activity feature required a huge new branch of code. Here's the pull request:

1
$ cd /var/www/mp && git pull origin master
2
remote: Counting objects: 183, done.
3
remote: Compressing objects: 100% (183/183), done.
4
remote: Total 183 (delta 115), reused 0 (delta 0), pack-reused 0
5
Receiving objects: 100% (183/183), 111.48 KiB | 0 bytes/s, done.
6
Resolving deltas: 100% (115/115), done.
7
From github.com:newscloud/mp
8
 * branch            master     -> FETCH_HEAD
9
   923b514..cd16262  master     -> origin/master
10
Updating 923b514..cd16262
11
Fast-forward
12
 common/components/MiscHelpers.php                                                 |   8 +--
13
 common/mail/finalize-html.php                                                     |  28 ++++++++-
14
 common/mail/invitation-html.php                                                   |  39 ++++++++++++-
15
 composer.lock                                                                     | 228 +++++++++++++++++++++++++++++++++++++-----------------------------------
16
 console/migrations/m161202_020757_create_meeting_activity_table.php               |  35 +++++++++++
17
 console/migrations/m161202_021355_create_meeting_activity_choice_table.php        |  34 +++++++++++
18
 console/migrations/m161202_024352_extend_meeting_setting_table_for_activities.php |  22 +++++++
19
 console/migrations/m161202_024403_extend_user_setting_table_for_activities.php    |  24 ++++++++
20
 console/migrations/m161203_010030_extend_meeting_table_for_activities.php         |  22 +++++++
21
 frontend/assets/AppAsset.php                                                      |   2 +-
22
 frontend/assets/HomeAsset.php                                                     |   2 +-
23
 frontend/assets/MapAsset.php                                                      |   2 +-
24
 frontend/assets/MeetingAsset.php                                                  |   2 +-
25
 frontend/config/main.php                                                          |   1 +
26
 frontend/controllers/DaemonController.php                                         |   2 +-
27
 frontend/controllers/MeetingActivityChoiceController.php                          |  70 ++++++++++++++++++++++
28
 frontend/controllers/MeetingActivityController.php                                | 261 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
 frontend/controllers/MeetingController.php                                        |  94 ++++++++++++++++++++++++++++--
30
 frontend/controllers/MeetingTimeController.php                                    |   4 +-
31
 frontend/models/Fix.php                                                           |   9 +--
32
 frontend/models/Meeting.php                                                       | 125 ++++++++++++++++++++++++++++++++++------
33
 frontend/models/MeetingActivity.php                                               | 260 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34
 frontend/models/MeetingActivityChoice.php                                         | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++
35
 frontend/models/MeetingLog.php                                                    |  43 +++++++++++++-
36
 frontend/models/MeetingPlaceChoice.php                                            |   3 +-
37
 frontend/models/MeetingTimeChoice.php                                             |   3 +-
38
 frontend/models/Participant.php                                                   |   2 +
39
 frontend/views/meeting-activity/_choices.php                                      |  42 ++++++++++++++
40
 frontend/views/meeting-activity/_form.php                                         |  46 +++++++++++++++
41
 frontend/views/meeting-activity/_list.php                                         |  78 +++++++++++++++++++++++++
42
 frontend/views/meeting-activity/_panel.php                                        |  81 ++++++++++++++++++++++++++
43
 frontend/views/meeting-activity/_search.php                                       |  39 +++++++++++++
44
 frontend/views/meeting-activity/_thread.php                                       |  15 +++++
45
 frontend/views/meeting-activity/create.php                                        |  21 +++++++
46
 frontend/views/meeting-activity/index.php                                         |  42 ++++++++++++++
47
 frontend/views/meeting-activity/update.php                                        |  23 ++++++++
48
 frontend/views/meeting-setting/_form.php                                          |   2 +
49
 frontend/views/meeting-time/_panel.php                                            |   2 +-
50
 frontend/views/meeting-time/view.php                                              |   4 +-
51
 frontend/views/meeting/_command_bar_planning.php                                  |  11 +++-
52
 frontend/views/meeting/_grid.php                                                  |   9 ++-
53
 frontend/views/meeting/_panel_what.php                                            |   1 +
54
 frontend/views/meeting/view.php                                                   |  22 +++++--
55
 frontend/views/meeting/view_confirmed.php                                         |  19 ++++++
56
 frontend/views/meeting/viewactivity.php                                           |  40 +++++++++++++
57
 frontend/views/participant/_panel.php                                             |   4 +-
58
 frontend/views/user-setting/_form.php                                             |   7 ++-
59
 frontend/web/css/site.css                                                         |   9 ++-
60
 frontend/web/js/meeting.js                                                        | 284 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
61
 49 files changed, 2027 insertions(+), 257 deletions(-)
62
 create mode 100644 console/migrations/m161202_020757_create_meeting_activity_table.php
63
 create mode 100644 console/migrations/m161202_021355_create_meeting_activity_choice_table.php
64
 create mode 100644 console/migrations/m161202_024352_extend_meeting_setting_table_for_activities.php
65
 create mode 100644 console/migrations/m161202_024403_extend_user_setting_table_for_activities.php
66
 create mode 100644 console/migrations/m161203_010030_extend_meeting_table_for_activities.php
67
 create mode 100644 frontend/controllers/MeetingActivityChoiceController.php
68
 create mode 100644 frontend/controllers/MeetingActivityController.php
69
 create mode 100644 frontend/models/MeetingActivity.php
70
 create mode 100644 frontend/models/MeetingActivityChoice.php
71
 create mode 100644 frontend/views/meeting-activity/_choices.php
72
 create mode 100644 frontend/views/meeting-activity/_form.php
73
 create mode 100644 frontend/views/meeting-activity/_list.php
74
 create mode 100644 frontend/views/meeting-activity/_panel.php
75
 create mode 100644 frontend/views/meeting-activity/_search.php
76
 create mode 100644 frontend/views/meeting-activity/_thread.php
77
 create mode 100644 frontend/views/meeting-activity/create.php
78
 create mode 100644 frontend/views/meeting-activity/index.php
79
 create mode 100644 frontend/views/meeting-activity/update.php
80
 create mode 100644 frontend/views/meeting/viewactivity.php

It was so large that I decided to make a fun video scrolling through all the changes in GitHub with appropriate music playing in the background... enjoy:

Overall, building the activities feature was challenging and helpful for me to think about the site architecture and how to make fast, stable progress on the codebase of a one-person startup. Use replication, but reflect first on the overall scope.

The activity feature ended up touching more areas than I had anticipated. 

Planning ahead will help you avoid getting stuck in never-ending coding traps for new features. If you do find yourself in some deep trench, a coding nightmare that just won't end, check in your changes to your feature branch, switch back to master, and work on something else. It helps to clear your head.

I definitely took a slightly different approach to guiding you in this episode, and I hope it was helpful.

Have your own thoughts? Ideas? Feedback? You can always reach me on Twitter @lookahead_io directly. Watch for upcoming tutorials here in the Building Your Startup With PHP series. There's a lot of surprising stuff ahead.

Again, if you haven't tried out Meeting Planner or Simple Planner yet, go ahead and schedule your first meeting:

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.