Skip to content

Instantly share code, notes, and snippets.

Avatar

Derdus derduskenga

View GitHub Profile
View survey.php
<?php
include_once 'util.php';
include_once 'db.php';
include_once 'user.php';
include_once 'sms.php';
class Survey {
protected $title;
protected $description;
public function addUserToSurvey ($pdo, $users, $surveyId, $level,$invitationsStatus){
//$users is an indexed array of phone numbers.
View user.php
<?php
include_once 'util.php';
include_once 'db.php';
class User {
protected $phoneNumber;
protected $name;
public function allPhoneNumbers($pdo){
//returns an array of phone numbers
try{
$stmt = $pdo->prepare("SELECT phone_number FROM user");
View menusurvey.sql
-- phpMyAdmin SQL Dump
-- version 5.0.2
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Jul 28, 2021 at 02:05 PM
-- Server version: 10.4.13-MariaDB
-- PHP Version: 7.4.7
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
View registerMenufunction.php
public function registerMenu($textArray, $phoneNumber){
//building menu for user registration
$level = count($textArray);
if($level == 1){
echo "CON Please enter your full name:";
} else if($level == 2){
echo "CON Please enter set you PIN:";
}else if($level == 3){
echo "CON Please re-enter your PIN:";
}else if($level == 4){
View sms.php
<?php
require 'vendor/autoload.php';
use AfricasTalking\SDK\AfricasTalking;
include_once 'util.php';
class Sms {
protected $AT;
function __construct()
{
$this->AT = new AfricasTalking(Util::$API_USERNAME, Util::$API_KEY);
}
View goToMainMenufunction.php
<?php
public function goToMainMenu($text){
$explodedText = explode("*",$text);
while(array_search(Util::$GO_TO_MAIN_MENU, $explodedText) != false){
$firstIndex = array_search(Util::$GO_TO_MAIN_MENU, $explodedText);
$explodedText = array_slice($explodedText, $firstIndex + 1);
}
return join("*",$explodedText);
}
View index.js
const express = require('express');
const routes = require('./routes/userRoutes');
const Parser = require('body-parser');
const app = express();
app.use(Parser.urlencoded({extended:true}));
app.use(routes);
app.listen(process.env.API_PORT);
@derduskenga
derduskenga / index.php
Last active Jul 27, 2021
Implementing a mobile money USSD menu with branded SMS app
View index.php
<?php
$menu = new Menu();
if($text == "" && $isUserRegistered == true){
//user is registered and string is is empty
echo "CON " . $menu->mainMenuRegistered("<Add a name here>");
}else if($text == "" && $isUserRegistered== false){
//user is unregistered and string is is empty
$menu->mainMenuUnRegistered();
}else if($isUserRegistered== false){
//user is unregistered and string is not empty
@derduskenga
derduskenga / home.js
Created Sep 23, 2020
This is a gist example
View home.js
console.log('Testing something')
View userRoutes.js
const express = require('express');
const userController = require('../controllers/userController');
const route = express.Router();
route.post('/user', userController.newUser);
module.exports = route;