Skip to content

Commit

Permalink
Add phone number to group. Review comments for MRES.
Browse files Browse the repository at this point in the history
  • Loading branch information
edwh committed Sep 19, 2022
1 parent 4ab2edd commit 2ed66cc
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 22 deletions.
23 changes: 15 additions & 8 deletions app/Console/Commands/ImportGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Console\Commands;

use App\Helpers\Fixometer;
use App\User;
use Illuminate\Console\Command;

Expand Down Expand Up @@ -60,17 +61,19 @@ public function handle()
return iconv( "Windows-1252", "UTF-8", $str );
}, $fields);

// Format is 'Name', 'Location', 'Country', 'Latitude', 'Longitude', 'Website', 'Phone', 'Networks', 'Description'.
// Format is 'Name', 'Location', 'Postcode', 'Area', 'Country', 'Latitude', 'Longitude', 'Website', 'Phone', 'Networks', 'Description'.

$groupname = $fields[0];
$location = $fields[1];
$country = $fields[2];
$lat = $fields[3];
$lng = $fields[4];
$website = $fields[5];
$phone = $fields[6];
$networks = $fields[7];
$description = $fields[8];
$postcode = $fields[2];
$area = $fields[3];
$country = $fields[4];
$lat = $fields[5];
$lng = $fields[6];
$website = $fields[7];
$phone = $fields[8];
$networks = $fields[9];
$description = $fields[10];

// Validate.
if (!$groupname) {
Expand Down Expand Up @@ -115,11 +118,15 @@ public function handle()
$group = new \App\Group();
$group->name = $groupname;
$group->location = $location;
$group->postcode = $postcode;
$group->area = $area;
$group->latitude = $lat;
$group->longitude = $lng;
$group->country = $country;
$group->website = $website;
$group->phone = $phone;
$group->free_text = $description;
$group->shareable_code = Fixometer::generateUniqueShareableCode(\App\Group::class, 'shareable_code');
$group->save();

if ($networks) {
Expand Down
31 changes: 20 additions & 11 deletions app/Console/Commands/ImportMRES.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ImportMRES extends Command
*
* @var string
*/
protected $signature = 'import:mres {input} {output} {--networks=}';
protected $signature = 'import:mres {input} {output} {--networks=CSV list of ids}';


/**
Expand Down Expand Up @@ -52,7 +52,7 @@ public function handle()
fgetcsv($inputFile);

// Write headers to output.
fputcsv($outputFile, ['Name', 'Location', 'Country', 'Latitude', 'Longitude', 'Website', 'Phone', 'Networks', 'Description']);
fputcsv($outputFile, ['Name', 'Location', 'Postcode', 'Area', 'Country', 'Latitude', 'Longitude', 'Website', 'Phone', 'Networks', 'Description']);

while (!feof($inputFile))
{
Expand All @@ -66,15 +66,14 @@ public function handle()
$hostname = $fields[4];
$organisateur = $fields[5];
$dates = $fields[6];
$website = $fields[7];
$catsupport = $fields[8];
$geoloc1 = $fields[9];
$lat = $fields[10];
$lng = $fields[11];
$address = $fields[12];
$ville = $fields[13];
$cp = $fields[14];
$website2 = $fields[15];
$regroupements = $fields[7];
$website = $fields[8];
$lat = $fields[9];
$lng = $fields[10];
$address = $fields[11];
$ville = $fields[12];
$cp = $fields[13];
$website2 = $fields[14];

// Validate.
if (!$groupname) {
Expand Down Expand Up @@ -130,13 +129,23 @@ public function handle()
$description .= "<p>Organisateur: " . htmlspecialchars($organisateur) . "</p>";
}

if ($inscription) {
$description .= "<p>Inscription: " . htmlspecialchars($inscription) . "</p>";
}

if ($regroupements) {
$description .= "<p>Regroupement: " . htmlspecialchars($regroupements) . "</p>";
}

$website = str_replace('http://', 'https://', $website);
$location = "$address, $ville, $cp";

fputcsv($outputFile,
[
$groupname,
$location,
$cp,
$ville,
'France',
$lat,
$lng,
Expand Down
3 changes: 2 additions & 1 deletion app/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class Group extends Model implements Auditable
'network_id',
'external_id',
'devices_updated_at',
'timezone'
'timezone',
'phone'
];

protected $appends = ['ShareableLink', 'approved', 'auto_approve'];
Expand Down
3 changes: 3 additions & 0 deletions app/Http/Controllers/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public function create(Request $request, $networkId = null)
$location = $request->input('location');
$text = $request->input('free_text');
$timezone = $request->input('timezone');
$phone = $request->input('phone');

if (empty($name)) {
$error['name'] = 'Please input a name.';
Expand Down Expand Up @@ -154,6 +155,7 @@ public function create(Request $request, $networkId = null)
'free_text' => $text,
'shareable_code' => Fixometer::generateUniqueShareableCode(\App\Group::class, 'shareable_code'),
'timezone' => $timezone,
'phone' => $phone,
];

try {
Expand Down Expand Up @@ -620,6 +622,7 @@ public function edit(Request $request, $id, Geocoder $geocoder)
$update = [
'name' => $data['name'],
'website' => array_key_exists('website', $data) ? $data['website'] : null,
'phone' => array_key_exists('phone', $data) ? $data['phone'] : null,
'free_text' => $data['free_text'],
'location' => array_key_exists('location', $data) ? $data['location'] : null,
'timezone' => array_key_exists('timezone', $data) ? $data['timezone'] : null,
Expand Down
11 changes: 11 additions & 0 deletions app/Http/Resources/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ class Group extends JsonResource
* )
*/

/**
* @OA\Property(
* property="phone",
* title="phone",
* description="An optional phone number to contact the group.",
* format="string",
* example="https://therestartproject.org"
* )
*/

/**
* @OA\Property(
* property="website",
Expand Down Expand Up @@ -238,6 +248,7 @@ public function toArray($request)
'area' => $this->area,
'country' => $this->country,
'website' => $this->website,
'phone' => $this->phone,
'description' => $this->free_text,
'stats' => $stats,
'updated_at' => Carbon::parse($this->updated_at)->toIso8601String(),
Expand Down
32 changes: 32 additions & 0 deletions database/migrations/2022_09_19_135345_add_group_phone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddGroupPhone extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('groups', function (Blueprint $table) {
$table->string('phone', 40)->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('groups', function (Blueprint $table) {
$table->dropColumn('phone');
});
}
}
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<exclude>./tests/Feature/Admin/Users/WikiLoginTests.php</exclude>
<exclude>./tests/Feature/Microtasks/ExampleTest.php</exclude>
<exclude>./tests/Feature/Stats/StatsTestCase.php</exclude>
<exclude>./tests/Feature/StyleTest.php</exclude>
<exclude>./tests/Feature/Users/Registration/DiscourseAccountCreationTests.php</exclude>
</testsuite>

Expand Down
6 changes: 6 additions & 0 deletions resources/js/components/GroupDescription.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
</p>
<read-more v-else :html="group.free_text" class="mt-2" :max-chars="440" :more-str="__('groups.read_more')" :less-str="__('groups.read_less')" />
</div>
<p v-if="group.phone" class="font-weight-bold">
{{ __('groups.field_phone') }}:
<a :href="'tel:' + group.phone">
{{ group.phone }}
</a>
</p>
<div class="d-flex pt-1 pb-1" v-if="discourseGroup">
<div class="mr-2">
<b-img-lazy src="/icons/talk_ico.svg" class="icon" />
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,6 @@
'you_have_joined' => 'You have joined <a class="plain-link" href=":url">:name</a>',
'groups_title_admin' => 'Groups to moderate',
'group_requires_moderation' => 'Group requires moderation',
'field_phone' => 'Phone number',
'phone_small' => '(Optional)',
];
2 changes: 2 additions & 0 deletions resources/lang/fr-BE/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,6 @@
'talk_group_add_body' => 'Merci de suivre le Repair Café :group_name ! Vous recevrez désormais des notifications lorsque de nouveaux événements seront planifiés et seront ajoutés aux messages de Repair Café. <a href="https://talk.restarters.net/t/how-to-communicate-with-your-repair-group/6293">Découvrez comment fonctionnent les messages de Repair Café et comment modifier vos paramètres de notification</a>.',
'you_have_joined' => 'Vous avez rejoint <a class="plain-link" href=":url">:name</a>',
'groups_title_admin' => 'Repair Cafés à modérer',
'field_phone' => 'Numéro de téléphone',
'phone_small' => '(Optionnel)',
];
2 changes: 2 additions & 0 deletions resources/lang/fr/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,6 @@
'talk_group_add_body' => 'Merci de suivre le Repair Café :group_name ! Vous recevrez désormais des notifications lorsque de nouveaux événements seront planifiés et seront ajoutés aux messages de Repair Café. <a href="https://talk.restarters.net/t/how-to-communicate-with-your-repair-group/6293">Découvrez comment fonctionnent les messages de Repair Café et comment modifier vos paramètres de notification</a>.',
'you_have_joined' => 'Vous avez rejoint <a class="plain-link" href=":url">:name</a>',
'groups_title_admin' => 'Repair Cafés à modérer',
'field_phone' => 'Numéro de téléphone',
'phone_small' => '(Optionnel)',
];
9 changes: 7 additions & 2 deletions resources/views/group/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,13 @@

</div>

<div class="vue">
<GroupTimeZone :value="null" />
<div class="form-group">
<label for="phone">@lang('groups.field_phone'):</label>
<input class="form-control field" id="phone" name="phone" type="tel" aria-describedby="phoneHelpBlock" />

<small id="phoneHelpBlock" class="form-text text-muted">
@lang('groups.phone_small')
</small>
</div>

</div>
Expand Down
9 changes: 9 additions & 0 deletions resources/views/group/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@
<GroupTimeZone value="{{ App\Group::find($formdata->idgroups)->timezone }}" />
</div>

<div class="form-group">
<label for="phone">@lang('groups.field_phone'):</label>
<input class="form-control field" id="phone" name="phone" type="tel" value="{{ $formdata->phone }}" aria-describedby="phoneHelpBlock" />

<small id="phoneHelpBlock" class="form-text text-muted">
@lang('groups.phone_small')
</small>
</div>

</div>

<div class="col-lg-5">
Expand Down
9 changes: 9 additions & 0 deletions tests/Unit/GroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,13 @@ public function timezoneProvider() {
[ NULL, NULL, NULL, NULL, TRUE ],
];
}

public function can_store_phone() {
$group = factory(Group::class)->create([
'phone' => 1234
]);

$group2 = Group::find($group->id);
self::assertEquals(1234, $group2->phone);
}
}

0 comments on commit 2ed66cc

Please sign in to comment.