Exemple #1
0
 /**
  * Class constructor.
  *
  * @param CRM_Core_Selector_API $object
  *   An object that implements the selector API.
  * @param int $pageID
  *   Default pageID.
  * @param int $sortID
  *   Default sortID.
  * @param int $action
  *   The actions to potentially support.
  * @param CRM_Core_Page|CRM_Core_Form $store place in session to store some values
  * @param int $output
  *   What do we so with the output, session/template//both.
  *
  * @param null $prefix
  * @param null $case
  *
  * @return \CRM_Core_Selector_Controller
  */
 public function __construct($object, $pageID, $sortID, $action, $store = NULL, $output = self::TEMPLATE, $prefix = NULL, $case = NULL)
 {
     $this->_object = $object;
     $this->_pageID = $pageID ? $pageID : 1;
     $this->_sortID = $sortID ? $sortID : NULL;
     $this->_action = $action;
     $this->_store = $store;
     $this->_output = $output;
     $this->_prefix = $prefix;
     $this->_case = $case;
     // fix sortID
     if ($this->_sortID && strpos($this->_sortID, '_') === FALSE) {
         $this->_sortID .= '_u';
     }
     $params = array('pageID' => $this->_pageID);
     // let the constructor initialize this, should happen only once
     if (!isset(self::$_template)) {
         self::$_template = CRM_Core_Smarty::singleton();
     }
     $this->_sortOrder =& $this->_object->getSortOrder($action);
     $this->_sort = new CRM_Utils_Sort($this->_sortOrder, $this->_sortID);
     /*
      * if we are in transfer mode, do not goto database, use the
      * session values instead
      */
     if ($output == self::TRANSFER) {
         $params['total'] = $this->_store->get($this->_prefix . 'rowCount');
     } else {
         $params['total'] = $this->_object->getTotalCount($action, $this->_case);
     }
     $this->_total = $params['total'];
     $this->_object->getPagerParams($action, $params);
     /*
      * Set the default values of RowsPerPage
      */
     $storeRowCount = $store->get($this->_prefix . CRM_Utils_Pager::PAGE_ROWCOUNT);
     if ($storeRowCount) {
         $params['rowCount'] = $storeRowCount;
     } elseif (!isset($params['rowCount'])) {
         $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT;
     }
     $this->_pager = new CRM_Utils_Pager($params);
     list($this->_pagerOffset, $this->_pagerRowCount) = $this->_pager->getOffsetAndRowCount();
 }
 /**
  * Browse all contribution pages.
  *
  * @param mixed $action
  *   Unused parameter.
  */
 public function browse($action = NULL)
 {
     Civi::resources()->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header');
     $this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', 'String', $this);
     // @todo Unused local variable can be safely removed.
     // But are there any side effects of CRM_Utils_Request::retrieve() that we
     // need to preserve?
     $createdId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE, 0);
     if ($this->_sortByCharacter == 'all' || !empty($_POST)) {
         $this->_sortByCharacter = '';
         $this->set('sortByCharacter', '');
     }
     $this->search();
     $params = array();
     $whereClause = $this->whereClause($params, FALSE);
     $this->pagerAToZ($whereClause, $params);
     $params = array();
     $whereClause = $this->whereClause($params, TRUE);
     $this->pager($whereClause, $params);
     list($offset, $rowCount) = $this->_pager->getOffsetAndRowCount();
     //check for delete CRM-4418
     $allowToDelete = CRM_Core_Permission::check('delete in CiviContribute');
     $query = "\n  SELECT  id\n    FROM  civicrm_contribution_page\n   WHERE  {$whereClause}\n   ORDER BY is_active desc, title asc\n   LIMIT  {$offset}, {$rowCount}";
     $contribPage = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Contribute_DAO_ContributionPage');
     $contribPageIds = array();
     while ($contribPage->fetch()) {
         $contribPageIds[$contribPage->id] = $contribPage->id;
     }
     //get all section info.
     $contriPageSectionInfo = CRM_Contribute_BAO_ContributionPage::getSectionInfo($contribPageIds);
     $query = "\nSELECT *\nFROM civicrm_contribution_page\nWHERE {$whereClause}\nORDER BY is_active desc, title asc\n   LIMIT {$offset}, {$rowCount}";
     $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Contribute_DAO_ContributionPage');
     //get all campaigns.
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
     //get configure actions links.
     $configureActionLinks = self::configureActionLinks();
     while ($dao->fetch()) {
         $contribution[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $contribution[$dao->id]);
         // form all action links
         $action = array_sum(array_keys($this->actionLinks()));
         //add configure actions links.
         $action += array_sum(array_keys($configureActionLinks));
         //add online contribution links.
         $action += array_sum(array_keys(self::onlineContributionLinks()));
         //add contribution search links.
         $action += array_sum(array_keys(self::contributionLinks()));
         if ($dao->is_active) {
             $action -= (int) CRM_Core_Action::ENABLE;
         } else {
             $action -= (int) CRM_Core_Action::DISABLE;
         }
         //CRM-4418
         if (!$allowToDelete) {
             $action -= (int) CRM_Core_Action::DELETE;
         }
         //build the configure links.
         $sectionsInfo = CRM_Utils_Array::value($dao->id, $contriPageSectionInfo, array());
         $contribution[$dao->id]['configureActionLinks'] = CRM_Core_Action::formLink(self::formatConfigureLinks($sectionsInfo), $action, array('id' => $dao->id), ts('Configure'), TRUE, 'contributionpage.configure.actions', 'ContributionPage', $dao->id);
         //build the contributions links.
         $contribution[$dao->id]['contributionLinks'] = CRM_Core_Action::formLink(self::contributionLinks(), $action, array('id' => $dao->id), ts('Contributions'), TRUE, 'contributionpage.contributions.search', 'ContributionPage', $dao->id);
         //build the online contribution links.
         $contribution[$dao->id]['onlineContributionLinks'] = CRM_Core_Action::formLink(self::onlineContributionLinks(), $action, array('id' => $dao->id), ts('Links'), TRUE, 'contributionpage.online.links', 'ContributionPage', $dao->id);
         //build the normal action links.
         $contribution[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $dao->id), ts('more'), TRUE, 'contributionpage.action.links', 'ContributionPage', $dao->id);
         //show campaigns on selector.
         $contribution[$dao->id]['campaign'] = CRM_Utils_Array::value($dao->campaign_id, $allCampaigns);
     }
     if (isset($contribution)) {
         $this->assign('rows', $contribution);
     }
 }