Social.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. require_once(PATH::ENTITY . "Entity.php");
  3. /**
  4. * Social.
  5. *
  6. * Represents a social link.
  7. */
  8. class Social extends Entity{
  9. /**
  10. * @var int User profile URL.
  11. */
  12. private $url;
  13. /**
  14. * @var string Social site name.
  15. */
  16. private $site_name;
  17. /**
  18. * @var string Path to the site logo.
  19. */
  20. private $logo;
  21. /**
  22. * @var string Link text.
  23. */
  24. private $text;
  25. /**
  26. * Constructor.
  27. *
  28. * Searches the database and retrieves the information about the social link, populating it.
  29. */
  30. public function __construct($id){
  31. $user_id = parse_ini_file(__DIR__ . "/../config/config.ini", true)["user"]["id"];
  32. $statement = get_context()->get_db()->prepare("
  33. SELECT site_name, url, logo, text
  34. FROM social, user_social
  35. WHERE social.id = user_social.social AND user = :user AND user_social.id = :id
  36. ");
  37. $statement->bindValue(':id', $id, PDO::PARAM_INT);
  38. $statement->bindValue(':user', $user_id, PDO::PARAM_INT);
  39. $statement->execute();
  40. $r_social = $statement->fetch(PDO::FETCH_ASSOC);
  41. if ($r_social !== false){
  42. $this->url = $r_social["url"];
  43. $this->site_name = $r_social["site_name"];
  44. $this->logo = $r_social["logo"];
  45. $this->text = Text::get($r_social["text"]);
  46. }
  47. else Log::error("Social link with id '$id' doesn't exist for user '$user_id'");
  48. }
  49. /**
  50. * Retrieves the link URL.
  51. *
  52. * @return string link URL.
  53. */
  54. public function get_url(){return $this->url;}
  55. /**
  56. * Retrieves the social site name.
  57. *
  58. * @return string The social site name.
  59. */
  60. public function get_site_name(){return $this->site_name;}
  61. /**
  62. * Retrieves the site logo.
  63. *
  64. * @return string The site logo file path.
  65. */
  66. public function get_logo(){return $this->logo;}
  67. /**
  68. * Retrieves the social link text.
  69. *
  70. * @return string The social link text.
  71. */
  72. public function get_text(){return $this->text;}
  73. }