PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/ow_plugins/birthdays/components/my_birthday_widget.php

https://bitbucket.org/Noelfhim/no_ftp
PHP | 115 lines | 68 code | 14 blank | 33 comment | 9 complexity | 7cb4deda1568015f07e1a2c19d0eabe5 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * This software is intended for use with Oxwall Free Community Software http://www.oxwall.org/ and is
  4. * licensed under The BSD license.
  5. * ---
  6. * Copyright (c) 2011, Oxwall Foundation
  7. * All rights reserved.
  8. * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
  9. * following conditions are met:
  10. *
  11. * - Redistributions of source code must retain the above copyright notice, this list of conditions and
  12. * the following disclaimer.
  13. *
  14. * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
  15. * the following disclaimer in the documentation and/or other materials provided with the distribution.
  16. *
  17. * - Neither the name of the Oxwall Foundation nor the names of its contributors may be used to endorse or promote products
  18. * derived from this software without specific prior written permission.
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  20. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  24. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. /**
  28. * @author Aybat Duyshokov <duyshokov@gmail.com>
  29. * @package ow_system_plugins.base.components
  30. * @since 1.0
  31. */
  32. class BIRTHDAYS_CMP_MyBirthdayWidget extends BASE_CLASS_Widget
  33. {
  34. public function __construct( BASE_CLASS_WidgetParameter $params )
  35. {
  36. parent::__construct();
  37. $service = BIRTHDAYS_BOL_Service::getInstance();
  38. $user = BOL_UserService::getInstance()->findUserById($params->additionalParamList['entityId']);
  39. if( $user === null )
  40. {
  41. $this->setVisible(false);
  42. return;
  43. }
  44. $eventParams = array(
  45. 'action' => 'birthdays_view_my_birthdays',
  46. 'ownerId' => $user->getId(),
  47. 'viewerId' => OW::getUser()->getId()
  48. );
  49. try
  50. {
  51. OW::getEventManager()->getInstance()->call('privacy_check_permission', $eventParams);
  52. }
  53. catch( RedirectException $e )
  54. {
  55. $this->setVisible(false);
  56. return;
  57. }
  58. $result = $service->findListByBirthdayPeriod(date('Y-m-d'), date('Y-m-d', strtotime('+7 day')), 0, 1, array( $user->getId()));
  59. $isComingSoon = !empty($result);
  60. $this->assign('ballonGreenSrc', OW::getPluginManager()->getPlugin('birthdays')->getStaticUrl().'img/' . 'ballon-lime-green.png');
  61. $data = BOL_QuestionService::getInstance()->getQuestionData(array( $user->getId() ), array('birthdate'));
  62. if ( (!$isComingSoon && !$params->customizeMode) || !array_key_exists('birthdate', $data[$user->getId()]) )
  63. {
  64. $this->setVisible(false);
  65. return;
  66. }
  67. $birtdate = $data[$user->getId()]['birthdate'];
  68. $dateInfo = UTIL_DateTime::parseDate($birtdate, UTIL_DateTime::MYSQL_DATETIME_DATE_FORMAT);
  69. $label = '';
  70. if ( $dateInfo['day'] == date('d') )
  71. {
  72. $label = '<span class="ow_lbutton ow_green">' . OW::getLanguage()->text('base', 'date_time_today') . '</span>';
  73. }
  74. else if ( $dateInfo['day'] == date('d') + 1 )
  75. {
  76. $label = '<span class="ow_lbutton ow_green">' . OW::getLanguage()->text('base', 'date_time_tomorrow') . '</span>';
  77. }
  78. else
  79. {
  80. $label = '<span class="ow_small">' . UTIL_DateTime::formatBirthdate($dateInfo['year'], $dateInfo['month'], $dateInfo['day']) . '</span>';
  81. }
  82. $this->assign('label', $label);
  83. }
  84. public static function getStandardSettingValueList()
  85. {
  86. return array(
  87. self::SETTING_TITLE => OW::getLanguage()->text('birthdays', 'my_widget_title'),
  88. self::SETTING_ICON => self::ICON_USER,
  89. self::SETTING_SHOW_TITLE => true,
  90. self::SETTING_WRAP_IN_BOX => true,
  91. self::SETTING_FREEZE => true
  92. );
  93. }
  94. public static function getAccess()
  95. {
  96. return self::ACCESS_ALL;
  97. }
  98. }