Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //class Set Email
- class SetEmail extends ChangeAttribute
- {
- //Constructor
- public function __construct($arguments)
- {
- parent::__construct($arguments, "Email");
- }
- //Change Email
- public function Execute ($message)
- {
- parent::Execute($message);
- }
- }
- ?>
- <?php
- //class changes an attribute
- class ChangeAttribute extends Operation
- {
- protected $attribute;
- protected $VkId;
- //Constructor
- public function __construct($arguments, $attribute)
- {
- $this -> attribute = $attribute;
- parent::__construct($arguments);
- }
- //Get Attribute ID
- public function AttributeId()
- {
- return intval($this->arguments["database"]->select("UsersAttributes", ["Id"], ["AttributeName" => $this -> attribute])[0]["Id"]);
- }
- //Updates the attribute in DB
- public function UpdateAttribute($value)
- {
- $this->arguments["database"]->update("UserAtrLinkage",
- ["Value" => $value],
- ["AND" => ["UserId" => $this->arguments["user"]->VkId, "AttrId" => $this -> AttributeId()]]);
- }
- //Add the attribute to DB
- public function AddAttribute($value)
- {
- $this->arguments["database"]->insert("UserAtrLinkage", [
- "AttrId" => $this -> AttributeId(),
- "UserId" => $this->arguments["user"]->VkId,
- "Value" => $value
- ]);
- }
- //Add or Update
- public function Execute ($message)
- {
- if (!empty(reset($this -> arguments["parameters"])))
- {
- if ($this->arguments["database"]->has("UserAtrLinkage", ["AND" => ["UserId" => $this->arguments["user"]->VkId, "AttrId" => $this -> AttributeId()]]))
- {
- $this -> UpdateAttribute((reset($this -> arguments["parameters"])));
- }
- else
- {
- $this -> AddAttribute((reset($this -> arguments["parameters"])));
- }
- }
- $this -> Say ($message);
- }
- }
- ?>
- <?php
- //класс операции
- abstract class Operation
- {
- //Arguments
- protected $arguments;
- //Constructor
- public function __construct($arguments)
- {
- $this->arguments = $arguments;
- }
- // Class factory
- public static function initial($operation, $arguments)
- {
- return new $operation($arguments);
- }
- //Say $message to current user
- public function Say ($message)
- {
- $this -> request_params = array(
- 'message' => $message,
- 'user_id' => $this -> arguments["user"] -> VkId,
- 'access_token' => VkBot\Settings\CommunityToken,
- 'v' => '5.0'
- );
- $this -> get_params = http_build_query($this -> request_params);
- file_get_contents('https://api.vk.com/method/messages.send?'. $this -> get_params);
- }
- //Abstract method execute
- abstract public function Execute($message);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement