public function setup()
 {
     global $current_user;
     $current_user = SugarTestUserUtilities::createAnonymousUser();
     //for the purpose of this test, we need to create a campaign and relate it to a campaign tracker object
     //create campaign
     $c = new Campaign();
     $c->name = 'CT test ' . time();
     $c->campaign_type = 'Email';
     $c->status = 'Active';
     $timeDate = new TimeDate();
     $c->end_date = $timeDate->to_display_date(date('Y') + 1 . '-01-01');
     $c->assigned_id = $current_user->id;
     $c->team_id = '1';
     $c->team_set_id = '1';
     $c->save();
     $this->campaign = $c;
     //create campaign tracker
     $ct = new CampaignTracker();
     $ct->tracker_name = 'CampaignTrackerTest' . time();
     $ct->tracker_url = 'sugarcrm.com';
     $ct->campaign_id = $this->campaign->id;
     $ct->save();
     $this->campaign_tracker = $ct;
 }
function CustomScheduler()
{
    global $sugar_config, $db;
    $timeDate = new TimeDate();
    $timeDateNow = $timeDate->getNow(true)->asDb();
    $days_offset = 15;
    $GLOBALS['log']->fatal("Checking Opportunities...");
    $query = "select opportunities.id from opportunities\n\twhere opportunities.sales_stage != 'Closed Won'\n\tand DATEDIFF(opportunities.date_modified,'" . $timeDateNow . "') < " . $days_offset . "\n\tand !opportunities.deleted";
    $GLOBALS['log']->fatal("Query: " . $query);
    $res = $db->query($query, true, 'Error: ');
    while ($row = $db->fetchByAssoc($res)) {
        $opportunity = new Opportunity();
        if (!is_null($opportunity->retrieve($row['id']))) {
            $user = new User();
            if (!is_null($user->retrieve($opportunity->assigned_user_id))) {
                $emailsTo = array();
                $emailSubject = "Opportunity Alert";
                $emailBody = "The following Opportunity has " . $days_offset . " days without changes.<br /><br />\n\t\t\t\tName: " . $opportunity->name . "<br />\n\t\t\t\tAccount: " . $opportunity->account_name . "<br />\n\t\t\t\tAmount: " . $opportunity->amount . "<br />\n\t\t\t\tSales Stage: " . $opportunity->sales_stage . "<br />\n\t\t\t\tDate Close: " . $opportunity->date_closed . "<br /><br />\n\t\t\t\tYou can see the opportunity here:<br />\n\t\t\t\t<a href=\"" . $sugar_config['site_url'] . "/index.php?module=Opportunities&action=DetailView&record=" . $opportunity->id . "\">" . $opportunity->name . "</a>";
                $emailsTo[] = $user->email1;
                SendEmail($emailsTo, $emailSubject, $emailBody);
            }
        }
    }
    $GLOBALS['log']->fatal("Opportunities checked");
    return true;
}
 function CreateTaskAndCallForNewOpportunity($bean)
 {
     $timeDate = new TimeDate();
     if (empty($bean->fetched_row['id'])) {
         $task = new Task();
         $task->name = "Send Proposal";
         $task->priority = "High";
         $task->status = "Not Started";
         $task->date_due = $timeDate->getNow(true)->modify("+1 days")->asDb();
         $task->parent_type = "Opportunities";
         $task->parent_id = $bean->id;
         $task->assigned_user_id = $bean->assigned_user_id;
         $task->save();
         $call = new Call();
         $call->name = "Follow up";
         $call->direction = "Outbound";
         $call->status = "Planned";
         $call->duration_hours = 0;
         $call->duration_minutes = 15;
         $call->date_start = $timeDate->getNow(true)->modify("+2 days")->asDb();
         $call->parent_type = "Opportunities";
         $call->parent_id = $bean->id;
         $call->assigned_user_id = $bean->assigned_user_id;
         $call->save();
     }
 }
Example #4
0
 public function ping($api, $args)
 {
     if (isset($args['sub_method']) && $args['sub_method'] == 'whattimeisit') {
         require_once 'include/SugarDateTime.php';
         $dt = new SugarDateTime();
         $td = new TimeDate();
         return $td->asIso($dt);
     }
     // Just a normal ping request
     return 'pong';
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 protected function assignResult($event)
 {
     $this->conversation = $event['conversation_to'];
     $this->type = $event['event_type'];
     $this->timestamp = TimeDate::fromMysql($event['timestamp']);
     $this->status = $event['status'];
 }
Example #6
0
 public function setUp()
 {
     $this->scheduler = new TestScheduler(false);
     $GLOBALS['timedate'] = $this->timedate = TimeDate::getInstance();
     $this->timedate->allow_cache = true;
     $this->now = $this->timedate->getNow();
 }
Example #7
0
 public function testGetTimeDate()
 {
     global $current_user;
     $this->_setPrefs("Y-m-d", "H:i", "GMT");
     $f = $this->time_date->get_date_time_format();
     $this->assertEquals("Y-m-d H:i", $f);
     $f = $this->time_date->get_date_time_format(true);
     $this->assertEquals("Y-m-d H:i", $f);
     $f = $this->time_date->get_date_time_format(false);
     $this->assertEquals("Y-m-d H:i", $f);
     $f = $this->time_date->get_date_time_format(null);
     $this->assertEquals("Y-m-d H:i", $f);
     $f = $this->time_date->get_date_time_format(true, null);
     $this->assertEquals("Y-m-d H:i", $f);
     $f = $this->time_date->get_date_time_format(false, null);
     $this->assertEquals("Y-m-d H:i", $f);
     $f = $this->time_date->get_date_time_format(null, null);
     $this->assertEquals("Y-m-d H:i", $f);
     $f = $this->time_date->get_date_time_format(true, $current_user);
     $this->assertEquals("Y-m-d H:i", $f);
     $f = $this->time_date->get_date_time_format(false, $current_user);
     $this->assertEquals("Y-m-d H:i", $f);
     $f = $this->time_date->get_date_time_format(null, $current_user);
     $this->assertEquals("Y-m-d H:i", $f);
     $f = $this->time_date->get_date_time_format($current_user);
     $this->assertEquals("Y-m-d H:i", $f);
     $f = $this->time_date->get_date_time_format($current_user);
     $this->assertEquals("Y-m-d H:i", $f);
     $f = $this->time_date->get_date_time_format($current_user);
     $this->assertEquals("Y-m-d H:i", $f);
 }
 /**
  * checks the request for the order by and if that is not set then it checks the session for it
  *
  * @return array containing the keys orderBy => field being ordered off of and sortOrder => the sort order of that field
  */
 function getOrderBy($orderBy = '', $direction = '')
 {
     if (!empty($orderBy) || !empty($_REQUEST[$this->var_order_by])) {
         if (!empty($_REQUEST[$this->var_order_by])) {
             $direction = 'ASC';
             $orderBy = $_REQUEST[$this->var_order_by];
             if (!empty($_REQUEST['lvso']) && (empty($_SESSION['lvd']['last_ob']) || strcmp($orderBy, $_SESSION['lvd']['last_ob']) == 0)) {
                 $direction = $_REQUEST['lvso'];
                 $trackerManager = TrackerManager::getInstance();
                 if ($monitor = $trackerManager->getMonitor('tracker')) {
                     $monitor->setValue('module_name', $GLOBALS['module']);
                     $monitor->setValue('item_summary', "lvso=" . $direction . "&" . $this->var_order_by . "=" . $_REQUEST[$this->var_order_by]);
                     $monitor->setValue('action', 'listview');
                     $monitor->setValue('user_id', $GLOBALS['current_user']->id);
                     $monitor->setValue('date_modified', TimeDate::getInstance()->nowDb());
                     $monitor->save();
                 }
             }
         }
         $_SESSION[$this->var_order_by] = array('orderBy' => $orderBy, 'direction' => $direction);
         $_SESSION['lvd']['last_ob'] = $orderBy;
     } else {
         if (!empty($_SESSION[$this->var_order_by])) {
             $orderBy = $_SESSION[$this->var_order_by]['orderBy'];
             $direction = $_SESSION[$this->var_order_by]['direction'];
         } else {
             $orderBy = 'date_entered';
             $direction = 'DESC';
         }
     }
     return array('orderBy' => $orderBy, 'sortOrder' => $direction);
 }
 public function ejecutar($focus, $string_parametros)
 {
     $this->procesar_parametros($string_parametros);
     $alarma = loadBean('gcoop_alarmas');
     $alarma->parent_type = $focus->module_dir;
     $alarma->parent_id = $focus->id;
     $alarma->destinatario = $this->destinatario;
     $alarma->notificacion = $this->notificacion;
     $alarma->parametro = $this->parametro;
     $alarma->valor = $this->valor;
     #sumarle dias no fin de semana!
     $fecha = new DateTime();
     $dia = new DateInterval('P1D');
     while ($this->cantidad_dias > 0) {
         $fecha->add($dia);
         if ($fecha->format('N') < 6) {
             $this->cantidad_dias -= 1;
         }
     }
     $timedate = TimeDate::getInstance();
     $alarma->fecha_disparo = $timedate->asDb($fecha);
     $alarma->save();
     if (method_exists($focus, 'notificar')) {
         $focus->notificar("Se creó alarama con fecha de disparo {$alarma->fecha_disparo}", 'Alarma');
     }
 }
Example #10
0
    protected function generateItem($item)
    {
        $name = !empty($item['name_value_list']['name']['value']) ? htmlentities($item['name_value_list']['name']['value']) : '';
        $url = $GLOBALS['sugar_config']['site_url'] . htmlentities('/index.php?module=' . $item['module_name'] . '&action=DetailView&record=' . $item['id']);
        $date = TimeDate::httpTime(TimeDate::getInstance()->fromDb($item['name_value_list']['date_modified']['value'])->getTimestamp());
        $description = '';
        $displayFieldNames = true;
        if (count($item['name_value_list']) == 2 && isset($item['name_value_list']['name'])) {
            $displayFieldNames = false;
        }
        foreach ($item['name_value_list'] as $k => $v) {
            if ($k == 'name' || $k == 'date_modified') {
                continue;
            }
            if ($displayFieldNames) {
                $description .= '<b>' . htmlentities($k) . ':<b>&nbsp;';
            }
            $description .= htmlentities($v['value']) . "<br>";
        }
        echo <<<EORSS
    <item>
        <title>{$name}</title>
        <link>{$url}</link>
        <description><![CDATA[{$description}]]></description>
        <pubDate>{$date} GMT</pubDate>
        <guid>{$item['id']}</guid>
    </item>

EORSS;
    }
 /**
  * This method implements the run function of RunnableSchedulerJob and handles processing a SchedulersJob
  *
  * @param Mixed $data parameter passed in from the job_queue.data column when a SchedulerJob is run
  * @return bool true on success, false on error
  */
 public function run($data)
 {
     global $app_strings, $language;
     $app_strings = return_application_language($language);
     $admin = BeanFactory::getBean('Administration');
     $config = $admin->getConfigForModule('Forecasts', 'base');
     $timeperiodInterval = $config['timeperiod_interval'];
     $timeperiodLeafInterval = $config['timeperiod_leaf_interval'];
     $parentTimePeriod = TimePeriod::getLatest($timeperiodInterval);
     $latestTimePeriod = TimePeriod::getLatest($timeperiodLeafInterval);
     $currentTimePeriod = TimePeriod::getCurrentTimePeriod($timeperiodLeafInterval);
     if (empty($latestTimePeriod)) {
         $GLOBALS['log']->error(string_format($app_strings['ERR_TIMEPERIOD_TYPE_DOES_NOT_EXIST'], array($timeperiodLeafInterval)) . '[latest]');
         return false;
     } else {
         if (empty($currentTimePeriod)) {
             $GLOBALS['log']->error(string_format($app_strings['ERR_TIMEPERIOD_TYPE_DOES_NOT_EXIST'], array($timeperiodLeafInterval)) . ' [current]');
             return false;
         } else {
             if (empty($parentTimePeriod)) {
                 $GLOBALS['log']->error(string_format($app_strings['ERR_TIMEPERIOD_TYPE_DOES_NOT_EXIST'], array($timeperiodLeafInterval)) . ' [parent]');
                 return false;
             }
         }
     }
     $timedate = TimeDate::getInstance();
     //We run the rebuild command if the latest TimePeriod is less than the specified configuration interval
     //from the current TimePeriod
     $correctStartDate = $timedate->fromDbDate($currentTimePeriod->start_date);
     $latestStartDate = $timedate->fromDbDate($latestTimePeriod->start_date);
     $shownForward = $config['timeperiod_shown_forward'];
     //Move the current start date forward by the leaf period amounts
     for ($x = 0; $x < $shownForward; $x++) {
         $correctStartDate->modify($parentTimePeriod->next_date_modifier);
     }
     $leafCycle = $latestTimePeriod->leaf_cycle;
     //If the current start data that was modified according to the shown forward period is past the latest
     //leaf period we need to build more timeperiods
     while ($correctStartDate > $latestStartDate) {
         //We need to keep creating leaf periods until we are in sync.
         //If the leaf period we need to create is the start of the leaf cycle
         //then we should also create the parent TimePeriod record.
         $startDate = $latestStartDate->modify($latestTimePeriod->next_date_modifier);
         $leafCycle = $leafCycle == $parentTimePeriod->leaf_periods ? 1 : $leafCycle + 1;
         if ($leafCycle == 1) {
             $parentTimePeriod = TimePeriod::getByType($timeperiodInterval);
             $parentTimePeriod->setStartDate($startDate->asDbDate());
             $parentTimePeriod->name = $parentTimePeriod->getTimePeriodName($leafCycle);
             $parentTimePeriod->save();
         }
         $leafTimePeriod = TimePeriod::getByType($timeperiodLeafInterval);
         $leafTimePeriod->setStartDate($startDate->asDbDate());
         $leafTimePeriod->name = $leafTimePeriod->getTimePeriodName($leafCycle, $parentTimePeriod);
         $leafTimePeriod->leaf_cycle = $leafCycle;
         $leafTimePeriod->parent_id = $parentTimePeriod->id;
         $leafTimePeriod->save();
     }
     $this->job->succeedJob();
     return true;
 }
Example #12
0
 public function getAgenda($api, $args)
 {
     // Fetch the next 14 days worth of meetings (limited to 20)
     $end_time = new SugarDateTime("+14 days");
     $start_time = new SugarDateTime("-1 hour");
     $meeting = BeanFactory::newBean('Meetings');
     $meetingList = $meeting->get_list('date_start', "date_start > " . $GLOBALS['db']->convert($GLOBALS['db']->quoted($start_time->asDb()), 'datetime') . " AND date_start < " . $GLOBALS['db']->convert($GLOBALS['db']->quoted($end_time->asDb()), 'datetime'));
     // Setup the breaks for the various time periods
     $datetime = new SugarDateTime();
     $today_stamp = $datetime->get_day_end()->getTimestamp();
     $tomorrow_stamp = $datetime->setDate($datetime->year, $datetime->month, $datetime->day + 1)->get_day_end()->getTimestamp();
     $timeDate = TimeDate::getInstance();
     $returnedMeetings = array('today' => array(), 'tomorrow' => array(), 'upcoming' => array());
     foreach ($meetingList['list'] as $meetingBean) {
         $meetingStamp = $timeDate->fromUser($meetingBean->date_start)->getTimestamp();
         $meetingData = $this->formatBean($api, $args, $meetingBean);
         if ($meetingStamp < $today_stamp) {
             $returnedMeetings['today'][] = $meetingData;
         } else {
             if ($meetingStamp < $tomorrow_stamp) {
                 $returnedMeetings['tomorrow'][] = $meetingData;
             } else {
                 $returnedMeetings['upcoming'][] = $meetingData;
             }
         }
     }
     return $returnedMeetings;
 }
Example #13
0
 public function testUserDateFormat()
 {
     $gmt_default_date_start = $this->time_date->get_gmt_db_datetime();
     $date1 = $this->time_date->handle_offset($gmt_default_date_start, $GLOBALS['timedate']->get_date_time_format());
     $date2 = $this->time_date->asUser($this->time_date->getNow());
     $this->assertEquals($date1, $date2, "HandleOffset should be equaivalent to nowDb");
 }
Example #14
0
 /**
  * {@inheritDoc}
  */
 protected function build($builder)
 {
     $durations = \Service::getParameter('bzion.league.duration');
     foreach ($durations as $duration => &$value) {
         $durations[$duration] = $duration;
     }
     return $builder->add('first_team', new MatchTeamType())->add('second_team', new MatchTeamType())->add('duration', 'choice', array('choices' => $durations, 'constraints' => new NotBlank(), 'expanded' => true))->add('server_address', 'text', array('required' => false, 'attr' => array('placeholder' => 'brad.guleague.org:5100')))->add('time', new DatetimeWithTimezoneType(), array('constraints' => array(new NotBlank(), new LessThan(array('value' => \TimeDate::now()->addMinutes(10), 'message' => 'The timestamp of the match must not be in the future'))), 'data' => \TimeDate::now(\Controller::getMe()->getTimezone())))->add('enter', 'submit');
 }
Example #15
0
 /**
  * {@inheritdoc}
  */
 protected function build($builder)
 {
     $durations = \Service::getParameter('bzion.league.duration');
     foreach ($durations as $duration => &$value) {
         $durations[$duration] = $duration;
     }
     return $builder->add('first_team', new MatchTeamType(), array('disableTeam' => $this->isEdit() && $this->editing->isOfficial()))->add('second_team', new MatchTeamType(), array('disableTeam' => $this->isEdit() && $this->editing->isOfficial()))->add('duration', 'choice', array('choices' => $durations, 'constraints' => new NotBlank(), 'expanded' => true))->add('server_address', 'text', array('required' => false, 'attr' => array('placeholder' => 'brad.guleague.org:5100')))->add('time', new DatetimeWithTimezoneType(), array('constraints' => array(new NotBlank(), new LessThan(array('value' => \TimeDate::now()->addMinutes(10), 'message' => 'The timestamp of the match must not be in the future'))), 'data' => $this->isEdit() ? $this->editing->getTimestamp()->setTimezone(\Controller::getMe()->getTimezone()) : \TimeDate::now(\Controller::getMe()->getTimezone()), 'with_seconds' => $this->isEdit()))->add('map', new ModelType('Map'), array('required' => false))->add('type', 'choice', array('choices' => array(\Match::OFFICIAL => 'Official', \Match::FUN => 'Fun match', \Match::SPECIAL => 'Special event match'), 'disabled' => $this->editing && $this->editing->isOfficial(), 'label' => 'Match Type'))->add('enter', 'submit');
 }
 /**
  * @dataProvider dateRanges
  */
 public function testparseDateRange($range, $start, $end)
 {
     $this->time_date->setNow(SugarDateTime::createFromFormat(TimeDate::DB_DATETIME_FORMAT, "2011-08-30 12:01:02", new DateTimeZone($this->time_date->userTimezone())));
     $this->time_date->allow_cache = true;
     $daterage = $this->time_date->parseDateRange($range);
     $this->assertEquals($start, $daterage[0]->format(TimeDate::DB_DATETIME_FORMAT), 'Start date is wrong');
     $this->assertEquals($end, $daterage[1]->format(TimeDate::DB_DATETIME_FORMAT), 'End date is wrong');
 }
 public function tearDown()
 {
     SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
     unset($GLOBALS['current_user']);
     unset($GLOBALS['app_list_strings']);
     unset($GLOBALS['beanList']);
     $GLOBALS['timedate'] = TimeDate::getInstance();
 }
Example #18
0
 public function setUp()
 {
     $this->sugarWidgetField = new SugarWidgetFieldDateTime48616Mock(new LayoutManager());
     global $current_user, $timedate;
     $timedate = TimeDate::getInstance();
     $current_user = SugarTestUserUtilities::createAnonymousUser();
     //$this->setOutputBuffering = false;
 }
 public function setUp()
 {
     global $timedate, $current_user;
     $timedate = TimeDate::getInstance();
     require 'include/modules.php';
     $GLOBALS['beanList'] = $beanList;
     $GLOBALS['beanFiles'] = $beanFiles;
     $current_user = SugarTestUserUtilities::createAnonymousUser();
     $this->nowTime = $timedate->asDb($timedate->getNow()->get("-10 minutes"));
     $this->tenMinutesLaterTime = $timedate->asDb($timedate->getNow()->get("+10 minutes"));
     $current_user->is_admin = 1;
     $current_user->save();
     $this->meeting = SugarTestMeetingUtilities::createMeeting();
     $this->meeting->team_id = $current_user->team_id;
     $this->meeting->team_set_id = $current_user->team_set_id;
     $this->meeting->team_id = $current_user->team_id;
     $this->meeting->team_set_id = $current_user->team_set_id;
     $this->meeting->assigned_user_id = $current_user->id;
     $this->meeting->save();
     $this->meeting->load_relationship('users');
     $this->meeting->users->add($current_user);
     $this->call = SugarTestCallUtilities::createCall();
     $this->call->team_id = $current_user->team_id;
     $this->call->team_set_id = $current_user->team_set_id;
     $this->call->assigned_user_id = $current_user->id;
     $this->call->save();
     $this->call->load_relationships('users');
     $this->call->users->add($current_user);
     $this->contact = SugarTestContactUtilities::createContact();
     $this->contact->email1 = '*****@*****.**';
     $this->contact->contacts_users_id = $current_user->id;
     $this->contact->load_relationship('user_sync');
     $this->contact->user_sync->add($current_user);
     $this->contact->sync_contact = 1;
     $this->contact->save();
     $this->task = SugarTestTaskUtilities::createTask();
     $this->task->assigned_user_id = $current_user->id;
     $this->task->team_id = $current_user->id;
     $this->task->team_set_id = $current_user->id;
     $this->task->save();
     //$this->useOutputBuffering = false;
     /**
      * This provider returns an Array of Array data.  Each Array contains the following data
      * 0 => String - Left side module name
      * 1 => String - Right side module name
      * 2 => String - Relationship Query
      * 3 => boolean to return deleted records or not (this is actually ignored by the function)
      * 4 => integer offset to start with
      * 5 => integer value for the maximum number of results
      * 6 => array of fields to select and return
      * 7 => load_relationships - Relationship name to use
      * 8 => array of expected results
      * 9 => integer of expected total count
      * 10 => array of expected soap error
      * @return array The provider array
      */
     $this->testData = array(array('Users', 'Meetings', "( (m1.date_modified > '{$this->nowTime}' AND m1.date_modified <= '{$this->tenMinutesLaterTime}' AND m1.deleted = 0) OR (m1.date_modified > '{$this->nowTime}' AND m1.date_modified <= '{$this->tenMinutesLaterTime}' AND m1.deleted = 1) AND m1.id IN ('{$this->meeting->id}')) OR (m1.id NOT IN ('{$this->meeting->id}') AND m1.deleted = 0) AND m2.id = '{$current_user->id}'", 0, 0, 3000, $this->callsAndMeetingsSelectFields, 'meetings_users', array('id' => $this->meeting->id), 1, $this->noSoapErrorArray), array('Users', 'Calls', "( m1.deleted = 0) AND m2.id = '{$current_user->id}'", 0, 0, 3000, $this->callsAndMeetingsSelectFields, 'calls_users', array('id' => $this->call->id), 1, $this->noSoapErrorArray), array('Users', 'Contacts', "( (m1.date_modified > '{$this->nowTime}' AND m1.date_modified <= '{$this->tenMinutesLaterTime}' AND {0}.deleted = 0) OR ({0}.date_modified > '{$this->nowTime}' AND {0}.date_modified <= '{$this->tenMinutesLaterTime}' AND {0}.deleted = 1) AND m1.id IN ('31a219bd-b9c1-2c3e-aa5d-4f2778ab0347','c794bc39-e4fb-f515-f1d5-4f285ca88965','d51a0555-8f84-9e62-0fbc-4f2787b5d839','a1219ae6-5a6b-0d1b-c49f-4f2854bc2912')) OR (m1.id NOT IN ('31a219bd-b9c1-2c3e-aa5d-4f2778ab0347','c794bc39-e4fb-f515-f1d5-4f285ca88965','d51a0555-8f84-9e62-0fbc-4f2787b5d839','a1219ae6-5a6b-0d1b-c49f-4f2854bc2912') AND {0}.deleted = 0) AND m2.id = '1'", 0, 0, 3000, $this->contactsSelectFields, 'contacts_users', array('id' => $this->contact->id, 'email1' => '*****@*****.**'), 1, $this->noSoapErrorArray), array('Users', 'Tasks', " ( (m1.date_modified > '{$this->nowTime}' AND m1.date_modified <= '{$this->tenMinutesLaterTime}' AND {0}.deleted = 0) OR ({0}.date_modified > '{$this->nowTime}' AND {0}.date_modified <= '{$this->tenMinutesLaterTime}' AND {0}.deleted = 1) AND m1.id IN ('{$this->task->id}')) OR (m1.id NOT IN ('{$this->task->id}') AND {0}.deleted = 0) AND m2.id = '1'", 0, 0, 3000, $this->tasksSelectFields, 'tasks_assigned_user', array('id' => $this->task->id), 1, $this->noSoapErrorArray));
 }
Example #20
0
 function Common()
 {
     global $db;
     $this->db = $db;
     if (empty($this->db)) {
         $this->db = DBManagerFactory::getInstance();
     }
     $this->timedate = TimeDate::getInstance();
 }
Example #21
0
 /**
  * @dataProvider providerCorrectNextMonth
  * @outputBuffering disabled
  */
 public function testCorrectNextMonth($testDate, $direction, $expectedString)
 {
     global $timedate;
     $timedate = TimeDate::getInstance();
     $this->calendar = new Calendar('month');
     $this->calendar->date_time = $timedate->fromString($testDate);
     $uri = $this->calendar->get_neighbor_date_str($direction);
     $this->assertContains($expectedString, $uri, "Failed to get {$direction} expected URL: {$expectedString} from date: {$testDate}");
 }
 /**
  * Create a TimeDate object from another one, ignoring its timezone
  *
  * @param  \TimeDate   $from     The original timestamp
  * @param  string|null $timezone The timezone to add to the object (defaults
  *                               to the PHP's default)
  * @return \TimeDate
  */
 private function createTimeDate($from, $timezone = null)
 {
     if ($from === null) {
         return null;
     }
     // Make sure it's a TimeDate instance
     $time = \TimeDate::from($from);
     return \TimeDate::create($time->year, $time->month, $time->day, $time->hour, $time->minute, $time->second, $timezone);
 }
Example #23
0
 /**
  * getTimePeriodName
  *
  * Returns the timeperiod name.  The TimePeriod base implementation simply returns the $count argument passed
  * in from the code
  *
  * @param $count The timeperiod series count
  * @return string The formatted name of the timeperiod
  */
 public function getTimePeriodName($count)
 {
     $timedate = TimeDate::getInstance();
     $year = $timedate->fromDbDate($this->start_date);
     if (isset($this->currentSettings['timeperiod_fiscal_year']) && $this->currentSettings['timeperiod_fiscal_year'] == 'next_year') {
         $year->modify('+1 year');
     }
     return string_format($this->name_template, array($year->format('Y')));
 }
Example #24
0
 /**
  * Handles export field sanitizing for field type
  *
  * @param $value string value to be sanitized
  * @param $vardef array representing the vardef definition
  * @param $focus SugarBean object
  * @param $row Array of a row of data to be exported
  *
  * @return string sanitized value
  */
 public function exportSanitize($value, $vardef, $focus, $row = array())
 {
     $timedate = TimeDate::getInstance();
     $db = DBManagerFactory::getInstance();
     //If it's in ISO format, convert it to db format
     if (preg_match('/(\\d{4})\\-?(\\d{2})\\-?(\\d{2})T(\\d{2}):?(\\d{2}):?(\\d{2})\\.?\\d*([Z+-]?)(\\d{0,2}):?(\\d{0,2})/i', $value)) {
         $value = $timedate->fromIso($value)->asDbDate(false);
     }
     return $timedate->to_display_date($db->fromConvert($value, 'date'), false);
 }
 /**
  * Returns number of hours from now until the specified date.
  */
 public function evaluate()
 {
     $params = DateExpression::parse($this->getParameters()->evaluate());
     if (!$params) {
         return false;
     }
     $now = TimeDate::getInstance()->getNow(true);
     $tsdiff = $params->ts - $now->ts;
     return (int) ($tsdiff / 3600);
 }
Example #26
0
 public function setUp()
 {
     $this->sugarWidgetField = new SugarWidgetFieldDateTime49008Mock(new LayoutManager());
     global $current_user, $timedate;
     $timedate = TimeDate::getInstance();
     $current_user = SugarTestUserUtilities::createAnonymousUser();
     $current_user->setPreference('timezone', 'America/Los_Angeles');
     $current_user->save();
     $current_user->db->commit();
 }
Example #27
0
 public function testAutomaticExpiry()
 {
     $victim = $this->getNewPlayer();
     $ban = Ban::addBan($victim->getId(), $this->getNewPlayer()->getId(), TimeDate::now()->addDay(), "Reason");
     $this->assertTrue($victim->isBanned());
     $this->assertEquals(Ban::getBan($victim->getId())->getId(), $ban->getId());
     $ban->setExpiration(TimeDate::now()->subDay());
     $this->assertFalse($victim->isBanned());
     $this->assertNull(Ban::getBan($victim->getId()));
 }
Example #28
0
 /**
  * Store the newest entry's date into the last update file, so that the user
  * isn't shown the same changes in the future
  *
  * @param  string  $path The path to the last update file
  * @param  boolean $date The date command line argument (used to determine
  *                       whether we should store the last update or not)
  * @return void
  */
 private function storeLastUpdate($path, $date)
 {
     if ($date !== null) {
         // The user probably run the command to see old changes, we don't
         // consider this a result of an update
         return;
     }
     $data = array('date' => $this->lastUpdateDate->toFormattedDateString(), 'changes' => $this->alreadyListedChanges);
     file_put_contents($path, Yaml::dump($data, 3));
 }
Example #29
0
 /**
  * Utility method to allow for subclasses to do the same export calls
  *
  * @param ServiceBase $api
  * @param string $filename The File name for the export
  * @param string $content What should be in the exported file
  * @return mixed
  */
 protected function doExport(ServiceBase $api, $filename, $content)
 {
     $api->setHeader("Pragma", "cache");
     $api->setHeader("Content-Type", "application/octet-stream; charset=" . $GLOBALS['locale']->getExportCharset());
     $api->setHeader("Content-Disposition", "attachment; filename={$filename}.csv");
     $api->setHeader("Content-transfer-encoding", "binary");
     $api->setHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT");
     $api->setHeader("Last-Modified", TimeDate::httpTime());
     $api->setHeader("Cache-Control", "post-check=0, pre-check=0");
     return $GLOBALS['locale']->translateCharset($content, 'UTF-8', $GLOBALS['locale']->getExportCharset());
 }
Example #30
0
 /**
  * Handle the admin notes form
  * @param  Form   $form   The form
  * @param  Player $player The player in question
  * @param  Player $me     The currently logged in player
  * @return Form   The updated form
  */
 private function handleAdminNotesForm($form, $player, $me)
 {
     $notes = $form->get('notes')->getData();
     if ($form->get('save_and_sign')->isClicked()) {
         $notes .= ' — ' . $me->getUsername() . ' on ' . TimeDate::now()->toRFC2822String();
     }
     $player->setAdminNotes($notes);
     $this->getFlashBag()->add('success', "The admin notes for {$player->getUsername()} have been updated");
     // Reset the form so that the user sees the updated admin notes
     return $this->creator->create();
 }