Skip to content
Snippets Groups Projects
  • Jared Hancock's avatar
    0fbc09ad
    i18n: Add locale-based date time formats · 0fbc09ad
    Jared Hancock authored
    This patch adds support for automatic date and time formatting based on a
    selection of locale. The locale can default to the system or user specified
    language+locale, or can be elected separately. For instance, English
    speakers can pick between US, GB, and many other English speaking locales.
    
    This also removes the need of the %timezone table and uses the timezonedb
    built into PHP 5.3+. User's can now select from a much longer list of
    database and no longer need to deal with the DST checkbox.
    0fbc09ad
    History
    i18n: Add locale-based date time formats
    Jared Hancock authored
    This patch adds support for automatic date and time formatting based on a
    selection of locale. The locale can default to the system or user specified
    language+locale, or can be elected separately. For instance, English
    speakers can pick between US, GB, and many other English speaking locales.
    
    This also removes the need of the %timezone table and uses the timezonedb
    built into PHP 5.3+. User's can now select from a much longer list of
    database and no longer need to deal with the DST checkbox.
class.note.php 2.39 KiB
<?php
/*********************************************************************
    class.note.php

    Simple note interface for affixing notes to users and organizations

    Peter Rotich <peter@osticket.com>
    Jared Hancock <jared@osticket.com>
    Copyright (c)  2006-2013 osTicket
    http://www.osticket.com

    Released under the GNU General Public License WITHOUT ANY WARRANTY.
    See LICENSE.TXT for details.

    vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
require_once(INCLUDE_DIR . 'class.orm.php');

class QuickNoteModel extends VerySimpleModel {
    static $meta = array(
        'table' => NOTE_TABLE,
        'pk' => array('id'),
        'ordering' => array('sort', 'created')
    );
}

class QuickNote extends QuickNoteModel {

    static $types = array(
        'U' => /* @trans */ 'User',
        'O' => /* @trans */ 'Organization',
    );
    var $_staff;

    function display() {
        return Format::display($this->body);
    }

    function getStaff() {
        if (!isset($this->_staff) && $this->staff_id) {
            $this->_staff = Staff::lookup($this->staff_id);
        }
        return $this->_staff;
    }

    function getFormattedTime() {
        return Format::datetime(strpos($this->updated, '0000-') !== 0
            ? $this->updated : $this->created);
    }

    function getExtType() {
        return static::$types[$this->ext_id[0]];
    }

    function getExtIconClass() {
        switch ($this->ext_id[0]) {
        case 'U':
            return 'user';
        case 'O':
            return 'building';
        }
    }

    function getIconTitle() {
        return sprintf(__(
            // `%s` will be the type of note (`user` or `orgnaization`)
            "%s Note"),
            __(static::$types[$this->ext_id[0]]));
    }
    static function forUser($user, $org=false) {
        if ($org)
            return static::objects()->filter(array('ext_id__in' =>
                array('U'.$user->get('id'), 'O'.$org->get('id'))));
        else
            return static::objects()->filter(array('ext_id' => 'U'.$user->get('id')));
    }

    static function forOrganization($org) {
        return static::objects()->filter(array('ext_id' => 'O'.$org->get('id')));
    }

    function save($refetch=false) {
        if (count($this->dirty))
            $this->updated = new SQLFunction('NOW');
        return parent::save($refetch);
    }
}