tag.php 2.3 KB

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