Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • None
  • system
    • base
    • caching
    • console
    • db
      • ar
      • schema
    • validators
    • web
      • actions
      • auth
      • helpers
      • widgets
        • captcha
        • pagers
  • zii
    • widgets
      • grid

Classes

  • AccountsGridViewProfileWidget
  • ActionMenu
  • ActionsGridViewProfileWidget
  • ActionsQuickCreateRelationshipBehavior
  • ActiveDateRangeInput
  • ApplicationConfigBehavior
  • Attachments
  • ChatBox
  • CommonControllerBehavior
  • ContactMapInlineTags
  • ContactsGridViewProfileWidget
  • CronForm
  • CSaveRelationsBehavior
  • DateRangeInputsWidget
  • DocsGridViewProfileWidget
  • DocViewer
  • DocViewerProfileWidget
  • EButtonColumnWithClearFilters
  • EmailDeliveryBehavior
  • EmailProgressControl
  • EncryptedFieldsBehavior
  • EventsChartProfileWidget
  • FileUploader
  • FontPickerInput
  • Formatter
  • FormView
  • GridViewWidget
  • History
  • IframeWidget
  • ImportExportBehavior
  • InlineActionForm
  • InlineEmailAction
  • InlineEmailForm
  • InlineEmailModelBehavior
  • InlineQuotes
  • JSONEmbeddedModelFieldsBehavior
  • JSONFieldsDefaultValuesBehavior
  • LeadRoutingBehavior
  • LeftWidget
  • LoginThemeHelper
  • LoginThemeHelperBase
  • MarketingGridViewProfileWidget
  • MediaBox
  • MessageBox
  • MobileFormatter
  • MobileFormLayoutRenderer
  • MobileLayoutRenderer
  • MobileLoginThemeHelper
  • MobileViewLayoutRenderer
  • ModelFileUploader
  • NewWebLeadsGridViewProfileWidget
  • NormalizedJSONFieldsBehavior
  • NoteBox
  • OnlineUsers
  • OpportunitiesGridViewProfileWidget
  • Panel
  • ProfileDashboardManager
  • ProfileGridViewWidget
  • ProfileLayoutEditor
  • ProfilesGridViewProfileWidget
  • Publisher
  • PublisherActionTab
  • PublisherCalendarEventTab
  • PublisherCallTab
  • PublisherCommentTab
  • PublisherEventTab
  • PublisherSmallCalendarEventTab
  • PublisherTab
  • PublisherTimeTab
  • QuickContact
  • QuickCreateRelationshipBehavior
  • QuotesGridViewProfileWidget
  • RecordAliasesWidget
  • RecordViewLayoutManager
  • RecordViewWidgetManager
  • RememberPagination
  • Reminders
  • ResponseBehavior
  • ResponsiveHtml
  • SearchIndexBehavior
  • ServicesGridViewProfileWidget
  • SmallCalendar
  • SmartActiveDataProvider
  • SmartDataProviderBehavior
  • SmartSort
  • SocialForm
  • SortableWidgetManager
  • SortableWidgets
  • TagBehavior
  • TagCloud
  • TemplatesGridViewProfileWidget
  • TimeZone
  • TopContacts
  • TopSites
  • TransformedFieldStorageBehavior
  • TranslationLogger
  • TwitterFeed
  • TwoColumnSortableWidgetManager
  • UpdaterBehavior
  • UpdatesForm
  • UserIdentity
  • UsersChartProfileWidget
  • WorkflowBehavior
  • X2ActiveGridView
  • X2ActiveGridViewForSortableWidgets
  • X2AssetManager
  • X2AuthManager
  • X2ChangeLogBehavior
  • X2ClientScript
  • X2Color
  • X2DateUtil
  • X2FixtureManager
  • X2FlowFormatter
  • X2GridView
  • X2GridViewBase
  • X2GridViewForSortableWidgets
  • X2GridViewSortableWidgetsBehavior
  • X2LeadsGridViewProfileWidget
  • X2LinkableBehavior
  • X2ListView
  • X2PillBox
  • X2ProgressBar
  • X2SmartSearchModelBehavior
  • X2TimestampBehavior
  • X2TranslationBehavior
  • X2UrlRule
  • X2WebModule
  • X2Widget
  • X2WidgetList
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /*****************************************************************************************
  3:  * X2Engine Open Source Edition is a customer relationship management program developed by
  4:  * X2Engine, Inc. Copyright (C) 2011-2016 X2Engine Inc.
  5:  * 
  6:  * This program is free software; you can redistribute it and/or modify it under
  7:  * the terms of the GNU Affero General Public License version 3 as published by the
  8:  * Free Software Foundation with the addition of the following permission added
  9:  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 10:  * IN WHICH THE COPYRIGHT IS OWNED BY X2ENGINE, X2ENGINE DISCLAIMS THE WARRANTY
 11:  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 12:  * 
 13:  * This program is distributed in the hope that it will be useful, but WITHOUT
 14:  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 15:  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
 16:  * details.
 17:  * 
 18:  * You should have received a copy of the GNU Affero General Public License along with
 19:  * this program; if not, see http://www.gnu.org/licenses or write to the Free
 20:  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 21:  * 02110-1301 USA.
 22:  * 
 23:  * You can contact X2Engine, Inc. P.O. Box 66752, Scotts Valley,
 24:  * California 95067, USA. or at email address contact@x2engine.com.
 25:  * 
 26:  * The interactive user interfaces in modified source and object code versions
 27:  * of this program must display Appropriate Legal Notices, as required under
 28:  * Section 5 of the GNU Affero General Public License version 3.
 29:  * 
 30:  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 31:  * these Appropriate Legal Notices must retain the display of the "Powered by
 32:  * X2Engine" logo. If the display of the logo is not reasonably feasible for
 33:  * technical reasons, the Appropriate Legal Notices must display the words
 34:  * "Powered by X2Engine".
 35:  *****************************************************************************************/
 36: 
 37: /**
 38:  * Date formatting utilities 
 39:  * 
 40:  * @package application.components 
 41:  */
 42: class X2DateUtil {
 43: 
 44:     public static function dateBox($date) {
 45:         $str = '<div class="date-box" title="';
 46:         $str .= date('Y-m-d H:i',$date);
 47:         
 48:         $str .= '"><span class="month">';
 49:         $str .= date('M',$date);
 50:         $str .= '</span><span class="day">';
 51:         $str .= date('d',$date);
 52:         $str .= '</span></div>';
 53:         return $str;
 54:     }
 55:     
 56:     public static function actionDate($date,$priority,$complete='No') {
 57:         if($complete=="No"){
 58:             if($priority == '3')
 59:                 $priority = ' p-3';
 60:             elseif($priority == '2')
 61:                 $priority = ' p-2';
 62:             else
 63:                 $priority = ' p-1';
 64:         }else{
 65:             $priority='';
 66:         }
 67:         
 68:         $str = '<div class="date-box'.$priority.'" title="';
 69:         $str .= date('Y-m-d H:i',$date);
 70:         
 71:         $str .= '"><span class="month">';
 72:         $str .= Yii::app()->getLocale()->getMonthName(date('n',$date),'abbreviated');
 73:         // $str .= date('M',$date);
 74:         $str .= '</span><span class="day">';
 75:         $str .= date('d',$date);
 76:         $str .= '</span></div>';
 77:         return $str;
 78:     }
 79: 
 80:     /**
 81:      * Meant to replace getDateRange
 82:      */
 83:     public static function parseDateRange (
 84:         $range=null, $startDate=null, $endDate=null, $strict=null) {
 85: 
 86:         $dateRange = array();
 87:         $dateRange['strict'] = false;
 88:         if (isset($strict) && $strict)
 89:             $dateRange['strict'] = true;
 90: 
 91:         $dateRange['range'] = 'custom';
 92:         if (isset($range))
 93:             $dateRange['range'] = $range;
 94: 
 95:         switch ($dateRange['range']) {
 96: 
 97:             case 'thisDay':
 98:                 $dateRange['start'] = strtotime('today'); // first of this month
 99:                 $dateRange['end'] = time(); // now
100:                 break;
101:             case 'thisWeek':
102:                 $dateRange['start'] = strtotime('mon this week'); // first of this month
103:                 $dateRange['end'] = time(); // now
104:                 break;
105:             case 'thisMonth':
106:                 $dateRange['start'] = mktime(0, 0, 0, date('n'), 1); // first of this month
107:                 $dateRange['end'] = time(); // now
108:                 break;
109:             case 'thisQuarter':
110:                 $retVal = self::startOfQuarter();
111:                 $dateRange['start'] = $retVal[0];
112:                 $dateRange['end'] = time(); // now
113:                 break;
114:             case 'thisYear':
115:                 $dateRange['start'] = mktime(0, 0, 0, 1, 1);  // first of the year
116:                 $dateRange['end'] = time(); // now
117:                 break;
118: 
119: 
120:             case 'lastWeek':
121:                 $dateRange['start'] = strtotime('mon last week'); // first of last month
122:                 $dateRange['end'] = strtotime('mon this week') - 1;  // first of this month
123:                 break;
124:             case 'lastMonth':
125:                 $dateRange['start'] = mktime(0, 0, 0, date('n') - 1, 1); // first of last month
126:                 $dateRange['end'] = mktime(0, 0, 0, date('n'), 1) - 1;  // first of this month
127:                 break;
128:             case 'lastYear':
129:                 $dateRange['start'] = mktime(0, 0, 0, 1, 1, date('Y') - 1);  // first of last year
130:                 $dateRange['end'] = mktime(0, 0, 0, 1, 1, date('Y')) - 1;   // first of this year
131:                 break;
132: 
133:             case 'trailingDay':
134:                 $dateRange['start'] = strtotime('- 24 hours');
135:                 $dateRange['end'] = time(); // now
136:                 break;
137:             case 'trailingWeek':
138:                 $dateRange['start'] = strtotime('- 7 days');
139:                 $dateRange['end'] = time(); // now
140:                 break;
141:             case 'trailingMonth':
142:                 $dateRange['start'] = strtotime('- 1 month');
143:                 $dateRange['end'] = time(); // now
144:                 break;
145:             case 'trailingQuarter':
146:                 $dateRange['start'] = strtotime('- 3 months');
147:                 $dateRange['end'] = time(); // now
148:                 break;
149:             case 'trailingYear':
150:                 $dateRange['start'] = strtotime('- 1 year');
151:                 $dateRange['end'] = time(); // now
152:                 break;
153: 
154: 
155:             case 'all':
156:                 $dateRange['start'] = 0;        // every record
157:                 $dateRange['end'] = time();
158:                 if (isset($endDate)) {
159:                     $dateRange['end'] = Formatter::parseDate($endDate);
160:                     if ($dateRange['end'] == false)
161:                         $dateRange['end'] = time();
162:                     else
163:                         $dateRange['end'] = strtotime('23:59:59', $dateRange['end']);
164:                 }
165:                 break;
166: 
167:             case 'custom':
168:             default:
169:                 $dateRange['end'] = time();
170:                 if (isset($endDate)) {
171:                     $dateRange['end'] = Formatter::parseDate($endDate);
172:                     if ($dateRange['end'] == false)
173:                         $dateRange['end'] = time();
174:                     else
175:                         $dateRange['end'] = strtotime('23:59:59', $dateRange['end']);
176:                 }
177: 
178:                 $dateRange['start'] = strtotime('1 month ago', $dateRange['end']);
179:                 if (isset($startDate)) {
180:                     $dateRange['start'] = Formatter::parseDate($startDate);
181:                     if ($dateRange['start'] == false)
182:                         $dateRange['start'] = strtotime('-30 days 0:00', $dateRange['end']);
183:                     else
184:                         $dateRange['start'] = strtotime('0:00', $dateRange['start']);
185:                 }
186:         }
187:         return $dateRange;
188:     }
189: 
190: 
191:     /**
192:      * Legacy Method: Should be replaced with dateRangeToDates
193:      * 
194:      * This function returns a date range to be used for generating a report
195:      * based on the dropdown value the user selected. I think it might occur elsewhere
196:      * in the code and could probably be refactored.
197:      * @return array An array with the date range values
198:      */
199:     public static function getDateRange(
200:         $startKey='start',$endKey='end',$rangeKey='range', $defaultRange='custom') {
201: 
202:         $dateRange = array();
203:         $dateRange['strict'] = false;
204:         if (isset($_GET['strict']) && $_GET['strict'])
205:             $dateRange['strict'] = true;
206: 
207:         $dateRange['range'] = $defaultRange;
208:         if (isset($_GET[$rangeKey]))
209:             $dateRange['range'] = $_GET[$rangeKey];
210: 
211:         switch ($dateRange['range']) {
212: 
213:             case 'thisWeek':
214:                 $dateRange['start'] = strtotime('mon this week'); // first of this month
215:                 $dateRange['end'] = time(); // now
216:                 break;
217:             case 'thisMonth':
218:                 $dateRange['start'] = mktime(0, 0, 0, date('n'), 1); // first of this month
219:                 $dateRange['end'] = time(); // now
220:                 break;
221:             case 'lastWeek':
222:                 $dateRange['start'] = strtotime('mon last week'); // first of last month
223:                 $dateRange['end'] = strtotime('mon this week') - 1;  // first of this month
224:                 break;
225:             case 'lastMonth':
226:                 $dateRange['start'] = mktime(0, 0, 0, date('n') - 1, 1); // first of last month
227:                 $dateRange['end'] = mktime(0, 0, 0, date('n'), 1) - 1;  // first of this month
228:                 break;
229:             case 'thisYear':
230:                 $dateRange['start'] = mktime(0, 0, 0, 1, 1);  // first of the year
231:                 $dateRange['end'] = time(); // now
232:                 break;
233:             case 'lastYear':
234:                 $dateRange['start'] = mktime(0, 0, 0, 1, 1, date('Y') - 1);  // first of last year
235:                 $dateRange['end'] = mktime(0, 0, 0, 1, 1, date('Y')) - 1;   // first of this year
236:                 break;
237:             case 'all':
238:                 $dateRange['start'] = 0;        // every record
239:                 $dateRange['end'] = time();
240:                 if (isset($_GET[$endKey])) {
241:                     $dateRange['end'] = Formatter::parseDate($_GET[$endKey]);
242:                     if ($dateRange['end'] == false)
243:                         $dateRange['end'] = time();
244:                     else
245:                         $dateRange['end'] = strtotime('23:59:59', $dateRange['end']);
246:                 }
247:                 break;
248: 
249:             case 'custom':
250:             default:
251:                 $dateRange['end'] = time();
252:                 if (isset($_GET[$endKey])) {
253:                     $dateRange['end'] = Formatter::parseDate($_GET[$endKey]);
254:                     if ($dateRange['end'] == false)
255:                         $dateRange['end'] = time();
256:                     else
257:                         $dateRange['end'] = strtotime('23:59:59', $dateRange['end']);
258:                 }
259: 
260:                 $dateRange['start'] = strtotime('1 month ago', $dateRange['end']);
261:                 if (isset($_GET[$startKey])) {
262:                     $dateRange['start'] = Formatter::parseDate($_GET[$startKey]);
263:                     if ($dateRange['start'] == false)
264:                         $dateRange['start'] = strtotime('-30 days 0:00', $dateRange['end']);
265:                     else
266:                         $dateRange['start'] = strtotime('0:00', $dateRange['start']);
267:                 }
268:         }
269:         return $dateRange;
270:     }
271: 
272:     public static function startOfQuarter() {
273:         $current_month = date('m');
274:         $current_year = date('Y');
275: 
276:         if($current_month>=1 && $current_month<=3) {
277:             $start_date = strtotime('1-January-'.$current_year);
278:             $end_date = strtotime('1-April-'.$current_year);
279:         } else  if($current_month>=4 && $current_month<=6) {
280:             $start_date = strtotime('1-April-'.$current_year);
281:             $end_date = strtotime('1-July-'.$current_year); 
282:         } else  if($current_month>=7 && $current_month<=9) {
283:             $start_date = strtotime('1-July-'.$current_year);
284:             $end_date = strtotime('1-October-'.$current_year);
285:         } else  if($current_month>=10 && $current_month<=12) {
286:             $start_date = strtotime('1-October-'.$current_year);
287:             $end_date = strtotime('1-Janauary-'.($current_year+1));
288:         }
289: 
290:         return array($start_date, $end_date);
291:     }
292: 
293: }
294: ?>
295: 
X2CRM Documentation API documentation generated by ApiGen 2.8.0