Tag.php 2.4 KB

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