idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
53,400
|
public function getFavorites ( ) : UserFavoritesData { $ json = $ this -> client -> performApiCallWithJsonResponse ( 'get' , '/user/favorites' ) ; return ResponseHandler :: create ( $ json , ResponseHandler :: METHOD_USER_FAVORITES ) -> handle ( ) ; }
|
Get user favorites .
|
53,401
|
public function addRating ( int $ type , int $ itemId , int $ rating ) : UserRatingsDataNoLinks { if ( ! in_array ( $ type , self :: $ ratingTypes , true ) ) { throw new InvalidArgumentException ( 'Invalid rating type, use one of these instead: ' . implode ( self :: $ ratingTypes , ', ' ) ) ; } try { $ json = $ this -> client -> performApiCallWithJsonResponse ( 'put' , sprintf ( 'user/ratings/%s/%d/%d' , $ type , ( int ) $ itemId , ( int ) $ rating ) , [ 'http_errors' => true ] ) ; } catch ( ClientException $ e ) { $ message = $ this -> getApiErrorMessage ( $ e -> getResponse ( ) ) ; if ( $ message !== '' ) { throw CouldNotAddOrUpdateUserRatingException :: reason ( $ message ) ; } throw CouldNotAddOrUpdateUserRatingException :: reason ( $ e -> getMessage ( ) ) ; } return ResponseHandler :: create ( $ json , ResponseHandler :: METHOD_USER_RATINGS_ADD ) -> handle ( ) ; }
|
Add user rating .
|
53,402
|
public function updateRating ( int $ type , int $ itemId , int $ rating ) : UserRatingsDataNoLinks { return $ this -> addRating ( $ type , $ itemId , $ rating ) ; }
|
Update user rating .
|
53,403
|
private function getApiErrorMessage ( ResponseInterface $ response ) : string { try { $ body = $ response -> getBody ( ) -> getContents ( ) ; } catch ( \ RuntimeException $ re ) { return '' ; } if ( strpos ( $ body , '"Error"' ) !== false && ( $ body = json_decode ( $ body , true ) ) && array_key_exists ( 'Error' , $ body ) ) { return $ body [ 'Error' ] ; } return '' ; }
|
Extract error message from response body .
|
53,404
|
protected function getId ( ) { if ( $ key = $ this -> manager -> config ( 'model_primary_key' ) ) { return $ this -> manager -> getInstance ( ) -> { $ key } ; } return $ this -> manager -> getInstance ( ) -> getKey ( ) ; }
|
Returns the id of the current object instance .
|
53,405
|
public function changeConfig ( $ config ) { if ( ! is_array ( $ config ) ) { return false ; } $ this -> config = array_merge ( $ this -> config , $ config ) ; return true ; }
|
Change the configuration values .
|
53,406
|
public function set ( $ key , $ content , $ expiry = 0 ) { $ cacheObj = new \ stdClass ( ) ; if ( ! is_string ( $ content ) ) { $ content = serialize ( $ content ) ; } $ cacheObj -> content = $ content ; if ( ! $ expiry ) { $ cacheObj -> expiryTimestamp = time ( ) + 315360000 ; } elseif ( $ expiry > 2592000 ) { $ cacheObj -> expiryTimestamp = $ expiry ; } else { $ cacheObj -> expiryTimestamp = time ( ) + $ expiry ; } if ( $ cacheObj -> expiryTimestamp < time ( ) ) { $ this -> delete ( $ key ) ; return false ; } $ cacheFileData = json_encode ( $ cacheObj ) ; if ( $ this -> config [ 'gzipCompression' ] ) { $ cacheFileData = gzcompress ( $ cacheFileData ) ; } $ filePath = $ this -> getFilePathFromKey ( $ key ) ; $ result = file_put_contents ( $ filePath , $ cacheFileData ) ; return $ result ? true : false ; }
|
Sets an item in the cache .
|
53,407
|
public function delete ( $ key ) { $ filePath = $ this -> getFilePathFromKey ( $ key ) ; if ( ! file_exists ( $ filePath ) ) { return false ; } return unlink ( $ filePath ) ; }
|
Remove a value from the cache .
|
53,408
|
private function deleteDirectoryTree ( $ directory ) { $ filePaths = scandir ( $ directory ) ; foreach ( $ filePaths as $ filePath ) { if ( $ filePath == '.' || $ filePath == '..' ) { continue ; } $ fullFilePath = $ directory . '/' . $ filePath ; if ( is_dir ( $ fullFilePath ) ) { $ result = $ this -> deleteDirectoryTree ( $ fullFilePath ) ; if ( $ result ) { $ result = rmdir ( $ fullFilePath ) ; } } else { if ( basename ( $ fullFilePath ) == '.keep' ) { continue ; } $ result = unlink ( $ fullFilePath ) ; } if ( ! $ result ) { return false ; } } return true ; }
|
Removes cache files from a given directory .
|
53,409
|
public function increment ( $ key , $ offset = 1 ) { $ filePath = $ this -> getFilePathFromKey ( $ key ) ; if ( ! file_exists ( $ filePath ) ) { return false ; } if ( ! is_readable ( $ filePath ) ) { return false ; } $ cacheFileData = file_get_contents ( $ filePath ) ; if ( $ this -> config [ 'gzipCompression' ] ) { $ cacheFileData = gzuncompress ( $ cacheFileData ) ; } $ cacheObj = json_decode ( $ cacheFileData ) ; $ content = $ cacheObj -> content ; if ( $ unserializedContent = @ unserialize ( $ content ) ) { $ content = $ unserializedContent ; } if ( ! $ content || ! is_numeric ( $ content ) ) { return false ; } $ content += $ offset ; return $ this -> set ( $ key , $ content , $ cacheObj -> expiryTimestamp ) ; }
|
Increments a value within the cache .
|
53,410
|
public function replace ( $ key , $ content , $ expiry = 0 ) { if ( ! $ this -> get ( $ key ) ) { return false ; } return $ this -> set ( $ key , $ content , $ expiry ) ; }
|
Replaces a value within the cache .
|
53,411
|
protected function getFilePathFromKey ( $ key ) { $ key = basename ( $ key ) ; $ badChars = [ '-' , '.' , '_' , '\\' , '*' , '\"' , '?' , '[' , ']' , ':' , ';' , '|' , '=' , ',' ] ; $ key = str_replace ( $ badChars , '/' , $ key ) ; while ( strpos ( $ key , '//' ) !== false ) { $ key = str_replace ( '//' , '/' , $ key ) ; } $ directoryToCreate = $ this -> config [ 'cacheDirectory' ] ; $ endOfDirectory = strrpos ( $ key , '/' ) ; if ( $ endOfDirectory !== false ) { $ directoryToCreate = $ this -> config [ 'cacheDirectory' ] . substr ( $ key , 0 , $ endOfDirectory ) ; } if ( ! file_exists ( $ directoryToCreate ) ) { $ result = mkdir ( $ directoryToCreate , 0777 , true ) ; if ( ! $ result ) { return false ; } } $ filePath = $ this -> config [ 'cacheDirectory' ] . $ key . '.' . $ this -> config [ 'fileExtension' ] ; return $ filePath ; }
|
Returns the file path from a given cache key creating the relevant directory structure if necessary .
|
53,412
|
protected function createFromObject ( SymfonyUploadedFile $ file ) { $ path = $ file -> getPathname ( ) ; $ original_name = $ file -> getClientOriginalName ( ) ; $ mime_type = $ file -> getClientMimeType ( ) ; $ size = $ file -> getSize ( ) ; $ error = $ file -> getError ( ) ; $ upload_file = new UploadedFile ( $ path , $ original_name , $ mime_type , $ size , $ error ) ; if ( $ upload_file -> isValid ( ) === false ) { throw new FileException ( $ upload_file -> getErrorMessage ( $ upload_file -> getError ( ) ) ) ; } return $ upload_file ; }
|
Build a \ Torann \ MediaSort \ File \ UploadedFile object from a Symfony \ Component \ HttpFoundation \ File \ UploadedFile object .
|
53,413
|
protected function createFromBase64 ( $ filename , $ data ) { $ destination = sys_get_temp_dir ( ) . '/' . str_random ( 4 ) . '-' . $ filename ; if ( is_dir ( dirname ( $ destination ) ) === false ) { mkdir ( dirname ( $ destination ) , 0755 , true ) ; } file_put_contents ( $ destination , base64_decode ( $ data ) , 0 ) ; $ mime_type = mime_content_type ( $ destination ) ; return new UploadedFile ( $ destination , $ filename , $ mime_type ) ; }
|
Build a Torann \ MediaSort \ File \ UploadedFile object from a base64 encoded image array . Usually from an API request .
|
53,414
|
protected function createFromUrl ( $ file ) { $ ch = curl_init ( ) ; curl_setopt_array ( $ ch , [ CURLOPT_URL => $ file , CURLOPT_RETURNTRANSFER => 1 , CURLOPT_USERAGENT => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36' , CURLOPT_FOLLOWLOCATION => 1 , ] ) ; $ raw_file = curl_exec ( $ ch ) ; curl_close ( $ ch ) ; $ size_info = getimagesizefromstring ( $ raw_file ) ; $ mime = $ size_info [ 'mime' ] ; $ file_path = @ tempnam ( sys_get_temp_dir ( ) , 'STP' ) ; file_put_contents ( $ file_path , $ raw_file ) ; $ name = strtok ( pathinfo ( $ file , PATHINFO_BASENAME ) , '?' ) ; if ( empty ( pathinfo ( $ file , PATHINFO_EXTENSION ) ) ) { $ name = $ name . '.' . $ this -> getExtension ( $ mime ) ; } if ( function_exists ( 'mb_strlen' ) ) { $ size = mb_strlen ( $ raw_file , '8bit' ) ; } else { $ size = strlen ( $ raw_file ) ; } return new UploadedFile ( $ file_path , $ name , $ mime , $ size , 0 ) ; }
|
Fetch a remote file using a string URL and convert it into an instance of Torann \ MediaSort \ File \ UploadedFile .
|
53,415
|
protected function setPathPrefix ( ) { if ( $ this -> media -> local_root ) { $ root = $ this -> media -> getInterpolator ( ) -> interpolate ( $ this -> media -> local_root ) ; $ this -> filesystem -> getDriver ( ) -> getAdapter ( ) -> setPathPrefix ( $ root ) ; } }
|
Set local path prefix from settings .
|
53,416
|
protected function registerMediaSort ( ) { $ this -> media_sort_null = sha1 ( time ( ) ) ; if ( defined ( 'MEDIASORT_NULL' ) === false ) { define ( 'MEDIASORT_NULL' , $ this -> media_sort_null ) ; } }
|
Register \ Torann \ MediaSort \ MediaSort with the container .
|
53,417
|
public function all ( ) : LanguageData { $ json = $ this -> client -> performApiCallWithJsonResponse ( 'get' , '/languages' ) ; return ResponseHandler :: create ( $ json , ResponseHandler :: METHOD_LANGUAGES ) -> handle ( ) ; }
|
Get all available languages .
|
53,418
|
public function getById ( $ id , array $ options = [ ] ) { $ query = $ this -> createBaseBuilder ( $ options ) ; return $ query -> find ( $ id ) ; }
|
Get a resource by its primary key
|
53,419
|
public function getRecent ( array $ options = [ ] ) { $ query = $ this -> createBaseBuilder ( $ options ) ; $ query -> orderBy ( $ this -> getCreatedAtColumn ( ) , 'DESC' ) ; return $ query -> get ( ) ; }
|
Get all resources ordered by recentness
|
53,420
|
public function getRecentWhere ( $ column , $ value , array $ options = [ ] ) { $ query = $ this -> createBaseBuilder ( $ options ) ; $ query -> where ( $ column , $ value ) ; $ query -> orderBy ( $ this -> getCreatedAtColumn ( ) , 'DESC' ) ; return $ query -> get ( ) ; }
|
Get all resources by a where clause ordered by recentness
|
53,421
|
public function getWhere ( $ column , $ value , array $ options = [ ] ) { $ query = $ this -> createBaseBuilder ( $ options ) ; $ query -> where ( $ column , $ value ) ; return $ query -> get ( ) ; }
|
Get resources by a where clause
|
53,422
|
public function getWhereArray ( array $ clauses , array $ options = [ ] ) { $ query = $ this -> createBaseBuilder ( $ options ) ; $ this -> applyWhereArray ( $ query , $ clauses ) ; return $ query -> get ( ) ; }
|
Get resources by multiple where clauses
|
53,423
|
public function getWhereIn ( $ column , array $ values , array $ options = [ ] ) { $ query = $ this -> createBaseBuilder ( $ options ) ; $ query -> whereIn ( $ column , $ values ) ; return $ query -> get ( ) ; }
|
Get resources where a column value exists in array
|
53,424
|
public function delete ( $ id ) { $ query = $ this -> createQueryBuilder ( ) ; $ query -> where ( $ this -> getPrimaryKey ( $ query ) , $ id ) ; $ query -> delete ( ) ; }
|
Delete a resource by its primary key
|
53,425
|
public function deleteWhere ( $ column , $ value ) { $ query = $ this -> createQueryBuilder ( ) ; $ query -> where ( $ column , $ value ) ; $ query -> delete ( ) ; }
|
Delete resources by a where clause
|
53,426
|
public function deleteWhereArray ( array $ clauses ) { $ query = $ this -> createQueryBuilder ( ) ; $ this -> applyWhereArray ( $ query , $ clauses ) ; $ query -> delete ( ) ; }
|
Delete resources by multiple where clauses
|
53,427
|
protected function createBaseBuilder ( array $ options = [ ] ) { $ query = $ this -> createQueryBuilder ( ) ; $ this -> applyResourceOptions ( $ query , $ options ) ; if ( empty ( $ options [ 'sort' ] ) ) { $ this -> defaultSort ( $ query , $ options ) ; } return $ query ; }
|
Creates a new query builder with Optimus options set
|
53,428
|
protected function defaultSort ( Builder $ query , array $ options = [ ] ) { if ( isset ( $ this -> sortProperty ) ) { $ direction = $ this -> sortDirection === 1 ? 'DESC' : 'ASC' ; $ query -> orderBy ( $ this -> sortProperty , $ direction ) ; } }
|
Order query by the specified sorting property
|
53,429
|
public function move ( $ source , $ target ) { $ this -> filesystem -> put ( $ target , file_get_contents ( $ source ) , $ this -> media -> visibility ) ; }
|
Move an uploaded file to it s intended target .
|
53,430
|
public function getQueuedAttachments ( ) { $ queued = [ ] ; foreach ( $ this -> getMediaFiles ( ) as $ name => $ attachment ) { if ( $ attachment -> isQueued ( ) ) { $ queued [ $ name ] = $ attachment ; } } return $ queued ; }
|
Return all queued attachments that need processing .
|
53,431
|
public function getAttribute ( $ key ) { if ( array_key_exists ( $ key , $ this -> getMediaFiles ( ) ) ) { return $ this -> media_files [ $ key ] ; } return parent :: getAttribute ( $ key ) ; }
|
Handle the dynamic retrieval of media items .
|
53,432
|
public function setAttribute ( $ key , $ value ) { if ( array_key_exists ( $ key , $ this -> getMediaFiles ( ) ) ) { if ( $ value ) { $ this -> media_files [ $ key ] -> setUploadedFile ( $ value , $ key ) ; } return $ this ; } return parent :: setAttribute ( $ key , $ value ) ; }
|
Handle the dynamic setting of media items .
|
53,433
|
protected function registerMedia ( $ name , $ options ) { $ this -> media_files [ $ name ] = new Manager ( $ name , $ this -> mergeOptions ( $ options ) ) ; $ this -> media_files [ $ name ] -> setInstance ( $ this ) ; }
|
Register an media type and add the media to the list of media to be processed during saving .
|
53,434
|
protected function mergeOptions ( $ options ) { $ options = array_merge ( config ( 'mediasort' , [ ] ) , ( array ) $ options ) ; $ options [ 'styles' ] = array_merge ( ( array ) $ options [ 'styles' ] , [ 'original' => '' ] ) ; return $ options ; }
|
Merge configuration options .
|
53,435
|
protected function processSomeFiles ( $ models , $ media ) { foreach ( $ models as $ model ) { foreach ( $ model -> getMediaFiles ( ) as $ file ) { if ( in_array ( $ file -> name , $ media ) ) { $ file -> reprocess ( ) ; } } } }
|
Process a only a specified subset of MediaSort files .
|
53,436
|
protected function processAllFiles ( $ models ) { foreach ( $ models as $ model ) { foreach ( $ model -> getMediaFiles ( ) as $ file ) { $ file -> reprocess ( ) ; } } }
|
Process all MediaSort attachments defined on a class .
|
53,437
|
public function getDisk ( ) { if ( $ this -> disk_instance === null ) { $ class = "\\Torann\\MediaSort\\Disks\\" . ucfirst ( $ this -> config ( 'disk' ) ) ; if ( class_exists ( $ class ) === false ) { throw new InvalidClassException ( "Disk type \"{$class}\" not found." ) ; } $ this -> disk_instance = Container :: getInstance ( ) -> makeWith ( $ class , [ 'media' => $ this ] ) ; } return $ this -> disk_instance ; }
|
Get disk instance .
|
53,438
|
public function setConfig ( $ config ) { $ this -> config = $ config ; if ( strpos ( $ this -> config [ 'url' ] , '{id}' ) === false ) { throw new Exception ( 'Invalid Url: an id interpolation is required.' , 1 ) ; } $ this -> config [ 'disk' ] = Arr :: get ( $ this -> config , 'disk' , config ( 'filesystems.default' , 'local' ) ) ; }
|
Mutator method for the config property .
|
53,439
|
public function setQueue ( $ queue , $ value ) { if ( is_array ( $ value ) === false ) { $ value = [ $ value ] ; } $ this -> queues [ $ queue ] = array_merge ( $ this -> getQueue ( $ queue ) , $ value ) ; }
|
Set an item to be queued .
|
53,440
|
public function toArray ( $ skip_empty = false , $ include_original = true ) { if ( $ skip_empty === true && $ this -> hasMedia ( ) === false ) { return null ; } $ urls = [ ] ; foreach ( $ this -> styles as $ name => $ style ) { if ( $ include_original === false && $ this -> config ( 'default_style' ) === $ name ) { continue ; } $ urls [ $ name ] = $ this -> url ( $ name ) ; } return $ urls ; }
|
Generates an array of all style urls .
|
53,441
|
public function path ( $ style = '' ) { if ( $ this -> getAttribute ( 'filename' ) ) { return $ this -> getInterpolator ( ) -> interpolate ( $ this -> url , $ style ) ; } return '' ; }
|
Generates the filesystem path to an uploaded file .
|
53,442
|
public function getAttribute ( $ key ) { $ key = preg_replace ( '/^_/' , '' , $ key ) ; switch ( $ key ) { case 'size' : $ key = 'file_size' ; break ; case 'filename' : case 'original_filename' : $ key = 'file_name' ; break ; } return $ this -> getInstance ( ) -> getAttribute ( "{$this->name}_{$key}" ) ; }
|
Return the attachment attribute value .
|
53,443
|
public function getQueuedFilePath ( ) { return $ this -> getInterpolator ( ) -> interpolate ( $ this -> joinPaths ( $ this -> config ( 'queue_path' ) , $ this -> getAttribute ( 'queued_file' ) ) ) ; }
|
Get the queued file path .
|
53,444
|
public function processQueue ( Model $ instance , $ path = null , bool $ cleanup = true ) { $ this -> setInstance ( $ instance ) ; $ path = $ path ? : $ this -> getQueuedFilePath ( ) ; $ this -> addUploadedFile ( $ path ) ; $ this -> save ( ) ; $ this -> getInstance ( ) -> save ( ) ; if ( $ cleanup === true && realpath ( $ path ) !== false ) { @ unlink ( $ path ) ; @ rmdir ( dirname ( $ path ) ) ; } }
|
Trigger queued files for processing .
|
53,445
|
protected function flushWrites ( ) { if ( count ( $ this -> getQueue ( 'write' ) ) === 0 ) { return ; } $ this -> updateQueueState ( self :: QUEUE_WORKING ) ; foreach ( $ this -> getQueue ( 'write' ) as $ name => $ style ) { if ( $ style && $ this -> uploaded_file -> isImage ( ) ) { $ file = $ this -> getResizer ( ) -> resize ( $ this -> uploaded_file , $ style ) ; } else { $ file = $ this -> uploaded_file -> getRealPath ( ) ; } if ( $ filePath = $ this -> path ( $ name ) ) { $ this -> move ( $ file , $ filePath ) ; } } $ this -> resetQueue ( 'write' ) ; $ this -> updateQueueState ( self :: QUEUE_DONE ) ; }
|
Process the queued for writes .
|
53,446
|
public function getQueuedStateText ( ) { switch ( ( int ) $ this -> getAttribute ( 'queue_state' ) ) { case self :: QUEUE_NA : return '' ; case self :: QUEUE_DONE : return 'done' ; case self :: QUEUE_WAITING : return 'waiting' ; case self :: QUEUE_WORKING : return 'working' ; default : return 'unknown' ; } }
|
Get queue state text .
|
53,447
|
public function updateQueueState ( int $ state ) { if ( $ this -> isQueueable ( ) ) { $ this -> getInstance ( ) -> getConnection ( ) -> table ( $ this -> getInstance ( ) -> getTable ( ) ) -> where ( $ this -> getInstance ( ) -> getQualifiedKeyName ( ) , $ this -> getInstance ( ) -> getKey ( ) ) -> update ( [ "{$this->name}_queue_state" => $ state , ] ) ; } }
|
Use the model s connecting and table to quickly update the queue state and bypass the save event in the model to prevent an event loop .
|
53,448
|
protected function instanceWrite ( $ property , $ value ) { $ field = "{$this->name}_{$property}" ; if ( $ property === 'file_name' ) { $ this -> getInstance ( ) -> setAttribute ( $ field , $ value ) ; } elseif ( preg_match ( '/^queue(d?)_/' , $ property ) ) { if ( $ this -> isQueueable ( ) ) { $ this -> getInstance ( ) -> setAttribute ( $ field , $ value ) ; } } else { if ( in_array ( $ field , $ this -> getInstance ( ) -> getFillable ( ) ) ) { $ this -> getInstance ( ) -> setAttribute ( $ field , $ value ) ; } } }
|
Set an attachment attribute on the underlying model instance .
|
53,449
|
public function getFileManager ( ) { if ( $ this -> file_manager_instance === null ) { $ this -> file_manager_instance = new FileManager ( $ this ) ; } return $ this -> file_manager_instance ; }
|
Get the file manager instance .
|
53,450
|
public function getResizer ( ) { $ options = [ 'image_quality' => $ this -> config ( 'image_quality' ) , 'auto_orient' => $ this -> config ( 'auto_orient' ) , 'color_palette' => $ this -> config ( 'color_palette' ) , ] ; return new Resizer ( $ this -> config ( 'image_processor' ) , $ options ) ; }
|
Get the resizer instance .
|
53,451
|
public function beforeDispatch ( Event $ event ) { if ( Configure :: read ( 'Cache.check' ) === false ) { return null ; } $ request = $ event -> data [ 'request' ] ; $ url = $ request -> here ( ) ; $ url = str_replace ( $ request -> base , '' , $ url ) ; $ file = $ this -> getFile ( $ url ) ; if ( $ file === null ) { return null ; } $ cacheContent = $ this -> extractCacheContent ( $ file ) ; $ cacheInfo = $ this -> extractCacheInfo ( $ cacheContent ) ; $ cacheTime = $ cacheInfo [ 'time' ] ; if ( $ cacheTime < time ( ) && $ cacheTime != 0 ) { unlink ( $ file ) ; return null ; } $ response = $ event -> data [ 'response' ] ; $ event -> stopPropagation ( ) ; $ response -> modified ( filemtime ( $ file ) ) ; if ( $ response -> checkNotModified ( $ request ) ) { return $ response ; } $ pathSegments = explode ( '.' , $ file ) ; $ ext = array_pop ( $ pathSegments ) ; $ this -> _deliverCacheFile ( $ request , $ response , $ file , $ ext ) ; return $ response ; }
|
Checks if a requested cache file exists and sends it to the browser
|
53,452
|
protected function _writeFile ( $ content , $ duration ) { $ now = time ( ) ; if ( ! $ duration ) { $ cacheTime = 0 ; } elseif ( is_numeric ( $ duration ) ) { $ cacheTime = $ now + $ duration ; } else { $ cacheTime = strtotime ( $ duration , $ now ) ; } $ url = $ this -> request -> here ( ) ; $ url = str_replace ( $ this -> request -> base , '' , $ url ) ; if ( $ url === '/' ) { $ url = '_root' ; } $ cache = $ url ; $ prefix = Configure :: read ( 'Cache.prefix' ) ; if ( $ prefix ) { $ cache = $ prefix . '_' . $ url ; } if ( $ url !== '_root' ) { $ cache = Inflector :: slug ( $ cache ) ; } if ( empty ( $ cache ) ) { return false ; } $ ext = $ this -> response -> mapType ( $ this -> response -> type ( ) ) ; $ content = $ this -> _compress ( $ content , $ ext ) ; $ cache = $ cache . '.html' ; $ content = '<!--cachetime:' . $ cacheTime . ';ext:' . $ ext . ' . $ content ; $ folder = CACHE . 'views' . DS ; if ( Configure :: read ( 'debug' ) && ! is_dir ( $ folder ) ) { mkdir ( $ folder , 0770 , true ) ; } $ file = $ folder . $ cache ; return file_put_contents ( $ file , $ content ) ; }
|
Write a cached version of the file
|
53,453
|
public function getOptions ( ) { if ( isset ( $ this -> options [ 'id' ] ) ) unset ( $ this -> options [ 'id' ] ) ; $ this -> registerAnimateCss ( ) ; if ( ArrayHelper :: isIndexed ( $ this -> options ) ) { $ str = '' ; foreach ( $ this -> options as $ value ) { $ str .= '"' . $ value . '",' ; } return chop ( $ str , ' ,' ) ; } return Json :: encode ( $ this -> options ) ; }
|
Get widget options
|
53,454
|
public function registerAnimateCss ( ) { if ( isset ( $ this -> options [ 'animation' ] ) && $ this -> options [ 'animation' ] === false ) { if ( isset ( $ this -> options [ 'customClass' ] ) ) { AnimateCssAsset :: register ( $ this -> view ) ; } } }
|
Add support Animate . css
|
53,455
|
protected function itemsToValues ( IItems $ items ) { $ values = [ ] ; foreach ( $ items as $ item ) { $ valueId = $ item -> get ( 'id' ) ; $ parsedItem = $ item -> parseValue ( ) ; $ values [ $ valueId ] = \ array_merge ( [ self :: SELECT_RAW => $ parsedItem [ 'raw' ] ] , $ parsedItem [ 'text' ] ) ; } return $ values ; }
|
Convert the item list to values .
|
53,456
|
private function tryParseAttribute ( $ displayValue , IItem $ item ) { $ parsedValue = $ item -> parseAttribute ( $ displayValue ) ; if ( isset ( $ parsedValue [ 'text' ] ) ) { return $ parsedValue [ 'text' ] ; } return $ item -> get ( $ displayValue ) ; }
|
Parse a column as text or return the native value if that failed .
|
53,457
|
private function determineCount ( $ items , & $ count , $ idList ) { $ usedOptionsIdList = \ array_unique ( \ array_filter ( \ array_map ( function ( $ item ) { return $ item -> get ( 'id' ) ; } , \ iterator_to_array ( $ items ) ) ) ) ; if ( empty ( $ usedOptionsIdList ) ) { return ; } $ valueCol = $ this -> getColName ( ) ; $ query = $ this -> connection -> createQueryBuilder ( ) -> select ( $ this -> getColName ( ) ) -> addSelect ( \ sprintf ( 'COUNT(%s) AS count' , $ this -> getColName ( ) ) ) -> from ( $ this -> getMetaModel ( ) -> getTableName ( ) ) -> where ( $ this -> getColName ( ) . ' IN (:ids)' ) -> groupBy ( $ this -> getColName ( ) ) -> setParameter ( 'ids' , $ usedOptionsIdList , Connection :: PARAM_STR_ARRAY ) ; if ( $ idList !== null && ! empty ( $ idList ) ) { $ query -> andWhere ( 'id IN (:idList)' ) -> setParameter ( 'idList' , $ idList , Connection :: PARAM_STR_ARRAY ) ; } $ query = $ query -> execute ( ) ; while ( $ row = $ query -> fetch ( \ PDO :: FETCH_ASSOC ) ) { $ count [ $ row -> { $ valueCol } ] = $ row -> count ; } }
|
Determine the option count for the passed items .
|
53,458
|
public function href ( $ service , $ url = null , array $ options = [ ] ) { $ url = Router :: url ( $ url , true ) ; $ SocialShareUrl = new SocialShareUrl ( ) ; return $ SocialShareUrl -> getUrl ( $ service , $ url , $ options ) ; }
|
Creates a share URL .
|
53,459
|
public function link ( $ service , $ text , $ url = null , array $ attributes = [ ] ) { $ defaults = [ 'target' => $ this -> _config [ 'target' ] ] ; $ attributes += $ defaults ; $ options = [ ] ; if ( ! empty ( $ attributes [ 'text' ] ) ) { $ options [ 'text' ] = $ attributes [ 'text' ] ; unset ( $ attributes [ 'text' ] ) ; } if ( ! empty ( $ attributes [ 'image' ] ) ) { $ options [ 'image' ] = $ attributes [ 'image' ] ; unset ( $ attributes [ 'image' ] ) ; } return $ this -> Html -> link ( $ text , $ this -> href ( $ service , $ url , $ options ) , $ attributes ) ; }
|
Creates an HTML link to share a URL .
|
53,460
|
public function fa ( $ service , $ url = null , array $ options = [ ] ) { $ defaults = [ 'target' => $ this -> _config [ 'target' ] ] ; $ options += $ defaults ; $ options [ 'escape' ] = false ; $ icon = $ this -> icon ( $ service , $ options ) ; unset ( $ options [ 'icon_class' ] ) ; $ attributes = $ options ; unset ( $ attributes [ 'text' ] ) ; unset ( $ attributes [ 'image' ] ) ; return $ this -> Html -> link ( $ icon , $ this -> href ( $ service , $ url , $ options ) , $ attributes ) ; }
|
Creates an HTML link to share a URL using a Font Awesome icon .
|
53,461
|
public function icon ( $ service , array $ options = [ ] ) { $ class = 'fa ' . ( ! empty ( $ this -> _fa [ $ service ] ) ? $ this -> _fa [ $ service ] : $ this -> _config [ 'default_fa' ] ) ; if ( ! empty ( $ options [ 'icon_class' ] ) ) { $ class = $ options [ 'icon_class' ] ; } return '<i class="' . $ class . '"></i>' ; }
|
Creates an icon
|
53,462
|
protected function getCriteria ( Builder $ builder , array $ query ) { $ criteria = [ ] ; foreach ( $ query as $ value ) { $ criterion = Criterion :: make ( $ value , $ this -> _getDefaultSortOrder ( ) ) ; if ( $ this -> isFieldSortable ( $ builder , $ criterion -> getField ( ) ) ) { $ criteria [ ] = $ criterion ; } } return $ criteria ; }
|
Builds sort criteria based on model s sortable fields and query parameters .
|
53,463
|
protected function isFieldSortable ( Builder $ builder , $ field ) { $ sortable = $ this -> _getSortableAttributes ( $ builder ) ; return in_array ( $ field , $ sortable ) || in_array ( '*' , $ sortable ) ; }
|
Check if field is sortable for given model .
|
53,464
|
protected function applyCriteria ( Builder $ builder , array $ criteria ) { foreach ( $ criteria as $ criterion ) { $ criterion -> apply ( $ builder ) ; } }
|
Applies criteria to query
|
53,465
|
public function translate ( $ text , $ to , $ from = null , $ category = null , $ contentType = ApiCall \ Translate :: CONTENT_TYPE_TEXT ) { $ apiCall = new ApiCall \ Translate ( $ text , $ to , $ from , $ category , $ contentType ) ; return $ this -> call ( $ apiCall ) ; }
|
Translates a given text or html to the given language
|
53,466
|
public function translateArray ( array $ texts , $ to , $ from = null ) { $ apiCall = new ApiCall \ TranslateArray ( $ texts , $ to , $ from ) ; return $ this -> call ( $ apiCall ) ; }
|
Translates an array of texts
|
53,467
|
public function breakSentences ( $ text , $ language ) { $ apiCall = new ApiCall \ BreakSentences ( $ text , $ language ) ; return $ this -> call ( $ apiCall ) ; }
|
Break a given text into the sentences it contains
|
53,468
|
public function getLanguageNames ( array $ languageCodes , $ locale ) { $ apiCall = new ApiCall \ GetLanguageNames ( $ languageCodes , $ locale ) ; return $ this -> call ( $ apiCall ) ; }
|
Get a list of language names for the given language codes readable for the given locale
|
53,469
|
private function generateCacheKeyForRequest ( RequestInterface $ request ) { $ normalizedRequest = $ this -> getNormalizedRequest ( $ request ) ; return md5 ( $ normalizedRequest -> __toString ( ) ) ; }
|
Generate a unique key for the given request
|
53,470
|
private function normalizeHeaders ( array $ headers ) { $ ignoreHeaders = $ this -> ignoreHeaders ; foreach ( $ ignoreHeaders as $ ignoreHeader ) { $ headers = array_filter ( $ headers , function ( $ header ) use ( $ ignoreHeader ) { return stripos ( $ header , $ ignoreHeader . ':' ) !== 0 ; } ) ; } return $ headers ; }
|
Get only those headers that should not be ignored
|
53,471
|
public function get ( $ pages = 0 ) { $ endpoint = $ this -> getEndpoint ( ) ; $ params = $ this -> getParams ( ) ; $ list = $ this -> getClient ( ) -> request ( $ endpoint , 'GET' , $ params ) ; $ i = 1 ; while ( $ list [ 'metadata' ] [ 'continue' ] ) { if ( $ pages > 0 && $ pages >= $ i ) { return $ list ; } $ params [ 'continue' ] = $ list [ 'metadata' ] [ 'continue' ] ; $ i_list = $ this -> getClient ( ) -> request ( $ endpoint , 'GET' , $ params ) ; $ i_list [ 'items' ] = array_merge ( $ list [ 'items' ] , $ i_list [ 'items' ] ) ; $ list = $ i_list ; unset ( $ i_list ) ; $ i ++ ; } return $ list ; }
|
Get all values from a list endpoint . Full list is returned as if made in a single call .
|
53,472
|
protected function convertOptionsList ( $ statement , $ aliasColumn , $ valueColumn , & $ count = null ) { $ arrReturn = array ( ) ; while ( $ values = $ statement -> fetch ( \ PDO :: FETCH_OBJ ) ) { if ( is_array ( $ count ) ) { $ count [ $ values -> $ aliasColumn ] = $ values -> mm_count ; } $ arrReturn [ $ values -> $ aliasColumn ] = $ values -> $ valueColumn ; } return $ arrReturn ; }
|
Convert the database result into a proper result array .
|
53,473
|
protected function isProperlyConfigured ( ) { if ( isset ( $ this -> isProperlyConfigured ) ) { return $ this -> isProperlyConfigured ; } return $ this -> isProperlyConfigured = $ this -> checkConfiguration ( ) ; }
|
Ensure the attribute has been configured correctly .
|
53,474
|
public function convertValuesToValueIds ( $ values ) { $ tableName = $ this -> getSelectSource ( ) ; $ idColumn = $ this -> getIdColumn ( ) ; $ aliasColumn = $ this -> getAliasColumn ( ) ; if ( $ idColumn === $ aliasColumn ) { return $ values ; } $ values = \ array_unique ( \ array_filter ( $ values ) ) ; if ( empty ( $ values ) ) { return [ ] ; } return $ this -> connection -> createQueryBuilder ( ) -> select ( $ idColumn ) -> from ( $ tableName ) -> where ( $ aliasColumn . ' IN (:values)' ) -> setParameter ( 'values' , $ values , Connection :: PARAM_STR_ARRAY ) -> execute ( ) -> fetch ( \ PDO :: FETCH_ASSOC ) ; }
|
Convert the passed values to a list of value ids .
|
53,475
|
public static function make ( $ value , $ defaultOrder = self :: ORDER_ASCENDING ) { $ value = static :: prepareValue ( $ value ) ; list ( $ field , $ order ) = static :: parseFieldAndOrder ( $ value , $ defaultOrder ) ; static :: validateFieldName ( $ field ) ; return new static ( $ field , $ order ) ; }
|
Creates criterion object for given value .
|
53,476
|
public function apply ( Builder $ builder ) { $ sortMethod = 'sort' . studly_case ( $ this -> getField ( ) ) ; if ( method_exists ( $ builder -> getModel ( ) , $ sortMethod ) ) { call_user_func_array ( [ $ builder -> getModel ( ) , $ sortMethod ] , [ $ builder , $ this -> getOrder ( ) ] ) ; } else { $ builder -> orderBy ( $ this -> getField ( ) , $ this -> getOrder ( ) ) ; } }
|
Applies criterion to query .
|
53,477
|
protected static function parseFieldAndOrder ( $ value , $ defaultOrder ) { if ( preg_match ( '/^([^,]+)(,(asc|desc))?$/' , $ value , $ match ) ) { return [ $ match [ 1 ] , isset ( $ match [ 3 ] ) ? $ match [ 3 ] : $ defaultOrder ] ; } throw new InvalidArgumentException ( sprintf ( 'Unable to parse field name or order from "%s"' , $ value ) ) ; }
|
Parse query parameter and get field name and order .
|
53,478
|
public function fork ( ) { if ( ! function_exists ( 'pcntl_fork' ) ) { return false ; } $ pid = pcntl_fork ( ) ; if ( $ pid == - 1 ) { return false ; } elseif ( $ pid ) { return true ; } else { $ this -> start ( ) ; exit ( 0 ) ; } }
|
Fork a watch into a new process
|
53,479
|
public function stop ( ) { $ this -> setStop ( true ) ; foreach ( $ this -> getWatches ( ) as $ watch ) { $ watch -> stop ( ) ; } }
|
Stop all watches in the collection and break the loop
|
53,480
|
public function stream ( $ cycles = 0 ) { $ i_cycles = 0 ; while ( true ) { if ( $ this -> getStop ( ) ) { $ this -> internal_stop ( ) ; return ; } foreach ( $ this -> getWatches ( ) as $ watch ) { if ( $ this -> getStop ( ) ) { $ this -> internal_stop ( ) ; return ; } foreach ( $ watch -> stream ( 1 ) as $ message ) { if ( $ this -> getStop ( ) ) { $ this -> internal_stop ( ) ; return ; } yield $ message ; } } $ i_cycles ++ ; if ( $ cycles > 0 && $ cycles >= $ i_cycles ) { return ; } } }
|
Generator interface for looping
|
53,481
|
protected function getAttributeNamesFrom ( $ metaModelName ) { $ metaModel = $ this -> factory -> getMetaModel ( $ metaModelName ) ; $ result = [ ] ; if ( empty ( $ metaModel ) ) { return $ result ; } foreach ( $ metaModel -> getAttributes ( ) as $ attribute ) { $ name = $ attribute -> getName ( ) ; $ column = $ attribute -> getColName ( ) ; $ type = $ attribute -> get ( 'type' ) ; $ result [ $ column ] = \ sprintf ( '%s (%s - %s)' , $ name , $ column , $ type ) ; } return $ result ; }
|
Retrieve all attribute names from a given MetaModel name .
|
53,482
|
public function getFiltersParams ( BuildWidgetEvent $ event ) { if ( ! $ this -> scopeMatcher -> currentScopeIsBackend ( ) ) { return ; } if ( ( $ event -> getEnvironment ( ) -> getDataDefinition ( ) -> getName ( ) !== 'tl_metamodel_attribute' ) || ( $ event -> getProperty ( ) -> getName ( ) !== 'select_filterparams' ) ) { return ; } $ model = $ event -> getModel ( ) ; $ properties = $ event -> getProperty ( ) ; $ arrExtra = $ properties -> getExtra ( ) ; $ filterId = $ model -> getProperty ( 'select_filter' ) ; if ( empty ( $ filterId ) ) { return ; } $ filterSettings = $ this -> filterSettingFactory -> createCollection ( $ filterId ) ; if ( $ filterSettings == null ) { return ; } $ arrExtra [ 'subfields' ] = $ filterSettings -> getParameterDCA ( ) ; $ properties -> setExtra ( $ arrExtra ) ; }
|
Set the sub fields for the sub - dca based in the mm_filter selection .
|
53,483
|
private static function writeTempFile ( $ data ) { $ file = tempnam ( sys_get_temp_dir ( ) , self :: $ temp_file_prefix ) ; file_put_contents ( $ file , $ data ) ; register_shutdown_function ( function ( ) use ( $ file ) { if ( file_exists ( $ file ) ) { unlink ( $ file ) ; } } ) ; return $ file ; }
|
Create a temporary file to be used and destroyed at shutdown
|
53,484
|
public static function InClusterConfig ( ) { $ config = new Config ( ) ; $ config -> setToken ( file_get_contents ( '/var/run/secrets/kubernetes.io/serviceaccount/token' ) ) ; $ config -> setCertificateAuthorityPath ( '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt' ) ; $ config -> setServer ( 'https://kubernetes.default.svc' ) ; return $ config ; }
|
Create a config based off running inside a cluster
|
53,485
|
private function getContextOptions ( ) { $ opts = array ( 'http' => array ( 'ignore_errors' => true , 'header' => "Accept: application/json, */*\r\nContent-Encoding: gzip\r\n" ) , ) ; if ( ! empty ( $ this -> config -> getCertificateAuthorityPath ( ) ) ) { $ opts [ 'ssl' ] [ 'cafile' ] = $ this -> config -> getCertificateAuthorityPath ( ) ; } if ( ! empty ( $ this -> config -> getClientCertificatePath ( ) ) ) { $ opts [ 'ssl' ] [ 'local_cert' ] = $ this -> config -> getClientCertificatePath ( ) ; } if ( ! empty ( $ this -> config -> getClientKeyPath ( ) ) ) { $ opts [ 'ssl' ] [ 'local_pk' ] = $ this -> config -> getClientKeyPath ( ) ; } $ token = $ this -> config -> getToken ( ) ; if ( ! empty ( $ token ) ) { $ opts [ 'http' ] [ 'header' ] .= "Authorization: Bearer ${token}\r\n" ; } return $ opts ; }
|
Get common options to be used for the stream context
|
53,486
|
public function getStreamContext ( $ verb = 'GET' , $ opts = [ ] ) { $ o = array_merge_recursive ( $ this -> getContextOptions ( ) , $ opts ) ; $ o [ 'http' ] [ 'method' ] = $ verb ; if ( substr ( $ verb , 0 , 5 ) == 'PATCH' ) { switch ( $ verb ) { case 'PATCH-JSON' : $ o [ 'http' ] [ 'header' ] .= "Content-Type: application/json-patch+json\r\n" ; break ; case 'PATCH-STRATEGIC-MERGE' : $ o [ 'http' ] [ 'header' ] .= "Content-Type: application/strategic-merge-patch+json\r\n" ; break ; case 'PATCH' : case 'PATCH-MERGE' : default : $ o [ 'http' ] [ 'header' ] .= "Content-Type: application/merge-patch+json\r\n" ; break ; } } else { $ o [ 'http' ] [ 'header' ] .= "Content-Type: application/json\r\n" ; } return stream_context_create ( $ o ) ; }
|
Get the stream context
|
53,487
|
public function createWatch ( $ endpoint , $ params = [ ] , \ Closure $ callback ) { $ watch = new Watch ( $ this , $ endpoint , $ params , $ callback ) ; return $ watch ; }
|
Create a Watch for api feed
|
53,488
|
public function decision ( $ string ) { $ dominantClass = $ this -> sentiment -> categorise ( $ string ) ; switch ( $ dominantClass ) { case 'neg' : return self :: NEGATIVE ; case 'neu' : return self :: NEUTRAL ; case 'pos' : return self :: POSITIVE ; } }
|
Get the sentiment of a phrase .
|
53,489
|
public function scores ( $ string ) { $ scores = $ this -> sentiment -> score ( $ string ) ; $ array = [ ] ; foreach ( [ self :: NEGATIVE , self :: NEUTRAL , self :: POSITIVE ] as $ value ) { $ array [ $ value ] = round ( $ scores [ substr ( $ value , 0 , 3 ) ] , 2 ) ; } return $ array ; }
|
Get scores for each decision .
|
53,490
|
public function exportAction ( ) { $ request = $ this -> getRequest ( ) ; if ( ! $ request -> isPost ( ) ) { $ this -> _redirect ( self :: ADMINHTML_SALES_ORDER_INDEX ) ; } $ orderIds = $ this -> getRequest ( ) -> getPost ( 'order_ids' , array ( ) ) ; try { $ filePath = Mage :: getModel ( 'australia/shipping_carrier_eparcel_export_csv' ) -> exportOrders ( $ orderIds ) ; $ this -> _prepareDownloadResponse ( basename ( $ filePath ) , file_get_contents ( $ filePath ) ) ; } catch ( Exception $ e ) { Mage :: getSingleton ( 'core/session' ) -> addError ( $ e -> getMessage ( ) ) ; $ this -> _redirect ( self :: ADMINHTML_SALES_ORDER_INDEX ) ; } }
|
Generate and export a CSV file for the given orders .
|
53,491
|
public function exportTableratesAction ( ) { $ rates = Mage :: getResourceModel ( 'australia/shipping_carrier_eparcel_collection' ) ; $ response = array ( array ( 'Country' , 'Region/State' , 'Postcodes' , 'Weight from' , 'Weight to' , 'Parcel Cost' , 'Cost Per Kg' , 'Delivery Type' , 'Charge Code Individual' , 'Charge Code Business' ) ) ; foreach ( $ rates as $ rate ) { $ countryId = $ rate -> getData ( 'dest_country_id' ) ; $ countryCode = Mage :: getModel ( 'directory/country' ) -> load ( $ countryId ) -> getIso3Code ( ) ; $ regionId = $ rate -> getData ( 'dest_region_id' ) ; $ regionCode = Mage :: getModel ( 'directory/region' ) -> load ( $ regionId ) -> getCode ( ) ; $ response [ ] = array ( $ countryCode , $ regionCode , $ rate -> getData ( 'dest_zip' ) , $ rate -> getData ( 'condition_from_value' ) , $ rate -> getData ( 'condition_to_value' ) , $ rate -> getData ( 'price' ) , $ rate -> getData ( 'price_per_kg' ) , $ rate -> getData ( 'delivery_type' ) , $ rate -> getData ( 'charge_code_individual' ) , $ rate -> getData ( 'charge_code_business' ) ) ; } $ csv = new Varien_File_Csv ( ) ; $ temp = tmpfile ( ) ; foreach ( $ response as $ responseRow ) { $ csv -> fputcsv ( $ temp , $ responseRow ) ; } rewind ( $ temp ) ; $ contents = stream_get_contents ( $ temp ) ; $ this -> _prepareDownloadResponse ( 'tablerates.csv' , $ contents ) ; fclose ( $ temp ) ; }
|
Export the eParcel table rates as a CSV file .
|
53,492
|
public function validateAction ( ) { if ( ! $ this -> getRequest ( ) -> isPost ( ) ) { $ this -> getResponse ( ) -> setHttpResponseCode ( 405 ) ; return ; } $ data = $ this -> getRequest ( ) -> getPost ( ) ; if ( empty ( $ data ) || ! isset ( $ data [ 'country_id' ] , $ data [ 'region_id' ] , $ data [ 'street' ] , $ data [ 'city' ] , $ data [ 'postcode' ] ) ) { $ this -> getResponse ( ) -> setHttpResponseCode ( 400 ) ; return ; } $ country = Mage :: getModel ( 'directory/country' ) -> load ( $ data [ 'country_id' ] ) -> getName ( ) ; $ region = Mage :: getModel ( 'directory/region' ) -> load ( $ data [ 'region_id' ] ) -> getCode ( ) ; $ result = Mage :: helper ( 'australia/address' ) -> validate ( $ data [ 'street' ] , $ region , $ data [ 'city' ] , $ data [ 'postcode' ] , $ country ) ; $ this -> getResponse ( ) -> setHeader ( 'Content-type' , 'application/json' ) ; $ this -> getResponse ( ) -> setBody ( Mage :: helper ( 'core' ) -> jsonEncode ( $ result ) ) ; }
|
Sends a request to the address validation backend to validate the address the customer provided on the checkout page .
|
53,493
|
public function collectRates ( Mage_Shipping_Model_Rate_Request $ request ) { if ( ! $ this -> getConfigFlag ( 'active' ) ) { return false ; } $ origCountry = Mage :: getStoreConfig ( 'shipping/origin/country_id' , $ request -> getStore ( ) ) ; if ( $ origCountry != Fontis_Australia_Helper_Data :: AUSTRALIA_COUNTRY_CODE ) { return false ; } if ( $ this -> _client == null ) { return false ; } $ fromPostcode = str_pad ( ( int ) Mage :: getStoreConfig ( 'shipping/origin/postcode' , $ this -> getStore ( ) ) , 4 , '0' , STR_PAD_LEFT ) ; $ toPostcode = str_pad ( ( int ) $ request -> getDestPostcode ( ) , 4 , '0' , STR_PAD_LEFT ) ; $ destCountry = $ request -> getDestCountryId ( ) ; if ( ! $ destCountry ) { $ destCountry = Fontis_Australia_Helper_Data :: AUSTRALIA_COUNTRY_CODE ; } $ helper = Mage :: helper ( 'australia/australiapost' ) ; $ weight = ( float ) $ request -> getPackageWeight ( ) ; $ length = ( int ) $ helper -> getAttribute ( $ request , 'length' ) ; $ width = ( int ) $ helper -> getAttribute ( $ request , 'width' ) ; $ height = ( int ) $ helper -> getAttribute ( $ request , 'height' ) ; $ extraCover = max ( ( int ) $ request -> getPackageValue ( ) , self :: EXTRA_COVER_LIMIT ) ; $ config = array ( 'from_postcode' => $ fromPostcode , 'to_postcode' => $ toPostcode , 'length' => $ length , 'width' => $ width , 'height' => $ height , 'weight' => $ weight , 'country_code' => $ destCountry ) ; $ this -> _getQuotes ( $ extraCover , $ config ) ; $ _result = $ this -> _result -> asArray ( ) ; if ( empty ( $ _result ) ) { return false ; } return $ this -> _result ; }
|
Collects the shipping rates for Australia Post from the REST API .
|
53,494
|
protected function _isAvailableShippingMethod ( $ name , $ destCountry ) { return $ this -> _isOptionVisibilityRequired ( $ name , $ destCountry ) && ! $ this -> _isOptionVisibilityNever ( $ name , $ destCountry ) ; }
|
Determines whether a shipping method should be added to the result .
|
53,495
|
protected function _isOptionVisibilityNever ( $ name , $ destCountry ) { $ suboptions = $ this -> _getOptionVisibilities ( $ destCountry , Fontis_Australia_Model_Shipping_Carrier_Australiapost_Source_Visibility :: NEVER ) ; foreach ( $ suboptions as $ suboption ) { if ( stripos ( $ name , $ suboption ) !== false ) { return true ; } } return false ; }
|
Checks whether a shipping method option has the visibility never
|
53,496
|
protected function _isOptionVisibilityRequired ( $ name , $ destCountry ) { $ suboptions = $ this -> _getOptionVisibilities ( $ destCountry , Fontis_Australia_Model_Shipping_Carrier_Australiapost_Source_Visibility :: REQUIRED ) ; foreach ( $ suboptions as $ suboption ) { if ( stripos ( $ name , $ suboption ) === false ) { return false ; } } return true ; }
|
Checks whether a shipping method has the visibility required
|
53,497
|
protected function createMethod ( $ code , $ title , $ price ) { $ method = Mage :: getModel ( 'shipping/rate_result_method' ) ; $ method -> setCarrier ( $ this -> _code ) ; $ method -> setCarrierTitle ( $ this -> getConfigData ( 'title' ) ) ; $ method -> setMethod ( $ code ) ; $ method -> setMethodTitle ( $ title ) ; $ method -> setPrice ( $ this -> getFinalPriceWithHandlingFee ( $ price ) ) ; return $ method ; }
|
Simplifies creating a new shipping method .
|
53,498
|
public function getCode ( $ type , $ code = '' ) { $ helper = Mage :: helper ( 'australia' ) ; $ codes = array ( 'services' => array ( 'AUS_LETTER_EXPRESS_SMALL' => $ helper -> __ ( 'Express Post Small Envelope' ) , 'AUS_LETTER_REGULAR_LARGE' => $ helper -> __ ( 'Large Letter' ) , 'AUS_PARCEL_COURIER' => $ helper -> __ ( 'Courier Post' ) , 'AUS_PARCEL_COURIER_SATCHEL_MEDIUM' => $ helper -> __ ( 'Courier Post Assessed Medium Satchel' ) , 'AUS_PARCEL_EXPRESS' => $ helper -> __ ( 'Express Post' ) , 'AUS_PARCEL_REGULAR' => $ helper -> __ ( 'Parcel Post' ) , 'INT_PARCEL_COR_OWN_PACKAGING' => $ helper -> __ ( 'International Courier' ) , 'INT_PARCEL_EXP_OWN_PACKAGING' => $ helper -> __ ( 'International Express' ) , 'INT_PARCEL_STD_OWN_PACKAGING' => $ helper -> __ ( 'International Standard' ) , 'INT_PARCEL_AIR_OWN_PACKAGING' => $ helper -> __ ( 'International Economy Air' ) , 'INT_PARCEL_SEA_OWN_PACKAGING' => $ helper -> __ ( 'International Economy Sea' ) , ) , 'extra_cover' => array ( 'AUS_SERVICE_OPTION_SIGNATURE_ON_DELIVERY' => $ helper -> __ ( 'Signature on Delivery' ) , 'AUS_SERVICE_OPTION_COURIER_EXTRA_COVER_SERVICE' => $ helper -> __ ( 'Standard cover' ) ) ) ; if ( ! isset ( $ codes [ $ type ] ) ) { return false ; } elseif ( '' === $ code ) { return $ codes [ $ type ] ; } if ( ! isset ( $ codes [ $ type ] [ $ code ] ) ) { return false ; } else { return $ codes [ $ type ] [ $ code ] ; } }
|
Returns an associative array of shipping method codes .
|
53,499
|
public function addHistory ( $ event ) { $ order = $ event -> getOrder ( ) ; if ( $ order && $ order -> getPayment ( ) ) { if ( $ order -> getPayment ( ) -> getMethod ( ) == Fontis_Australia_Model_Payment_Directdeposit :: CODE ) { $ order -> addStatusHistoryComment ( 'Order placed with Direct Deposit' ) -> setIsCustomerNotified ( false ) ; } elseif ( $ order -> getPayment ( ) -> getMethod ( ) == Fontis_Australia_Model_Payment_Bpay :: CODE ) { $ order -> addStatusHistoryComment ( 'Order placed with BPay' ) -> setIsCustomerNotified ( false ) ; } } }
|
Adds a history entry to orders placed using AU direct deposit or BPay .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.