Skip to content
This repository has been archived by the owner on Mar 18, 2019. It is now read-only.

Commit

Permalink
Set up InteractionMode0Controller to handle InteractionMode1
Browse files Browse the repository at this point in the history
  • Loading branch information
abrbhat committed Jun 25, 2013
1 parent dc29964 commit 485942b
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 22 deletions.
2 changes: 1 addition & 1 deletion configuration.inc.default
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ define('DB_USER',APPLICATION_NAME);
define('DB_PASS','password');

/**
* Response to get_service_list
* Response to get_service_codes
* GROUP - Return List of Groups
* SERVICES - Return list of Services
*/
Expand Down
59 changes: 51 additions & 8 deletions controllers/InteractionMode0Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,67 @@ public function generateResponse($endpoint)
{
$incomingSMS=new IncomingSMS;
$previousQuery=QueryRecord::getRecord($incomingSMS->getFrom());
if(($incomingSMS->getSubKeyword()==SUB_KEYWORD_MORE)&&$previousQuery)

if(!($previousQuery))
{
//return error;
}
if($previousQuery['interaction_mode']==1)
{
if($previousQuery['interaction_mode']==1)
if( ($incomingSMS->getSubKeyword()==SUB_KEYWORD_MORE)&&
( ($previousQuery['additional_info']=='GROUPS')||
($previousQuery['additional_info']=='SERVICES') ) )
{
$page=$previousQuery['previous_page']+1;
$type=$previousQuery['additional_info'];
$controller=new InteractionMode1Controller($this->template);
$controller->generateResponse($endpoint,$page,$type);
$controller->generateResponse($endpoint,$type,$page);
}
else

else
{
//error
$validQuery=FALSE;
if(self::findGroupNumber($incomingSMS->getQueryText()))
{
$groupNumber=self::findGroupNumber($incomingSMS->getQueryText());
$page=1;
$validQuery=TRUE;
}
else if (($incomingSMS->getSubKeyword()==SUB_KEYWORD_MORE)&&(self::findGroupNumber($previousQuery['additional_info'])))
{
$groupNumber=self::findGroupNumber($previousQuery['additional_info']);
$page=$previousQuery['previous_page']+1;
$validQuery=TRUE;
}
if($validQuery)
{
$xmlurl = file_get_contents($endpoint.'/services.xml');
$xml = simplexml_load_string($xmlurl, null, LIBXML_NOCDATA);
$groupList=ServiceList::getGroupList($xml);
$group=$groupList[$groupNumber];
$serviceList=ServiceList::getServiceList($xml,$group);
$pages=InteractionMode1Controller::constructPages($serviceList,'SERVICES');
QueryRecord::save(1,$page,GROUP_OPTIONS_PREFIX.$groupNumber);
$this->template->smsBlocks=$pages['page'.$page];
}
else
{
//error
}
}
}


}
private static function findGroupNumber($string)
{
if(preg_match('/^'.GROUP_OPTIONS_PREFIX.'([0-9]*$)/', $string,$matches))
{
return $matches[1];
}
else
{
//error
return 0;
}

}
}
}
4 changes: 2 additions & 2 deletions controllers/InteractionMode1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct(Template $template)
parent::__construct($template);
}

public function generateResponse($endpoint,$page=1,$type=GET_SERVICE_LIST_RESPONSE)
public function generateResponse($endpoint,$type=GET_SERVICE_LIST_RESPONSE,$page=1)
{
$list=array();
$xmlurl = file_get_contents($endpoint.'/services.xml');
Expand All @@ -41,7 +41,7 @@ public function generateResponse($endpoint,$page=1,$type=GET_SERVICE_LIST_RESPON
//error
}
}
private static function constructPages(array $list,$type)
public static function constructPages(array $list,$type)
{
$prefix=($type=='SERVICES')?SERVICE_OPTIONS_PREFIX:GROUP_OPTIONS_PREFIX;
$pages=array();
Expand Down
15 changes: 9 additions & 6 deletions models/IncomingSMS.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@ public function __construct()
{
$this->smsFrom = trim(self::fetchValuefromKey(SMS_FROM));
$this->smsBody = trim(self::fetchValuefromKey(SMS_BODY));
$this->smsAPIKey= trim(self::fetchValuefromKey(SMS_API_KEY_PARAM));
$this->smsAPIKey= defined('SMS_API_KEY_PARAM')?trim(self::fetchValuefromKey(SMS_API_KEY_PARAM)):NULL;
$this->smsBodyPieces=explode(" ",$this->smsBody,3);
}

public function isAPIKeyValid()
{

if(isset($this->smsAPIKey))
{

if(($this->smsAPIKey)==SMS_API_KEY)
return TRUE;
else
{
throw new Exception('Invalid Key');
}
}

return TRUE;
}

public function isKeywordMatched()
Expand Down Expand Up @@ -99,11 +101,12 @@ public function getQueryText()
*All the pieces after Keyword and subKeyword are QueryText
*/
$QueryTextIndex=$potentialQueryTextIndex;
$QueryText=$this->smsBodyPieces[$QueryTextIndex];
for($i=$QueryTextIndex+1;$i<=2;$i++)
$QueryText=isset($this->smsBodyPieces[$QueryTextIndex])?$this->smsBodyPieces[$QueryTextIndex]:NULL;
foreach($this->smsBodyPieces as $key => $value)
{
$QueryText=$QueryText." ".$this->smsBodyPieces[$i];
}
if($key>$QueryTextIndex)
$QueryText=$QueryText." ".$value;
}
return $QueryText;
}

Expand Down
12 changes: 7 additions & 5 deletions models/ServiceList.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
*/
class ServiceList
{
public static function getServiceList($xml)
public static function getServiceList($xml,$group='All')
{

foreach ($xml->service as $service)
{
$serviceCode=(int)$service->service_code;
$serviceList[$serviceCode]=(string)$service->service_name;

{
if(((string)$service->group==$group)||($group=='All'))
{
$serviceCode=(int)$service->service_code;
$serviceList[$serviceCode]=(string)$service->service_name;
}
}
uasort($serviceList, 'self::cmp');
return $serviceList;
Expand Down

0 comments on commit 485942b

Please sign in to comment.