idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
39,800
public function getHashName ( ) { if ( $ this -> _hashName === null ) { $ this -> _hashName = sha1 ( get_called_class ( ) ) ; } return $ this -> _hashName ; }
Get a unique identifier hash based on the name and config values like icon and label .
39,801
public function getViewPath ( ) { $ module = $ this -> module ; if ( substr ( $ module , 0 , 1 ) !== '@' ) { $ module = '@' . $ module ; } return implode ( DIRECTORY_SEPARATOR , [ Yii :: getAlias ( $ module ) , 'views' , 'aws' , $ this -> getViewFolderName ( ) ] ) ; }
Return the view path for view context .
39,802
public function setTitle ( $ title ) { if ( is_array ( $ title ) ) { list ( $ category , $ message ) = $ title ; $ this -> _title = Yii :: t ( $ category , $ message ) ; } else { $ this -> _title = $ title ; } }
Setter method for title .
39,803
public function getModel ( ) { if ( $ this -> _model === null ) { $ this -> _model = Yii :: createObject ( $ this -> modelClass ) ; } return $ this -> _model ; }
Get Model Object
39,804
public function actionIndex ( $ inline = false , $ relation = false , $ arrayIndex = false , $ modelClass = false , $ modelSelection = false ) { $ apiEndpoint = $ this -> model -> ngRestApiEndpoint ( ) ; $ config = $ this -> model -> getNgRestConfig ( ) ; $ userSortSettings = Yii :: $ app -> adminuser -> identity -> setting -> get ( 'ngrestorder.admin/' . $ apiEndpoint , false ) ; if ( $ userSortSettings && is_array ( $ userSortSettings ) && $ config -> getDefaultOrder ( ) !== false ) { $ config -> defaultOrder = [ $ userSortSettings [ 'field' ] => $ userSortSettings [ 'sort' ] ] ; } $ crud = Yii :: createObject ( $ this -> renderCrud ) ; $ crud -> setModel ( $ this -> model ) ; $ crud -> setSettingButtonDefinitions ( $ this -> globalButtons ) ; $ crud -> setIsInline ( $ inline ) ; $ crud -> setModelSelection ( $ modelSelection ) ; if ( $ relation && is_numeric ( $ relation ) && $ arrayIndex !== false && $ modelClass !== false ) { $ crud -> setRelationCall ( [ 'id' => $ relation , 'arrayIndex' => $ arrayIndex , 'modelClass' => $ modelClass ] ) ; } $ ngrest = new NgRest ( $ config ) ; return $ ngrest -> render ( $ crud ) ; }
Render the ngrest default index template .
39,805
public function actionExportDownload ( $ key ) { $ sessionkey = Yii :: $ app -> session -> get ( 'tempNgRestFileKey' ) ; $ fileName = Yii :: $ app -> session -> get ( 'tempNgRestFileName' ) ; $ mimeType = Yii :: $ app -> session -> get ( 'tempNgRestFileMime' ) ; if ( $ sessionkey !== base64_decode ( $ key ) ) { throw new ForbiddenHttpException ( 'Invalid download key.' ) ; } $ content = FileHelper :: getFileContent ( '@runtime/' . $ sessionkey . '.tmp' ) ; Yii :: $ app -> session -> remove ( 'tempNgRestFileKey' ) ; Yii :: $ app -> session -> remove ( 'tempNgRestFileName' ) ; Yii :: $ app -> session -> remove ( 'tempNgRestFileMime' ) ; @ unlink ( Yii :: getAlias ( '@runtime/' . $ sessionkey . '.tmp' ) ) ; return Yii :: $ app -> response -> sendContentAsFile ( $ content , $ fileName , [ 'mimeType' => $ mimeType ] ) ; }
Get the file content response for a given key .
39,806
public function renderWindowClassView ( $ className , $ namespace , $ moduleId ) { $ alias = Inflector :: humanize ( Inflector :: camel2words ( $ className ) ) ; return $ this -> view -> render ( '@admin/commands/views/aw/classfile.php' , [ 'className' => $ className , 'namespace' => $ namespace , 'luyaText' => $ this -> getGeneratorText ( 'aw/create' ) , 'moduleId' => $ moduleId , 'alias' => $ alias , ] ) ; }
Render the view file with its parameters .
39,807
public function actionCreate ( ) { $ name = $ this -> prompt ( "Please enter a name for the Active Window:" , [ 'required' => true , ] ) ; $ className = $ this -> createClassName ( $ name , $ this -> suffix ) ; $ moduleId = $ this -> selectModule ( [ 'text' => 'What module should ' . $ className . ' belong to?' , 'onlyAdmin' => true ] ) ; $ module = Yii :: $ app -> getModule ( $ moduleId ) ; $ folder = $ module -> basePath . DIRECTORY_SEPARATOR . 'aws' ; $ file = $ folder . DIRECTORY_SEPARATOR . $ className . '.php' ; $ namespace = $ module -> getNamespace ( ) . '\\aws' ; if ( FileHelper :: createDirectory ( $ folder ) && FileHelper :: writeFile ( $ file , $ this -> renderWindowClassView ( $ className , $ namespace , $ moduleId ) ) ) { $ object = Yii :: createObject ( [ 'class' => $ namespace . '\\' . $ className ] ) ; if ( FileHelper :: createDirectory ( $ object -> getViewPath ( ) ) && FileHelper :: writeFile ( $ object -> getViewPath ( ) . DIRECTORY_SEPARATOR . 'index.php' , $ this -> renderWindowClassViewFile ( $ className , $ moduleId ) ) ) { $ this -> outputInfo ( "View file generated." ) ; } return $ this -> outputSuccess ( "Active Window '$file' created." ) ; } return $ this -> outputError ( "Error while writing the Actice Window file '$file'." ) ; }
Create a new ActiveWindow class based on you properties .
39,808
public function can ( $ type ) { if ( ! in_array ( $ type , [ Auth :: CAN_CREATE , Auth :: CAN_DELETE , Auth :: CAN_UPDATE , Auth :: CAN_VIEW ] ) ) { throw new InvalidConfigException ( "Invalid type of permission check." ) ; } $ can = Yii :: $ app -> auth -> matchApi ( $ this -> userAuthClass ( ) -> identity -> id , $ this -> id , $ type ) ; if ( ! $ can ) { throw new ForbiddenHttpException ( "User is unable to access the API due to insufficient permissions." ) ; } return true ; }
Check if the current user have given permissions type .
39,809
public function checkEndpointAccess ( ) { UserOnline :: refreshUser ( $ this -> userAuthClass ( ) -> identity , $ this -> id ) ; if ( ! Yii :: $ app -> auth -> matchApi ( $ this -> userAuthClass ( ) -> identity -> id , $ this -> id , false ) ) { throw new ForbiddenHttpException ( 'Unable to access this action due to insufficient permissions.' ) ; } }
Checks if the current api endpoint exists in the list of accessables APIs .
39,810
public function checkAndStore ( ) { if ( ! $ this -> user -> validatePassword ( $ this -> oldpass ) ) { return $ this -> addError ( 'oldpass' , 'The previous old password is invalid.' ) ; } if ( ! $ this -> user -> changePassword ( $ this -> newpass ) ) { return $ this -> addErrors ( $ this -> user -> getErrors ( ) ) ; } }
Checks if the password is valid and stores the new password .
39,811
public function flowSaveImage ( Item $ image ) { Yii :: $ app -> db -> createCommand ( ) -> insert ( $ this -> getConfigValue ( 'table' ) , [ $ this -> getConfigValue ( 'itemField' ) => $ this -> id , $ this -> getConfigValue ( 'imageField' ) => $ image -> id , ] ) -> execute ( ) ; }
This method will be called when the storage item is created so you can perform the database save action by implementing this method .
39,812
public function flowDeleteImage ( Item $ image ) { Yii :: $ app -> db -> createCommand ( ) -> delete ( $ this -> getConfigValue ( 'table' ) , [ $ this -> getConfigValue ( 'imageField' ) => $ image -> id ] ) -> execute ( ) ; }
This method will be called when the delete button will be triggered for an uploaded image . Now you should removed the corresponding reference item in your database table . The image objec deletion will be trigger by the active window .
39,813
public function callbackSave ( $ newpass , $ newpasswd ) { if ( ! $ this -> model || ! $ this -> model instanceof ChangePasswordInterface ) { throw new Exception ( "Unable to find related model object or the model does not implemented the \luya\admin\aws\ChangePasswordInterface." ) ; } if ( strlen ( $ newpass ) < $ this -> minCharLength ) { return $ this -> sendError ( Module :: t ( 'aws_changeapssword_minchar' , [ 'min' => $ this -> minCharLength ] ) ) ; } if ( $ newpass !== $ newpasswd ) { return $ this -> sendError ( Module :: t ( 'aws_changepassword_notequal' ) ) ; } if ( $ this -> model -> changePassword ( $ newpass ) ) { return $ this -> sendSuccess ( Module :: t ( 'aws_changepassword_succes' ) ) ; } $ error = current ( $ this -> model -> getFirstErrors ( ) ) ; return $ this -> sendError ( $ error ) ; }
The method which is going to change the password on the current model .
39,814
public function callbackList ( ) { $ data = $ this -> model -> flowListImages ( ) ; $ images = [ ] ; foreach ( Yii :: $ app -> storage -> findImages ( [ 'in' , 'id' , $ data ] ) as $ item ) { $ images [ $ item -> id ] = $ item -> applyFilter ( 'small-crop' ) -> toArray ( ) ; } return $ this -> sendSuccess ( 'list loaded' , [ 'images' => $ images , ] ) ; }
Returns a list of uploaded images .
39,815
public function callbackRemove ( $ imageId ) { $ image = Yii :: $ app -> storage -> getImage ( $ imageId ) ; if ( $ image ) { $ this -> model -> flowDeleteImage ( $ image ) ; if ( Storage :: removeImage ( $ image -> id , true ) ) { return $ this -> sendSuccess ( 'image has been removed' ) ; } } return $ this -> sendError ( 'Unable to remove this image' ) ; }
Remove a given image from the collection .
39,816
public function callbackUpload ( ) { $ config = new Config ( ) ; $ config -> setTempDir ( $ this -> getTempFolder ( ) ) ; $ file = new File ( $ config ) ; $ request = new Request ( ) ; if ( $ _SERVER [ 'REQUEST_METHOD' ] === 'GET' ) { if ( $ file -> checkChunk ( ) ) { header ( "HTTP/1.1 200 Ok" ) ; } else { header ( "HTTP/1.1 204 No Content" ) ; exit ; } } else { if ( $ file -> validateChunk ( ) ) { $ file -> saveChunk ( ) ; } else { header ( "HTTP/1.1 400 Bad Request" ) ; exit ; } } if ( $ file -> validateFile ( ) && $ file -> save ( $ this -> getUploadFolder ( ) . '/' . $ request -> getFileName ( ) ) ) { $ file = Yii :: $ app -> storage -> addFile ( $ this -> getUploadFolder ( ) . '/' . $ request -> getFileName ( ) , $ request -> getFileName ( ) , 0 , true ) ; if ( $ file ) { @ unlink ( $ this -> getUploadFolder ( ) . '/' . $ request -> getFileName ( ) ) ; $ image = Yii :: $ app -> storage -> addImage ( $ file -> id ) ; if ( $ image ) { $ image -> applyFilter ( 'small-crop' ) ; $ this -> model -> flowSaveImage ( $ image ) ; return 'done' ; } } } else { } }
Flow Uploader Upload .
39,817
public function getAdminValue ( ) { if ( $ this -> i18n ) { $ this -> value = I18n :: decode ( $ this -> value ) ; } elseif ( $ this -> autoDecodeJson && Json :: isJson ( $ this -> value ) ) { $ this -> value = Json :: decode ( $ this -> value ) ; } return $ this -> value ; }
The value is passed from the administration area side to the angular view .
39,818
public function getActiveWindowObject ( ) { if ( $ this -> _activeWindowObject === null ) { $ activeWindow = $ this -> findActiveWindow ( $ this -> activeWindowHash ) ; $ object = Yii :: createObject ( $ activeWindow [ 'objectConfig' ] ) ; $ object -> setItemId ( $ this -> itemId ) ; $ object -> setConfigHash ( $ this -> config -> getHash ( ) ) ; $ object -> setActiveWindowHash ( $ this -> activeWindowHash ) ; Yii :: $ app -> session -> set ( $ this -> activeWindowHash , $ this -> itemId ) ; $ this -> _activeWindowObject = $ object ; } return $ this -> _activeWindowObject ; }
Get current Active Window Object .
39,819
public function findActiveWindow ( $ activeWindowHash ) { $ activeWindows = $ this -> getConfig ( ) -> getPointer ( 'aw' ) ; return isset ( $ activeWindows [ $ activeWindowHash ] ) ? $ activeWindows [ $ activeWindowHash ] : false ; }
Find the active window in the config based on a given Hash .
39,820
protected static function injector ( $ type , $ ngModel , $ label , $ options = [ ] , array $ mergeOptions = [ ] ) { foreach ( $ mergeOptions as $ key => $ value ) { if ( ! is_array ( $ value ) && is_bool ( $ value ) ) { $ mergeOptions [ $ key ] = ( int ) $ value ; } } $ opt = array_merge ( $ mergeOptions , [ 'model' => $ ngModel , 'label' => $ label , 'options' => $ options , 'fieldid' => Inflector :: camel2id ( Inflector :: camelize ( $ ngModel . '-' . $ type ) ) , 'fieldname' => Inflector :: camel2id ( Inflector :: camelize ( $ ngModel ) ) , ] ) ; return new AngularObject ( [ 'type' => $ type , 'options' => $ opt , ] ) ; }
Internal method to use to create the angular injector helper method like in angular context of directives . js
39,821
public static function optionsArrayInput ( $ data ) { if ( is_scalar ( $ data ) ) { return $ data ; } $ output = [ ] ; foreach ( $ data as $ value => $ label ) { if ( is_array ( $ label ) ) { if ( ! isset ( $ label [ 'label' ] ) || ! isset ( $ label [ 'value' ] ) ) { throw new InvalidConfigException ( "The options array data for the given element must contain a label and value key." ) ; } $ output [ ] = $ label ; } else { $ output [ ] = [ 'label' => $ label , 'value' => $ value ] ; } } return $ output ; }
Ensures the input structure for optional data for selects radios etc .
39,822
public static function directive ( $ name , array $ options = [ ] ) { return Html :: tag ( Inflector :: camel2id ( $ name ) , null , $ options ) ; }
Create a Angular Directive tag based on the name .
39,823
public static function sortRelationArray ( $ ngModel , $ label , array $ sourceData , array $ options = [ ] ) { return self :: injector ( TypesInterface :: TYPE_SORT_RELATION_ARRAY , $ ngModel , $ label , [ 'sourceData' => $ sourceData ] , $ options ) ; }
Sort Relation Array .
39,824
public static function radio ( $ ngModel , $ label , array $ data , array $ options = [ ] ) { return self :: injector ( TypesInterface :: TYPE_RADIO , $ ngModel , $ label , self :: optionsArrayInput ( $ data ) , $ options ) ; }
Radio Input .
39,825
public static function asyncRequest ( $ ngModel , $ label , $ api , $ fields , array $ options = [ ] ) { return self :: injector ( TYpesInterface :: TYPE_ASYNC_VALUE , $ ngModel , $ label , [ ] , [ 'api' => $ api , 'fields' => $ fields ] ) ; }
Generates a directive which requies a value from an api where the model is the primary key field of the api . Angular code example
39,826
public static function readonly ( $ ngModel , $ label , array $ options = [ ] ) { return self :: injector ( TypesInterface :: TYPE_READONLY , $ ngModel , $ label , [ ] , $ options ) ; }
Generate a read only attribute tag .
39,827
public function getDbTableShema ( ) { if ( $ this -> _dbTableShema === null ) { $ this -> _dbTableShema = Yii :: $ app -> db -> getTableSchema ( $ this -> dbTableName , true ) ; } return $ this -> _dbTableShema ; }
Get the database table schema .
39,828
public function generateApiContent ( $ fileNamespace , $ className , $ modelClass ) { $ alias = Inflector :: humanize ( Inflector :: camel2words ( $ className ) ) ; return $ this -> view -> render ( '@admin/commands/views/crud/create_api.php' , [ 'namespace' => $ fileNamespace , 'className' => $ className , 'modelClass' => $ modelClass , 'luyaVersion' => $ this -> getGeneratorText ( 'crud/create' ) , 'alias' => $ alias , ] ) ; }
Generate the api file content based on its view file .
39,829
public function generateModelContent ( $ fileNamepsace , $ className , $ apiEndpoint , TableSchema $ schema , $ i18nFields ) { $ alias = Inflector :: humanize ( Inflector :: camel2words ( $ className ) ) ; $ dbTableName = $ schema -> fullName ; $ fields = [ ] ; $ textfields = [ ] ; $ properties = [ ] ; $ ngrestFieldConfig = [ ] ; foreach ( $ schema -> columns as $ k => $ v ) { $ properties [ $ v -> name ] = $ v -> type ; if ( $ v -> isPrimaryKey ) { continue ; } $ fields [ ] = $ v -> name ; if ( $ v -> phpType == 'string' ) { $ textfields [ ] = $ v -> name ; } if ( $ v -> type == 'text' ) { $ ngrestFieldConfig [ $ v -> name ] = 'textarea' ; } if ( $ v -> type == 'string' ) { $ ngrestFieldConfig [ $ v -> name ] = 'text' ; } if ( $ v -> type == 'integer' || $ v -> type == 'bigint' || $ v -> type == 'smallint' || $ v -> type == 'tinyint' ) { $ ngrestFieldConfig [ $ v -> name ] = 'number' ; } if ( $ v -> type == 'decimal' || $ v -> type == 'float' || $ v -> type == 'double' ) { $ ngrestFieldConfig [ $ v -> name ] = 'decimal' ; } if ( $ v -> type == 'boolean' ) { $ ngrestFieldConfig [ $ v -> name ] = 'toggleStatus' ; } } ; return $ this -> view -> render ( '@admin/commands/views/crud/create_model.php' , [ 'namespace' => $ fileNamepsace , 'className' => $ className , 'luyaVersion' => $ this -> getGeneratorText ( 'crud/create' ) , 'apiEndpoint' => $ apiEndpoint , 'dbTableName' => $ dbTableName , 'fields' => $ fields , 'textFields' => $ textfields , 'rules' => $ this -> generateRules ( $ schema ) , 'labels' => $ this -> generateLabels ( $ schema ) , 'properties' => $ properties , 'ngrestFieldConfig' => $ ngrestFieldConfig , 'i18nFields' => $ i18nFields , 'alias' => $ alias , ] ) ; }
Generate the model content based on its view file .
39,830
public function generateBuildSummery ( $ apiEndpoint , $ apiClassPath , $ humanizeModelName , $ controllerRoute ) { return $ this -> view -> render ( '@admin/commands/views/crud/build_summary.php' , [ 'apiEndpoint' => $ apiEndpoint , 'apiClassPath' => $ apiClassPath , 'humanizeModelName' => $ humanizeModelName , 'controllerRoute' => $ controllerRoute , ] ) ; }
Generate the block build summary based on its view file .
39,831
public function actionModel ( $ model = null ) { if ( ! $ model ) { $ model = $ this -> prompt ( 'Namespaced path to the ngrest model (e.g. "app\models\Users"):' ) ; } $ object = Yii :: createObject ( [ 'class' => $ model ] ) ; if ( ! $ object instanceof NgRestModelInterface ) { throw new Exception ( "Model must be instance of NgRestModelInterface." ) ; } $ reflector = new \ ReflectionClass ( $ model ) ; $ fileName = $ reflector -> getFileName ( ) ; $ path = dirname ( $ fileName ) ; $ apiEndpoint = $ object -> ngrestApiEndpoint ( ) ; $ i18n = ! empty ( $ object -> i18n ) ; $ data = [ 'path' => $ path , 'fileName' => basename ( $ fileName ) , 'content' => $ this -> generateModelContent ( $ reflector -> getNamespaceName ( ) , $ reflector -> getShortName ( ) , $ apiEndpoint , Yii :: $ app -> db -> getTableSchema ( $ object -> tableName ( ) , true ) , $ i18n ) , ] ; $ this -> generateFile ( $ data ) ; }
Generate only the ngrest model
39,832
public function i18nAttributeValue ( $ attributeName ) { $ value = $ this -> { $ attributeName } ; if ( $ this -> isI18n ( $ attributeName ) && Json :: isJson ( $ value ) ) { return I18n :: decodeFindActive ( $ value ) ; } return $ this -> { $ attributeName } ; }
Checks whether given attribute is in the list of i18n fields if so the field value will be decoded and the value for the current active language is returned .
39,833
public function i18nAttributesValue ( array $ attributes ) { $ values = [ ] ; foreach ( $ attributes as $ attribute ) { $ values [ $ attribute ] = $ this -> i18nAttributeValue ( $ attribute ) ; } return $ values ; }
Returns the decoded i18n value for a set of attributes .
39,834
public function ngRestFullQuerySearch ( $ query ) { $ find = $ this -> ngRestFind ( ) ; $ operand = [ ] ; foreach ( $ this -> genericSearchFields ( ) as $ column ) { $ operand [ ] = [ 'like' , $ column , $ query ] ; } $ find -> andWhere ( new OrCondition ( $ operand ) ) ; return $ find ; }
Search trough the whole table as ajax fallback when pagination is enabled .
39,835
public function getNgRestCallType ( ) { if ( $ this -> _ngrestCallType === null ) { $ this -> _ngrestCallType = ( ! Yii :: $ app instanceof \ yii \ web \ Application ) ? false : Yii :: $ app -> request -> get ( 'ngrestCallType' , false ) ; } return $ this -> _ngrestCallType ; }
Determine the current call type based on get params as they can change the output behavior to make the ngrest crud list view .
39,836
public function getNgRestPrimaryKey ( ) { if ( $ this -> _ngRestPrimaryKey === null ) { $ keys = static :: primaryKey ( ) ; if ( ! isset ( $ keys [ 0 ] ) ) { throw new InvalidConfigException ( "The NgRestModel '" . __CLASS__ . "' requires at least one primaryKey in order to work." ) ; } return ( array ) $ keys ; } return $ this -> _ngRestPrimaryKey ; }
Getter method for NgRest Primary Key .
39,837
public function getNgRestConfig ( ) { if ( $ this -> _config == null ) { $ config = new Config ( ) ; $ configBuilder = new ConfigBuilder ( static :: class ) ; $ this -> ngRestConfig ( $ configBuilder ) ; $ config -> setConfig ( $ configBuilder -> getConfig ( ) ) ; foreach ( $ this -> i18n as $ fieldName ) { $ config -> appendFieldOption ( $ fieldName , 'i18n' , true ) ; } $ config -> setApiEndpoint ( static :: ngRestApiEndpoint ( ) ) ; $ config -> setPrimaryKey ( $ this -> getNgRestPrimaryKey ( ) ) ; $ config -> setFilters ( $ this -> ngRestFilters ( ) ) ; $ config -> setDefaultOrder ( $ this -> ngRestListOrder ( ) ) ; $ config -> setAttributeGroups ( $ this -> ngRestAttributeGroups ( ) ) ; $ config -> setGroupByField ( $ this -> ngRestGroupByField ( ) ) ; $ config -> setGroupByExpanded ( $ this -> ngRestGroupByExpanded ( ) ) ; $ config -> setTableName ( $ this -> tableName ( ) ) ; $ config -> setAttributeLabels ( $ this -> attributeLabels ( ) ) ; $ config -> setActiveButtons ( $ this -> ngRestActiveButtons ( ) ) ; if ( $ this -> ngRestRelations ( ) && count ( $ this -> getNgRestPrimaryKey ( ) ) > 1 ) { throw new InvalidConfigException ( "You can not use the ngRestRelations() on composite key model." ) ; } foreach ( $ this -> generateNgRestRelations ( ) as $ relation ) { $ config -> setRelation ( $ relation ) ; } $ config -> onFinish ( ) ; $ this -> _config = $ config ; } return $ this -> _config ; }
Build and call the full config object if not build yet for this model .
39,838
protected function generateNgRestRelations ( ) { $ relations = [ ] ; foreach ( $ this -> ngRestRelations ( ) as $ key => $ item ) { if ( ! $ item instanceof NgRestRelation ) { if ( ! isset ( $ item [ 'class' ] ) ) { $ item [ 'class' ] = 'luya\admin\ngrest\base\NgRestRelation' ; } $ item = Yii :: createObject ( $ item ) ; } $ item -> setModelClass ( $ this -> className ( ) ) ; $ item -> setArrayIndex ( $ key ) ; $ relations [ $ key ] = $ item ; } return $ relations ; }
Generate an array with NgRestRelation objects
39,839
public function getNgRestRelationByIndex ( $ index ) { $ relations = $ this -> generateNgRestRelations ( ) ; return isset ( $ relations [ $ index ] ) ? $ relations [ $ index ] : false ; }
Get the NgRest Relation defintion object .
39,840
public function validatePassword ( $ attribute ) { if ( ! $ this -> hasErrors ( ) ) { $ user = $ this -> getUser ( ) ; if ( $ user && $ this -> userAttemptBruteForceLock ( $ user ) ) { return $ this -> addError ( $ attribute , Module :: t ( 'model_loginform_max_user_attempts' , [ 'time' => Yii :: $ app -> formatter -> asRelativeTime ( $ user -> login_attempt_lock_expiration ) ] ) ) ; } if ( ! $ user || ! $ user -> validatePassword ( $ this -> password ) ) { if ( $ this -> attempts ) { $ this -> addError ( $ attribute , Module :: t ( 'model_loginform_wrong_user_or_password' , [ 'attempt' => $ this -> attempts , 'allowedAttempts' => $ this -> allowedAttempts ] ) ) ; } else { $ this -> addError ( $ attribute , Module :: t ( 'model_loginform_wrong_user_or_password' ) ) ; } } } }
Inline validator .
39,841
private function userAttemptBruteForceLock ( User $ user ) { if ( $ this -> userAttemptBruteForceLockHasExceeded ( $ user ) ) { return true ; } $ this -> attempts = $ user -> login_attempt + 1 ; if ( $ this -> attempts >= $ this -> allowedAttempts ) { $ user -> updateAttributes ( [ 'login_attempt_lock_expiration' => time ( ) + $ this -> lockoutTime ] ) ; } $ user -> updateAttributes ( [ 'login_attempt' => $ this -> attempts ] ) ; }
Check if the given user has a lockout otherwise upcount the attempts .
39,842
private function userAttemptBruteForceLockHasExceeded ( User $ user ) { if ( $ user -> login_attempt_lock_expiration > time ( ) ) { $ user -> updateAttributes ( [ 'login_attempt' => 0 ] ) ; return true ; } return false ; }
Check if lockout has expired or not .
39,843
public function sendSecureLogin ( ) { $ token = $ this -> getUser ( ) -> getAndStoreToken ( ) ; return Yii :: $ app -> mail -> compose ( Module :: t ( 'login_securetoken_mail_subject' ) , Module :: t ( 'login_securetoken_mail' , [ 'url' => Url :: base ( true ) , 'token' => $ token , ] ) ) -> address ( $ this -> user -> email ) -> send ( ) ; }
Send the secure token by mail .
39,844
public function validateSecureToken ( $ token , $ userId ) { $ user = User :: findOne ( $ userId ) ; if ( ! $ user ) { return false ; } if ( $ this -> userAttemptBruteForceLockHasExceeded ( $ user ) ) { return false ; } if ( $ user -> secure_token == sha1 ( $ token ) && $ user -> secure_token_timestamp >= ( time ( ) - $ this -> secureTokenExpirationTime ) ) { return $ user ; } return false ; }
Validate the secure token .
39,845
public function login ( ) { if ( $ this -> validate ( ) ) { $ user = $ this -> getUser ( ) ; $ user -> detachBehavior ( 'LogBehavior' ) ; $ user -> updateAttributes ( [ 'force_reload' => false , 'login_attempt' => 0 , 'login_attempt_lock_expiration' => null , 'auth_token' => Yii :: $ app -> security -> hashData ( Yii :: $ app -> security -> generateRandomString ( ) , $ user -> password_salt ) , ] ) ; UserLogin :: updateAll ( [ 'is_destroyed' => true ] , [ 'user_id' => $ user -> id ] ) ; $ login = new UserLogin ( [ 'auth_token' => $ user -> auth_token , 'user_id' => $ user -> id , 'is_destroyed' => false , ] ) ; $ login -> save ( ) ; UserOnline :: refreshUser ( $ user , 'login' ) ; return $ user ; } return false ; }
Login the current user if valid .
39,846
private function arrayFilter ( $ value , $ field ) { foreach ( $ this -> _where as $ expression ) { if ( $ expression [ 'field' ] == $ field ) { switch ( $ expression [ 'op' ] ) { case '=' : return ( $ value == $ expression [ 'value' ] ) ; case '==' : return ( $ value === $ expression [ 'value' ] ) ; case '>' : return ( $ value > $ expression [ 'value' ] ) ; case '>=' : return ( $ value >= $ expression [ 'value' ] ) ; case '<' : return ( $ value < $ expression [ 'value' ] ) ; case '<=' : return ( $ value <= $ expression [ 'value' ] ) ; case 'in' : return in_array ( $ value , $ expression [ 'value' ] ) ; } } } return true ; }
Process items against where filters
39,847
private function filter ( ) { $ containerData = $ this -> getDataProvider ( ) ; $ whereExpression = $ this -> _where ; if ( empty ( $ whereExpression ) ) { $ data = $ containerData ; } else { $ data = array_filter ( $ containerData , function ( $ item ) { foreach ( $ item as $ field => $ value ) { if ( ! $ this -> arrayFilter ( $ value , $ field ) ) { return false ; } } return true ; } ) ; } if ( $ this -> _offset !== null ) { $ data = array_slice ( $ data , $ this -> _offset , null , true ) ; } if ( $ this -> _limit !== null ) { $ data = array_slice ( $ data , 0 , $ this -> _limit , true ) ; } if ( $ this -> _binds ) { foreach ( $ this -> _binds as $ id => $ values ) { if ( isset ( $ data [ $ id ] ) ) { $ data [ $ id ] = array_merge ( $ data [ $ id ] , $ values ) ; } } } return $ data ; }
Filter container data provider against where conditions
39,848
public function one ( ) { $ data = $ this -> filter ( ) ; return ( count ( $ data ) !== 0 ) ? $ this -> createItem ( array_values ( $ data ) [ 0 ] ) : false ; }
Find One based on the where condition .
39,849
public function findOne ( $ id ) { return ( $ itemArray = $ this -> getItemDataProvider ( $ id ) ) ? $ this -> createItem ( $ itemArray ) : false ; }
FindOne with the specific ID .
39,850
public function eventBeforeValidate ( ) { if ( is_array ( $ this -> effect_json_values ) ) { $ this -> effect_json_values = Json :: encode ( $ this -> effect_json_values ) ; } }
Encode the the effect_json_values array to a json structure .
39,851
public function effectDefinition ( $ effect , $ key = null ) { $ definition = isset ( $ this -> effectDefinitions [ $ effect ] ) ? $ this -> effectDefinitions [ $ effect ] : false ; if ( ! $ definition ) { return false ; } if ( $ key ) { return $ definition [ $ key ] ; } return $ definition ; }
Get the definition for a given effect name .
39,852
public function hasMissingRequiredEffectDefinition ( $ effect ) { foreach ( $ this -> effectDefinition ( $ effect , 'required' ) as $ param ) { if ( $ this -> getJsonValue ( $ param ) === false ) { return true ; } } return false ; }
Check if a missing required param is not provided in the chain .
39,853
protected function getJsonValue ( $ key ) { return array_key_exists ( $ key , $ this -> effect_json_values ) ? $ this -> effect_json_values [ $ key ] : false ; }
Get the value for a effect json key .
39,854
public static function lock ( $ userId , $ table , $ pk , $ translation , array $ translationArgs = [ ] ) { $ model = self :: findOne ( [ 'user_id' => $ userId ] ) ; if ( $ model ) { $ model -> updateAttributes ( [ 'last_timestamp' => time ( ) , 'lock_table' => $ table , 'lock_pk' => $ pk , 'lock_translation' => $ translation , 'lock_translation_args' => Json :: encode ( $ translationArgs ) , ] ) ; } }
Lock the user for an action .
39,855
public static function unlock ( $ userId ) { $ model = self :: findOne ( [ 'user_id' => $ userId ] ) ; if ( $ model ) { $ model -> updateAttributes ( [ 'last_timestamp' => time ( ) , 'lock_table' => '' , 'lock_pk' => '' , 'lock_translation' => '' , 'lock_translation_args' => '' , ] ) ; } }
Unlock the user from an action .
39,856
public static function refreshUser ( User $ user , $ route ) { if ( $ user -> is_api_user ) { return ; } $ model = self :: findOne ( [ 'user_id' => $ user -> id ] ) ; if ( $ model ) { return ( bool ) $ model -> updateAttributes ( [ 'last_timestamp' => time ( ) , 'invoken_route' => $ route ] ) ; } $ model = new self ( [ 'last_timestamp' => time ( ) , 'user_id' => $ user -> id , 'invoken_route' => $ route ] ) ; return $ model -> save ( ) ; }
Refresh the state of the current user or add if not exists .
39,857
public static function getList ( ) { $ time = time ( ) ; $ return = [ ] ; foreach ( self :: find ( ) -> with ( 'user' ) -> all ( ) as $ item ) { $ inactiveSince = ( $ time - $ item -> last_timestamp ) ; $ return [ ] = [ 'firstname' => $ item -> user -> firstname , 'lastname' => $ item -> user -> lastname , 'email' => $ item -> user -> email , 'last_timestamp' => $ item -> last_timestamp , 'is_active' => ( $ inactiveSince >= ( 3 * 60 ) ) ? false : true , 'inactive_since' => round ( ( $ inactiveSince / 60 ) ) . ' min' , 'lock_description' => Module :: t ( $ item -> lock_translation , empty ( $ item -> lock_translation_args ) ? [ ] : Json :: decode ( $ item -> lock_translation_args ) ) , ] ; } return $ return ; }
Get the user online list .
39,858
public function triggerJob ( ) { try { $ class = $ this -> model_class ; $ model = $ class :: findOne ( $ this -> primary_key ) ; if ( $ model ) { $ oldValue = $ model -> { $ this -> target_attribute_name } ; $ model -> { $ this -> target_attribute_name } = StringHelper :: typeCast ( $ this -> new_attribute_value ) ; $ model -> save ( true , [ $ this -> target_attribute_name ] ) ; return $ this -> updateAttributes ( [ 'old_attribute_value' => $ oldValue , 'is_done' => true ] ) ; } } catch ( \ Exception $ err ) { $ this -> delete ( ) ; } }
Job Trigger .
39,859
public function hasTriggerPermission ( $ class ) { $ model = new $ class ( ) ; if ( ! $ model instanceof NgRestModel ) { return false ; } return Yii :: $ app -> adminmenu -> getApiDetail ( $ class :: ngRestApiEndpoint ( ) ) ; }
Ensure if the given class is an ngrest model and permission exists .
39,860
public function pushQueue ( ) { $ delay = $ this -> schedule_timestamp - time ( ) ; if ( $ delay < 1 ) { $ delay = 0 ; } Yii :: $ app -> adminqueue -> delay ( $ delay ) -> push ( new ScheduleJob ( [ 'schedulerId' => $ this -> id ] ) ) ; }
Push the given scheduler model into the queue .
39,861
public function actionIndex ( $ token ) { if ( empty ( Yii :: $ app -> remoteToken ) || sha1 ( Yii :: $ app -> remoteToken ) !== $ token ) { throw new Exception ( 'The provided remote token is wrong.' ) ; } UserOnline :: clearList ( $ this -> module -> userIdleTimeout ) ; return [ 'yii_version' => Yii :: getVersion ( ) , 'luya_version' => Boot :: VERSION , 'app_title' => Yii :: $ app -> siteTitle , 'app_debug' => ( int ) YII_DEBUG , 'app_env' => YII_ENV , 'app_transfer_exceptions' => ( int ) Yii :: $ app -> errorHandler -> transferException , 'admin_online_count' => UserOnline :: find ( ) -> count ( ) , 'app_elapsed_time' => Yii :: getLogger ( ) -> getElapsedTime ( ) , 'packages' => Yii :: $ app -> getPackageInstaller ( ) -> getConfigs ( ) , 'packages_update_timestamp' => Yii :: $ app -> getPackageInstaller ( ) -> getTimestamp ( ) , ] ; }
Retrieve administration informations if the token is valid .
39,862
public function getTableName ( ) { if ( $ this -> _tableName === null ) { $ this -> _tableName = $ this -> model -> tableName ( ) ; } return $ this -> _tableName ; }
Getter tableName .
39,863
public function callbackLoadRelations ( ) { return TagRelation :: find ( ) -> where ( [ 'table_name' => TaggableTrait :: cleanBaseTableName ( $ this -> tableName ) , 'pk_id' => $ this -> getItemId ( ) ] ) -> asArray ( ) -> all ( ) ; }
Get only tags for the current record .
39,864
public function callbackSaveRelation ( $ tagId ) { $ find = TagRelation :: find ( ) -> where ( [ 'tag_id' => $ tagId , 'table_name' => TaggableTrait :: cleanBaseTableName ( $ this -> tableName ) , 'pk_id' => $ this -> getItemId ( ) ] ) -> one ( ) ; if ( $ find ) { TagRelation :: deleteAll ( [ 'tag_id' => $ tagId , 'table_name' => TaggableTrait :: cleanBaseTableName ( $ this -> tableName ) , 'pk_id' => $ this -> getItemId ( ) ] ) ; return 0 ; } else { $ model = new TagRelation ( ) ; $ model -> setAttributes ( [ 'tag_id' => $ tagId , 'table_name' => TaggableTrait :: cleanBaseTableName ( $ this -> tableName ) , 'pk_id' => $ this -> getItemId ( ) , ] ) ; $ model -> insert ( false ) ; return 1 ; } }
Save or delete a given tag id from the list of tags .
39,865
public function callbackSaveTag ( $ tagName ) { $ model = Tag :: find ( ) -> where ( [ 'name' => $ tagName ] ) -> exists ( ) ; if ( $ model ) { return false ; } $ model = new Tag ( ) ; $ model -> name = $ tagName ; $ model -> save ( ) ; return $ model -> id ; }
Save new tag to the list of tags .
39,866
public function getPointerPlugins ( $ pointer ) { $ plugins = [ ] ; foreach ( $ this -> getPointer ( $ pointer , [ ] ) as $ field ) { $ plugins [ ] = self :: createField ( $ field ) ; } return $ plugins ; }
Get all plugin objects for a given pointer .
39,867
public function getOption ( $ key ) { return ( $ this -> hasPointer ( 'options' ) && array_key_exists ( $ key , $ this -> _config [ 'options' ] ) ) ? $ this -> _config [ 'options' ] [ $ key ] : false ; }
Get an option by its key from the options pointer . Define options like
39,868
public function getExtraFields ( ) { if ( $ this -> _extraFields === null ) { $ extraFields = [ ] ; foreach ( $ this -> getConfig ( ) as $ pointer => $ fields ) { if ( is_array ( $ fields ) ) { foreach ( $ fields as $ field ) { if ( isset ( $ field [ 'extraField' ] ) && $ field [ 'extraField' ] ) { if ( ! array_key_exists ( $ field [ 'name' ] , $ extraFields ) ) { $ extraFields [ ] = $ field [ 'name' ] ; } } } } } $ this -> _extraFields = $ extraFields ; } return $ this -> _extraFields ; }
Get all extra fields .
39,869
public function removeImageSources ( ) { $ log = [ ] ; foreach ( StorageImage :: find ( ) -> where ( [ 'filter_id' => $ this -> id ] ) -> all ( ) as $ img ) { $ source = $ img -> serverSource ; $ image = $ img -> delete ( ) ; $ log [ $ source ] = $ image ; } return $ log ; }
Remove image sources of the file .
39,870
public function applyFilterChain ( $ source , $ fileSavePath ) { $ loadFrom = $ source ; foreach ( StorageFilterChain :: find ( ) -> where ( [ 'filter_id' => $ this -> id ] ) -> with ( [ 'effect' ] ) -> all ( ) as $ chain ) { $ chain -> applyFilter ( $ loadFrom , $ fileSavePath ) ; $ loadFrom = $ fileSavePath ; } return true ; }
Apply the current filter chain .
39,871
public function actionIndex ( ) { Yii :: $ app -> adminqueue -> run ( false ) ; Config :: set ( Config :: CONFIG_QUEUE_TIMESTAMP , time ( ) ) ; return ExitCode :: OK ; }
Run the queue jobs .
39,872
public function get ( $ key , $ default = null ) { $ array = $ this -> data ; foreach ( explode ( self :: SEPERATOR , $ key ) as $ item ) { if ( is_array ( $ array ) && array_key_exists ( $ item , $ array ) ) { $ array = $ array [ $ item ] ; } else { return $ default ; } } return $ array ; }
Get a key of the user settings dot notation is allowed to return a key of an array .
39,873
public function getArray ( array $ keys , array $ defaultMapping = [ ] ) { $ data = [ ] ; foreach ( $ keys as $ key ) { $ data [ $ key ] = $ this -> get ( $ key , array_key_exists ( $ key , $ defaultMapping ) ? $ defaultMapping [ $ key ] : null ) ; } return $ data ; }
Returns multiple array keys from the user settings table .
39,874
public function has ( $ key ) { $ array = $ this -> data ; foreach ( explode ( self :: SEPERATOR , $ key ) as $ item ) { if ( is_array ( $ array ) && array_key_exists ( $ item , $ array ) ) { $ array = $ array [ $ item ] ; } else { return false ; } } return true ; }
Check if an element existing inside the user settings or not .
39,875
public function remove ( $ key ) { if ( $ this -> has ( $ key ) ) { $ array = & $ this -> data ; foreach ( explode ( self :: SEPERATOR , $ key ) as $ item ) { if ( array_key_exists ( $ item , $ array ) ) { $ lastArray = & $ array ; $ array = & $ array [ $ item ] ; } } unset ( $ lastArray [ $ item ] ) ; if ( empty ( $ lastArray ) ) { unset ( $ lastArray ) ; } $ this -> save ( ) ; return true ; } return false ; }
Remove an element from the user settings data array .
39,876
public function set ( $ key , $ value ) { $ array = & $ this -> data ; $ keys = explode ( self :: SEPERATOR , $ key ) ; $ i = 1 ; foreach ( $ keys as $ item ) { if ( is_array ( $ array ) && array_key_exists ( $ item , $ array ) && ! is_array ( $ array [ $ item ] ) && $ i !== count ( $ keys ) ) { return false ; } $ array = & $ array [ $ item ] ; $ i ++ ; } $ array = $ value ; $ this -> save ( ) ; return true ; }
Add a new element to the user settings array .
39,877
public function actionUser ( ) { while ( true ) { $ email = $ this -> prompt ( 'User E-Mail:' ) ; if ( ! empty ( User :: findByEmail ( $ email ) ) ) { $ this -> outputError ( 'The provided E-Mail already exists in the System.' ) ; } else { break ; } } $ titleArray = [ 'Mr' => 1 , 'Mrs' => 2 ] ; $ title = $ this -> select ( 'Title:' , $ titleArray ) ; $ firstname = $ this -> prompt ( 'Firstname:' ) ; $ lastname = $ this -> prompt ( 'Lastname:' ) ; $ password = $ this -> prompt ( 'User Password:' ) ; if ( $ this -> confirm ( "Are you sure to create the User '$email'?" ) !== true ) { return $ this -> outputError ( 'Abort user creation process.' ) ; } $ user = new User ( ) ; $ user -> email = $ email ; $ user -> password_salt = Yii :: $ app -> getSecurity ( ) -> generateRandomString ( ) ; $ user -> password = Yii :: $ app -> getSecurity ( ) -> generatePasswordHash ( $ password . $ user -> password_salt ) ; $ user -> firstname = $ firstname ; $ user -> lastname = $ lastname ; $ user -> title = $ titleArray [ $ title ] ; if ( ! $ user -> save ( ) ) { return $ this -> outputError ( 'User validation error: ' . VarDumper :: dumpAsString ( $ user -> getErrors ( ) ) ) ; } $ groupSelect = [ ] ; foreach ( Group :: find ( ) -> all ( ) as $ entry ) { $ groupSelect [ $ entry -> id ] = $ entry -> name . ' (' . $ entry -> text . ')' ; $ this -> output ( $ entry -> id . ' - ' . $ groupSelect [ $ entry -> id ] ) ; } $ groupId = $ this -> select ( 'Select Group the user should belong to:' , $ groupSelect ) ; $ this -> insert ( '{{%admin_user_group}}' , [ 'user_id' => $ user -> id , 'group_id' => $ groupId , ] ) ; return $ this -> outputSuccess ( "The user ($email) has been created." ) ; }
Create a new user and append them to an existing group .
39,878
public function actionResetPassword ( ) { $ user = null ; while ( empty ( $ user ) ) { $ email = $ this -> email ? : $ this -> prompt ( 'User E-Mail:' ) ; $ user = User :: findByEmail ( $ email ) ; if ( empty ( $ user ) ) { $ this -> outputError ( 'The provided E-Mail not found in the System.' ) ; } } $ password = $ this -> password ? : $ this -> prompt ( 'User Password:' ) ; if ( $ this -> confirm ( "Are you sure to change the password of User '$email'?" ) !== true ) { return $ this -> outputError ( 'Abort password change process.' ) ; } $ user -> password_salt = Yii :: $ app -> getSecurity ( ) -> generateRandomString ( ) ; $ user -> password = Yii :: $ app -> getSecurity ( ) -> generatePasswordHash ( $ password . $ user -> password_salt ) ; if ( $ user -> save ( true , [ 'password' , 'password_salt' ] ) ) { return $ this -> outputSuccess ( "The password for user ($email) has been changed." ) ; } return $ this -> outputError ( "The password could not changed.\n" . implode ( "\n" , $ user -> firstErrors ) ) ; }
Change the password of a admin user .
39,879
private function insert ( $ table , array $ fields ) { return Yii :: $ app -> db -> createCommand ( ) -> insert ( $ table , $ fields ) -> execute ( ) ; }
Helper to insert data in database table .
39,880
public function onAfterLogin ( UserEvent $ event ) { if ( ! $ this -> identity -> is_api_user ) { Yii :: $ app -> language = $ this -> getInterfaceLanguage ( ) ; } }
After the login process of the user set the admin interface language based on the user settings .
39,881
public function getInterfaceLanguage ( ) { return $ this -> getIsGuest ( ) ? $ this -> defaultLanguage : $ this -> identity -> setting -> get ( 'luyadminlanguage' , $ this -> defaultLanguage ) ; }
Return the interface language for the given logged in user .
39,882
public function onBeforeLogout ( ) { UserOnline :: removeUser ( $ this -> id ) ; $ this -> identity -> updateAttributes ( [ 'auth_token' => Yii :: $ app -> security -> hashData ( Yii :: $ app -> security -> generateRandomString ( ) , $ this -> identity -> password_salt ) , ] ) ; UserLogin :: updateAll ( [ 'is_destroyed' => true ] , [ 'user_id' => $ this -> id ] ) ; }
After loging out the useronline status must be refreshed and the current user must be deleted from the user online list .
39,883
public function canApi ( $ apiEndpoint , $ typeVerification = false ) { return ! $ this -> isGuest && Yii :: $ app -> auth -> matchApi ( $ this -> getId ( ) , $ apiEndpoint , $ typeVerification ) ; }
Perform a can api match request for the logged in user if user is logged in returns false otherwhise .
39,884
public function canRoute ( $ route ) { return ! $ this -> isGuest && Yii :: $ app -> auth -> matchRoute ( $ this -> getId ( ) , $ route ) ; }
Perform a can route auth request match for the logged in user if user is logged in returns false otherwhise .
39,885
public function setLabelField ( $ labelField ) { if ( is_string ( $ labelField ) ) { $ labelField = explode ( "," , $ labelField ) ; } $ this -> _labelField = $ labelField ; }
Setter method for Label Field .
39,886
protected function getRelationApiEndpoint ( ) { $ class = $ this -> _query -> modelClass ; $ menu = Yii :: $ app -> adminmenu -> getApiDetail ( $ class :: ngRestApiEndpoint ( ) ) ; if ( ! $ menu ) { throw new InvalidConfigException ( "Unable to find the API endpoint, maybe insufficent permission or missing admin module context (admin module prefix)." ) ; } return 'admin/' . $ menu [ 'permissionApiEndpoint' ] ; }
Get the admin api endpoint name .
39,887
private function transformGenericSearchToData ( $ response ) { if ( $ response instanceof ActiveQueryInterface ) { return $ response -> asArray ( true ) -> all ( ) ; } elseif ( $ response instanceof QueryInterface ) { return $ response -> all ( ) ; } return $ response ; }
Transform the different generic search response into an array .
39,888
public function actionIndex ( $ query ) { $ search = [ ] ; $ module = Yii :: $ app -> getModule ( 'admin' ) ; foreach ( Yii :: $ app -> adminmenu -> getModules ( ) as $ node ) { if ( isset ( $ node [ 'searchModelClass' ] ) && ! empty ( $ node [ 'searchModelClass' ] ) ) { $ model = Yii :: createObject ( $ node [ 'searchModelClass' ] ) ; if ( ! $ model instanceof GenericSearchInterface ) { throw new Exception ( 'The model must be an instance of GenericSearchInterface' ) ; } $ data = $ this -> transformGenericSearchToData ( $ model -> genericSearch ( $ query ) ) ; if ( count ( $ data ) > 0 ) { $ stateProvider = $ model -> genericSearchStateProvider ( ) ; $ search [ ] = [ 'hideFields' => $ model -> genericSearchHiddenFields ( ) , 'type' => 'custom' , 'menuItem' => $ node , 'data' => $ data , 'stateProvider' => $ stateProvider , ] ; } unset ( $ data ) ; } } foreach ( Yii :: $ app -> adminmenu -> getItems ( ) as $ api ) { if ( $ api [ 'permissionIsApi' ] ) { $ ctrl = $ module -> createController ( $ api [ 'permissionApiEndpoint' ] ) ; $ controller = $ ctrl [ 0 ] ; $ data = $ this -> transformGenericSearchToData ( $ controller -> model -> genericSearch ( $ query ) ) ; if ( count ( $ data ) > 0 ) { $ search [ ] = [ 'hideFields' => $ controller -> model -> genericSearchHiddenFields ( ) , 'type' => 'api' , 'menuItem' => $ api , 'data' => $ data , 'stateProvider' => $ controller -> model -> genericSearchStateProvider ( ) , ] ; } unset ( $ data ) ; } } $ searchData = new SearchData ( ) ; $ searchData -> query = $ query ; $ searchData -> num_rows = count ( $ search ) ; $ searchData -> save ( ) ; return $ search ; }
Administration Global search provider .
39,889
public function field ( $ attribute , $ label = null , $ options = [ ] ) { $ config = $ this -> fieldConfig ; if ( ! isset ( $ config [ 'class' ] ) ) { $ config [ 'class' ] = $ this -> fieldClass ; } return Yii :: createObject ( ArrayHelper :: merge ( $ config , $ options , [ 'attribute' => $ attribute , 'form' => $ this , 'label' => $ label , ] ) ) ; }
Generate a field based on attribute name and optional label .
39,890
public function render ( RenderInterface $ render ) { $ this -> render = $ render ; $ this -> render -> setConfig ( $ this -> config ) ; return $ this -> render -> render ( ) ; }
Renders the Config for the Given Render Interface .
39,891
public static function createPluginObject ( $ className , $ name , $ alias , $ i18n , $ args = [ ] ) { return Yii :: createObject ( array_merge ( [ 'class' => $ className , 'name' => $ name , 'alias' => $ alias , 'i18n' => $ i18n , ] , $ args ) ) ; }
Generates an NgRest Plugin Object .
39,892
public function getTypeBadge ( ) { switch ( $ this -> type ) { case self :: TYPE_INFO : return '<span class="badge badge-info">info</span>' ; case self :: TYPE_WARNING : return '<span class="badge badge-warning">Warning</span>' ; case self :: TYPE_ERROR : return '<span class="badge badge-danger">Error</span>' ; case self :: TYPE_SUCCESS : return '<span class="badge badge-success">success</span>' ; } }
Get the html badge for a status type in order to display inside the admin module .
39,893
private static function getRequestIdentifier ( ) { if ( self :: $ requestIdentifier === null ) { self :: $ requestIdentifier = uniqid ( 'logger' , true ) ; } return self :: $ requestIdentifier ; }
Generate request identifier .
39,894
private static function getHashArray ( $ message , $ groupIdentifier ) { $ hash = md5 ( static :: getRequestIdentifier ( ) . Json :: encode ( ( array ) $ groupIdentifier ) ) ; if ( isset ( self :: $ identiferIndex [ $ hash ] ) ) { self :: $ identiferIndex [ $ hash ] ++ ; } else { self :: $ identiferIndex [ $ hash ] = 1 ; } $ hashIndex = self :: $ identiferIndex [ $ hash ] ; return [ 'hash' => $ hash , 'index' => $ hashIndex , ] ; }
Get array index based on identifiers .
39,895
private static function log ( $ type , $ message , $ trace , $ groupIdentifier ) { $ hashArray = static :: getHashArray ( $ message , $ groupIdentifier ) ; $ file = 'unknown' ; $ line = 'unknown' ; $ fn = 'unknown' ; $ fnArgs = [ ] ; if ( isset ( $ trace [ 0 ] ) ) { $ file = ! isset ( $ trace [ 0 ] [ 'file' ] ) ? : $ trace [ 0 ] [ 'file' ] ; $ line = ! isset ( $ trace [ 0 ] [ 'line' ] ) ? : $ trace [ 0 ] [ 'line' ] ; $ fn = ! isset ( $ trace [ 0 ] [ 'function' ] ) ? : $ trace [ 0 ] [ 'function' ] ; $ fnArgs = ! isset ( $ trace [ 0 ] [ 'args' ] ) ? : $ trace [ 0 ] [ 'args' ] ; } if ( isset ( $ trace [ 1 ] ) ) { $ fn = ! isset ( $ trace [ 1 ] [ 'function' ] ) ? : $ trace [ 1 ] [ 'function' ] ; $ fnArgs = ! isset ( $ trace [ 1 ] [ 'args' ] ) ? : $ trace [ 1 ] [ 'args' ] ; } if ( $ message instanceof Arrayable ) { $ message = $ message -> toArray ( ) ; } $ model = new self ( ) ; $ model -> attributes = [ 'time' => time ( ) , 'message' => is_array ( $ message ) ? Json :: encode ( $ message ) : $ message , 'type' => $ type , 'trace_file' => $ file , 'trace_line' => $ line , 'trace_function' => $ fn , 'trace_function_args' => Json :: encode ( $ fnArgs ) , 'get' => ( isset ( $ _GET ) ) ? Json :: encode ( $ _GET ) : '{}' , 'post' => ( isset ( $ _POST ) ) ? Json :: encode ( $ _POST ) : '{}' , 'session' => ( isset ( $ _SESSION ) ) ? Json :: encode ( $ _SESSION ) : '{}' , 'server' => ( isset ( $ _SERVER ) ) ? Json :: encode ( $ _SERVER ) : '{}' , 'group_identifier' => $ hashArray [ 'hash' ] , 'group_identifier_index' => $ hashArray [ 'index' ] , ] ; return $ model -> save ( false ) ; }
Internal generate log message .
39,896
public static function success ( $ message , $ groupIdentifier = null ) { return static :: log ( self :: TYPE_SUCCESS , $ message , debug_backtrace ( false , 2 ) , $ groupIdentifier ) ; }
Log a success message .
39,897
public static function info ( $ message , $ groupIdentifier = null ) { return static :: log ( self :: TYPE_INFO , $ message , debug_backtrace ( false , 2 ) , $ groupIdentifier ) ; }
Log an info message .
39,898
public static function warning ( $ message , $ groupIdentifier = null ) { return static :: log ( self :: TYPE_WARNING , $ message , debug_backtrace ( false , 2 ) , $ groupIdentifier ) ; }
Log a warning message .
39,899
public function getCaption ( ) { if ( $ this -> _caption === null ) { if ( $ this -> getKey ( 'caption' , false ) ) { $ this -> _caption = $ this -> getKey ( 'caption' ) ; } else { $ this -> _caption = $ this -> file -> caption ; } } return $ this -> _caption ; }
Return the caption text for this image if not defined or none give its null .