private static function setupDataSource($view, $source, $params)
 {
     $source->setStart(ArrayUtil::get($params, 'start', 0));
     $source->setLimit(ArrayUtil::get($params, 'limit', self::DEFAULT_PROXY_LIMIT));
     $sortColumn = ArrayUtil::get($params, 'sort', null);
     if ($sortColumn) {
         $sortColumn = self::getSortColumn($view, $sortColumn);
         $source->setSort($sortColumn, ArrayUtil::get($params, 'dir', 'ASC'));
     }
 }
 function where($query)
 {
     $qb = $this->_em->createQueryBuilder()->select(['subdivisionAltName'])->from('app\\Models\\Geography\\SubdivisionAltName', 'subdivisionAltName');
     // Order by
     if (is_null(ArrayUtil::get($query['orderBy'], NULL))) {
         $qb->orderBy('subdivisionAltName.id', 'ASC');
     }
     $limit = is_null(ArrayUtil::get($query['limit'], NULL)) ? 80 : (int) $query['limit'];
     $qb->setMaxResults($limit);
     return $qb->getQuery()->getResult();
 }
Пример #3
0
 /**
  * Returns the "module/action" url for the current widget.
  */
 public static function getWidgetUrl($parse)
 {
     $action = ArrayUtil::get($parse, 'component_name', null);
     if ($action) {
         $module = $parse['module'];
     } else {
         $context = sfContext::getInstance();
         $action = $context->getActionName();
         $module = $context->getModuleName();
     }
     return sprintf('%s/%s', $module, $action);
 }
 public function execute($filterChain)
 {
     $context = $this->context;
     if ($this->isFirstCall() && $context->getRequest()->getMethod() == sfRequest::POST) {
         $actionInstance = $this->context->getActionStack()->getLastEntry()->getActionInstance();
         $formcfg = self::getFormConfig($context);
         if ($formcfg === null) {
             $edit = $actionInstance->getRequestParameter('edit');
             $apikey = $context->getRequest()->hasParameter('af_apikey');
             if (!is_array($edit) || !$apikey) {
                 // Normal AJAX POST requests and plain forms don't have
                 // validators from the XML config.
                 $validators = array();
                 $formcfg = array();
             } else {
                 self::renderErrors(array(), 'The form is outdated. Please, refresh it.');
             }
         } else {
             $validators = $formcfg['validators'];
             $fileTypes = $formcfg['fileTypes'];
         }
         if (ArrayUtil::get($formcfg, 'wizard', false)) {
             afWizard::checkStepOrRenderError();
         }
         $errors = array();
         $errorMessage = null;
         $requestParameters = sfToolkit13::arrayDeepMerge($context->getRequest()->getParameterHolder()->getAll(), $context->getRequest()->getFiles());
         foreach ($validators as $field => $fieldValidators) {
             $tmp_field = $field;
             if ($fileTypes[$field] == 'combo') {
                 $tmp_field = substr($field, 0, -1) . "_value]";
             }
             foreach ($fieldValidators as $class => $args) {
                 $params = ArrayUtil::get($args, 'params', array());
                 $validator = afValidatorFactory::createValidator($class, $params);
                 $value = afValidatorFactory::prepareValue($tmp_field, $validator, $requestParameters);
                 try {
                     $validator->clean($value);
                 } catch (sfValidatorError $e) {
                     $errors[] = array($tmp_field, $e->getMessage());
                 }
             }
         }
         if (!empty($errors)) {
             self::renderErrors($errors, $errorMessage);
         }
         if (ArrayUtil::get($formcfg, 'wizard', false)) {
             $this->updateWizardState();
         }
         self::removeIterationNumber($this->context->getRequest()->getParameterHolder());
     }
     return $filterChain->execute();
 }
Пример #5
0
 /**
  * Example value in $headers:   ['Authorization' => 'Bearer TOKEN_GOES_HERE'];
  * @param   array       $headers
  * @param   string      $key
  * @param   string      $tokenType
  * @param   string      $separator
  * @return  string|null
  */
 public static function getAccessToken($headers, $key = 'Authorization', $tokenType = 'Bearer', $separator = ' ')
 {
     $value = ArrayUtil::get($headers[strtolower($key)]);
     if (is_null($value)) {
         return null;
     }
     if (!is_array($value)) {
         return null;
     }
     if (sizeof($value) != 1) {
         return null;
     }
     $tokenString = $value[0];
     $tokenArray = explode($tokenType . $separator, $tokenString);
     if (sizeof($tokenArray) != 2) {
         return null;
     }
     return $tokenArray[1];
 }
 private static function extractValues($row, $keys)
 {
     $values = array();
     foreach ($keys as $key) {
         $values[] = StringUtil::removeTagsAndEntities(ArrayUtil::get($row, $key, ''));
     }
     return $values;
 }
Пример #7
0
 /**
  * Get a specific key from the settings data.
  *
  * @param  string|array $key
  * @param  mixed        $default Optional default value.
  *
  * @return mixed
  */
 public function get($key, $default = null)
 {
     $this->checkLoaded();
     return ArrayUtil::get($this->data, $key, $default);
 }
 public function end()
 {
     $this->afExtjs->public['init'] = ArrayUtil::get($this->afExtjs->public, 'init', '');
     $this->afExtjs->public['init'] .= "\r\n\t    Ext.QuickTips.init();\r\n\t    Ext.apply(Ext.QuickTips.getQuickTip(), {\r\n\t\t    trackMouse: true\r\n\t\t});\r\n\t\tExt.form.Field.prototype.msgTarget = 'side';\r\n\t\tExt.History.init();\r\n\t\tafApp.urlPrefix = '" . sfContext::getInstance()->getRequest()->getRelativeUrlRoot() . "';\r\n\t    afApp.sharpPrefix = '" . $this->sharpPrefix . "';\r\n\t\t";
     $this->afExtjs->init();
 }
Пример #9
0
 private static function getProxyAttributes($parse)
 {
     $start = ArrayUtil::get($parse, 'params', 'proxystart', 0);
     $limit = ArrayUtil::get($parse, 'params', 'maxperpage', afDataFacade::DEFAULT_PROXY_LIMIT);
     $proxyUrl = UrlUtil::getListjsonUrl(afExtjsWidgets::getWidgetUrl($parse));
     $customProxyUrl = ArrayUtil::get($parse, 'proxy', $proxyUrl);
     if ($customProxyUrl !== 'parser/listjson') {
         $proxyUrl = $customProxyUrl;
     }
     $proxyUrl = UrlUtil::abs($proxyUrl);
     $proxyUrl = self::setupProxyUrl($proxyUrl, $parse);
     $args = array('url' => $proxyUrl, 'limit' => $limit, 'start' => $start);
     if (isset($parse["stateId"]) && $parse["stateId"] === "true") {
         $args['stateId'] = true;
     }
     return $args;
 }
    public function __construct($containerObject, $attributes = array(), $submitContainerObject = false)
    {
        $this->afExtjs = afExtjs::getInstance();
        $this->afExtjs->setAddons(array('js' => array($this->afExtjs->getPluginsDir() . 'submit/RobustSubmitAction.js')));
        $pe = isset($attributes['preExecute']) ? $attributes['preExecute'] : '';
        if (isset($attributes['label'])) {
            $this->attributes['text'] = $attributes['label'];
            unset($attributes['label']);
        }
        if (isset($attributes['action'])) {
            $this->attributes['url'] = $attributes['action'];
            $attributes['action'] = UrlUtil::addParam($attributes['action'], '_csrf_token', sfContext::getInstance()->getRequest()->getAttribute('_csrf_token'));
            if (!isset($attributes['method'])) {
                $attributes['method'] = 'post';
            }
            $submitContainerObject = $submitContainerObject ? $submitContainerObject : $containerObject;
            if (isset($submitContainerObject->attributes['classic']) && $submitContainerObject->attributes['classic']) {
                $source = 'Ext.getCmp("' . $submitContainerObject->attributes['id'] . '").submit(' . $this->afExtjs->asAnonymousClass(array('url' => $attributes['action'], 'method' => $attributes['method'])) . ');';
                if (isset($attributes['preExecute']) && $attributes['preExecute']) {
                    $pe_file = isset($attributes['preExecute']) ? $attributes['preExecute'] : '';
                    $source = $this->preExecuteSource($pe_file, $source);
                }
                $this->attributes['handler'] = $this->afExtjs->asMethod(array('parameters' => '', 'source' => $source));
            } else {
                if (!isset($attributes['params'])) {
                    $attributes['params'] = array();
                }
                $submitUrl = $attributes['action'];
                if (!StringUtil::startsWith($submitUrl, 'http')) {
                    $submitUrl = sfContext::getInstance()->getRequest()->getUriPrefix() . sfContext::getInstance()->getRequest()->getRelativeUrlRoot() . $submitUrl;
                }
                if (method_exists($submitContainerObject, 'getValidators')) {
                    $attributes['params']['af_formcfg'] = afEditJsonRenderer::buildFormcfg($submitUrl, $submitContainerObject->getValidators(), $submitContainerObject->getFieldTypes(), ArrayUtil::get($attributes, 'wizard', false));
                }
                unset($attributes['wizard']);
                /**
                 * timeout, sets the submit timeout action in milisecs, default to 300000ms(300s)
                 */
                if (!isset($attributes['timeout'])) {
                    $attributes['timeout'] = '300000';
                }
                $source = 'Ext.getCmp("' . $submitContainerObject->attributes['id'] . '").getForm().doAction("robustsubmit", ' . $this->afExtjs->asAnonymousClass(array('url' => $submitUrl, 'waitMsg' => 'loading...', 'params' => $attributes['params'], 'timeout' => $attributes['timeout'], 'failure' => $this->afExtjs->asMethod(array('parameters' => 'form,action', 'source' => 'var onclose=function(){if(action.result && action.result.redirect){var load=action.result.load || "center";afApp.load(action.result.redirect,load);}}; if(action.result){ if(action.result.message){Ext.Msg.alert("Failure", action.result.message, onclose);}}else{Ext.Msg.alert("Failure", "Some error appeared!", onclose);}')), 'success' => $this->afExtjs->asMethod(array('parameters' => 'form,action', 'source' => '
									/**
		  							* Test for popuped window
		  							*/
		  							var _form = Ext.getCmp("' . $submitContainerObject->attributes['id'] . '");
		  							
		  							var _win = null;
		  							if(_form){
		  								_win = _form.findParentByType("window");		  								
		  							}	  							
		  							/*************************************************************/
		  							var showInstantNotification = function(){
										if(message){
											if(showInWindow){
												var w = new Ext.Window({
													html:message,
													title:"Success",
													bodyStyle:"padding:10px",
													autoScroll:true,
													frame:true,		  										
													resizable:true,
													maximizable:true		  										
												}).show();		  									
												if(w.getBox().width > 600) w.setWidth(600);
												if(w.getBox().height > 400){ w.setHeight(400);w.setWidth(w.getWidth()+20)}
												w.center();		  									
											}else{
											    afApp.notify("Success",message);
											}
										}
		  								if(_win){		  								
		  									if(winProp.hidePopup === false) return;
		  									
		  									if(!afApp.hasDesktop()) { // destroy method cousing error on desktop layout
		  									   //destroy the popup because content most probably have been changed, see ticket #891 for more info
		  									   _win.destroy();
		  									}
		  									_win.close();
		  									
		  									return false;
		  								}
		  							}
		  							/*reload load_widgets store*/
		  							var load_widgets=action.result.load_widgets ||action.options.params.load_widgets;
		  							if(load_widgets && load_widgets.length>0)
		  							afApp.reloadGridsData(load_widgets);				  							
		  							
		  							/*executeAfter - can execute a js code after submit, the js code comes from json response*/
		  							var executeAfter=action.result.executeAfter || false;
		  							if(executeAfter)eval(executeAfter);
		  							
		  							var confirm=action.result.confirm ||action.options.params.confirm; 
		  							var ajax=action.result.ajax ||action.options.params.ajax;
		  							var message=action.result.message ||action.options.params.message;
		  							var redirect=action.result.redirect ||action.options.params.redirect;
		  							var target=action.result.target ||action.options.params.target;
		  							var winProp=action.result.winProp ||action.options.params.winProp;
		  							var load=action.result.load || "center";
									
									var showInWindow=action.result.window ||action.options.params.window;
									var forceRedirect = action.result.forceRedirect;
		  							if(forceRedirect !== false) forceRedirect = true;		  							
		  							winProp = Ext.util.JSON.decode(winProp);		  							
		  							winProp = winProp || {};		  							
		  							Ext.apply(winProp,{forceRedirect:forceRedirect,isPopup:_win});
									
		  							var win;		  										
		  							if(message){
		  							
		  								if(confirm){
		  									Ext.Msg.confirm("Confirmation",message, function(btn){
		  									
			  									if (btn=="yes"&&redirect&&redirect!="undefined"){ 
			  										
			  										if(ajax)
			  										{
			  											Ext.Ajax.request({ 
				  											url: redirect, 
				  											method:"post",
				  											success:function(response, options){
				  												response=Ext.decode(response.responseText);
																if (!response.success) {
				  													Ext.Msg.alert("Failure",response.message||"Unable to do the operation.");
																	return;
				  												}
				  												if(response.message){
				  													Ext.Msg.alert("Success",response.message);																	
				  												}
				  											}
			  											});
			  										}
			  										else
			  										{
														showInstantNotification();
			  											afApp.load(redirect,load,target,winProp);				
			  										}
			  										
			  										return false; 
			  									
			  									}else{ 
			  										return true;
												}
											});
		  								}
		  								else{	
		  									if(redirect && (!confirm || confirm == "undefined")){
												showInstantNotification();		  										
		  										if(redirect&&redirect!="undefined"){
													afApp.load(redirect,load,target,winProp);
													return false; 
												}else{ 
													return true;
												}												
												Ext.Msg.buttonText = {yes: "Yes",no: "No"}		  										
		  									}else{
												showInstantNotification();
		  										/*Ext.Msg.alert("Success", message, function(){
													if(!confirm||confirm=="undefined"){
														if(redirect){
															afApp.load(redirect,"center",target,winProp);
														}' . (isset($attributes['afterSuccess']) ? $attributes['afterSuccess'] : '') . '
													}
												});*/
												' . (isset($attributes['afterSuccess']) ? $attributes['afterSuccess'] : '') . '
		  									}
		  								}		  								
		  							}else{
		  								if(redirect){
											showInstantNotification();
											if(afApp.hasDesktop()) {
											    
											    if (redirect.indexOf("#")>-1) {
											        tmp = redirect.substring(0, redirect.indexOf("#"));
											        if(afApp.windows.get(tmp)) {
                                                        afApp.windows.get(tmp).close();
                                                    } 
                                                    // alert(redirect);
											    }
											    if(afApp.windows.get(redirect)) {
                                                    afApp.windows.get(redirect).close();
                                                } 
                                            }
		  									afApp.load(redirect,load,target,winProp);
										}' . (isset($attributes['afterSuccess']) ? $attributes['afterSuccess'] : '') . '
		  							} ')))) . ');';
                if (isset($attributes['preExecute']) && $attributes['preExecute']) {
                    $pe_file = isset($attributes['preExecute']) ? $attributes['preExecute'] : '';
                    $source = $this->preExecuteSource($pe_file, $source);
                }
                $this->attributes['handler'] = $this->afExtjs->asMethod(array('parameters' => '', 'source' => $source));
                unset($attributes['action']);
                unset($attributes['afterSuccess']);
                unset($attributes['params']);
                unset($attributes['timeout']);
            }
        }
        parent::__construct($containerObject, $attributes);
    }