Beispiel #1
0
 /**
  * Sets user group for the user.
  *
  * @param kyUserGroup $user_group User group.
  * @return kyUser
  */
 public function setUserGroup(kyUserGroup $user_group)
 {
     $this->user_group = ky_assure_object($user_group, 'kyUserGroup');
     $this->user_group_id = $this->user_group !== null ? $this->user_group->getId() : null;
     return $this;
 }
<?php

ini_set('html_errors', 0);
ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);
require_once dirname(__FILE__) . "/ressources/kayaco/kyIncludes.php";
define('DEBUG', true);
kyConfig::set(new kyConfig("http://www.articatech.net/support/api/index.php", "bea5b97c-a838-8ca4-9dda-aec5043cccae", "MmUxYzRmMDMtM2RjNC1iY2Y0LTRkOGEtNjYzN2Q3N2U3MWE2N2FiZjk2NzEtMzQxZS0yMTA0LTUxN2YtOWZiY2VkOTQyNTMy"));
$registered_user_group = kyUserGroup::getAll()->filterByTitle("30 days free")->first();
echo "registered_user_group: {$registered_user_group}\n";
//load some user organization
$org = new kyUserOrganization();
$org->setName("MyCompany");
$data = $org->buildData(true);
$org->create();
print_r($data);
$user_organizations = kyUserOrganization::getAll();
foreach ($user_organizations as $user_organization) {
    $id = $user_organization->getId();
    $company = $user_organization->getName();
    echo "Company: {$company} -> {$id}\n";
}
return;
/**
 * Create new user in Registered group:
 * fullname: Anno Ying
 * email: anno.ying@example.com
 * password: qwerty123
 */
$user = $registered_user_group->newUser("Daniel touzeau", "*****@*****.**", "qwerty123")->setUserOrganization($user_organization)->setSalutation(kyUser::SALUTATION_MR)->setSendWelcomeEmail(true)->create();
 /**
  * Add user group to the list of groups that this news item will be visible to.
  * Automatically sets custom user visibility flag to True.
  *
  * @param kyUserGroup $user_group User group that this news item will be visible to.
  * @param bool $clear Clear the list before adding.
  * @return kyNewsItem
  */
 public function addUserGroup(kyUserGroup $user_group, $clear = false)
 {
     if ($clear) {
         $this->user_groups = array();
         $this->user_group_ids = array();
     }
     if (!in_array($user_group->getId(), $this->user_group_ids)) {
         $this->user_group_ids[] = $user_group->getId();
         $this->user_visibility_custom = true;
     }
     return $this;
 }
 /**
  * Add user group to the list of groups that can be assigned to this department.
  * Automatically sets custom user visibility flag to True.
  *
  * @param kyUserGroup $user_group User group that can be assigned to this department.
  * @param bool $clear Clear the list before adding.
  * @return kyDepartment
  */
 public function addUserGroup(kyUserGroup $user_group, $clear = false)
 {
     if ($clear) {
         $this->user_groups = array();
         $this->user_group_ids = array();
     }
     //do nothing if it's already present
     if (in_array($user_group->getId(), $this->user_group_ids)) {
         return $this;
     }
     $this->user_group_ids[] = $user_group->getId();
     $this->user_visibility_custom = true;
     return $this;
 }
 /**
  * Creates new user group.
  * WARNING: Data is not sent to Kayako unless you explicitly call create() on this method's result.
  *
  * @param string $title Title of new user group.
  * @param string $type Type of new user group - one of kyUserGroup::TYPE_* constants.
  * @return kyUserGroup
  */
 public static function createNew($title, $type = self::TYPE_REGISTERED)
 {
     $new_user_group = new kyUserGroup();
     $new_user_group->setTitle($title);
     $new_user_group->setType($type);
     return $new_user_group;
 }
<?php 
    }
    ?>
			</div>
		</fieldset>

		<input type="submit" name="submit_department" value="Next">
	</form>
<?php 
}
//we are rendering General Information form
if ($render === 'general') {
    //load the department we've chosen in Department form
    $department = kyDepartment::get($department_id);
    //load user group for ticket type and priority visibility test
    $user_group = kyUserGroup::getAll()->filterByTitle(USER_GROUP_TITLE)->first();
    //load public ticket types
    $ticket_types = kyTicketType::getAll()->filterByType(kyTicketType::TYPE_PUBLIC);
    //get only types visible to user group
    if ($user_group !== null) {
        $ticket_types = $ticket_types->filterByIsVisibleToUserGroup(true, $user_group);
    }
    //load public ticket priorities
    $ticket_priorities = kyTicketPriority::getAll()->filterByType(kyTicketPriority::TYPE_PUBLIC);
    //get only priorities visible to user group
    if ($user_group !== null) {
        $ticket_priorities = $ticket_priorities->filterByIsVisibleToUserGroup(true, $user_group);
    }
    ?>
	<form method="POST">
		<input type="hidden" name="page" id="page" value="general">
 /**
  * Returns whether this ticket type is visible to specified user group.
  *
  * @param kyUserGroup|int $user_group User group or its identifier.
  * @return bool
  * @filterBy
  */
 public function isVisibleToUserGroup($user_group)
 {
     if ($this->type !== self::TYPE_PUBLIC) {
         return false;
     }
     if ($this->user_visibility_custom === false) {
         return true;
     }
     if ($user_group instanceof kyUserGroup) {
         $user_group_id = $user_group->getId();
     } else {
         $user_group_id = intval($user_group);
     }
     return in_array($user_group_id, $this->user_group_ids);
 }
 * lastname: Doe
 * username: lazyguy
 * email: john.doe@lazycorp.com
 * password: veryhardpassword
 */
$staff_user = $lazy_staff_group->newStaff("John", "Doe", "lazyguy", "*****@*****.**", "veryhardpassword")->setDesignation("useless specialist")->setSignature("Sorry I couldn't help you")->create();
print 'Created: ' . $staff_user;
/**
 * Update staff user mobile number.
 */
$staff_user->setMobileNumber("427 078 528")->update();
print 'Updated: ' . $staff_user;
/**
 * Load Registered user group.
 */
$registered_user_group = kyUserGroup::getAll()->filterByTitle("Registered")->first();
print 'Fetched: ' . $registered_user_group;
/**
 * Load some user organization.
 */
$user_organization = kyUserOrganization::getAll()->first();
print 'Fetched: ' . $user_organization;
/**
 * Create new user in Registered group:
 * fullname: Anno Ying
 * email: anno.ying@example.com
 * password: qwerty123
 */
$user = $registered_user_group->newUser("Anno Ying", "*****@*****.**", "qwerty123")->setUserOrganization($user_organization)->setSalutation(kyUser::SALUTATION_MR)->setSendWelcomeEmail(false)->create();
print 'Created: ' . $user;
/**