Example #1
0
File: Set.php Project: kidaa30/yes
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the
  * type of action and executes that action.
  * Finally it calls the parent's run method.
  *
  * @return void
  */
 public function run()
 {
     // get the requested action
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
     // assign vars to templates
     $this->assign('action', $action);
     $sid = CRM_Utils_Request::retrieve('sid', 'Positive', $this, FALSE, 0);
     if ($sid) {
         CRM_Price_BAO_PriceSet::checkPermission($sid);
     }
     // what action to take ?
     if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
         $this->edit($sid, $action);
     } elseif ($action & CRM_Core_Action::PREVIEW) {
         $this->preview($sid);
     } elseif ($action & CRM_Core_Action::COPY) {
         $session = CRM_Core_Session::singleton();
         CRM_Core_Session::setStatus(ts('A copy of the price set has been created'), ts('Saved'), 'success');
         $this->copy();
     } else {
         // if action is delete do the needful.
         if ($action & CRM_Core_Action::DELETE) {
             $usedBy = CRM_Price_BAO_PriceSet::getUsedBy($sid);
             if (empty($usedBy)) {
                 // prompt to delete
                 $session = CRM_Core_Session::singleton();
                 $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/price', 'action=browse'));
                 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_DeleteSet', 'Delete Price Set', NULL);
                 // $id = CRM_Utils_Request::retrieve('sid', 'Positive', $this, false, 0);
                 $controller->set('sid', $sid);
                 $controller->setEmbedded(TRUE);
                 $controller->process();
                 $controller->run();
             } else {
                 // add breadcrumb
                 $url = CRM_Utils_System::url('civicrm/admin/price', 'reset=1');
                 CRM_Utils_System::appendBreadCrumb(ts('Price Sets'), $url);
                 $this->assign('usedPriceSetTitle', CRM_Price_BAO_PriceSet::getTitle($sid));
                 $this->assign('usedBy', $usedBy);
                 $comps = array('Event' => 'civicrm_event', 'Contribution' => 'civicrm_contribution_page', 'EventTemplate' => 'civicrm_event_template');
                 $priceSetContexts = array();
                 foreach ($comps as $name => $table) {
                     if (array_key_exists($table, $usedBy)) {
                         $priceSetContexts[] = $name;
                     }
                 }
                 $this->assign('contexts', $priceSetContexts);
             }
         }
         // finally browse the price sets
         $this->browse();
     }
     // parent run
     return parent::run();
 }
Example #2
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the
  * type of action and executes that action.
  *
  * @param null
  *
  * @return void
  * @access public
  */
 function run()
 {
     // get the field id
     $this->_fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this, FALSE, 0);
     //get the price set id
     if (!$this->_sid) {
         $this->_sid = CRM_Utils_Request::retrieve('sid', 'Positive', $this);
     }
     if ($this->_sid) {
         CRM_Price_BAO_PriceSet::checkPermission($this->_sid);
         $this->_isSetReserved = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'is_reserved');
         $this->assign('isReserved', $this->_isSetReserved);
     }
     //as url contain $sid so append breadcrumb dynamically.
     $breadcrumb = array(array('title' => ts('Price Fields'), 'url' => CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&sid=' . $this->_sid)));
     CRM_Utils_System::appendBreadCrumb($breadcrumb);
     if ($this->_fid) {
         $fieldTitle = CRM_Price_BAO_PriceField::getTitle($this->_fid);
         $this->assign('fid', $this->_fid);
         $this->assign('fieldTitle', $fieldTitle);
         CRM_Utils_System::setTitle(ts('%1 - Price Options', array(1 => $fieldTitle)));
         $htmlType = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceField', $this->_fid, 'html_type');
         $this->assign('addMoreFields', TRUE);
         //for text price field only single option present
         if ($htmlType == 'Text') {
             $this->assign('addMoreFields', FALSE);
         }
     }
     // get the requested action
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
     // assign vars to templates
     $this->assign('action', $action);
     $oid = CRM_Utils_Request::retrieve('oid', 'Positive', $this, FALSE, 0);
     // what action to take ?
     if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::VIEW | CRM_Core_Action::DELETE) && !$this->_isSetReserved) {
         // no browse for edit/update/view
         $this->edit($action);
     } else {
         $this->browse();
     }
     // Call the parents run method
     return parent::run();
 }
Example #3
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the
  * type of action and executes that action.
  *
  * @param null
  *
  * @return void
  * @access public
  */
 function run()
 {
     // get the group id
     $this->_sid = CRM_Utils_Request::retrieve('sid', 'Positive', $this);
     $fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this, FALSE, 0);
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
     if ($this->_sid) {
         $usedBy = CRM_Price_BAO_PriceSet::getUsedBy($this->_sid);
         $this->assign('usedBy', $usedBy);
         $this->_isSetReserved = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'is_reserved');
         $this->assign('isReserved', $this->_isSetReserved);
         CRM_Price_BAO_PriceSet::checkPermission($this->_sid);
         $comps = array('Event' => 'civicrm_event', 'Contribution' => 'civicrm_contribution_page', 'EventTemplate' => 'civicrm_event_template');
         $priceSetContexts = array();
         foreach ($comps as $name => $table) {
             if (array_key_exists($table, $usedBy)) {
                 $priceSetContexts[] = $name;
             }
         }
         $this->assign('contexts', $priceSetContexts);
     }
     if ($action & CRM_Core_Action::DELETE && !$this->_isSetReserved) {
         if (empty($usedBy)) {
             // prompt to delete
             $session = CRM_Core_Session::singleton();
             $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid));
             $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_DeleteField', 'Delete Price Field', '');
             $controller->set('fid', $fid);
             $controller->setEmbedded(TRUE);
             $controller->process();
             $controller->run();
         } else {
             // add breadcrumb
             $url = CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1');
             CRM_Utils_System::appendBreadCrumb(ts('Price'), $url);
             $this->assign('usedPriceSetTitle', CRM_Price_BAO_PriceField::getTitle($fid));
         }
     }
     if ($this->_sid) {
         $groupTitle = CRM_Price_BAO_PriceSet::getTitle($this->_sid);
         $this->assign('sid', $this->_sid);
         $this->assign('groupTitle', $groupTitle);
         CRM_Utils_System::setTitle(ts('%1 - Price Fields', array(1 => $groupTitle)));
     }
     // assign vars to templates
     $this->assign('action', $action);
     // what action to take ?
     if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD) && !$this->_isSetReserved) {
         // no browse for edit/update/view
         $this->edit($action);
     } elseif ($action & CRM_Core_Action::PREVIEW) {
         $this->preview($fid);
     } else {
         $this->browse();
     }
     // Call the parents run method
     return parent::run();
 }