Exemple #1
0
 public function testPositioning()
 {
     $other_file = tempnam(sys_get_temp_dir() . 'tmp', 'history');
     $el1 = $this->_history->append($other_file);
     $el2 = $this->_history->append($other_file);
     $el3 = $this->_history->append($other_file);
     $this->assertEquals(3, $this->_history->getCount());
     $this->assertEquals($el3, $this->_history->getFirst());
     $this->assertEquals($el1, $this->_history->getLast());
     $this->assertEquals($el2, $this->_history->getNth(1));
     $this->assertEquals($el1, $this->_history->getNext());
     $this->assertFalse($this->_history->getNext());
     unlink($other_file);
 }
 function browse()
 {
     $smarty = new Sugar_Smarty();
     global $mod_strings;
     $smarty->assign('mod_strings', $mod_strings);
     $smarty->assign('view_module', $this->module);
     $smarty->assign('view', $this->layout);
     if (!empty($_REQUEST['subpanel'])) {
         $smarty->assign('subpanel', $_REQUEST['subpanel']);
     }
     $stamps = array();
     global $timedate;
     $userFormat = $timedate->get_date_time_format();
     $page = !empty($_REQUEST['page']) ? $_REQUEST['page'] : 0;
     $count = $this->history->getCount();
     $ts = $this->history->getNth($page * $this->pageSize);
     $snapshots = array();
     for ($i = 0; $i <= $this->pageSize && $ts > 0; $i++) {
         if ($page * $this->pageSize + $i + 1 == $count) {
             $label = translate('LBL_MB_DEFAULT_LAYOUT');
             $isDefault = true;
         } else {
             $dbDate = $timedate->fromTimestamp($ts)->asDb();
             $label = $timedate->to_display_date_time($dbDate);
             $isDefault = false;
         }
         $snapshots[$ts] = array('label' => $label, 'isDefault' => $isDefault);
         $ts = $this->history->getNext();
     }
     if (count($snapshots) > $this->pageSize) {
         $smarty->assign('nextPage', true);
     }
     $snapshots = array_slice($snapshots, 0, $this->pageSize, true);
     $smarty->assign('currentPage', $page);
     $smarty->assign('snapshots', $snapshots);
     $html = $smarty->fetch('modules/ModuleBuilder/tpls/history.tpl');
     echo $html;
 }