Esempio n. 1
0
 /**
  * create the list of options to create New objects for the application and format is as a block
  *
  * @return void
  * @access private
  */
 private function setTemplateShortcutValues()
 {
     $config =& CRM_Core_Config::singleton();
     static $shortCuts = array();
     if (!$shortCuts) {
         if (CRM_Core_Permission::check('add contacts')) {
             require_once 'CRM/Contact/BAO/ContactType.php';
             $shortCuts = CRM_Contact_BAO_ContactType::getCreateNewList();
             if (CRM_Core_Permission::access('Quest')) {
                 $shortCuts = array_merge($shortCuts, array(array('path' => 'civicrm/quest/search', 'query' => 'reset=1', 'ref' => 'quest-search', 'title' => ts('Quest Search'))));
             }
         }
         // new activity (select target contact)
         $shortCuts = array_merge($shortCuts, array(array('path' => 'civicrm/activity', 'query' => 'action=add&reset=1&context=standalone', 'ref' => 'new-activity', 'title' => ts('Activity'))));
         if (CRM_Core_Permission::check('access CiviCase') && CRM_Core_Permission::check('add contacts') && in_array('CiviCase', $config->enableComponents)) {
             require_once 'CRM/Core/OptionGroup.php';
             $atype = CRM_Core_OptionGroup::getValue('activity_type', 'Open Case', 'name');
             if ($atype) {
                 $shortCuts = array_merge($shortCuts, array(array('path' => 'civicrm/case/add', 'query' => "reset=1&action=add&atype={$atype}&context=standalone", 'ref' => 'new-case', 'title' => ts('Case'))));
             }
         }
         if (CRM_Core_Permission::check('access CiviContribute') && CRM_Core_Permission::check('edit contributions') && in_array('CiviContribute', $config->enableComponents)) {
             $shortCuts = array_merge($shortCuts, array(array('path' => 'civicrm/contribute/add', 'query' => "reset=1&action=add&context=standalone", 'ref' => 'new-contribution', 'title' => ts('Contribution'))));
         }
         // new email (select recipients)
         $shortCuts = array_merge($shortCuts, array(array('path' => 'civicrm/activity/add', 'query' => 'atype=3&action=add&reset=1&context=standalone', 'ref' => 'new-email', 'title' => ts('Email'))));
         if (CRM_Core_Permission::check('access CiviEvent') && CRM_Core_Permission::check('edit event participants') && in_array('CiviEvent', $config->enableComponents)) {
             $shortCuts = array_merge($shortCuts, array(array('path' => 'civicrm/participant/add', 'query' => "reset=1&action=add&context=standalone", 'ref' => 'new-participant', 'title' => ts('Event Registration'))));
         }
         if (CRM_Core_Permission::check('access CiviGrant') && CRM_Core_Permission::check('edit grants') && in_array('CiviGrant', $config->enableComponents)) {
             $shortCuts = array_merge($shortCuts, array(array('path' => 'civicrm/grant/add', 'query' => "reset=1&action=add&context=standalone", 'ref' => 'new-grant', 'title' => ts('Grant'))));
         }
         if (CRM_Core_Permission::check('access CiviMember') && CRM_Core_Permission::check('edit memberships') && in_array('CiviMember', $config->enableComponents)) {
             $shortCuts = array_merge($shortCuts, array(array('path' => 'civicrm/member/add', 'query' => "reset=1&action=add&context=standalone", 'ref' => 'new-membership', 'title' => ts('Membership'))));
         }
         if (CRM_Core_Permission::check('access CiviPledge') && CRM_Core_Permission::check('edit pledges') && in_array('CiviPledge', $config->enableComponents)) {
             $shortCuts = array_merge($shortCuts, array(array('path' => 'civicrm/pledge/add', 'query' => "reset=1&action=add&context=standalone", 'ref' => 'new-pledge', 'title' => ts('Pledge'))));
         }
         if (CRM_Core_Permission::check('edit groups')) {
             $shortCuts = array_merge($shortCuts, array(array('path' => 'civicrm/group/add', 'query' => 'reset=1', 'ref' => 'new-group', 'title' => ts('Group'))));
         }
         if (CRM_Core_Permission::check('administer CiviCRM')) {
             $shortCuts = array_merge($shortCuts, array(array('path' => 'civicrm/admin/tag', 'query' => 'reset=1&action=add', 'ref' => 'new-tag', 'title' => ts('Tag'))));
         }
         if (empty($shortCuts)) {
             return null;
         }
     }
     $values = array();
     foreach ($shortCuts as $short) {
         $value = array();
         if (isset($short['url'])) {
             $value['url'] = $short['url'];
         } else {
             $value['url'] = CRM_Utils_System::url($short['path'], $short['query'], false);
         }
         $value['title'] = $short['title'];
         $value['ref'] = $short['ref'];
         $values[] = $value;
     }
     // call shortcut hook
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::shortcuts($values);
     self::setProperty(self::CREATE_NEW, 'templateValues', array('shortCuts' => $values));
 }