Commit e02f1040 authored by Armando Lüscher's avatar Armando Lüscher

Correct typos and minor code styling.

parent 4df1b58d
...@@ -49,7 +49,7 @@ class Conversation ...@@ -49,7 +49,7 @@ class Conversation
protected $user_id; protected $user_id;
/** /**
* Telegram chat_id * Telegram chat id
* *
* @var int * @var int
*/ */
...@@ -59,23 +59,23 @@ class Conversation ...@@ -59,23 +59,23 @@ class Conversation
* Group name let you share the session among commands * Group name let you share the session among commands
* Call this as the same name of the command if you don't need to share the conversation * Call this as the same name of the command if you don't need to share the conversation
* *
* @var strint * @var string
*/ */
protected $group_name; protected $group_name;
/** /**
* Command to be execute if the conversation is active * Command to be executed if the conversation is active
* *
* @var string * @var string
*/ */
protected $command; protected $command;
/** /**
* Conversation contructor initialize a new conversation * Conversation contructor to initialize a new conversation
* *
* @param int $user_id * @param int $user_id
* @param int $chat_id * @param int $chat_id
* @param string $name * @param string $group_name
* @param string $command * @param string $command
*/ */
public function __construct($user_id, $chat_id, $group_name = null, $command = null) public function __construct($user_id, $chat_id, $group_name = null, $command = null)
...@@ -91,7 +91,7 @@ class Conversation ...@@ -91,7 +91,7 @@ class Conversation
} }
/** /**
* Check if the conversation already exist * Check if the conversation already exists
* *
* @return bool * @return bool
*/ */
...@@ -101,7 +101,7 @@ class Conversation ...@@ -101,7 +101,7 @@ class Conversation
if ($this->is_fetched) { if ($this->is_fetched) {
return true; return true;
} }
//select an active conversation //Select an active conversation
$conversation = ConversationDB::selectConversation($this->user_id, $this->chat_id, 1); $conversation = ConversationDB::selectConversation($this->user_id, $this->chat_id, 1);
$this->is_fetched = true; $this->is_fetched = true;
...@@ -114,13 +114,13 @@ class Conversation ...@@ -114,13 +114,13 @@ class Conversation
return true; return true;
} }
//a track with the same name was already opened, store the data inside the class //A conversation with the same name was already opened, store the data inside the class
if ($this->conversation['conversation_name'] == $this->group_name) { if ($this->conversation['conversation_name'] == $this->group_name) {
$this->data = json_decode($this->conversation['data'], true); $this->data = json_decode($this->conversation['data'], true);
return true; return true;
} }
//a conversation with a differet name has been opened unsetting the DB one and reacreatea a new one //A conversation with a different name has been opened, unset the DB one and recreate a new one
ConversationDB::updateConversation(['status' => 'cancelled'], ['chat_id' => $this->chat_id, 'user_id' => $this->user_id, 'status' => 'active']); ConversationDB::updateConversation(['status' => 'cancelled'], ['chat_id' => $this->chat_id, 'user_id' => $this->user_id, 'status' => 'active']);
return false; return false;
} }
...@@ -130,9 +130,7 @@ class Conversation ...@@ -130,9 +130,7 @@ class Conversation
} }
/** /**
* Check if the Conversation already exist * Check if a conversation has already been created in the database. If the conversation is not found, a new conversation is created. Start fetches the data stored in the database.
*
* Check if a conversation has already been created in the database. If the conversation is not found, a new conversation is created. start fetch the data stored in the database
* *
* @return bool * @return bool
*/ */
...@@ -148,11 +146,13 @@ class Conversation ...@@ -148,11 +146,13 @@ class Conversation
/** /**
* Store the array/variable in the database with json_encode() function * Store the array/variable in the database with json_encode() function
* *
* @todo Verify the query before assigning the $data member variable
*
* @param array $data * @param array $data
*/ */
public function update($data) public function update($data)
{ {
//conversation must exist! //Conversation must exist!
if ($this->conversationExist()) { if ($this->conversationExist()) {
$fields['data'] = json_encode($data); $fields['data'] = json_encode($data);
...@@ -165,11 +165,9 @@ class Conversation ...@@ -165,11 +165,9 @@ class Conversation
/** /**
* Delete the conversation from the database * Delete the conversation from the database
* *
* Currently the Convevrsation is not deleted but just unsetted * Currently the Conversation is not deleted but just set to 'stopped'
* *
* @TODO should return something * @todo should return something
*
* @param array $data
*/ */
public function stop() public function stop()
{ {
...@@ -181,7 +179,7 @@ class Conversation ...@@ -181,7 +179,7 @@ class Conversation
/** /**
* Retrieve the command to execute from the conversation * Retrieve the command to execute from the conversation
* *
* @param string * @return string|null
*/ */
public function getConversationCommand() public function getConversationCommand()
{ {
...@@ -192,9 +190,9 @@ class Conversation ...@@ -192,9 +190,9 @@ class Conversation
} }
/** /**
* Retrive the data store in the conversation * Retrieve the data stored in the conversation
* *
* @param array $data * @return array
*/ */
public function getData() public function getData()
{ {
......
...@@ -28,13 +28,13 @@ class ConversationDB extends DB ...@@ -28,13 +28,13 @@ class ConversationDB extends DB
} }
/** /**
* Conversation contructor initialize a new conversation * Select a conversation from the DB
* *
* @param int $user_id * @param int $user_id
* @param int $chat_id * @param int $chat_id
* @param bool $limit * @param bool $limit
* *
* @return array * @return array|bool
*/ */
public static function selectConversation($user_id, $chat_id, $limit = null) public static function selectConversation($user_id, $chat_id, $limit = null)
{ {
...@@ -50,7 +50,7 @@ class ConversationDB extends DB ...@@ -50,7 +50,7 @@ class ConversationDB extends DB
$tokens = [':chat_id' => $chat_id, ':user_id' => $user_id]; $tokens = [':chat_id' => $chat_id, ':user_id' => $user_id];
if (!is_null($limit)) { if (!is_null($limit)) {
$query .=' LIMIT :limit'; $query .= ' LIMIT :limit';
} }
$sth = self::$pdo->prepare($query); $sth = self::$pdo->prepare($query);
...@@ -73,7 +73,7 @@ class ConversationDB extends DB ...@@ -73,7 +73,7 @@ class ConversationDB extends DB
* Insert the conversation in the database * Insert the conversation in the database
* *
* @param string $conversation_command * @param string $conversation_command
* @param string $conversation_name * @param string $conversation_group_name
* @param int $user_id * @param int $user_id
* @param int $chat_id * @param int $chat_id
* *
...@@ -127,13 +127,13 @@ class ConversationDB extends DB ...@@ -127,13 +127,13 @@ class ConversationDB extends DB
} }
/** /**
* Insert the conversation in the database * Update the conversation in the database
* *
* @param string $table * @param string $table
* @param array $fields_values * @param array $fields_values
* @param array $where_fields_values * @param array $where_fields_values
* *
* @todo this function is generic should be moved in DB.php * @todo This function is generic should be moved in DB.php
* *
* @return bool * @return bool
*/ */
...@@ -156,8 +156,8 @@ class ConversationDB extends DB ...@@ -156,8 +156,8 @@ class ConversationDB extends DB
} }
++$a; ++$a;
++$tokens_counter; ++$tokens_counter;
$update .= '`'.$field.'` = :'.$tokens_counter; $update .= '`' . $field . '` = :' . $tokens_counter;
$tokens[':'.$tokens_counter] = $value; $tokens[':' . $tokens_counter] = $value;
} }
//Where //Where
...@@ -171,11 +171,11 @@ class ConversationDB extends DB ...@@ -171,11 +171,11 @@ class ConversationDB extends DB
$where .= 'WHERE '; $where .= 'WHERE ';
} }
++$tokens_counter; ++$tokens_counter;
$where .= '`'.$field .'`= :'.$tokens_counter ; $where .= '`' . $field .'`= :' . $tokens_counter ;
$tokens[':'.$tokens_counter] = $value; $tokens[':' . $tokens_counter] = $value;
} }
$query = 'UPDATE `'.$table.'` SET '.$update.' '.$where; $query = 'UPDATE `' . $table . '` SET ' . $update . ' ' . $where;
try { try {
$sth = self::$pdo->prepare($query); $sth = self::$pdo->prepare($query);
$status = $sth->execute($tokens); $status = $sth->execute($tokens);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment