static function getCompanyEmail($company_id) { // Get the email address for the company // Use the first Technical address that is not defined as name TICKET_SUPPORT // TICKET_SUPPORT is defined in conf/config.php // If that does not exist, use the main address $config = Config::Instance(); $contact = ''; $company = new Company(); $company->load($company_id); $party = $company->party; $sh = new SearchHandler(new PartyContactMethodCollection(new PartyContactMethod()), false); $sh->AddConstraint(new Constraint('type', '=', 'E')); $ticket_support = $config->get('TICKET_SUPPORT'); if (!empty($ticket_support)) { $sh->AddConstraint(new Constraint('name', '!=', $ticket_support)); } $party->addSearchHandler('contactmethods', $sh); $methods = $party->contactmethods; foreach ($methods as $method) { if ($method->technical == true) { // Technical contact favoured above all else $contact = $method->contact; break; } if ($method->main == true) { // If no contact yet found and this contact is the main contact, use this instead $contact = $method->contact; } } return $contact; }
function __construct($getCurrentValues = true) { parent::__construct(); $userPreferences = UserPreferences::instance(); $this->setModuleName('contacts'); $roleCollection = new RoleCollection(); $sh = new SearchHandler($roleCollection, false); $sh->AddConstraint(new Constraint('usercompanyid', '=', EGS_COMPANY_ID)); $sh->setOrderby('name'); $roleCollection->load($sh); $roles = array(); foreach ($roleCollection->getContents() as $role) { $roles[$role->id] = array('value' => $role->id, 'label' => $role->name); if ($getCurrentValues) { if (in_array($role->id, $userPreferences->getPreferenceValue('default-read-roles', 'contacts'))) { $roles[$role->id]['selected'] = true; } } } $this->registerPreference(array('name' => 'default-read-roles', 'display_name' => 'Default Read Access', 'type' => 'select_multiple', 'data' => $roles, 'default' => array())); foreach ($roleCollection->getContents() as $role) { $roles[$role->id] = array('value' => $role->id, 'label' => $role->name); if ($getCurrentValues) { if (in_array($role->id, $userPreferences->getPreferenceValue('default-write-roles', 'contacts'))) { $roles[$role->id]['selected'] = true; } } } $this->registerPreference(array('name' => 'default-write-roles', 'display_name' => 'Default Write Access', 'type' => 'select_multiple', 'data' => $roles, 'default' => array())); }
function getallids() { $personoverview = new PersonCollection($this->_templateobject); $sh = new SearchHandler($personoverview, false); $sh->AddConstraint(new Constraint('usercompanyid', '=', EGS_COMPANY_ID)); $sh->AddConstraint(new Constraint('usernameaccess', '=', EGS_USERNAME)); $sh->setLimit(1); $return = $personoverview->load($sh); echo json_encode($return); exit; }
public function add_response() { parent::_new(); $ticket = $this->_uses['Ticket']; $ticket->load($this->_data['id']); $ticketResponse = $this->_uses['TicketResponse']; $ticketResponse->ticket_id = $ticket->id; $responses = new TicketResponseCollection(new TicketResponse()); $sh = new SearchHandler($responses, false); $sh->AddConstraint(new Constraint('ticket_id', '=', $ticket->id)); $responses->load($sh); $this->view->set('responses', $responses->getContents()); }
public function sharing($model = '') { $flash = Flash::Instance(); if (!$this->checkParams(array('id', 'model'), $flash)) { sendTo(); } if (empty($model)) { $modelname = $this->_data['model']; } else { $modelname = $model; } $object = $this->_uses[$modelname]; $object->load($this->_data['id']); // What if 'owner' is not a field on the model? if ($object->owner != EGS_USERNAME && !isModuleAdmin()) { // We're not the owner, are we /really/ allowed to read this object? $objectPermissions = new ObjectRoleCollection(); if ($objectPermissions->getRows($object->id, $object->getTableName(), 'write')->count() == 0) { if (empty($model)) { $flash = Flash::Instance(); $flash->addError('You do not have permission to edit this ' . $modelname); sendTo($this->name, 'view', $this->_data['module'], array('id' => $this->_data['id'])); } return false; } } $roles = array(); $roleCollection = new RoleCollection(); $sh = new SearchHandler($roleCollection, false); $sh->AddConstraint(new Constraint('usercompanyid', '=', EGS_COMPANY_ID)); $roleCollection->load($sh); // $ObjectRole = new ObjectRole; $ObjectRole = DataObjectFactory::Factory('ObjectRole'); $writeRoles = $ObjectRole->getRoleID($this->_data['id'], $object->getTableName(), 'write'); if ($writeRoles === false) { $writeRoles = array(); } foreach ($roleCollection->getContents() as $role) { $roles[$role->id]['name'] = $role->name; if (array_key_exists($role->id, $writeRoles)) { $roles[$role->id]['selected'] = true; } } $this->view->set('writeRoles', $roles); // $ObjectRole = new ObjectRole; $ObjectRole = DataObjectFactory::Factory('ObjectRole'); $readRoles = $ObjectRole->getRoleID($this->_data['id'], $object->getTableName(), 'read'); if ($readRoles === false) { $readRoles = array(); } foreach ($roleCollection->getContents() as $role) { $roles[$role->id]['name'] = $role->name; if (array_key_exists($role->id, $readRoles)) { $roles[$role->id]['selected'] = true; } } $this->view->set('readRoles', $roles); // FIXME: I'm sure this isn't the way this is done $this->view->set('id', $this->_data['id']); $this->view->set('model_name', $this->_data['model']); $this->view->set('model', $object); return true; }