Example #1
0
    function testWholeSave( ) {
//		define('DIA_API_DEBUG', true);
        $save =& $this->_udm->getPlugin( 'DIA', 'Save');
        @$this->assertTrue($save->execute( ));
		$this->assertTrue($save->getSupporterKey());
        $save->setOptions( array_merge($this->dia_account, array( 'orgKey' => $this->dia_account['organization_key']) ));

		$this->_udm->uid = 1;
		$cal_save =& $this->_udm->getPlugin('AMPCalendar', 'Save');
		$this->assertTrue($cal_save->execute());
		$cal_id = $cal_save->cal->id;

		$dia_save =& $this->_udm->getPlugin('DIAEvent', 'Save');
        $dia_save->setOptions( array_merge($this->dia_account, array( 'orgKey' => $this->dia_account['organization_key']) ));

		$data = $dia_save->translate($dia_save->getData());
        if( isset( $data['typeid'])) {
            require_once( 'Modules/Calendar/Type/Type.php');
            $caltype = &new Calendar_Type( $this->_udm->dbcon, $data['typeid']);
            $caltype->mergeData( array( 'distributed_event_key' => 142));
            $this->assertTrue( $caltype->save( ));
        }

        @$event_key = $dia_save->execute( );
		$this->assertTrue($this->_plugin->getEventKey());
		$this->assertTrue($event_key);
        if ( !$event_key ){
            $this->fail( 'save event failed, no key returned');
            return;
        }

        $api =& DIA_API::create(null, $this->dia_account );
        @$event = $api->getEvent( $event_key );
		$this->assertNotNull($event);

        //check that $event fields are the same as those we populated the udm with
		foreach($data as $key => $value) {
			if(!array_search($key, $this->_plugin->translation)) continue;
			$this->assertEqual($data[$key], $event[$key]);
		}
		$this->assertEqual($event['Status'], 'Active');
		$this->assertEqual($event['distributed_event_KEY'], 142);

		$this->assertEqual(dia_datetotime($event['Start']), strtotime($data['date'].' '.$data['time']));

		$sql = 'select dia_key from calendar where id='.$cal_id;
		$results = $this->_udm->dbcon->GetOne($sql);
		$this->assertEqual($results, $event_key, "failed when $event_key not the same as the result of $sql");
    }
Example #2
0
 function translate($data)
 {
     $translation = $this->translation;
     foreach ($data as $key => $value) {
         if (isset($translation[$key])) {
             $return[$translation[$key]] = $value;
         } else {
             $return[$key] = $value;
         }
     }
     $recurring_options = array('None' => 0, 'YEARLY' => 4, 'MONTHLY' => 3, 'WEEKLY' => 2, 'DAILY' => 1);
     if (isset($data['Recurrence_Frequency']) && ($freq = $data['Recurrence_Frequency'])) {
         if (isset($recurring_options[$freq])) {
             if (isset($data['Recurrence_Interval']) && $data['Recurrence_Interval'] == 7) {
                 $return['recurring_options'] = $recurring_options['WEEKLY'];
             } else {
                 $return['recurring_options'] = $recurring_options[$freq];
             }
         } else {
             $return['recurring_options'] = 0;
         }
     }
     if ($data['Status'] == 'Active') {
         $return['publish'] = 1;
     } else {
         $return['publish'] = 0;
     }
     if (isset($data['Start']) && $data['Start']) {
         $start = dia_datetotime($data['Start']);
         if (isset($start) && $start) {
             $return['date'] = date('Y-m-d', $start);
             $return['time'] = date('g:i A', $start);
         }
     }
     if (isset($data['End']) && $data['End']) {
         $end = dia_datetotime($data['End']);
         if (isset($end) && $end) {
             $return['endtime'] = date('g:i A', $end);
         }
     }
     if (isset($data['distributed_event_KEY'])) {
         $type_lookup = AMPSystem_Lookup::instance('DistributedEvent');
         if ($type = array_search($data['distributed_event_KEY'], $type_lookup)) {
             $return['typeid'] = $type;
         }
     }
     return $return;
 }
Example #3
0
 function testCheckData()
 {
     if (!$this->_udm->doPlugin('DIAEvent', 'Read', array('dia_event_key' => $this->event_key))) {
         $this->fail('Could not check data because read failed');
         return;
     }
     $data = $this->_plugin->getData();
     foreach ($this->_plugin->translation as $key => $value) {
         if ('event_KEY' == $key) {
             continue;
         }
         $this->assertNotNull($this->event[$key], "event[{$key}] is null");
         $this->assertNotNull($data[$value], "data[{$value}] is null");
         $this->assertEqual($this->event[$key], $data[$value], "event[{$key}] != data[{$value}]");
     }
     $this->assertNotNull($this->event['Start']);
     $this->assertNotNull($data['date']);
     $this->assertNotNull($data['time']);
     $this->assertEqual(dia_datetotime($this->event['Start']), strtotime($data['date'] . ' ' . $data['time']), "event['Start'] == " . $this->event['Start'] . "; data['date'] data['time'] == " . $data['date'] . ' ' . $data['time']);
     $this->assertEqual($data['publish'], 1);
     $this->assertEqual($data['typeid'], 39);
 }
Example #4
0
 function translate_hacks($dia_data)
 {
     if (isset($dia_data['Start']) && $dia_data['Start']) {
         $start = dia_datetotime($dia_data['Start']);
         if (isset($start) && $start) {
             $dia_data['Start_Date'] = date('Y-m-d', $start);
             $dia_data['Start_Time'] = date('g:i A', $start);
         }
     }
     if (isset($dia_data['End']) && $dia_data['End']) {
         $end_time = dia_datetotime($dia_data['End']);
         if (isset($start) && $start) {
             $dia_data['End_Date'] = date('Y-m-d', $end_time);
             $dia_data['End_Time'] = date('g:i A', $end_time);
         }
     }
     if ($dia_data['Status'] == 'Active') {
         $dia_data['Status'] = 1;
     } else {
         $dia_data['Status'] = 0;
     }
     return $dia_data;
 }