/** * Function to build the form * * @return None * @access public */ public function buildQuickForm($check = FALSE) { parent::buildQuickForm(); if ($this->_action & CRM_Core_Action::DELETE) { return; } $types = CRM_Booking_BAO_Resource::buildOptions('type_id', 'create'); $this->add('select', 'type_id', ts('Resource type'), array('' => ts('- select -')) + $types, TRUE, array()); $this->add('text', 'label', ts('Label'), array('size' => 50, 'maxlength' => 255), TRUE); $this->add('textarea', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Booking_DAO_Resource', 'description'), FALSE); /* $this->addWysiwyg('description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Booking_DAO_Resource', 'description') );*/ $this->add('text', 'weight', ts('Weight'), CRM_Core_DAO::getAttribute('CRM_Booking_DAO_Resource', 'weight'), TRUE); $this->add('checkbox', 'is_active', ts('Enabled?')); $this->add('checkbox', 'is_unlimited', ts('Is Unlimited?')); $configSets = array('' => ts('- select -')); try { $activeSets = civicrm_api3('ResourceConfigSet', 'get', array('is_active' => 1, 'is_deleted' => 0)); foreach ($activeSets['values'] as $key => $set) { $configSets[$key] = $set['title']; } } catch (CiviCRM_API3_Exception $e) { } $this->add('select', 'set_id', ts('Resource configuration set'), $configSets, TRUE); $locations = CRM_Booking_BAO_Resource::buildOptions('location_id', 'create'); $this->add('select', 'location_id', ts('Resource Location'), array('' => ts('- select -')) + $locations, FALSE, array()); $this->addFormRule(array('CRM_Admin_Form_Resource', 'formRule'), $this); $cancelURL = CRM_Utils_System::url('civicrm/admin/resource', "&reset=1"); $cancelURL = str_replace('&', '&', $cancelURL); $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'), 'js' => array('onclick' => "location.href='{$cancelURL}'; return false;")))); }
/** * Browse all resources. * * @return void * @access public * @static */ function browse($action = NULL) { $types = CRM_Booking_BAO_Resource::buildOptions('type_id', 'create'); $locations = CRM_Booking_BAO_Resource::buildOptions('location_id', 'create'); // get all custom groups sorted by weight $resources = array(); $dao = new CRM_Booking_DAO_Resource(); $dao->orderBy('weight'); $dao->is_deleted = FALSE; $dao->find(); while ($dao->fetch()) { $resources[$dao->id] = array(); CRM_Core_DAO::storeValues($dao, $resources[$dao->id]); $resources[$dao->id]['type'] = CRM_Utils_Array::value(CRM_Utils_Array::value('type_id', $resources[$dao->id]), $types); $resources[$dao->id]['location'] = CRM_Utils_Array::value(CRM_Utils_Array::value('location_id', $resources[$dao->id]), $locations); // form all action links $action = array_sum(array_keys($this->links())); // update enable/disable links. if ($dao->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } $resources[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id)); } $this->assign('rows', $resources); }