PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/app/protected/modules/tasks/utils/sanitizers/TaskStatusSanitizerUtil.php

https://bitbucket.org/zurmo/zurmo/
PHP | 134 lines | 80 code | 4 blank | 50 comment | 16 complexity | b5ae3ce7035dffbb4bea3377d8eabb1c MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, GPL-2.0, LGPL-3.0, LGPL-2.1, BSD-2-Clause
  1. <?php
  2. /*********************************************************************************
  3. * Zurmo is a customer relationship management program developed by
  4. * Zurmo, Inc. Copyright (C) 2015 Zurmo Inc.
  5. *
  6. * Zurmo is free software; you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License version 3 as published by the
  8. * Free Software Foundation with the addition of the following permission added
  9. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  10. * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
  11. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  12. *
  13. * Zurmo is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License along with
  19. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  20. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  21. * 02110-1301 USA.
  22. *
  23. * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
  24. * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
  25. *
  26. * The interactive user interfaces in original and modified versions
  27. * of this program must display Appropriate Legal Notices, as required under
  28. * Section 5 of the GNU Affero General Public License version 3.
  29. *
  30. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  31. * these Appropriate Legal Notices must retain the display of the Zurmo
  32. * logo and Zurmo copyright notice. If the display of the logo is not reasonably
  33. * feasible for technical reasons, the Appropriate Legal Notices must display the words
  34. * "Copyright Zurmo Inc. 2015. All rights reserved".
  35. ********************************************************************************/
  36. /**
  37. * Sanitizer for handling task status.
  38. */
  39. class TaskStatusSanitizerUtil extends SanitizerUtil
  40. {
  41. /**
  42. * @param RedBean_OODBBean $rowBean
  43. */
  44. public function analyzeByRow(RedBean_OODBBean $rowBean)
  45. {
  46. if ($rowBean->{$this->columnName} != null)
  47. {
  48. $resolvedAcceptableValues = ArrayUtil::resolveArrayToLowerCase(static::getAcceptableValues());
  49. if (!in_array(strtolower($rowBean->{$this->columnName}), $resolvedAcceptableValues))
  50. {
  51. $label = Zurmo::t('ImportModule',
  52. '{attributeLabel} specified is invalid and this row will be skipped during import.',
  53. array('{attributeLabel}' => Task::getAnAttributeLabel('status')));
  54. $this->shouldSkipRow = true;
  55. $this->analysisMessages[] = $label;
  56. }
  57. }
  58. }
  59. /**
  60. * If a status value is missing or invalid, then skip the entire row during import.
  61. */
  62. public static function shouldNotSaveModelOnSanitizingValueFailure()
  63. {
  64. return true;
  65. }
  66. /**
  67. * Given a type, attempt to resolve it as a valid type. If the type is invalid, a
  68. * InvalidValueToSanitizeException will be thrown.
  69. * @param mixed $value
  70. * @return sanitized value
  71. * @throws InvalidValueToSanitizeException
  72. */
  73. public function sanitizeValue($value)
  74. {
  75. if ($value == null)
  76. {
  77. return $value;
  78. }
  79. try
  80. {
  81. if (strtolower($value) == strtolower(Task::STATUS_NEW) ||
  82. strtolower($value) == strtolower('New'))
  83. {
  84. return Task::STATUS_NEW;
  85. }
  86. elseif (strtolower($value) == strtolower(Task::STATUS_IN_PROGRESS) ||
  87. strtolower($value) == strtolower('In Progress'))
  88. {
  89. return Task::STATUS_IN_PROGRESS;
  90. }
  91. elseif (strtolower($value) == strtolower(Task::STATUS_AWAITING_ACCEPTANCE) ||
  92. strtolower($value) == strtolower('Awaiting Acceptance'))
  93. {
  94. return Task::STATUS_AWAITING_ACCEPTANCE;
  95. }
  96. elseif (strtolower($value) == strtolower(Task::STATUS_REJECTED) ||
  97. strtolower($value) == strtolower('Rejected'))
  98. {
  99. return Task::STATUS_REJECTED;
  100. }
  101. elseif (strtolower($value) == strtolower(Task::STATUS_COMPLETED) ||
  102. strtolower($value) == strtolower('Completed'))
  103. {
  104. return Task::STATUS_COMPLETED;
  105. }
  106. else
  107. {
  108. throw new InvalidValueToSanitizeException(Zurmo::t('ZurmoModule', 'Status specified is invalid.'));
  109. }
  110. }
  111. catch (NotFoundException $e)
  112. {
  113. throw new InvalidValueToSanitizeException(Zurmo::t('ZurmoModule', 'Status specified is invalid.'));
  114. }
  115. }
  116. protected static function getAcceptableValues()
  117. {
  118. return array(Task::STATUS_NEW,
  119. Task::STATUS_IN_PROGRESS,
  120. Task::STATUS_AWAITING_ACCEPTANCE,
  121. Task::STATUS_REJECTED,
  122. Task::STATUS_COMPLETED,
  123. 'New',
  124. 'In Progress',
  125. 'Awaiting Acceptance',
  126. 'Rejected',
  127. 'Completed');
  128. }
  129. }
  130. ?>