CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Discussion (deprecated) »
  • Alpha and Beta Release Testing »
  • 2.2 Release Testing »
  • event api does not work after upgrade
Pages: [1]

Author Topic: event api does not work after upgrade  (Read 2536 times)

sonicthoughts

  • Ask me questions
  • ****
  • Posts: 498
  • Karma: 10
event api does not work after upgrade
March 20, 2009, 06:35:24 am
I get no events returned.  It could be a permission problem but the permissions migrated.  there is a new permission  (since 2.0) called "view event info" which i also enabled.  the API fails for all users, including admin.  I'm starting to look into it, but wonder if I'm missing something big :)

Code is below:
<div id="eventspage" class="all2008">
<a name="top"></a> <?php

function cmp_date2($a,$b) {
  if ($a['start_date'] > $b['start_date']) return 1;
  if ($a['start_date'] < $b['start_date']) return -1;
  return 0;
}

if (module_exists('civicrm')) {
  civicrm_initialize(TRUE);
  require_once 'api/v2/Event.php';
  // This example limits listing to public and active events
  $params = array ('is_public'     => 1, 'is_active'     => 1);
  $myEvents = civicrm_event_search( $params );
  if ($myEvents) {
    $count = 0;
    $last = '';
    usort($myEvents,'cmp_date2');


print "<ul>\n";
  for ($i=0;$i < sizeof($myEvents); $i++) {
$event = $myEvents[$i];
 $now = date('Y-m-d H:i:s');
      if ($now > $event['start_date']) continue;
 list($title_place, $title_desc) = split(":",$event['title'],2);
print "<li><a href=\"#event$i\">$title_place</a></li> \n";
}
print "</ul>\n";


   for ($j=0;$j < sizeof($myEvents); $j++) {


    $event = $myEvents[$j];
      $now = date('Y-m-d H:i:s');
      if ($now > $event['start_date']) continue;
      $startdate = date('D M j Y',strtotime($event['start_date']));
      $enddate   = date('D M j Y',strtotime($event['end_date']));
      $starttime = date('g:i  A',strtotime($event['start_date']));
     

     $eventid = $event['id'];

      list($title_place, $title_desc) = split(":",$event['title'],2);
     
      $display = l($title_place.' '.$title_desc, 'civicrm/event/info', array(), 'reset=1&id='.$event['id']);
   echo '<div>';
echo '<a name="event' . $j . '"></a>';
 echo  '<h3>'.$display.'</h3>';

 $discr = $event['description'];
 echo  '<p>'.$discr.'</p>';

if ($last != $startdate) {
        $start_date = '<b> WHEN: </b>'.$startdate;
      }
print $start_date.'<br/>';

print '<b>TIME: </b>'.$starttime ;
echo '<br>';
require_once 'CRM/Core/DAO/LocBlock.php';
$addId = CRM_Core_DAO::getfieldvalue('CRM_Core_DAO_LocBlock',$event['loc_block_id'],'address_id');
if($addId){
$query = "SELECT  street_address , supplemental_address_1 , city , sp.abbreviation ,postal_code, cc.name FROM civicrm_address LEFT JOIN civicrm_state_province sp ON (civicrm_address.state_province_id =sp.id )LEFT JOIN civicrm_country cc ON (civicrm_address.country_id =cc.id ) WHERE civicrm_address.id=$addId";
$params = array();
$dao =& CRM_Core_DAO::executeQuery( $query, $params );
 $dao->fetch( );
$location = '<b>WHERE: </b>' ;
if($dao->street_address){
$location.= $dao->street_address.'<br />';}
if($dao->supplemental_address_1){
$location.= $dao->supplemental_address_1.'<br />';}
if($dao->city){
$location.= $dao->city.','.$dao->abbreviation.' '.$dao->postal_code.'<br />';}
print $location;
}

require_once 'CRM/Event/DAO/EventPage.php';
        $pageGroup= new CRM_Event_DAO_EventPage($eventid);
        $pageID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_EventPage', $eventid, 'id', 'event_id');

 require_once 'CRM/Core/DAO/OptionGroup.php';
        $optionGroupDAO = new CRM_Core_DAO_OptionGroup();
        $optionGroupDAO->name = 'civicrm_event_page.amount.'.$pageID;
        $ss = array();
        $i = 0;
        if ($optionGroupDAO->find(true) ) {
            $optionGroupId = $optionGroupDAO->id;
            require_once 'CRM/Core/DAO/OptionValue.php';
            $optionValueDAO = new CRM_Core_DAO_OptionValue();
            $optionValueDAO->option_group_id = $optionGroupDAO->id;
            $optionValueDAO->find();
            while ( $optionValueDAO->fetch( ) ) {

                $ss['optionLable'][$i] = $optionValueDAO->label;
                $ss['optionValue'][$i] = $optionValueDAO->value;
                $i++;
            }
        }
 require_once 'CRM/Core/BAO/PriceSet.php';
 $priceSetId = CRM_Core_BAO_PriceSet::getFor( 'civicrm_event_page', $eventid );
if($ss['optionValue'] && !$priceSetId){
       print '<b>COST: </b>'.'$'.$ss['optionValue'][0].' per person' ;
}
if ($event['is_online_registration'] ) {

        echo "<p class=\"regbutton\"><a href=\"http://jicny.com/civicrm/event/register?reset=1&id=" . $event['id'] . "\"><img src = \"/files/images/register_online_button.gif\" /></a></p>";
}

echo '<p class="totop"><a href="#top" class="totop">top</a></p>';
echo '</div>';
      $count++;
      $last = $startdate;
 //     if ($count > 8) break;
// this limits the number of events to 8 - put in whatever number suits you
    }
    if ($count > 0) {

    } else {
      echo 'No events found.';
    }
  } else {
    echo 'No events found.';
  }
}
?></div>
<p>&nbsp;</p>

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: event api does not work after upgrade
March 20, 2009, 11:37:30 am
I think you hit the same problem I had here

http://forum.civicrm.org/index.php/topic,7153.msg31392.html#msg31392

If you have more than 25 events then this will be it
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Discussion (deprecated) »
  • Alpha and Beta Release Testing »
  • 2.2 Release Testing »
  • event api does not work after upgrade

This forum was archived on 2017-11-26.