Tag.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bernhard Reiter <ockham@raz.or.at>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OC\Tagging;
  24. use \OCP\AppFramework\Db\Entity;
  25. /**
  26. * Class to represent a tag.
  27. *
  28. * @method string getOwner()
  29. * @method void setOwner(string $owner)
  30. * @method string getType()
  31. * @method void setType(string $type)
  32. * @method string getName()
  33. * @method void setName(string $name)
  34. */
  35. class Tag extends Entity {
  36. protected $owner;
  37. protected $type;
  38. protected $name;
  39. /**
  40. * Constructor.
  41. *
  42. * @param string $owner The tag's owner
  43. * @param string $type The type of item this tag is used for
  44. * @param string $name The tag's name
  45. */
  46. public function __construct($owner = null, $type = null, $name = null) {
  47. $this->setOwner($owner);
  48. $this->setType($type);
  49. $this->setName($name);
  50. }
  51. /**
  52. * Transform a database columnname to a property
  53. *
  54. * @param string $columnName the name of the column
  55. * @return string the property name
  56. * @todo migrate existing database columns to the correct names
  57. * to be able to drop this direct mapping
  58. */
  59. public function columnToProperty($columnName){
  60. if ($columnName === 'category') {
  61. return 'name';
  62. } elseif ($columnName === 'uid') {
  63. return 'owner';
  64. } else {
  65. return parent::columnToProperty($columnName);
  66. }
  67. }
  68. /**
  69. * Transform a property to a database column name
  70. *
  71. * @param string $property the name of the property
  72. * @return string the column name
  73. */
  74. public function propertyToColumn($property){
  75. if ($property === 'name') {
  76. return 'category';
  77. } elseif ($property === 'owner') {
  78. return 'uid';
  79. } else {
  80. return parent::propertyToColumn($property);
  81. }
  82. }
  83. }