Пример #1
0
 /**
  * Method to return a user based on the userID
  *
  * @author KnowledgeTree Team
  * @access public
  * @param string $userID The id of the user
  * @return array $response The formatted response array
  */
 public function get_user_by_id($userID)
 {
     $user = KTAPI_User::getById($userID);
     if (PEAR::isError($user)) {
         $response['status_code'] = 1;
         $response['message'] = $user->getMessage();
         return $response;
     }
     $results = $this->_get_user_details($user);
     $response['message'] = '';
     $response['status_code'] = 0;
     $response['results'] = $results;
     return $response;
 }
Пример #2
0
 /**
  *
  * Test KTAPI_User getList(), getById(), getByName, getByUsername()
  *
  * @TODO KTAPI_User::getByEmail()
  */
 function testUsers()
 {
     // getList()
     $list = KTAPI_User::getList();
     $this->assertTrue(count($list) > 0);
     // getById()
     $user = KTAPI_User::getById(1);
     $this->assertTrue($user->Username == 'admin');
     $this->assertTrue($user->Name == 'Administrator');
     // getByName()
     $user = KTAPI_User::getByName('Anonymous');
     $this->assertTrue($user->Id == -2);
     // getByUsername()
     $user = KTAPI_User::getByUsername('admin');
     $this->assertTrue($user->Id == 1);
 }
Пример #3
0
 function send_email($params)
 {
     $kt =& $this->KT;
     $message = $params['message'];
     $list = $params['users'];
     $list = explode(',', $list);
     $recipientsList = array();
     foreach ($list as $recipient) {
         if (trim($recipient) != '') {
             // check that value is present
             // if @ sign is present, signifies email address
             if (strpos($recipient, '@') === false) {
                 $recipient = trim($recipient);
                 switch (substr($recipient, 0, 2)) {
                     case 'u_':
                         $id = substr($recipient, 2);
                         $user = KTAPI_User::getById($id);
                         if ($user != null) {
                             $recipientsList[] = $user;
                         }
                         break;
                     case 'g_':
                         $id = substr($recipient, 2);
                         $group = KTAPI_Group::getById($id);
                         if ($group != null) {
                             $recipientsList[] = $group;
                         }
                         break;
                 }
             } else {
                 // Email - just add to list
                 $recipientsList[] = trim($recipient);
             }
         }
     }
     $document = $kt->get_document_by_id($params['document']);
     if (count($recipientsList) == 0) {
         $this->setResponse(array('status' => 'norecipients'));
         return false;
     } else {
         $result = $document->email($recipientsList, $message, TRUE);
         // true to attach document
         if (PEAR::isError($result)) {
             $this->setResponse(array('status' => $result->getMessage()));
             return false;
         }
         $this->setResponse(array('status' => 'documentemailed'));
     }
     return true;
 }