cm_webservice_user.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.webservices
  5. */
  6. require_once __DIR__.'/../inc/global.inc.php';
  7. require_once __DIR__.'/cm_webservice.php';
  8. /**
  9. * Description of cm_soap_user
  10. *
  11. * @author marcosousa
  12. */
  13. class WSCMUser extends WSCM
  14. {
  15. public function find_id_user($username, $password, $name)
  16. {
  17. if ($this->verifyUserPass($username, $password) == "valid") {
  18. $listResult = "#";
  19. $listArrayResult = [];
  20. $listArray = [];
  21. $list = $this->get_user_list_like_start(
  22. array('firstname' => $name),
  23. array('firstname')
  24. );
  25. foreach ($list as $userData) {
  26. $listArray[] = $userData['user_id'];
  27. }
  28. $list = $this->get_user_list_like_start(
  29. array('lastname' => $name),
  30. array('firstname')
  31. );
  32. foreach ($list as $userData) {
  33. $listArray[] = $userData['user_id'];
  34. }
  35. $list = $this->get_user_list_like_start(
  36. array('email' => $name),
  37. array('firstname')
  38. );
  39. foreach ($list as $userData) {
  40. $listArray[] = $userData['user_id'];
  41. }
  42. $listArrayResult = array_unique($listArray);
  43. foreach ($listArrayResult as $result) {
  44. $listResult .= $result."#";
  45. }
  46. return $listResult;
  47. }
  48. return "0";
  49. }
  50. public function get_link_user_picture($username, $password, $id)
  51. {
  52. if ($this->verifyUserPass($username, $password) == "valid") {
  53. $userPic = UserManager::getUserPicture($id);
  54. if (empty ($userPic)) {
  55. return "0";
  56. }
  57. return $userPic;
  58. }
  59. return "0";
  60. }
  61. public function get_user_name($username, $password, $id, $field)
  62. {
  63. if ($this->verifyUserPass($username, $password) == "valid") {
  64. $userInfo = api_get_user_info($id);
  65. switch ($field) {
  66. case 'firstname':
  67. return $userInfo['firstname'];
  68. break;
  69. case 'lastname':
  70. return $userInfo['lastname'];
  71. break;
  72. case 'bothfl':
  73. return $userInfo['firstname']." ".$userInfo['lastname'];
  74. break;
  75. case 'bothlf':
  76. return $userInfo['lastname']." ".$userInfo['firstname'];
  77. break;
  78. default:
  79. return $userInfo['firstname'];
  80. }
  81. return "0";
  82. }
  83. return "0";
  84. }
  85. public function send_invitation($username, $password, $userfriend_id, $content_message = '')
  86. {
  87. global $charset;
  88. if ($this->verifyUserPass($username, $password) == "valid") {
  89. $user_id = UserManager::get_user_id_from_username($username);
  90. $message_title = get_lang('Invitation');
  91. $count_is_true = SocialManager::send_invitation_friend($user_id,$userfriend_id, $message_title, $content_message);
  92. if ($count_is_true) {
  93. return Display::return_message(
  94. api_htmlentities(
  95. get_lang('InvitationHasBeenSent'),
  96. ENT_QUOTES,
  97. $charset
  98. ),
  99. 'normal',
  100. false
  101. );
  102. } else {
  103. return Display::return_message(
  104. api_htmlentities(
  105. get_lang('YouAlreadySentAnInvitation'),
  106. ENT_QUOTES,
  107. $charset
  108. ),
  109. 'error',
  110. false
  111. );
  112. }
  113. }
  114. return get_lang('InvalidId');
  115. }
  116. public function accept_friend($username, $password, $userfriend_id)
  117. {
  118. if ($this->verifyUserPass($username, $password) == "valid") {
  119. $user_id = UserManager::get_user_id_from_username($username);
  120. UserManager::relate_users($userfriend_id, $user_id, USER_RELATION_TYPE_FRIEND);
  121. SocialManager::invitation_accepted($userfriend_id, $user_id);
  122. return get_lang('AddedContactToList');
  123. }
  124. return get_lang('InvalidId');
  125. }
  126. public function denied_invitation($username, $password, $userfriend_id)
  127. {
  128. if ($this->verifyUserPass($username, $password) == "valid") {
  129. $user_id = UserManager::get_user_id_from_username($username);
  130. SocialManager::invitation_denied($userfriend_id, $user_id);
  131. return get_lang('InvitationDenied');
  132. }
  133. return get_lang('InvalidId');
  134. }
  135. /**
  136. * Get a list of users of which the given conditions match with a LIKE '%cond%'
  137. * @param array $conditions a list of condition (exemple : status=>STUDENT)
  138. * @param array $order_by a list of fields on which sort
  139. * @return array An array with all users of the platform.
  140. * @todo optional course code parameter, optional sorting parameters...
  141. *@todo Use the UserManager class
  142. * @todo security filter order by
  143. */
  144. private static function get_user_list_like_start($conditions = [], $order_by = [])
  145. {
  146. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  147. $return_array = [];
  148. $sql_query = "SELECT * FROM $user_table";
  149. if (count($conditions) > 0) {
  150. $sql_query .= ' WHERE ';
  151. foreach ($conditions as $field => $value) {
  152. $field = Database::escape_string($field);
  153. $value = Database::escape_string($value);
  154. $sql_query .= $field.' LIKE \''.$value.'%\'';
  155. }
  156. }
  157. $order = '';
  158. foreach ($order_by as $orderByItem) {
  159. $order .= Database::escape_string($orderByItem, null, false).', ';
  160. }
  161. $order = substr($order, 0, -2);
  162. if (count($order_by) > 0) {
  163. $sql_query .= ' ORDER BY '.$order;
  164. }
  165. $sql_result = Database::query($sql_query);
  166. while ($result = Database::fetch_array($sql_result)) {
  167. $return_array[] = $result;
  168. }
  169. return $return_array;
  170. }
  171. }