idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
39,900
public function getSource ( $ scheme = false ) { if ( ! $ this -> getFileExists ( ) ) { if ( Yii :: $ app -> storage -> autoFixMissingImageSources === false ) { return false ; } $ apply = Yii :: $ app -> storage -> createImage ( $ this -> getFileId ( ) , $ this -> getFilterId ( ) ) ; } $ fileName = $ this -> getFilterId ( ) . '_' . $ this -> getFile ( ) -> getSystemFileName ( ) ; return $ scheme ? Yii :: $ app -> storage -> fileAbsoluteHttpPath ( $ fileName ) : Yii :: $ app -> storage -> fileHttpPath ( $ fileName ) ; }
Get the source path to the image location on the webserver .
39,901
public function getServerSource ( ) { return $ this -> getFile ( ) ? Yii :: $ app -> storage -> fileServerPath ( $ this -> systemFileName ) : false ; }
The source to the image internal used on the Server .
39,902
public function getFile ( ) { if ( $ this -> _file === null ) { $ this -> _file = Yii :: $ app -> storage -> getFile ( $ this -> getFileId ( ) ) ; } return $ this -> _file ; }
Get image depending file object where the image was create from its like the original Source
39,903
public function applyFilter ( $ filterName ) { return ( $ filterItem = Yii :: $ app -> storage -> getFiltersArrayItem ( $ filterName ) ) ? Yii :: $ app -> storage -> addImage ( $ this -> getFileId ( ) , $ filterItem [ 'id' ] , ! YII_ENV_PROD ) : false ; }
Apply a new filter for the original ussed file and return the new created image object .
39,904
public function bindPluginEvents ( Event $ event ) { foreach ( $ this -> plugins as $ field => $ plugin ) { $ plugin = self :: findPluginInstance ( $ field , $ plugin , $ event -> sender -> tableName ( ) ) ; foreach ( $ plugin -> events ( ) as $ on => $ handler ) { $ event -> sender -> on ( $ on , is_string ( $ handler ) ? [ $ plugin , $ handler ] : $ handler ) ; } } }
Bing all plugin Events to the corresponding Owner Object .
39,905
private static function findPluginInstance ( $ field , array $ plugin , $ tableName ) { if ( ! isset ( self :: $ _pluginInstances [ $ tableName ] [ $ field ] ) ) { self :: $ _pluginInstances [ $ tableName ] [ $ field ] = NgRest :: createPluginObject ( $ plugin [ 'type' ] [ 'class' ] , $ plugin [ 'name' ] , $ plugin [ 'alias' ] , $ plugin [ 'i18n' ] , $ plugin [ 'type' ] [ 'args' ] ) ; } return self :: $ _pluginInstances [ $ tableName ] [ $ field ] ; }
Singleton Container for Plugin Objects .
39,906
public function getTags ( ) { return $ this -> hasMany ( Tag :: class , [ 'id' => 'tag_id' ] ) -> viaTable ( '{{%admin_tag_relation}}' , [ 'pk_id' => 'id' ] , function ( $ query ) { $ query -> andWhere ( [ 'table_name' => static :: cleanBaseTableName ( static :: tableName ( ) ) ] ) ; } ) ; }
Returns all related tag for the current active record item .
39,907
public function i18nWhere ( $ field , $ value ) { $ lang = Yii :: $ app -> composition -> langShortCode ; return $ this -> andWhere ( [ "JSON_EXTRACT({$field}, \"$.{$lang}\")" => $ value ] ) ; }
Very basic where condition for i18n fields which use mysql s JSON_EXTRACT function .
39,908
public function inPool ( $ pool = null ) { if ( empty ( $ pool ) ) { return $ this ; } $ model = Yii :: createObject ( $ this -> modelClass ) ; if ( ! array_key_exists ( $ pool , $ model -> ngRestPools ( ) ) ) { throw new InvalidConfigException ( "The requested pool identifier '{$pool}' does not exist in the ngRestPools() definition." ) ; } return $ this -> andWhere ( $ model -> ngRestPools ( ) [ $ pool ] ) ; }
Add the pool where condition if a pool is given .
39,909
public function addPlugin ( $ name , array $ args ) { $ plugin = [ 'class' => $ name , 'args' => $ args ] ; $ this -> config [ $ this -> pointer ] [ $ this -> field ] [ 'type' ] = $ plugin ; return $ this ; }
Add a Plugin to the current field pointer plugins array .
39,910
public function field ( $ name , $ alias = null , $ i18n = false ) { $ this -> config [ $ this -> pointer ] [ $ name ] = [ 'name' => $ name , 'i18n' => $ i18n , 'alias' => ( is_null ( $ alias ) ) ? $ name : $ alias , 'type' => null , 'extraField' => false , ] ; $ this -> field = $ name ; return $ this ; }
Define a field .
39,911
public function load ( $ objectType ) { if ( $ this -> pointer !== 'aw' ) { throw new Exception ( 'Register method can only be used in a pointer context.' ) ; } $ object = Yii :: createObject ( $ objectType ) ; if ( is_string ( $ objectType ) ) { $ config [ 'class' ] = $ objectType ; } else { $ config = $ objectType ; } $ config [ 'ngRestModelClass' ] = $ this -> ngRestModelClass ; $ this -> config [ $ this -> pointer ] [ $ object -> getHashName ( ) ] = [ 'objectConfig' => $ config , 'label' => $ object -> getLabel ( ) , 'icon' => $ object -> getIcon ( ) , ] ; return $ this ; }
Creates a new active window object using the given configuration .
39,912
public function copyFrom ( $ key , $ removeFields = [ ] ) { $ temp = $ this -> config [ $ key ] ; foreach ( $ removeFields as $ name ) { if ( array_key_exists ( $ name , $ temp ) ) { unset ( $ temp [ $ name ] ) ; } } $ this -> config [ $ this -> pointer ] = ArrayHelper :: merge ( $ this -> config [ $ this -> pointer ] , $ temp ) ; }
Copy from a pointer into another with optional removal of fields the copie will applied to the current active pointer .
39,913
public function getModel ( ) { if ( ! is_object ( $ this -> _model ) ) { $ this -> _model = Yii :: createObject ( [ 'class' => $ this -> _model ] ) ; } return $ this -> _model ; }
Getter method for model .
39,914
private function getOptionsData ( $ event ) { $ items = [ ] ; foreach ( $ this -> model -> find ( ) -> asArray ( $ this -> asArray ) -> all ( ) as $ item ) { if ( is_callable ( $ this -> labelField , false ) ) { $ label = call_user_func ( $ this -> labelField , $ item ) ; } else { if ( $ this -> labelField === null ) { $ this -> labelField = array_keys ( $ item ) ; } $ array = ArrayHelper :: filter ( $ item , $ this -> labelField ) ; foreach ( $ array as $ key => $ value ) { if ( $ event -> sender -> isI18n ( $ key ) ) { $ array [ $ key ] = I18n :: decodeFindActive ( $ value ) ; } } $ label = $ this -> labelTemplate ? vsprintf ( $ this -> labelTemplate , $ array ) : implode ( ', ' , $ array ) ; } $ items [ ] = [ 'value' => ( int ) $ item [ $ this -> modelPrimaryKey ] , 'label' => $ label ] ; } return [ 'items' => $ items ] ; }
Get the options data to display .
39,915
protected function setRelation ( array $ value , $ viaTableName , $ localTableId , $ foreignTableId , $ activeRecordId ) { Yii :: $ app -> db -> createCommand ( ) -> delete ( $ viaTableName , [ $ localTableId => $ activeRecordId ] ) -> execute ( ) ; $ batch = [ ] ; foreach ( $ value as $ k => $ v ) { if ( is_array ( $ v ) ) { if ( isset ( $ v [ 'value' ] ) ) { $ batch [ ] = [ $ activeRecordId , $ v [ 'value' ] ] ; } } else { $ batch [ ] = [ $ activeRecordId , $ v ] ; } } if ( ! empty ( $ batch ) ) { Yii :: $ app -> db -> createCommand ( ) -> batchInsert ( $ viaTableName , [ $ localTableId , $ foreignTableId ] , $ batch ) -> execute ( ) ; } return true ; }
Set the relation data based on the configuration .
39,916
protected function getUserId ( ) { if ( Yii :: $ app -> has ( 'adminuser' ) && Yii :: $ app -> adminuser -> getIdentity ( ) ) { return Yii :: $ app -> adminuser -> id ; } return 0 ; }
Returns the user id for the current admin user if logged in and component is existsi .
39,917
protected function isLoggable ( ) { if ( Yii :: $ app instanceof Application && Yii :: $ app -> hasModule ( 'admin' ) && Yii :: $ app -> has ( 'adminuser' ) ) { return true ; } return false ; }
Method to ensure whether the current log process should be run or not as log behavior can also be attached the very universal models .
39,918
public function eventAfterDelete ( $ event ) { if ( $ this -> isLoggable ( ) ) { Yii :: $ app -> db -> createCommand ( ) -> insert ( '{{%admin_ngrest_log}}' , [ 'user_id' => $ this -> getUserId ( ) , 'timestamp_create' => time ( ) , 'route' => $ this -> route , 'api' => $ this -> api , 'is_insert' => false , 'is_update' => false , 'is_delete' => true , 'attributes_json' => $ this -> toJson ( $ event -> sender -> getAttributes ( ) ) , 'table_name' => $ event -> sender -> tableName ( ) , 'pk_value' => implode ( "-" , $ event -> sender -> getPrimaryKey ( true ) ) , ] ) -> execute ( ) ; } }
After delete event .
39,919
public function actionIndex ( ) { if ( ! Yii :: $ app -> adminuser -> isGuest ) { return $ this -> redirect ( [ '/admin/default/index' ] ) ; } $ this -> registerAsset ( Login :: class ) ; $ this -> view -> registerJs ( "$('#email').focus(); checkInputLabels(); observeLogin('#loginForm', '" . Url :: toAjax ( 'admin/login/async' ) . "', '" . Url :: toAjax ( 'admin/login/async-token' ) . "'); " ) ; UserOnline :: clearList ( $ this -> module -> userIdleTimeout ) ; return $ this -> render ( 'index' ) ; }
Login Form .
39,920
public function actionAsync ( ) { if ( ( $ lockout = $ this -> sessionBruteForceLock ( ) ) ) { return $ this -> sendArray ( false , [ Module :: t ( 'login_async_submission_limit_reached' , [ 'time' => Yii :: $ app -> formatter -> asRelativeTime ( $ lockout ) ] ) ] ) ; } $ model = new LoginForm ( ) ; $ model -> allowedAttempts = $ this -> module -> loginUserAttemptCount ; $ model -> lockoutTime = $ this -> module -> loginUserAttemptLockoutTime ; $ loginData = Yii :: $ app -> request -> post ( 'login' ) ; Yii :: $ app -> session -> remove ( 'secureId' ) ; if ( $ loginData ) { $ model -> attributes = $ loginData ; if ( ( $ userObject = $ model -> login ( ) ) !== false ) { if ( $ this -> module -> secureLogin ) { if ( $ model -> sendSecureLogin ( ) ) { Yii :: $ app -> session -> set ( 'secureId' , $ model -> getUser ( ) -> id ) ; return $ this -> sendArray ( false , [ ] , true ) ; } return $ this -> sendArray ( false , [ 'Unable to send and store secure token.' ] ) ; } if ( Yii :: $ app -> adminuser -> login ( $ userObject ) ) { return $ this -> sendArray ( true ) ; } } } return $ this -> sendArray ( false , $ model -> getErrors ( ) , false ) ; }
Async single sign in action .
39,921
public function actionAsyncToken ( ) { if ( ( $ lockout = $ this -> sessionBruteForceLock ( ) ) ) { return $ this -> sendArray ( false , [ Module :: t ( 'login_async_submission_limit_reached' , [ 'time' => Yii :: $ app -> formatter -> asRelativeTime ( $ lockout ) ] ) ] ) ; } $ secureToken = Yii :: $ app -> request -> post ( 'secure_token' , false ) ; $ model = new LoginForm ( ) ; $ model -> secureTokenExpirationTime = $ this -> module -> secureTokenExpirationTime ; if ( $ secureToken ) { $ user = $ model -> validateSecureToken ( $ secureToken , Yii :: $ app -> session -> get ( 'secureId' ) ) ; if ( $ user && Yii :: $ app -> adminuser -> login ( $ user ) ) { Yii :: $ app -> session -> remove ( 'secureId' ) ; return $ this -> sendArray ( true ) ; } return $ this -> sendArray ( false , [ Module :: t ( 'login_async_token_error' ) ] ) ; } return $ this -> sendArray ( false , [ Module :: t ( 'login_async_token_globalerror' ) ] ) ; }
Async Secure Token Login .
39,922
private function sendArray ( $ refresh , array $ errors = [ ] , $ enterSecureToken = false , $ message = null ) { Yii :: $ app -> response -> format = Response :: FORMAT_JSON ; return [ 'refresh' => $ refresh , 'message' => $ message , 'errors' => $ errors , 'enterSecureToken' => $ enterSecureToken , 'time' => time ( ) , ] ; }
Change the response format to json and return the array .
39,923
private function sessionBruteForceLock ( ) { $ attempt = Yii :: $ app -> session -> get ( '__attempt_count' , 0 ) ; $ counter = $ attempt + 1 ; Yii :: $ app -> session -> set ( '__attempt_count' , $ counter ) ; $ lockout = Yii :: $ app -> session -> get ( '__attempt_lockout' ) ; if ( $ lockout && $ lockout > time ( ) ) { Yii :: $ app -> session -> set ( '__attempt_count' , 0 ) ; return $ lockout ; } if ( $ counter >= $ this -> module -> loginSessionAttemptCount ) { Yii :: $ app -> session -> set ( '__attempt_lockout' , time ( ) + $ this -> module -> loginSessionAttemptLockoutTime ) ; } return false ; }
Ensure current brute force attempt based on session .
39,924
public function run ( $ id ) { $ model = $ this -> findModel ( $ id ) ; if ( $ this -> checkAccess ) { call_user_func ( $ this -> checkAccess , $ this -> id , $ model ) ; } if ( $ model -> delete ( ) === false ) { if ( $ model -> hasErrors ( ) ) { Yii :: $ app -> getResponse ( ) -> setStatusCode ( 422 ) ; $ errors = [ ] ; foreach ( $ model -> getErrors ( ) as $ field => $ errorMessages ) { foreach ( $ errorMessages as $ message ) { $ errors [ ] = [ 'field' => $ field , 'message' => $ message ] ; } } return $ errors ; } throw new ServerErrorHttpException ( 'Failed to delete the object for unknown reason.' ) ; } Yii :: $ app -> getResponse ( ) -> setStatusCode ( 204 ) ; }
Run the delete action with enhanced error checking methods .
39,925
protected function install ( $ object ) { $ model = Property :: find ( ) -> where ( [ 'var_name' => $ object -> varName ( ) ] ) -> one ( ) ; if ( $ model ) { $ model -> setAttributes ( [ 'module_name' => $ object -> moduleName , 'class_name' => $ object :: className ( ) , ] ) ; $ model -> update ( false ) ; return $ model -> id ; } else { $ model = new Property ( ) ; $ model -> setAttributes ( [ 'var_name' => $ object -> varName ( ) , 'module_name' => $ object -> moduleName , 'class_name' => $ object :: className ( ) , ] ) ; $ insert = $ model -> insert ( false ) ; if ( $ insert ) { return $ model -> id ; } } }
Installation of the property
39,926
public function getFilesArray ( ) { if ( $ this -> _filesArray === null ) { $ this -> _filesArray = $ this -> getQueryCacheHelper ( ( new Query ( ) ) -> from ( '{{%admin_storage_file}}' ) -> select ( [ 'id' , 'is_hidden' , 'is_deleted' , 'folder_id' , 'name_original' , 'name_new' , 'name_new_compound' , 'mime_type' , 'extension' , 'hash_name' , 'hash_file' , 'upload_timestamp' , 'file_size' , 'upload_user_id' , 'caption' ] ) -> indexBy ( 'id' ) , self :: CACHE_KEY_FILE ) ; } return $ this -> _filesArray ; }
Get all storage files as an array from database .
39,927
public function getFilesArrayItem ( $ fileId ) { return isset ( $ this -> filesArray [ $ fileId ] ) ? $ this -> filesArray [ $ fileId ] : false ; }
Get a single file by file id from the files array .
39,928
public function getImagesArray ( ) { if ( $ this -> _imagesArray === null ) { $ this -> _imagesArray = $ this -> getQueryCacheHelper ( ( new Query ( ) ) -> from ( '{{%admin_storage_image}}' ) -> select ( [ 'id' , 'file_id' , 'filter_id' , 'resolution_width' , 'resolution_height' ] ) -> indexBy ( 'id' ) , self :: CACHE_KEY_IMAGE ) ; } return $ this -> _imagesArray ; }
Get all storage images as an array from database .
39,929
public function getImagesArrayItem ( $ imageId ) { return isset ( $ this -> imagesArray [ $ imageId ] ) ? $ this -> imagesArray [ $ imageId ] : false ; }
Get a single image by image id from the files array .
39,930
public function ensureFileUpload ( $ fileSource , $ fileName ) { if ( empty ( $ fileSource ) || empty ( $ fileName ) ) { throw new Exception ( "Filename and source can not be empty." ) ; } if ( $ fileName == 'blob' ) { $ ext = FileHelper :: getExtensionsByMimeType ( FileHelper :: getMimeType ( $ fileSource ) ) ; $ fileName = 'paste-' . date ( "Y-m-d-H-i" ) . '.' . $ ext [ 0 ] ; } $ fileInfo = FileHelper :: getFileInfo ( $ fileName ) ; $ mimeType = FileHelper :: getMimeType ( $ fileSource , null , ! $ this -> secureFileUpload ) ; if ( empty ( $ mimeType ) ) { throw new Exception ( "Unable to find mimeType for the given file, make sure the php extension 'fileinfo' is installed." ) ; } $ extensionsFromMimeType = FileHelper :: getExtensionsByMimeType ( $ mimeType ) ; if ( empty ( $ extensionsFromMimeType ) && empty ( $ this -> whitelistExtensions ) ) { throw new Exception ( "Unable to find extension for given mimeType \"{$mimeType}\" or it contains insecure data." ) ; } if ( ! empty ( $ this -> whitelistExtensions ) ) { $ extensionsFromMimeType = array_merge ( $ extensionsFromMimeType , $ this -> whitelistExtensions ) ; } if ( ! in_array ( $ fileInfo -> extension , $ extensionsFromMimeType ) && ! in_array ( $ mimeType , $ this -> whitelistMimeTypes ) ) { throw new Exception ( "The given file extension \"{$fileInfo->extension}\" for file with mimeType \"{$mimeType}\" is not matching any valid extension: " . VarDumper :: dumpAsString ( $ extensionsFromMimeType ) . "." ) ; } foreach ( $ extensionsFromMimeType as $ extension ) { if ( in_array ( $ extension , $ this -> dangerousExtensions ) ) { throw new Exception ( "The file extension '{$extension}' seems to be dangerous and can not be stored." ) ; } } if ( in_array ( $ mimeType , $ this -> dangerousMimeTypes ) && ! in_array ( $ mimeType , $ this -> whitelistMimeTypes ) ) { throw new Exception ( "The file mimeType '{$mimeType}' seems to be dangerous and can not be stored." ) ; } return [ 'fileInfo' => $ fileInfo , 'mimeType' => $ mimeType , 'fileName' => $ fileName , 'secureFileName' => Inflector :: slug ( str_replace ( '_' , '-' , $ fileInfo -> name ) , '-' ) , 'fileSource' => $ fileSource , 'fileSize' => filesize ( $ fileSource ) , 'extension' => $ fileInfo -> extension , 'hashName' => FileHelper :: hashName ( $ fileName ) , ] ; }
Ensure a file uploads and return relevant file infos .
39,931
public function addFile ( $ fileSource , $ fileName , $ folderId = 0 , $ isHidden = false ) { $ fileData = $ this -> ensureFileUpload ( $ fileSource , $ fileName ) ; $ fileHash = FileHelper :: md5sum ( $ fileSource ) ; $ newName = implode ( [ $ fileData [ 'secureFileName' ] . '_' . $ fileData [ 'hashName' ] , $ fileData [ 'extension' ] ] , '.' ) ; if ( ! $ this -> fileSystemSaveFile ( $ fileSource , $ newName ) ) { return false ; } $ model = new StorageFile ( ) ; $ model -> setAttributes ( [ 'name_original' => $ fileName , 'name_new' => $ fileData [ 'secureFileName' ] , 'name_new_compound' => $ newName , 'mime_type' => $ fileData [ 'mimeType' ] , 'extension' => $ fileData [ 'extension' ] , 'folder_id' => ( int ) $ folderId , 'hash_file' => $ fileHash , 'hash_name' => $ fileData [ 'hashName' ] , 'is_hidden' => $ isHidden ? true : false , 'is_deleted' => false , 'file_size' => $ fileData [ 'fileSize' ] , 'caption' => null , ] ) ; if ( $ model -> validate ( ) ) { if ( $ model -> save ( ) ) { $ this -> deleteHasCache ( self :: CACHE_KEY_FILE ) ; $ this -> _filesArray [ $ model -> id ] = $ model -> toArray ( ) ; return $ this -> getFile ( $ model -> id ) ; } } return false ; }
Add a new file based on the source to the storage system .
39,932
public function addImage ( $ fileId , $ filterId = 0 , $ throwException = false ) { try { if ( is_string ( $ filterId ) && ! is_numeric ( $ filterId ) ) { $ filterLookup = $ this -> getFiltersArrayItem ( $ filterId ) ; if ( ! $ filterLookup ) { throw new Exception ( "The provided filter name " . $ filterId . " does not exist." ) ; } $ filterId = $ filterLookup [ 'id' ] ; } $ query = ( new \ luya \ admin \ image \ Query ( ) ) -> where ( [ 'file_id' => $ fileId , 'filter_id' => $ filterId ] ) -> one ( ) ; if ( $ query && $ query -> fileExists ) { return $ query ; } $ fileQuery = $ this -> getFile ( $ fileId ) ; if ( ! $ fileQuery || ! $ fileQuery -> fileExists ) { if ( $ fileQuery !== false ) { throw new Exception ( "Unable to create image, the base file server source '{$fileQuery->serverSource}' does not exist." ) ; } throw new Exception ( "Unable to find the file with id '{$fileId}', image can not be created." ) ; } $ model = $ this -> createImage ( $ fileId , $ filterId ) ; if ( ! $ model ) { throw new Exception ( "Unable to create the image on the filesystem." ) ; } $ this -> _imagesArray [ $ model -> id ] = $ model -> toArray ( ) ; $ this -> deleteHasCache ( self :: CACHE_KEY_IMAGE ) ; return $ this -> getImage ( $ model -> id ) ; } catch ( \ Exception $ err ) { if ( $ throwException ) { throw $ err ; } } return false ; }
Add a new image based an existing file Id .
39,933
public function createImage ( $ fileId , $ filterId ) { $ image = StorageImage :: find ( ) -> where ( [ 'file_id' => $ fileId , 'filter_id' => $ filterId ] ) -> one ( ) ; if ( $ image && $ image -> fileExists ) { return $ image ; } $ file = StorageFile :: findOne ( $ fileId ) ; if ( ! $ file ) { return false ; } $ fileName = $ filterId . '_' . $ file -> name_new_compound ; $ fromTempFile = tempnam ( sys_get_temp_dir ( ) , 'fromFile' ) ; $ fromTempFile .= $ fileName ; $ content = $ file -> getContent ( ) ; if ( $ content === false ) { return false ; } $ writeFile = FileHelper :: writeFile ( $ fromTempFile , $ content ) ; if ( ! $ writeFile ) { return false ; } $ tempFile = tempnam ( sys_get_temp_dir ( ) , 'destFile' ) ; $ tempFile .= $ fileName ; if ( empty ( $ filterId ) ) { @ copy ( $ fromTempFile , $ tempFile ) ; } else { $ filter = StorageFilter :: findOne ( $ filterId ) ; if ( ! $ filter || ! $ filter -> applyFilterChain ( $ fromTempFile , $ tempFile ) ) { return false ; } } $ resolution = Storage :: getImageResolution ( $ tempFile ) ; $ this -> fileSystemSaveFile ( $ tempFile , $ fileName ) ; unlink ( $ tempFile ) ; unlink ( $ fromTempFile ) ; $ this -> flushImageArray ( ) ; if ( $ image ) { $ image -> resolution_height = $ resolution [ 'height' ] ; $ image -> resolution_width = $ resolution [ 'width' ] ; $ image -> save ( ) ; return $ image ; } $ image = new StorageImage ( ) ; $ image -> file_id = $ fileId ; $ image -> filter_id = $ filterId ; $ image -> resolution_height = $ resolution [ 'height' ] ; $ image -> resolution_width = $ resolution [ 'width' ] ; if ( ! $ image -> save ( ) ) { return false ; } return $ image ; }
Just creating the image based on input informations without usage of storage files or images list .
39,934
public function getFoldersArray ( ) { if ( $ this -> _foldersArray === null ) { $ query = ( new Query ( ) ) -> from ( '{{%admin_storage_folder}} as folder' ) -> select ( [ 'folder.id' , 'name' , 'parent_id' , 'timestamp_create' , 'COUNT(file.id) filesCount' ] ) -> where ( [ 'folder.is_deleted' => false ] ) -> orderBy ( [ 'name' => 'ASC' ] ) -> leftJoin ( '{{%admin_storage_file}} as file' , 'folder.id=file.folder_id AND file.is_deleted = 0' ) -> groupBy ( [ 'folder.id' ] ) -> indexBy ( [ 'id' ] ) ; $ this -> _foldersArray = $ this -> getQueryCacheHelper ( $ query , self :: CACHE_KEY_FOLDER ) ; } return $ this -> _foldersArray ; }
Get all storage folders as an array from database .
39,935
public function getFoldersArrayItem ( $ folderId ) { return ( isset ( $ this -> foldersArray [ $ folderId ] ) ) ? $ this -> foldersArray [ $ folderId ] : false ; }
Get a single folder by folder id from the folders array .
39,936
public function addFolder ( $ folderName , $ parentFolderId = 0 ) { $ model = new StorageFolder ( ) ; $ model -> name = $ folderName ; $ model -> parent_id = $ parentFolderId ; $ model -> timestamp_create = time ( ) ; $ this -> deleteHasCache ( self :: CACHE_KEY_FOLDER ) ; if ( $ model -> save ( false ) ) { return $ model -> id ; } return false ; }
Add new folder to the storage system .
39,937
public function getFiltersArray ( ) { if ( $ this -> _filtersArray === null ) { $ this -> _filtersArray = $ this -> getQueryCacheHelper ( ( new Query ( ) ) -> from ( '{{%admin_storage_filter}}' ) -> select ( [ 'id' , 'identifier' , 'name' ] ) -> indexBy ( 'identifier' ) -> orderBy ( [ 'name' => SORT_ASC ] ) , self :: CACHE_KEY_FILTER ) ; } return $ this -> _filtersArray ; }
Get all storage filters as an array from database .
39,938
public function getFiltersArrayItem ( $ filterIdentifier ) { return isset ( $ this -> filtersArray [ $ filterIdentifier ] ) ? $ this -> filtersArray [ $ filterIdentifier ] : false ; }
Get a single filter by filter identifier from the filters array .
39,939
public function getFilterId ( $ identifier ) { $ filter = $ this -> getFiltersArrayItem ( $ identifier ) ; return $ filter ? ( int ) $ filter [ 'id' ] : false ; }
Get the filter id based on the identifier .
39,940
private function getQueryCacheHelper ( \ yii \ db \ Query $ query , $ key ) { $ data = $ this -> getHasCache ( $ key ) ; if ( $ data === false ) { $ data = $ query -> all ( ) ; $ this -> setHasCache ( $ key , $ data ) ; } return $ data ; }
Caching helper method .
39,941
public function flushArrays ( ) { $ this -> _filesArray = null ; $ this -> _imagesArray = null ; $ this -> _foldersArray = null ; $ this -> _filtersArray = null ; $ this -> deleteHasCache ( self :: CACHE_KEY_FILE ) ; $ this -> deleteHasCache ( self :: CACHE_KEY_IMAGE ) ; $ this -> deleteHasCache ( self :: CACHE_KEY_FOLDER ) ; $ this -> deleteHasCache ( self :: CACHE_KEY_FILTER ) ; }
Will force to refresh all container arrays and clean up the cache
39,942
public function processThumbnails ( ) { foreach ( $ this -> findFiles ( [ 'is_hidden' => false , 'is_deleted' => false ] ) as $ file ) { if ( $ file -> isImage ) { $ this -> createImage ( $ file -> id , $ this -> getFilterId ( TinyCrop :: identifier ( ) ) ) ; $ this -> createImage ( $ file -> id , $ this -> getFilterId ( MediumThumbnail :: identifier ( ) ) ) ; } } $ this -> autoFixMissingImageSources = true ; foreach ( $ this -> findImages ( ) as $ image ) { if ( ! empty ( $ image -> file ) && ! $ image -> file -> isHidden && ! $ image -> file -> isDeleted ) { $ image -> source ; } } return true ; }
This method allwos you to generate all thumbnails for the file manager you can trigger this process when importing or creating several images at once so the user does not have to create the thumbnails
39,943
public function node ( $ name , $ icon , $ template = false ) { $ this -> _pointers [ 'node' ] = self :: $ index ; $ this -> _menu [ self :: $ index ] = [ 'id' => self :: $ index , 'moduleId' => $ this -> moduleContext -> id , 'template' => $ template , 'routing' => $ template ? 'custom' : 'default' , 'alias' => $ name , 'icon' => $ icon , 'permissionRoute' => false , 'permissionIsRoute' => false , 'searchModelClass' => false , ] ; self :: $ index ++ ; return $ this ; }
The node is the menu entry in the TOP navigation of the luya administration interface .
39,944
public function nodeRoute ( $ name , $ icon , $ route , $ searchModelClass = null ) { $ this -> _pointers [ 'node' ] = self :: $ index ; $ this -> _menu [ self :: $ index ] = [ 'id' => self :: $ index , 'moduleId' => $ this -> moduleContext -> id , 'template' => $ route , 'routing' => 'custom' , 'alias' => $ name , 'icon' => $ icon , 'permissionRoute' => $ route , 'permissionIsRoute' => true , 'searchModelClass' => $ searchModelClass , ] ; $ this -> _permissionRoutes [ ] = [ 'route' => $ route , 'alias' => $ name ] ; self :: $ index ++ ; return $ this ; }
A node which is a custom route to open nodes are the the top menu of the luya administration interfaces .
39,945
public function itemApi ( $ name , $ route , $ icon , $ apiEndpoint , array $ options = [ ] ) { $ item = [ 'alias' => $ name , 'route' => $ route , 'icon' => $ icon , 'permissionApiEndpoint' => $ apiEndpoint , 'permissionIsRoute' => false , 'permissionIsApi' => true , 'searchModelClass' => false , 'options' => $ this -> verifyOptions ( $ options ) , ] ; $ this -> _menu [ $ this -> _pointers [ 'node' ] ] [ 'groups' ] [ $ this -> _pointers [ 'group' ] ] [ 'items' ] [ ] = $ item ; $ this -> _permissionApis [ ] = [ 'api' => $ apiEndpoint , 'alias' => $ name , 'pool' => $ this -> getOptionValue ( $ item , 'pool' , null ) ] ; return $ this ; }
Add an item to a group . API items are based on the ngrest crud concept .
39,946
public function itemPoolApi ( $ name , $ route , $ icon , $ apiEndpoint , $ pool , array $ options = [ ] ) { return $ this -> itemApi ( $ name , $ route , $ icon , $ apiEndpoint , array_merge ( $ options , [ 'pool' => $ pool , ] ) ) ; }
Generate a permission for an API with a Pool
39,947
public function itemRoute ( $ name , $ route , $ icon , $ searchModelClass = null , array $ options = [ ] ) { $ this -> _menu [ $ this -> _pointers [ 'node' ] ] [ 'groups' ] [ $ this -> _pointers [ 'group' ] ] [ 'items' ] [ ] = [ 'alias' => $ name , 'route' => $ route , 'icon' => $ icon , 'permissionApiEndpoint' => null , 'permissionIsRoute' => true , 'permissionIsApi' => false , 'searchModelClass' => $ searchModelClass , 'options' => $ this -> verifyOptions ( $ options ) , ] ; $ this -> _permissionRoutes [ ] = [ 'route' => $ route , 'alias' => $ name ] ; return $ this ; }
Add an item to a group . Route items opens a angular view .
39,948
protected function verifyOptions ( array $ options = [ ] ) { foreach ( $ options as $ key => $ value ) { if ( ! in_array ( $ key , static :: $ options ) ) { unset ( $ options [ $ key ] ) ; } } return $ options ; }
Verify the additional options of an itemRoute or itemApi item .
39,949
public static function getOptionValue ( array $ item , $ optionName , $ defaultValue = false ) { if ( ! isset ( $ item [ 'options' ] ) ) { return $ defaultValue ; } return isset ( $ item [ 'options' ] [ $ optionName ] ) ? $ item [ 'options' ] [ $ optionName ] : $ defaultValue ; }
Helper method to get then value of an options inside an item .
39,950
public function getSortField ( ) { if ( $ this -> _sortField === false ) { return [ ] ; } if ( $ this -> _sortField ) { if ( is_array ( $ this -> _sortField ) ) { return [ $ this -> name => $ this -> _sortField ] ; } return [ $ this -> name => [ 'asc' => [ $ this -> _sortField => SORT_ASC ] , 'desc' => [ $ this -> _sortField => SORT_DESC ] ] ] ; } return [ $ this -> name ] ; }
Getter method for a sortField defintion .
39,951
public function getNgShowCondition ( $ ngModel ) { preg_match_all ( '/{(.*?)}/' , $ this -> condition , $ matches , PREG_SET_ORDER ) ; $ search = [ ] ; $ replace = [ ] ; foreach ( $ matches as $ match ) { $ search [ ] = $ match [ 0 ] ; $ replace [ ] = $ this -> replaceFieldFromNgModelContext ( $ ngModel , $ match [ 1 ] ) ; } return str_replace ( $ search , $ replace , $ this -> condition ) ; }
Get the ng - show condition from a given ngModel context .
39,952
public function createFormTag ( $ name , $ id , $ ngModel , array $ options = [ ] ) { $ defaultOptions = [ 'fieldid' => $ id , 'model' => $ ngModel , 'label' => $ this -> alias , 'fieldname' => $ this -> name , 'i18n' => $ this -> i18n ? 1 : '' , ] ; if ( $ this -> condition ) { $ defaultOptions [ 'ng-show' ] = $ this -> getNgShowCondition ( $ ngModel ) ; } return $ this -> createTag ( $ name , null , array_merge ( $ options , $ defaultOptions ) ) ; }
Helper method to create a form tag based on current object .
39,953
public function createListTag ( $ ngModel , array $ options = [ ] ) { return $ this -> createTag ( 'span' , null , ArrayHelper :: merge ( [ 'ng-bind' => $ ngModel ] , $ options ) ) ; }
Helper method to create a span tag with the ng - model in angular context for the crud overview
39,954
public function createCrudLoaderTag ( $ ngrestModelClass , $ ngRestModelSelectMode = null , array $ options = [ ] ) { $ menu = Yii :: $ app -> adminmenu -> getApiDetail ( $ ngrestModelClass :: ngRestApiEndpoint ( ) , Yii :: $ app -> request -> get ( 'pool' ) ) ; if ( $ menu ) { if ( $ ngRestModelSelectMode ) { $ options [ 'model-setter' ] = $ ngRestModelSelectMode ; $ options [ 'model-selection' ] = 1 ; } else { $ options [ 'model-selection' ] = 0 ; } return $ this -> createTag ( 'crud-loader' , null , array_merge ( [ 'api' => $ menu [ 'route' ] , 'alias' => $ menu [ 'alias' ] ] , $ options ) ) ; } return null ; }
Create a tag for relation window toggler with directive crudLoader based on a ngrest model class .
39,955
public function createSchedulerListTag ( $ ngModel , $ values , $ dataRow , array $ options = [ ] ) { return $ this -> createTag ( 'luya-schedule' , null , array_merge ( [ 'value' => $ ngModel , 'model-class' => get_class ( $ this -> renderContext -> getModel ( ) ) , 'title' => $ this -> alias , 'attribute-name' => $ this -> name , 'attribute-values' => Angular :: optionsArrayInput ( $ values ) , 'primary-key-value' => 'getRowPrimaryValue(' . $ dataRow . ')' , ] , $ options ) ) ; }
Create the Scheulder tag for a given field .
39,956
public function onSave ( $ event ) { if ( $ this -> isAttributeWriteable ( $ event ) && $ this -> onBeforeSave ( $ event ) ) { if ( $ this -> i18n ) { $ event -> sender -> setAttribute ( $ this -> name , $ this -> i18nFieldEncode ( $ event -> sender -> getAttribute ( $ this -> name ) ) ) ; } } }
This event will be triggered onSave event . If the model property is not writeable the event will not trigger .
39,957
public function onListFind ( $ event ) { if ( $ this -> isAttributeWriteable ( $ event ) && $ this -> onBeforeListFind ( $ event ) ) { if ( $ this -> i18n ) { $ event -> sender -> setAttribute ( $ this -> name , $ this -> i18nDecodedGetActive ( $ this -> i18nFieldDecode ( $ event -> sender -> getAttribute ( $ this -> name ) , $ this -> i18nEmptyValue ) ) ) ; } $ this -> onAfterListFind ( $ event ) ; } }
This event is only trigger when returning the ngrest crud list data . If the property of this plugin inside the model the event will not be triggered .
39,958
public function onFind ( $ event ) { if ( $ this -> isAttributeWriteable ( $ event ) && $ this -> onBeforeFind ( $ event ) ) { if ( $ this -> i18n ) { $ event -> sender -> setAttribute ( $ this -> name , $ this -> i18nDecodedGetActive ( $ this -> i18nFieldDecode ( $ event -> sender -> getAttribute ( $ this -> name ) , $ this -> i18nEmptyValue ) ) ) ; } $ this -> onAfterFind ( $ event ) ; } }
ActiveRecord afterFind event . If the property of this plugin inside the model the event will not be triggered .
39,959
public function onCollectServiceData ( $ event ) { if ( $ this -> onBeforeCollectServiceData ( $ event ) ) { $ data = $ this -> serviceData ( $ event ) ; if ( ! empty ( $ data ) ) { $ event -> sender -> addNgRestServiceData ( $ this -> name , $ data ) ; } } }
The ngrest services collector .
39,960
protected function isAttributeWriteable ( $ event ) { return ( $ event -> sender -> hasAttribute ( $ this -> name ) || $ event -> sender -> canSetProperty ( $ this -> name ) ) ; }
Check whether the current plugin attribute is writeable in the Model class or not . If not writeable some events will be stopped from further processing . This is mainly used when adding extraFields to the grid list view .
39,961
protected function writeAttribute ( $ event , $ value ) { $ property = $ this -> name ; $ event -> sender -> { $ property } = $ value ; }
Write a value to a plugin attribute or property .
39,962
public static function decode ( $ value , $ onEmptyValue = '' ) { $ languages = Yii :: $ app -> adminLanguage -> getLanguages ( ) ; if ( ! is_array ( $ value ) && ! empty ( $ value ) ) { try { $ value = Json :: decode ( $ value ) ; } catch ( InvalidParamException $ e ) { $ value = [ ] ; } } if ( empty ( $ value ) ) { $ value = [ ] ; } if ( ! is_array ( $ value ) ) { $ value = ( array ) $ value ; } foreach ( $ languages as $ lang ) { if ( ! array_key_exists ( $ lang [ 'short_code' ] , $ value ) ) { $ value [ $ lang [ 'short_code' ] ] = $ onEmptyValue ; } elseif ( empty ( $ value [ $ lang [ 'short_code' ] ] ) ) { $ value [ $ lang [ 'short_code' ] ] = $ onEmptyValue ; } } return $ value ; }
Decode from Json to PHP
39,963
public static function decodeArray ( array $ array , $ onEmptyValue = '' ) { $ decoded = [ ] ; foreach ( $ array as $ key => $ value ) { $ decoded [ $ key ] = static :: decode ( $ value , $ onEmptyValue ) ; } return $ decoded ; }
Decode an array with i18n values .
39,964
public static function decodeFindActive ( $ input , $ onEmptyValue = '' , $ lang = null ) { return static :: findActive ( static :: decode ( $ input , $ onEmptyValue ) , $ onEmptyValue , $ lang ) ; }
Decodes a json string and returns the current active language item .
39,965
public static function decodeFindActiveArray ( array $ input , $ onEmptyValue = '' , $ lang = null ) { return static :: findActiveArray ( static :: decodeArray ( $ input , $ onEmptyValue ) , $ onEmptyValue , $ lang ) ; }
Decodes an array with json strings and returns the current active language item for each entry .
39,966
public static function findActive ( array $ fieldValues , $ onEmptyValue = '' , $ lang = null ) { $ langShortCode = $ lang ? $ lang : Yii :: $ app -> adminLanguage -> getActiveShortCode ( ) ; return array_key_exists ( $ langShortCode , $ fieldValues ) ? $ fieldValues [ $ langShortCode ] : $ onEmptyValue ; }
Find the corresponding element inside an array for the current active language .
39,967
public static function findActiveArray ( array $ array , $ onEmptyValue = '' , $ lang = null ) { $ output = [ ] ; foreach ( $ array as $ key => $ value ) { $ output [ $ key ] = static :: findActive ( $ value , $ onEmptyValue , $ lang ) ; } return $ output ; }
Find the corresponding element inside an array for the current active language
39,968
public function actionItems ( $ nodeId ) { UserOnline :: unlock ( Yii :: $ app -> adminuser -> id ) ; return Yii :: $ app -> adminmenu -> getModuleItems ( $ nodeId ) ; }
The items action returns all items for a given node .
39,969
public function actionDashboard ( $ nodeId ) { $ data = Yii :: $ app -> adminmenu -> getNodeData ( $ nodeId ) ; $ accessList = [ ] ; if ( ! isset ( $ data [ 'groups' ] ) ) { return [ ] ; } foreach ( $ data [ 'groups' ] as $ groupkey => $ groupvalue ) { foreach ( $ groupvalue [ 'items' ] as $ row ) { if ( $ row [ 'permissionIsApi' ] ) { try { $ row [ 'alias' ] = Yii :: t ( $ data [ 'moduleId' ] , $ row [ 'alias' ] , [ ] , Yii :: $ app -> language ) ; } catch ( \ Exception $ e ) { } $ accessList [ ] = $ row ; } } } $ log = [ ] ; foreach ( $ accessList as $ access ) { $ data = ( new Query ( ) ) -> select ( [ 'timestamp_create' , 'user_id' , 'admin_ngrest_log.id' , 'is_update' , 'is_delete' , 'is_insert' , 'admin_user.firstname' , 'admin_user.lastname' ] ) -> from ( '{{%admin_ngrest_log}}' ) -> leftJoin ( '{{%admin_user}}' , '{{%admin_ngrest_log}}.user_id = {{%admin_user}}.id' ) -> orderBy ( 'timestamp_create DESC' ) -> limit ( 30 ) -> where ( 'api=:api and user_id!=0' , [ ':api' => $ access [ 'permissionApiEndpoint' ] ] ) -> all ( ) ; foreach ( $ data as $ row ) { $ date = mktime ( 0 , 0 , 0 , date ( 'n' , $ row [ 'timestamp_create' ] ) , date ( 'j' , $ row [ 'timestamp_create' ] ) , date ( 'Y' , $ row [ 'timestamp_create' ] ) ) ; if ( $ row [ 'is_update' ] ) { $ message = Module :: t ( 'dashboard_log_message_edit' , [ 'container' => $ access [ 'alias' ] ] ) ; } elseif ( $ row [ 'is_insert' ] ) { $ message = Module :: t ( 'dashboard_log_message_add' , [ 'container' => $ access [ 'alias' ] ] ) ; } elseif ( $ row [ 'is_delete' ] ) { $ message = Module :: t ( 'dashboard_log_message_delete' , [ 'container' => $ access [ 'alias' ] ] ) ; } $ log [ $ date ] [ ] = [ 'name' => $ row [ 'firstname' ] . ' ' . $ row [ 'lastname' ] , 'is_update' => $ row [ 'is_update' ] , 'is_insert' => $ row [ 'is_insert' ] , 'is_delete' => $ row [ 'is_delete' ] , 'timestamp' => $ row [ 'timestamp_create' ] , 'alias' => $ access [ 'alias' ] , 'message' => $ message , 'icon' => $ access [ 'icon' ] , ] ; } } $ array = [ ] ; krsort ( $ log , SORT_NUMERIC ) ; foreach ( $ log as $ day => $ values ) { $ array [ ] = [ 'day' => $ day , 'items' => $ values , ] ; } return $ array ; }
Get all dashabord items for a given node .
39,970
public function hasChild ( ) { return ( ( new \ luya \ admin \ folder \ Query ( ) ) -> where ( [ 'is_deleted' => 0 , 'parent_id' => $ this -> getId ( ) ] ) -> count ( ) > 0 ? true : false ) ; }
Whether the current folder has at least one child folder .
39,971
public function getParent ( ) { return ( ! empty ( $ this -> getParentId ( ) ) ) ? Yii :: $ app -> storage -> getFolder ( $ this -> getParentId ( ) ) : false ; }
Get the parent folder object .
39,972
public function getKey ( $ key , $ exception = true ) { if ( ! array_key_exists ( $ key , $ this -> _itemArray ) ) { if ( $ exception ) { throw new Exception ( "Unable to find the requested item key '$key' in item " . var_export ( $ this -> _itemArray , true ) ) ; } else { return false ; } } return $ this -> _itemArray [ $ key ] ; }
Returns a value for a given key inside the itemArray .
39,973
public function getWithRelation ( $ actionName ) { $ rel = $ this -> withRelations ( ) ; $ expand = Yii :: $ app -> request -> get ( 'expand' , null ) ; $ relationPrefixes = [ ] ; foreach ( StringHelper :: explode ( $ expand , ',' , true , true ) as $ relation ) { $ relationPrefixes [ ] = current ( explode ( "." , $ relation ) ) ; } if ( empty ( $ relationPrefixes ) ) { return [ ] ; } foreach ( $ rel as $ relationName ) { if ( is_array ( $ relationName ) && isset ( $ rel [ $ actionName ] ) ) { return $ this -> relationsFromExpand ( $ rel [ $ actionName ] , $ relationPrefixes ) ; } } return $ this -> relationsFromExpand ( $ rel , $ relationPrefixes ) ; }
Get the relations for the corresponding action name .
39,974
private function relationsFromExpand ( array $ relations , array $ expandPrefixes ) { $ valid = [ ] ; foreach ( $ expandPrefixes as $ prefix ) { foreach ( $ relations as $ relation ) { if ( StringHelper :: startsWith ( $ relation , $ prefix ) ) { $ valid [ ] = $ relation ; } } } return $ valid ; }
Ensure if the expand prefix exists in the relation .
39,975
public function prepareListQuery ( ) { $ modelClass = $ this -> modelClass ; $ find = $ modelClass :: ngRestFind ( ) ; $ this -> appendPoolWhereCondition ( $ find ) ; $ tagIds = Yii :: $ app -> request -> get ( 'tags' ) ; if ( $ tagIds ) { $ subQuery = clone $ find ; $ inQuery = $ subQuery -> joinWith ( [ 'tags tags' ] ) -> andWhere ( [ 'tags.id' => array_unique ( explode ( "," , $ tagIds ) ) ] ) -> select ( [ 'pk_id' ] ) ; $ find -> andWhere ( [ 'in' , $ modelClass :: primaryKey ( ) , $ inQuery ] ) ; } return $ find -> with ( $ this -> getWithRelation ( 'list' ) ) ; }
Prepare the NgRest List Query .
39,976
public function findModel ( $ id ) { $ model = $ this -> findModelClassObject ( $ this -> modelClass , $ id , 'view' ) ; if ( ! $ model ) { throw new NotFoundHttpException ( "Unable to find the Model for the given ID" ) ; } return $ model ; }
Get the Model for the API based on a given Id .
39,977
public function findModelClassObject ( $ modelClass , $ id , $ relationContext ) { $ keys = $ modelClass :: primaryKey ( ) ; if ( count ( $ keys ) > 1 ) { $ values = explode ( ',' , $ id ) ; if ( count ( $ keys ) === count ( $ values ) ) { return $ this -> findModelFromCondition ( array_combine ( $ keys , $ values ) , $ keys , $ modelClass , $ relationContext ) ; } } elseif ( $ id !== null ) { return $ this -> findModelFromCondition ( $ id , $ keys , $ modelClass , $ relationContext ) ; } return false ; }
Find the model for a given class and id .
39,978
public function actionServices ( ) { $ this -> checkAccess ( 'services' ) ; $ settings = [ ] ; $ apiEndpoint = $ this -> model -> ngRestApiEndpoint ( ) ; $ userSortSettings = Yii :: $ app -> adminuser -> identity -> setting -> get ( 'ngrestorder.admin/' . $ apiEndpoint , false ) ; if ( $ userSortSettings && is_array ( $ userSortSettings ) ) { if ( $ userSortSettings [ 'sort' ] == SORT_DESC ) { $ order = '-' . $ userSortSettings [ 'field' ] ; } else { $ order = '+' . $ userSortSettings [ 'field' ] ; } $ settings [ 'order' ] = $ order ; } $ userFilter = Yii :: $ app -> adminuser -> identity -> setting -> get ( 'ngrestfilter.admin/' . $ apiEndpoint , false ) ; if ( $ userFilter ) { $ settings [ 'filterName' ] = $ userFilter ; } $ modelClass = $ this -> modelClass ; if ( ObjectHelper :: isTraitInstanceOf ( $ this -> model , TaggableTrait :: class ) ) { $ tags = $ this -> model -> findTags ( ) ; } else { $ tags = false ; } return [ 'service' => $ this -> model -> getNgRestServices ( ) , '_tags' => $ tags , '_hints' => $ this -> model -> attributeHints ( ) , '_settings' => $ settings , '_locked' => [ 'data' => UserOnline :: find ( ) -> select ( [ 'lock_pk' , 'last_timestamp' , 'u.firstname' , 'u.lastname' , 'u.id' ] ) -> joinWith ( 'user as u' ) -> where ( [ 'lock_table' => $ modelClass :: tableName ( ) ] ) -> createCommand ( ) -> queryAll ( ) , 'userId' => Yii :: $ app -> adminuser -> id , ] , ] ; }
Service Action provides mutliple CRUD informations .
39,979
public function actionSearch ( $ query = null ) { $ this -> checkAccess ( 'search' ) ; if ( empty ( $ query ) ) { $ query = Yii :: $ app -> request -> post ( 'query' ) ; } $ find = $ this -> model -> ngRestFullQuerySearch ( $ query ) ; return new ActiveDataProvider ( [ 'query' => $ find -> with ( $ this -> getWithRelation ( 'search' ) ) , 'pagination' => $ this -> pagination , 'sort' => [ 'attributes' => $ this -> generateSortAttributes ( $ this -> model -> getNgRestConfig ( ) ) , ] ] ) ; }
Generate a response with pagination disabled .
39,980
public function generateSortAttributes ( Config $ config ) { $ sortAttributes = [ ] ; foreach ( $ config -> getPointerPlugins ( 'list' ) as $ plugin ) { $ sortAttributes = ArrayHelper :: merge ( $ plugin -> getSortField ( ) , $ sortAttributes ) ; } return $ sortAttributes ; }
Generate an array of sortable attribute defintions from a ngrest config object .
39,981
public function actionRelationCall ( $ arrayIndex , $ id , $ modelClass , $ query = null ) { $ this -> checkAccess ( 'relation-call' ) ; $ modelClass = base64_decode ( $ modelClass ) ; $ model = $ modelClass :: findOne ( ( int ) $ id ) ; if ( ! $ model ) { throw new InvalidCallException ( "Unable to resolve relation call model." ) ; } $ relation = $ model -> getNgRestRelationByIndex ( $ arrayIndex ) ; if ( ! $ relation ) { throw new InvalidCallException ( "Unable to find the given ng rest relation for this index value." ) ; } $ find = $ relation -> getDataProvider ( ) ; if ( $ find instanceof ActiveQuery && ! $ find -> multiple ) { throw new InvalidConfigException ( "The relation definition must be a hasMany() relation." ) ; } if ( $ find instanceof ActiveQueryInterface ) { $ find -> with ( $ this -> getWithRelation ( 'relation-call' ) ) ; } $ this -> appendPoolWhereCondition ( $ find ) ; $ targetModel = Yii :: createObject ( [ 'class' => $ relation -> getTargetModel ( ) ] ) ; if ( $ query ) { foreach ( $ targetModel -> getNgRestPrimaryKey ( ) as $ pkName ) { $ searchQuery = $ targetModel -> ngRestFullQuerySearch ( $ query ) -> select ( [ $ targetModel -> tableName ( ) . '.' . $ pkName ] ) ; $ find -> andWhere ( [ 'in' , $ targetModel -> tableName ( ) . '.' . $ pkName , $ searchQuery ] ) ; } } return new ActiveDataProvider ( [ 'query' => $ find , 'pagination' => $ this -> pagination , 'sort' => [ 'attributes' => $ this -> generateSortAttributes ( $ targetModel -> getNgRestConfig ( ) ) , ] ] ) ; }
Call the dataProvider for a foreign model .
39,982
public function actionFilter ( $ filterName , $ query = null ) { $ this -> checkAccess ( 'filter' ) ; $ model = $ this -> model ; $ filterName = Html :: encode ( $ filterName ) ; if ( ! array_key_exists ( $ filterName , $ model -> ngRestFilters ( ) ) ) { throw new InvalidCallException ( "The requested filter '$filterName' does not exists in the filter list." ) ; } $ find = $ model -> ngRestFilters ( ) [ $ filterName ] ; if ( $ query ) { foreach ( $ model -> getNgRestPrimaryKey ( ) as $ pkName ) { $ searchQuery = $ model -> ngRestFullQuerySearch ( $ query ) -> select ( [ $ model -> tableName ( ) . '.' . $ pkName ] ) ; $ find -> andWhere ( [ 'in' , $ model -> tableName ( ) . '.' . $ pkName , $ searchQuery ] ) ; } } $ this -> appendPoolWhereCondition ( $ find ) ; return new ActiveDataProvider ( [ 'query' => $ find , 'pagination' => $ this -> pagination , 'sort' => [ 'attributes' => $ this -> generateSortAttributes ( $ model -> getNgRestConfig ( ) ) , ] ] ) ; }
Filter the Api response by a defined Filtername .
39,983
public function actionActiveWindowCallback ( ) { $ this -> checkAccess ( 'active-window-callback' ) ; $ config = $ this -> model -> getNgRestConfig ( ) ; $ render = new RenderActiveWindowCallback ( ) ; $ ngrest = new NgRest ( $ config ) ; return $ ngrest -> render ( $ render ) ; }
Renders the Callback for an ActiveWindow .
39,984
public function actionActiveWindowRender ( ) { $ this -> checkAccess ( 'active-window-render' ) ; $ render = new RenderActiveWindow ( ) ; $ render -> setItemId ( Yii :: $ app -> request -> getBodyParam ( 'itemId' , false ) ) ; $ render -> setActiveWindowHash ( Yii :: $ app -> request -> getBodyParam ( 'activeWindowHash' , false ) ) ; $ ngrest = new NgRest ( $ this -> model -> getNgRestConfig ( ) ) ; return [ 'content' => $ ngrest -> render ( $ render ) , 'icon' => $ render -> getActiveWindowObject ( ) -> getIcon ( ) , 'label' => $ render -> getActiveWindowObject ( ) -> getLabel ( ) , 'title' => $ render -> getActiveWindowObject ( ) -> getTitle ( ) , 'requestDate' => time ( ) , ] ; }
Renders the index page of an ActiveWindow .
39,985
public function actionExport ( ) { $ this -> checkAccess ( 'export' ) ; $ header = Yii :: $ app -> request -> getBodyParam ( 'header' , 1 ) ; $ type = Yii :: $ app -> request -> getBodyParam ( 'type' ) ; $ attributes = Yii :: $ app -> request -> getBodyParam ( 'attributes' , [ ] ) ; $ fields = ArrayHelper :: getColumn ( $ attributes , 'value' ) ; switch ( strtolower ( $ type ) ) { case "csv" : $ mime = 'application/csv' ; $ extension = 'csv' ; break ; case "xlsx" : $ mime = 'application/vnd.ms-excel' ; $ extension = 'xlsx' ; break ; } $ query = $ this -> prepareListQuery ( ) -> select ( $ fields ) ; $ tempData = ExportHelper :: $ type ( $ query , $ fields , ( bool ) $ header ) ; $ key = uniqid ( 'ngrestexport' , true ) ; $ store = FileHelper :: writeFile ( '@runtime/' . $ key . '.tmp' , $ tempData ) ; $ menu = Yii :: $ app -> adminmenu -> getApiDetail ( $ this -> model -> ngRestApiEndpoint ( ) ) ; $ route = $ menu [ 'route' ] ; $ route = str_replace ( "/index" , "/export-download" , $ route ) ; if ( $ store ) { Yii :: $ app -> session -> set ( 'tempNgRestFileName' , Inflector :: slug ( $ this -> model -> tableName ( ) ) . '-export-' . date ( "Y-m-d-H-i" ) . '.' . $ extension ) ; Yii :: $ app -> session -> set ( 'tempNgRestFileMime' , $ mime ) ; Yii :: $ app -> session -> set ( 'tempNgRestFileKey' , $ key ) ; $ url = Url :: toRoute ( [ '/' . $ route ] , true ) ; $ param = http_build_query ( [ 'key' => base64_encode ( $ key ) , 'time' => time ( ) ] ) ; if ( StringHelper :: contains ( '?' , $ url ) ) { $ route = $ url . "&" . $ param ; } else { $ route = $ url . "?" . $ param ; } return [ 'url' => $ route , ] ; } throw new ErrorException ( "Unable to write the temporary file. Make sure the runtime folder is writeable." ) ; }
Export the Data into a temp CSV .
39,986
public function actionActiveButton ( $ hash , $ id ) { $ this -> checkAccess ( 'active-button' ) ; $ model = $ this -> findModel ( $ id ) ; return $ model -> handleNgRestActiveButton ( $ hash ) ; }
Trigger an Active Button handler .
39,987
public function textInput ( array $ options = [ ] ) { $ this -> element = Angular :: text ( '{model}' , '{label}' , [ 'fieldid' => $ this -> form -> getFieldId ( $ this -> attribute ) , 'ng-init' => '{initValue}' , ] ) ; return $ this ; }
Text input field
39,988
public function passwordInput ( array $ options = [ ] ) { $ this -> element = Angular :: password ( '{model}' , '{label}' , [ 'fieldid' => $ this -> form -> getFieldId ( $ this -> attribute ) , 'ng-init' => '{initValue}' , ] ) ; return $ this ; }
Passwword input field
39,989
public function dropDownList ( array $ data , array $ options = [ ] ) { $ this -> element = Angular :: select ( '{model}' , '{label}' , $ data , [ 'fieldid' => $ this -> form -> getFieldId ( $ this -> attribute ) , 'ng-init' => '{initValue}' , ] ) ; return $ this ; }
Generate a select dropdown with data as array .
39,990
public function checkboxList ( array $ data ) { $ this -> element = Angular :: checkboxArray ( '{model}' , '{label}' , $ data , [ 'fieldid' => $ this -> form -> getFieldId ( $ this -> attribute ) , 'ng-init' => '{initValue}' , ] ) ; return $ this ; }
Checkbox list input
39,991
public function radioList ( array $ data ) { $ this -> element = Angular :: radio ( '{model}' , '{label}' , $ data , [ 'fieldid' => $ this -> form -> getFieldId ( $ this -> attribute ) , 'ng-init' => '{initValue}' , ] ) ; return $ this ; }
radio list input
39,992
public function datetimePicker ( ) { $ this -> element = Angular :: datetime ( '{model}' , '{label}' , [ 'fieldid' => $ this -> form -> getFieldId ( $ this -> attribute ) , 'ng-init' => '{initValue}' , ] ) ; return $ this ; }
date time picker
39,993
private static function internalUpdateValues ( ) { $ update = [ ] ; foreach ( static :: fieldStateDescriber ( ) as $ field => $ value ) { $ update [ $ field ] = ( is_array ( $ value ) ) ? $ value [ 0 ] : $ value ; } return $ update ; }
Evalate the values to update .
39,994
public function getStorage ( ) { if ( $ this -> _storage === null ) { $ this -> _storage = Yii :: $ app -> storage ; } return $ this -> _storage ; }
Singleton behavior for storage component getter .
39,995
public function getMenu ( ) { if ( $ this -> _menu !== null ) { return $ this -> _menu ; } $ menu = [ ] ; foreach ( $ this -> getAdminModuleMenus ( ) as $ menuBuilder ) { if ( ! $ menuBuilder instanceof AdminMenuBuilderInterface ) { throw new Exception ( "admin menu must be instance of AdminMenuBuilderInterface" ) ; } $ data = $ menuBuilder -> menu ( ) ; $ menu = ArrayHelper :: merge ( $ data , $ menu ) ; } $ this -> _menu = $ menu ; return $ menu ; }
Return the menu array entries from all registered admin modules .
39,996
public function getNodeData ( $ id ) { if ( ! isset ( $ this -> getMenu ( ) [ $ id ] ) ) { return false ; } return $ this -> getMenu ( ) [ $ id ] ; }
Get the node for a given array key .
39,997
public function getModules ( ) { if ( $ this -> _modules !== null ) { return $ this -> _modules ; } $ responseData = [ ] ; foreach ( $ this -> getMenu ( ) as $ item ) { if ( $ item [ 'permissionIsRoute' ] ) { if ( ! Yii :: $ app -> auth -> matchRoute ( $ this -> getUserId ( ) , $ item [ 'permissionRoute' ] ) ) { continue ; } } if ( isset ( $ item [ 'groups' ] ) ) { $ permissionGranted = false ; foreach ( $ item [ 'groups' ] as $ groupName => $ groupItem ) { if ( count ( $ groupItem [ 'items' ] ) > 0 ) { if ( $ permissionGranted ) { continue ; } foreach ( $ groupItem [ 'items' ] as $ groupItemEntry ) { if ( $ permissionGranted ) { continue ; } if ( $ groupItemEntry [ 'permissionIsRoute' ] ) { if ( Yii :: $ app -> auth -> matchRoute ( $ this -> getUserId ( ) , $ groupItemEntry [ 'route' ] ) ) { $ permissionGranted = true ; } } elseif ( $ groupItemEntry [ 'permissionIsApi' ] ) { if ( Yii :: $ app -> auth -> matchApi ( $ this -> getUserId ( ) , $ groupItemEntry [ 'permissionApiEndpoint' ] ) ) { $ permissionGranted = true ; } } else { throw new Exception ( 'Menu item detected without permission entry' ) ; } } } } if ( ! $ permissionGranted ) { continue ; } } try { $ alias = Yii :: t ( $ item [ 'moduleId' ] , $ item [ 'alias' ] , [ ] , Yii :: $ app -> language ) ; } catch ( \ Exception $ err ) { $ alias = $ item [ 'alias' ] ; } $ responseData [ ] = [ 'moduleId' => $ item [ 'moduleId' ] , 'id' => $ item [ 'id' ] , 'template' => $ item [ 'template' ] , 'routing' => $ item [ 'routing' ] , 'alias' => $ alias , 'icon' => $ item [ 'icon' ] , 'searchModelClass' => $ item [ 'searchModelClass' ] , ] ; } $ this -> _modules = $ responseData ; return $ responseData ; }
Returns an Array with modules and checks the permission for those .
39,998
public function getItems ( ) { if ( $ this -> _items !== null ) { return $ this -> _items ; } $ data = [ ] ; foreach ( $ this -> getModules ( ) as $ node ) { foreach ( ArrayHelper :: getValue ( $ this -> getModuleItems ( $ node [ 'id' ] ) , 'groups' , [ ] ) as $ groupValue ) { foreach ( $ groupValue [ 'items' ] as $ array ) { $ array [ 'module' ] = $ node ; $ data [ ] = $ array ; } } } $ this -> _items = $ data ; return $ data ; }
Get all items for all nodes .
39,999
public function getApiDetail ( $ api , $ pool = null ) { $ items = $ this -> getItems ( ) ; if ( $ pool ) { $ items = ArrayHelper :: searchColumns ( $ items , 'pool' , $ pool ) ; } $ items = array_values ( $ items ) ; return ArrayHelper :: searchColumn ( $ items , 'permissionApiEndpoint' , $ api ) ; }
Return all informations about a menu point based on the api endpoint name .