Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.85 KB | None | 0 0
  1. <?php
  2.  
  3. //class Set Email
  4.  
  5. class SetEmail extends ChangeAttribute
  6.  
  7. {
  8.  
  9.         //Constructor
  10.             public function __construct($arguments)
  11.                 {
  12.                     parent::__construct($arguments, "Email");
  13.                 }
  14.  
  15.  
  16.  
  17.  
  18.         //Change Email
  19.             public function Execute ($message)
  20.                 {
  21.                     parent::Execute($message);
  22.                 }
  23.  
  24.      
  25.  
  26. }
  27. ?>
  28.  
  29.  
  30.  
  31.  
  32. <?php
  33.  
  34. //class changes an attribute
  35.  
  36. class ChangeAttribute extends Operation
  37.  
  38. {
  39.    
  40.     protected $attribute;
  41.     protected $VkId;
  42.  
  43.         //Constructor
  44.             public function __construct($arguments, $attribute)
  45.                 {
  46.                     $this -> attribute = $attribute;
  47.                     parent::__construct($arguments);
  48.                 }
  49.  
  50.         //Get Attribute ID
  51.                 public function AttributeId()
  52.                     {
  53.                         return intval($this->arguments["database"]->select("UsersAttributes", ["Id"], ["AttributeName" => $this -> attribute])[0]["Id"]);
  54.                     }
  55.  
  56.  
  57.         //Updates the attribute in DB
  58.             public function UpdateAttribute($value)
  59.                 {
  60.                     $this->arguments["database"]->update("UserAtrLinkage",
  61.                     ["Value" => $value],
  62.                     ["AND" => ["UserId" => $this->arguments["user"]->VkId, "AttrId" => $this -> AttributeId()]]);
  63.  
  64.                 }
  65.  
  66.         //Add the attribute to DB
  67.             public function AddAttribute($value)
  68.                 {
  69.                     $this->arguments["database"]->insert("UserAtrLinkage", [
  70.                     "AttrId" => $this -> AttributeId(),
  71.                     "UserId" => $this->arguments["user"]->VkId,
  72.                     "Value" => $value
  73.                     ]);
  74.                 }
  75.  
  76.  
  77.  
  78.         //Add or Update
  79.             public function Execute ($message)
  80.                 {
  81.                     if (!empty(reset($this -> arguments["parameters"])))
  82.                         {
  83.                    
  84.                           if ($this->arguments["database"]->has("UserAtrLinkage", ["AND" => ["UserId" => $this->arguments["user"]->VkId, "AttrId" => $this -> AttributeId()]]))
  85.                                 {
  86.                                     $this -> UpdateAttribute((reset($this -> arguments["parameters"])));
  87.                                 }
  88.                                  else
  89.                                          {
  90.                                             $this -> AddAttribute((reset($this -> arguments["parameters"])));
  91.                                          }
  92.  
  93.                         }
  94.                    
  95.                     $this -> Say ($message);
  96.                  
  97.                 }
  98.  
  99.        
  100.    
  101.  
  102.  
  103. }
  104. ?>
  105.  
  106.  
  107.  
  108.  
  109. <?php
  110.  
  111.  
  112.  
  113. //класс операции
  114.  
  115. abstract class Operation
  116.  
  117. {
  118.        
  119.         //Arguments
  120.             protected $arguments;      
  121.        
  122.        
  123.  
  124.         //Constructor
  125.             public function __construct($arguments)
  126.                 {
  127.                    
  128.                     $this->arguments = $arguments;
  129.                 }
  130.  
  131.        
  132.         // Class factory
  133.             public static function initial($operation, $arguments)
  134.                 {
  135.                     return new $operation($arguments);
  136.                 }
  137.            
  138.         //Say $message to current user            
  139.             public function Say ($message)
  140.                 {
  141.                
  142.                     $this -> request_params = array(
  143.                     'message' => $message,
  144.                     'user_id' => $this -> arguments["user"] -> VkId,
  145.                     'access_token' => VkBot\Settings\CommunityToken,
  146.                     'v' => '5.0'
  147.                      );
  148.  
  149.                     $this -> get_params = http_build_query($this -> request_params);
  150.  
  151.                     file_get_contents('https://api.vk.com/method/messages.send?'. $this -> get_params);
  152.  
  153.                 }
  154.  
  155.         //Abstract method execute
  156.             abstract public function Execute($message);
  157.  
  158.        
  159.  
  160.  
  161. }
  162. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement