/** * Runs when new ticket is created * @param object $ticket * @param object $customer [optional] * @return */ public function ticketNew($ticket, $customer = null) { // If email notifications are not disabled, notify admin $department = $ticket->getDepartment(); /*parse content for send into mail*/ $originalContent = $ticket->getContent(); $parsedContent = $this->_parseContent($ticket); $ticket->setContent(nl2br($parsedContent)); $ticket->setContent($this->_processContent($ticket->getContent(), array('ticket' => $ticket, 'department' => $department))); if ($department->getEnabled() && $department->getNotify()) { // Notify admin/department $tpl = $department->getToAdminNewEmail(); $sender = array('name' => $customer->getName(), 'email' => $customer->getEmail()); $recipientEmail = $department->getContact(); $recipientName = $department->getName(); $mailTemplate = $this->_getMailTemplate($ticket, $department); if (!is_null($mailTemplate)) { $this->log('Sending mail about new ticket ' . $ticket->getUid() . ' to department ' . $recipientName . '<' . $recipientEmail . '>'); $mailTemplate->setDesignConfig(array('area' => 'backend', 'store' => $ticket->getStoreId()))->sendTransactional($tpl, $sender, $recipientEmail, $recipientName, array('ticket' => $ticket, 'department' => $department), $ticket->getStoreId()); } } if ($customer) { $recipientEmail = is_string($customer) ? $customer : $customer->getEmail(); $recipientName = is_string($customer) ? $customer : $customer->getName(); } else { $recipientEmail = $ticket->getCustomerEmail(); $recipientName = $ticket->getCustomerName(); } if ($recipientEmail) { if ($ticket->getCreatedBy() == 'admin') { $tpl = $department->getNewFromAdminToCustomer(); } else { $tpl = $department->getToCustomerNewEmail(); } $sender = $department->getSender(); $mailTemplate = $this->_getMailTemplate($ticket, $department); if (isset($mailTemplate) && !is_null($mailTemplate)) { $this->log('Sending mail about new ticket ' . $ticket->getUid() . ' to customer ' . $recipientName . '<' . $recipientEmail . '>'); $mailTemplate->setDesignConfig(array('area' => 'frontend', 'store' => $ticket->getStoreId()))->sendTransactional($tpl, $sender, $recipientEmail, $recipientName, array('ticket' => $ticket, 'department' => $department), $ticket->getStoreId()); } } $ticket->setContent($originalContent); }
/** * Callback to render the "Name" metabox. * * @access private * @since 0.8 * @param object $entry An instance of the cnEntry object. * @param array $metabox The metabox attributes array set in self::register(). * @return void */ public static function name($entry, $metabox, $atts = array()) { // Grab an instance of the Connections object. $instance = Connections_Directory(); // This array will store field group IDs as the fields are registered. // This array will be checked for an existing ID before rendering // a field to prevent multiple field group IDs from being rendered. $groupIDs = array(); // This array will store field IDs as the fields are registered. // This array will be checked for an existing ID before rendering // a field to prevent multiple field IDs from being rendered. $fieldIDs = array(); $defaults = array('type' => array('individual', 'organization', 'family'), 'individual' => array('meta' => array('name' => array('show' => TRUE, 'field' => array('prefix' => array('id' => 'honorific_prefix', 'show' => TRUE, 'label' => __('Prefix', 'connections'), 'required' => FALSE, 'type' => 'text', 'value' => strlen($entry->getHonorificPrefix()) > 0 ? $entry->getHonorificPrefix('edit') : '', 'before' => '<span id="cn-name-prefix">', 'after' => '</span>'), 'first' => array('id' => 'first_name', 'show' => TRUE, 'label' => __('First Name', 'connections'), 'required' => TRUE, 'type' => 'text', 'value' => strlen($entry->getFirstName()) > 0 ? $entry->getFirstName('edit') : '', 'before' => '<span id="cn-name-first">', 'after' => '</span>'), 'middle' => array('id' => 'middle_name', 'show' => TRUE, 'label' => __('Middle Name', 'connections'), 'required' => FALSE, 'type' => 'text', 'value' => strlen($entry->getMiddleName()) > 0 ? $entry->getMiddleName('edit') : '', 'before' => '<span id="cn-name-middle">', 'after' => '</span>'), 'last' => array('id' => 'last_name', 'show' => TRUE, 'label' => __('Last Name', 'connections'), 'required' => TRUE, 'type' => 'text', 'value' => strlen($entry->getLastName()) > 0 ? $entry->getLastName('edit') : '', 'before' => '<span id="cn-name-last">', 'after' => '</span>'), 'suffix' => array('id' => 'honorific_suffix', 'show' => TRUE, 'label' => __('Suffix', 'connections'), 'required' => FALSE, 'type' => 'text', 'value' => strlen($entry->getHonorificSuffix()) > 0 ? $entry->getHonorificSuffix('edit') : '', 'before' => '<span id="cn-name-suffix">', 'after' => '</span>'))), 'title' => array('show' => TRUE, 'field' => array('title' => array('id' => 'title', 'show' => TRUE, 'label' => __('Title', 'connections'), 'required' => FALSE, 'type' => 'text', 'value' => strlen($entry->getTitle()) > 0 ? $entry->getTitle('edit') : ''))), 'organization' => array('show' => TRUE, 'field' => array('organization' => array('id' => 'organization', 'show' => TRUE, 'label' => __('Organization', 'connections'), 'required' => FALSE, 'type' => 'text', 'value' => strlen($entry->getOrganization()) > 0 ? $entry->getOrganization('edit') : ''))), 'department' => array('show' => TRUE, 'field' => array('department' => array('id' => 'department', 'show' => TRUE, 'label' => __('Department', 'connections'), 'required' => FALSE, 'type' => 'text', 'value' => strlen($entry->getDepartment()) > 0 ? $entry->getDepartment('edit') : ''))))), 'organization' => array('meta' => array('organization' => array('show' => TRUE, 'field' => array('organization' => array('id' => 'organization', 'show' => TRUE, 'label' => __('Organization', 'connections'), 'required' => FALSE, 'type' => 'text', 'value' => strlen($entry->getOrganization()) > 0 ? $entry->getOrganization('edit') : ''))), 'department' => array('show' => TRUE, 'field' => array('department' => array('id' => 'department', 'show' => TRUE, 'label' => __('Department', 'connections'), 'required' => FALSE, 'type' => 'text', 'value' => strlen($entry->getDepartment()) > 0 ? $entry->getDepartment('edit') : ''))), 'contact' => array('show' => TRUE, 'field' => array('contact_first_name' => array('id' => 'contact_first_name', 'show' => TRUE, 'label' => __('Contact First Name', 'connections'), 'required' => FALSE, 'type' => 'text', 'value' => strlen($entry->getContactFirstName()) > 0 ? $entry->getContactFirstName('edit') : '', 'before' => '<span class="cn-half-width" id="cn-contact-first-name">', 'after' => '</span>'), 'contact_last_name' => array('id' => 'contact_last_name', 'show' => TRUE, 'label' => __('Contact Last Name', 'connections'), 'required' => FALSE, 'type' => 'text', 'value' => strlen($entry->getContactLastName()) > 0 ? $entry->getContactLastName('edit') : '', 'before' => '<span class="cn-half-width" id="cn-contact-last-name">', 'after' => '</span>'))))), 'family' => array('callback' => array(__CLASS__, 'family'), 'meta' => array())); $atts = wp_parse_args(apply_filters('cn_metabox_name_atts', $atts), $defaults); foreach ((array) $atts['type'] as $entryType) { if (array_key_exists($entryType, $atts)) { if (isset($atts[$entryType]['callback'])) { call_user_func($atts[$entryType]['callback'], $entry, $atts[$entryType]['meta']); continue; } /* * Dump the output in a var that way it can mre more easily broke up and filters added later. */ $out = ''; foreach ($atts[$entryType]['meta'] as $type => $meta) { if (in_array($type, $groupIDs)) { continue; } else { $groupIDs[] = $type; } $out .= '<div class="cn-metabox" id="cn-metabox-section-' . $type . '">' . PHP_EOL; if ($meta['show'] == TRUE) { foreach ($meta['field'] as $field) { if (in_array($field['id'], $fieldIDs)) { continue; } else { $fieldIDs[] = $field['id']; } if ($field['show']) { $defaults = array('type' => '', 'class' => array(), 'id' => '', 'style' => array(), 'options' => array(), 'value' => '', 'required' => FALSE, 'label' => '', 'before' => '', 'after' => '', 'return' => TRUE); $field = wp_parse_args($field, $defaults); $out .= cnHTML::field(array('type' => $field['type'], 'class' => $field['class'], 'id' => $field['id'], 'style' => $field['style'], 'options' => $field['options'], 'required' => $field['required'], 'label' => $field['label'], 'before' => $field['before'], 'after' => $field['after'], 'return' => TRUE), $field['value']); } } } $out .= '</div>' . PHP_EOL; } echo $out; } } }
/** * Outputs entry data JSON encoded in HTML data attribute. * This is an action called by the `cn_action_entry_after` hook. * * @access public * @since 0.8 * @uses wp_parse_args() * @param array $atts Shortcode $atts passed by the `cn_action_entry_after` action hook. * @param object $entry An instance the the cnEntry object. * * @return string */ public static function JSON($atts, $entry) { $defaults = array('tag' => 'div', 'before' => '', 'after' => '', 'return' => FALSE, 'show_addresses' => TRUE, 'show_phone_numbers' => TRUE, 'show_email' => TRUE, 'show_im' => TRUE, 'show_social_media' => TRUE, 'show_links' => TRUE, 'show_dates' => TRUE, 'show_bio' => TRUE, 'show_notes' => TRUE); $atts = wp_parse_args($atts, $defaults); $data = array('type' => $entry->getEntryType(), 'id' => $entry->getId(), 'ruid' => $entry->getRuid(), 'slug' => $entry->getSlug(), 'name' => array('full' => $entry->getName($atts), 'prefix' => $entry->getHonorificPrefix(), 'first' => $entry->getFirstName(), 'middle' => $entry->getMiddleName(), 'last' => $entry->getLastName(), 'suffix' => $entry->getHonorificSuffix()), 'title' => $entry->getTitle(), 'organization' => $entry->getOrganization(), 'department' => $entry->getDepartment(), 'contact_name' => array('full' => $entry->getContactName(), 'first' => $entry->getContactFirstName(), 'last' => $entry->getContactLastName()), 'family_name' => $entry->getFamilyName(), 'family_members' => $entry->getFamilyMembers(), 'categories' => $entry->getCategory(), 'meta' => $entry->getMeta($atts)); if ($atts['show_addresses']) { $data['addresses'] = $entry->getAddresses($atts); } if ($atts['show_phone_numbers']) { $data['phone_numbers'] = $entry->getPhoneNumbers($atts); } if ($atts['show_email']) { $data['email_addresses'] = $entry->getEmailAddresses($atts); } if ($atts['show_im']) { $data['im'] = $entry->getIm($atts); } if ($atts['show_social_media']) { $data['social_media'] = $entry->getSocialMedia($atts); } if ($atts['show_links']) { $data['links'] = $entry->getLinks($atts); } if ($atts['show_dates']) { $data['dates'] = $entry->getDates($atts); } if ($atts['show_bio']) { $data['bio'] = $entry->getBio(); } if ($atts['show_notes']) { $data['notes'] = $entry->getNotes(); } $out = sprintf('<%1$s class="cn-entry-data-json" data-entry-data-json=\'%2$s\'></%1$s>', $atts['tag'], htmlspecialchars(json_encode($data), ENT_QUOTES, 'UTF-8')); $out = (empty($atts['before']) ? '' : $atts['before']) . $out . (empty($atts['after']) ? '' : $atts['after']) . PHP_EOL; return self::echoOrReturn($atts['return'], $out); }
/** * The core method that processes the content according to the * entry part that the shortcode should add to the content. * * @access private * @since 0.8 * @param array $atts The shortcode attributes array. * @param string $content The content captured between an open/close shortcode. * @param string $tag The shortcode tag. * * @return string The processed content. */ public function shortcode($atts, $content = '', $tag = 'cn_entry') { // Bail if self::$entry is not set because an instance of the cnEntry object is required. if (is_null($this->entry)) { return ''; } $defaults = array('part' => ''); // Normally we'd use shortcode_atts, but that strips keys from $atts that do not exist in $defaults. // Since $atts can contain various option for the different callback methods, we'll use wp_parse_args() // which leaves keys that do not exist in $atts. $atts = wp_parse_args($atts, $defaults); // All the core methods in the cnEntry_HTML class echo by default, make sure to return instead. $atts['return'] = TRUE; switch ($atts['part']) { case 'name': $out = $this->entry->getName($atts); break; case 'title': $out = $this->entry->getTitle(); break; case 'organization': $out = $this->entry->getOrganization(); break; case 'department': $out = $this->entry->getDepartment(); break; case 'contact': $out = $this->entry->getContactName($atts); break; case 'family_relationships': $out = $this->entry->getFamilyMembers($atts); break; case 'addresses': add_shortcode('cn_address', array($this, 'address')); $out = has_shortcode($content, 'cn_address') ? do_shortcode($content) : ''; remove_shortcode('cn_address'); break; case 'phone_numbers': add_shortcode('cn_phone', array($this, 'phone')); $out = has_shortcode($content, 'cn_phone') ? do_shortcode($content) : ''; remove_shortcode('cn_phone'); break; case 'email': add_shortcode('cn_email', array($this, 'email')); $out = has_shortcode($content, 'cn_email') ? do_shortcode($content) : ''; remove_shortcode('cn_email'); break; case 'im': add_shortcode('cn_im', array($this, 'im')); $out = has_shortcode($content, 'cn_im') ? do_shortcode($content) : ''; remove_shortcode('cn_im'); break; case 'social_networks': add_shortcode('cn_social_network', array($this, 'socialNetwork')); $out = has_shortcode($content, 'cn_social_network') ? do_shortcode($content) : ''; remove_shortcode('cn_social_network'); break; case 'links': add_shortcode('cn_link', array($this, 'link')); $out = has_shortcode($content, 'cn_link') ? do_shortcode($content) : ''; remove_shortcode('cn_link'); break; case 'dates': add_shortcode('cn_date', array($this, 'date')); $out = has_shortcode($content, 'cn_date') ? do_shortcode($content) : ''; remove_shortcode('cn_date'); break; case 'bio': $out = $this->entry->getBio(); break; case 'notes': $out = $this->entry->getNotes(); break; default: // Custom shortcodes can be applied to the content using this filter. $out = apply_filters('cn_entry_part-' . $part, $content, $atts, $this->entry); break; } return $out; }
/** * Returns Ticket details from object * * @param object $_ticketObject * * @return array $_ticket */ public function getTicketDetailsByObject($_ticketObject) { $_ticket = array(); $_ticket['ticketid'] = $_ticketObject->getId(); $_ticket['displayticketid'] = $_ticketObject->getDisplayId(); $_ticket['departmentid'] = $_ticketObject->getDepartmentId(); $_ticket['department'] = $_ticketObject->getDepartment()->getTitle(); $_ticket['ticketstatusid'] = $_ticketObject->getStatusId(); $_ticket['status'] = $_ticketObject->getStatus()->getTitle(); $_ticket['statusbgcolor'] = $_ticketObject->getStatus()->getStatusBackgroundColor(); $_ticket['priorityid'] = $_ticketObject->getPriorityId(); $_ticket['priority'] = $_ticketObject->getPriority()->getTitle(); $_ticket['prioritybgcolor'] = $_ticketObject->getPriority()->getBackgroundColor(); $_ticket['userid'] = $_ticketObject->getUserId(); $_ticket['tickettypeid'] = $_ticketObject->getTypeId(); $_ticket['type'] = $_ticketObject->getType()->getTitle(); $_ticket['userid'] = $_ticketObject->getUserId(); $_ticket['fullname'] = $_ticketObject->getFullName(); $_ticket['email'] = $_ticketObject->getEmail(); $_ticket['ownerstaffid'] = $_ticketObject->getOwnerStaffId(); $_ticket['lastreplier'] = $_ticketObject->getLastReplier(); $_ticket['subject'] = $_ticketObject->getSubject(); $_ticket['dateline'] = $_ticketObject->getCreationTime(); $_ticket['lastactivity'] = $_ticketObject->getLastActivity(); return $_ticket; }