idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
5,100
|
private function setOrderType ( $ data , ApiOrderInterface $ order , $ patch = false ) { $ type = $ this -> getProperty ( $ data , 'type' , $ order -> getType ( ) ) ; if ( isset ( $ data [ 'type' ] ) ) { if ( is_array ( $ type ) && isset ( $ type [ 'id' ] ) ) { $ typeId = $ type [ 'id' ] ; } elseif ( is_numeric ( $ type ) ) { $ typeId = $ type ; } else { throw new OrderException ( 'No typeid given' ) ; } } elseif ( ! $ patch ) { $ typeId = OrderType :: MANUAL ; } else { return ; } $ orderType = $ this -> getOrderTypeEntityById ( $ typeId ) ; if ( ! $ orderType ) { throw new EntityNotFoundException ( static :: $ orderTypeEntityName , $ typeId ) ; } $ order -> setType ( $ orderType ) ; }
|
Sets OrderType on an order
|
5,101
|
private function addContactRelation ( array $ data , $ key , $ addCallback ) { $ contact = null ; if ( array_key_exists ( $ key , $ data ) && is_array ( $ data [ $ key ] ) && array_key_exists ( 'id' , $ data [ $ key ] ) ) { $ contactId = $ data [ $ key ] [ 'id' ] ; $ contact = $ this -> em -> getRepository ( static :: $ contactEntityName ) -> find ( $ contactId ) ; if ( ! $ contact ) { throw new OrderDependencyNotFoundException ( static :: $ contactEntityName , $ contactId ) ; } $ addCallback ( $ contact ) ; } return $ contact ; }
|
Searches for contact in specified data and calls callback function
|
5,102
|
private function setCustomerAccount ( $ data , Order $ order , $ patch = false ) { $ accountData = $ this -> getProperty ( $ data , 'customerAccount' ) ; if ( $ accountData ) { if ( ! array_key_exists ( 'id' , $ accountData ) ) { throw new MissingOrderAttributeException ( 'account.id' ) ; } $ account = $ this -> accountRepository -> find ( $ accountData [ 'id' ] ) ; if ( ! $ account ) { throw new OrderDependencyNotFoundException ( 'Account' , $ accountData [ 'id' ] ) ; } $ order -> setCustomerAccount ( $ account ) ; return $ account ; } elseif ( ! $ patch ) { $ order -> setCustomerAccount ( null ) ; } return null ; }
|
Sets the customer account of an order
|
5,103
|
private function processItems ( $ data , Order $ order , $ locale , $ userId = null ) { $ result = true ; try { if ( $ this -> checkIfSet ( 'items' , $ data ) ) { if ( ! is_array ( $ data [ 'items' ] ) ) { throw new MissingOrderAttributeException ( 'items array' ) ; } $ items = $ data [ 'items' ] ; $ get = function ( $ item ) { return $ item -> getId ( ) ; } ; $ delete = function ( $ item ) use ( $ order ) { $ this -> removeItem ( $ item -> getEntity ( ) , $ order -> getEntity ( ) ) ; } ; $ update = function ( $ item , $ matchedEntry ) use ( $ locale , $ userId , $ order ) { $ item = $ item -> getEntity ( ) ; $ itemEntity = $ this -> updateItem ( $ item , $ matchedEntry , $ locale , $ userId ) ; return $ itemEntity ? true : false ; } ; $ add = function ( $ itemData ) use ( $ locale , $ userId , $ order ) { return $ this -> addItem ( $ itemData , $ locale , $ userId , $ order ) ; } ; $ result = $ this -> processSubEntities ( $ order -> getItems ( ) , $ items , $ get , $ add , $ update , $ delete ) ; } } catch ( \ Exception $ e ) { throw new OrderException ( 'Error while creating items: ' . $ e -> getMessage ( ) ) ; } return $ result ; }
|
Processes items defined in an order and creates item entities
|
5,104
|
public static function create ( $ accessor , $ name , array $ arguments = [ ] ) { $ container = static :: getContainer ( ) ; $ object = $ container -> get ( $ accessor ) ; return call_user_func_array ( [ $ object , $ name ] , $ arguments ) ; }
|
Get provided accessor from container and call method
|
5,105
|
public function registerNamespace ( $ namespace , $ paths , $ type = 'psr-0' ) { switch ( $ type ) { case 'psr-0' : parent :: registerNamespace ( $ namespace , $ paths ) ; break ; case 'psr-4' : $ this -> psr4Loader -> addNamespace ( $ namespace , $ paths ) ; break ; default : throw new AutoloadException ( "$type is not a known autoloader format" ) ; } }
|
Overridden to allow injecting psr - 4 into the mix . Also opens up doors for alternative formats to be used later . Either way it s a mess here right now
|
5,106
|
protected static function detectType ( array $ data ) { foreach ( [ self :: TYPE_TEXT , self :: TYPE_AUDIO , self :: TYPE_DOCUMENT , self :: TYPE_GAME , self :: TYPE_PHOTO , self :: TYPE_STICKER , self :: TYPE_VIDEO , self :: TYPE_VOICE , self :: TYPE_CONTACT , self :: TYPE_LOCATION , self :: TYPE_VENUE , self :: TYPE_VIDEO_NOTE , self :: TYPE_NEW_CHAT_MEMBERS , self :: TYPE_LEFT_CHAT_MEMBER , self :: TYPE_NEW_CHAT_TITLE , self :: TYPE_NEW_CHAT_PHOTO , self :: TYPE_DELETE_CHAT_PHOTO , self :: TYPE_GROUP_CHAT_CREATED , self :: TYPE_SUPERGROUP_CHAT_CREATED , self :: TYPE_CHANNEL_CHAT_CREATED , self :: TYPE_MESSAGE_PINNED , self :: TYPE_INVOICE , self :: TYPE_SUCCESSFUL_PAYMENT , ] as $ type ) { if ( isset ( $ data [ $ type ] ) ) { return $ type ; } } return static :: TYPE_UNKNOWN ; }
|
Detects message type
|
5,107
|
public function add ( MiddlewareInterface $ middleware ) : self { $ pipe = clone $ this ; array_push ( $ pipe -> middlewares , $ middleware ) ; return $ pipe ; }
|
Creates a new pipe with the given middleware connected .
|
5,108
|
public static function word ( int $ num ) : string { $ numberWordMap = [ 1 => Yii :: t ( 'yuncms' , 'One' ) , 2 => Yii :: t ( 'yuncms' , 'Two' ) , 3 => Yii :: t ( 'yuncms' , 'Three' ) , 4 => Yii :: t ( 'yuncms' , 'Four' ) , 5 => Yii :: t ( 'yuncms' , 'Five' ) , 6 => Yii :: t ( 'yuncms' , 'Six' ) , 7 => Yii :: t ( 'yuncms' , 'Seven' ) , 8 => Yii :: t ( 'yuncms' , 'Eight' ) , 9 => Yii :: t ( 'yuncms' , 'Nine' ) ] ; if ( isset ( $ numberWordMap [ $ num ] ) ) { return $ numberWordMap [ $ num ] ; } return ( string ) $ num ; }
|
Returns the word version of a number
|
5,109
|
public function get ( $ columns = [ '*' ] ) { $ result = $ this -> getBuilder ( ) -> get ( $ columns ) ; $ this -> resetBuilder ( ) ; return $ result ; }
|
Execute the query and retrieve result .
|
5,110
|
public function count ( $ columns = '*' ) { $ result = $ this -> getBuilder ( ) -> count ( $ columns ) ; $ this -> resetBuilder ( ) ; return ( int ) $ result ; }
|
Execute query as a count statement .
|
5,111
|
public function max ( $ column ) { $ result = $ this -> getBuilder ( ) -> max ( $ column ) ; $ this -> resetBuilder ( ) ; return $ result ; }
|
Retrieve the maximum value of a given column .
|
5,112
|
public function update ( array $ values ) { $ result = $ this -> getBuilder ( ) -> update ( $ values ) ; $ this -> resetBuilder ( ) ; return ( int ) $ result ; }
|
Execute query as an update statement .
|
5,113
|
public function raw ( $ value ) { $ result = $ this -> getBuilder ( ) -> raw ( $ value ) ; $ this -> resetBuilder ( ) ; return $ result ; }
|
Create a raw database expression .
|
5,114
|
public function renderSql ( ) { $ result = vsprintf ( $ this -> getBuilder ( ) -> getQuery ( ) -> toSql ( ) , $ this -> getBuilder ( ) -> getQuery ( ) -> getBindings ( ) ) ; $ this -> resetBuilder ( ) ; return $ result ; }
|
Render repository s query SQL string .
|
5,115
|
public function withTrashed ( ) { if ( ! in_array ( IlluminateEloquentSoftDeletes :: class , class_uses ( $ this -> getModel ( ) ) ) ) { throw new ModelNotSoftDeletable ( 'Model [%s] is not using the Soft Delete trait' ) ; } $ this -> setBuilder ( $ this -> getModel ( ) -> withTrashed ( ) ) ; return $ this ; }
|
Include soft deleted entries in query . Note this will reset the build
|
5,116
|
public function onlyTrashed ( ) { if ( ! in_array ( IlluminateEloquentSoftDeletes :: class , class_uses ( $ this -> getModel ( ) ) ) ) { throw new ModelNotSoftDeletable ( 'Model [%s] is not using the Soft Delete trait' ) ; } $ this -> setBuilder ( $ this -> getModel ( ) -> onlyTrashed ( ) ) ; return $ this ; }
|
Only include soft deleted entries in query . Note this will reset the build
|
5,117
|
public function getByContinuously ( $ column , $ value , array $ columns = [ '*' ] , $ retries = 10 , $ delayMs = 100 , $ maxDelay = 2000 , $ maxRetries = 100 ) { $ maxDelay = ( $ maxDelay > 2000 ) ? 2000 : $ maxDelay ; $ maxRetries = ( $ maxRetries > 100 ) ? 100 : $ maxRetries ; if ( $ delayMs > $ maxDelay ) { throw new NodesException ( 'Invalid input parameter. Maximum delay is ' . $ maxDelay . ' milliseconds' , 0 , null , false ) ; } if ( $ retries > $ maxRetries ) { throw new NodesException ( 'Invalid input parameter. Maximum retry amount is ' . $ maxRetries , 0 , null , false ) ; } for ( $ try = 0 ; $ try < $ retries ; $ try ++ ) { $ entity = $ this -> getBy ( $ column , $ value , $ columns ) ; if ( ! empty ( $ entity ) ) { return $ entity ; } usleep ( $ delayMs * 1000 ) ; } return false ; }
|
Retrieve entity by a specific column and value . Will retry with a delay until found .
|
5,118
|
public function getByIdContinuously ( $ id , array $ columns = [ '*' ] , $ retries = 10 , $ delayMs = 100 ) { return $ this -> getByContinuously ( 'id' , $ id , $ columns , $ retries , $ delayMs ) ; }
|
Retrieve entity by ID . Will retry with a delay until found .
|
5,119
|
public function getByIdContinuouslyOrFail ( $ id , array $ columns = [ '*' ] , $ retries = 10 , $ delayMs = 100 ) { $ result = $ this -> getByContinuously ( 'id' , $ id , $ columns , $ retries , $ delayMs ) ; if ( empty ( $ result ) ) { throw new EntityNotFoundException ( sprintf ( '%s not found continuously by Id with value [%s]' , get_class ( $ this -> getModel ( ) ) , $ id ) ) ; } return $ result ; }
|
Retrieve entity by ID . Will retry with a delay until found or throw an exception .
|
5,120
|
public function deleteMorphsByEntity ( IlluminateEloquentModel $ entity , $ relationName , $ forceDelete = false ) { $ entities = $ this -> getBuilder ( ) -> select ( [ 'id' ] ) -> where ( function ( $ query ) use ( $ entity , $ relationName ) { $ query -> where ( $ relationName . '_type' , '=' , get_class ( $ entity ) ) -> where ( $ relationName . '_id' , '=' , ( int ) $ entity -> id ) ; } ) -> get ( ) ; $ deleteCount = 0 ; foreach ( $ entities as $ e ) { $ status = ( $ forceDelete ) ? $ e -> forceDelete ( ) : $ e -> delete ( ) ; if ( ( bool ) $ status ) { $ deleteCount += 1 ; } } $ this -> resetBuilder ( ) ; return $ deleteCount ; }
|
Delete morphed relations by entity .
|
5,121
|
public function restoreMorphsByEntity ( IlluminateEloquentModel $ entity , $ relationName ) { if ( ! in_array ( IlluminateEloquentSoftDeletes :: class , class_uses ( $ this -> getModel ( ) ) ) ) { throw new ModelNotSoftDeletable ( 'Model [%s] is not using the Soft Delete trait' ) ; } $ entities = $ this -> onlyTrashed ( ) -> getBuilder ( ) -> select ( [ 'id' ] ) -> where ( function ( $ query ) use ( $ entity , $ relationName ) { $ query -> where ( $ relationName . '_type' , '=' , get_class ( $ entity ) ) -> where ( $ relationName . '_id' , '=' , ( int ) $ entity -> id ) ; } ) -> get ( ) ; $ restoreCount = 0 ; foreach ( $ entities as $ e ) { if ( ( bool ) $ e -> restore ( ) ) { $ restoreCount += 1 ; } } $ this -> resetBuilder ( ) ; return $ restoreCount ; }
|
Restore morphed relations by entity .
|
5,122
|
public function setModel ( IlluminateEloquentModel $ model ) { $ this -> model = $ model ; $ this -> setBuilder ( $ model -> newQuery ( ) ) ; return $ this ; }
|
Set repository model .
|
5,123
|
public function setBuilder ( IlluminateEloquentBuilder $ builder = null ) { if ( empty ( $ builder ) ) { $ builder = $ this -> getModel ( ) -> newQuery ( ) ; } $ this -> builder = $ builder ; return $ this ; }
|
Set repository builder .
|
5,124
|
public function register ( ) { wp_register_script ( $ this -> handle , $ this -> url , $ this -> dependencies , $ this -> version , $ this -> footer ) ; if ( ! empty ( $ this -> localize [ 'data' ] ) && ! empty ( $ this -> localize [ 'data' ] ) ) { wp_localize_script ( $ this -> handle , $ this -> localize [ 'name' ] , $ this -> localize [ 'data' ] ) ; } $ this -> is_registered = true ; }
|
Enqueue the script and localize the data as needed
|
5,125
|
public static function erase ( $ name ) { try { $ class = get_called_class ( ) ; $ cookie = new $ class ( $ name ) ; return $ cookie -> delete ( ) ; } catch ( CookieException $ ce ) { throw $ ce ; } }
|
Static method to quickly delete a cookie
|
5,126
|
private function isPerfectCache ( ) { if ( $ this -> cacheMap [ $ this -> hash ] + 0x93a80 > time ( ) ) { $ this -> cacheData = json_decode ( file_get_contents ( $ this -> cacheFile ) , true ) ; return is_array ( $ this -> cacheData ) ; } return false ; }
|
Check the current cache is perfect or not .
|
5,127
|
private function _exec ( ) { if ( $ this -> isCached ( ) && $ this -> isPerfectCache ( ) ) { return $ this -> getCache ( ) ; } else { return $ this -> fixer ( $ this -> search ( $ this -> query , $ this -> limit ) ) ; } }
|
Search data .
|
5,128
|
private function fixer ( $ data , $ noWrite = false ) { if ( $ noWrite or $ this -> writeCache ( $ data ) ) { $ data = $ noWrite ? $ data : json_decode ( $ data , true ) ; if ( $ data [ 'success' ] === true ) { if ( isset ( $ data [ 'data' ] [ 'tasks' ] [ 'items' ] ) ) { $ r = [ ] ; foreach ( $ data [ 'data' ] [ 'tasks' ] [ 'items' ] as $ k => $ v ) { $ responses = [ ] ; foreach ( $ v [ 'responses' ] as $ j => $ q ) { $ responses [ ] = [ "content" => $ q [ 'content' ] ] ; } $ r [ ] = [ "content" => $ v [ 'task' ] [ 'content' ] , "responses" => $ responses ] ; } return $ r ; } } } return false ; }
|
Fix raw data .
|
5,129
|
private function writeCache ( $ data ) { $ this -> cacheMap [ $ this -> hash ] = time ( ) ; $ handle = fopen ( $ this -> cacheMapFile , "w" ) ; flock ( $ handle , LOCK_EX ) ; $ write1 = fwrite ( $ handle , json_encode ( $ this -> cacheMap , JSON_UNESCAPED_SLASHES ) ) ; fclose ( $ handle ) ; $ handle = fopen ( $ this -> cacheFile , "w" ) ; flock ( $ handle , LOCK_EX ) ; $ write2 = fwrite ( $ handle , $ data ) ; fclose ( $ handle ) ; return ( ( bool ) $ write1 && ( bool ) $ write2 ) ; }
|
Write cache .
|
5,130
|
public function unbind ( ) { if ( $ this -> isBinded ( ) ) { $ this -> getSocket ( ) -> unbind ( $ this -> dsn ) ; $ this -> dsn = null ; } return $ this ; }
|
Unbinds socket from current binded dsn
|
5,131
|
public function receiveRequest ( $ wait = self :: WAIT ) { return $ this -> getSocket ( ) -> recv ( ( $ wait ? 0 : \ ZMQ :: MODE_DONTWAIT ) ) ; }
|
Getting next request from socket .
|
5,132
|
public function sendReply ( $ reply , $ wait = self :: WAIT ) { $ this -> getSocket ( ) -> send ( $ reply , ( $ wait ? 0 : \ ZMQ :: MODE_DONTWAIT ) ) ; return $ this ; }
|
Sending reply to ZMQ socket .
|
5,133
|
public function analyzeBlob ( $ text ) { $ config = Config :: getInstance ( ) ; $ url = $ config -> getParams ( ) [ 'credentials' ] [ 'url' ] . '/v2/profile' ; return $ this -> _worker -> post ( $ url , array ( 'body' => $ text , 'headers' => array ( 'Content-Type' => 'text/plain' ) , ) ) ; }
|
Analayze a blob of text .
|
5,134
|
public function getWorker ( ) { if ( $ this -> _worker === null ) { $ config = Config :: getInstance ( ) ; $ this -> setupWorker ( $ config ) ; } return $ this -> _worker ; }
|
Get the current worker .
|
5,135
|
public function setupWorker ( Config $ config ) { $ credentials = $ config -> getParams ( ) [ 'credentials' ] ; $ this -> _worker = new \ GuzzleHttp \ Client ( array ( 'defaults' => array ( 'auth' => array ( $ credentials [ 'username' ] , $ credentials [ 'password' ] ) , ) , ) ) ; }
|
Constructs the middleware REST client library .
|
5,136
|
public function setExpression ( $ expression ) { $ definitions = array ( '@yearly' => '0 0 1 1 *' , '@annually' => '0 0 1 1 *' , '@monthly' => '0 0 1 * *' , '@weekly' => '0 0 * * 0' , '@daily' => '0 0 * * *' , '@hourly' => '0 * * * *' ) ; if ( isset ( $ definitions [ $ expression ] ) ) { $ expression = $ definitions [ $ expression ] ; } $ expressionParts = explode ( ' ' , $ expression ) ; if ( count ( $ expressionParts ) < 5 || count ( $ expressionParts ) > 6 ) { throw new \ InvalidArgumentException ( sprintf ( '%s is not a valid CRON expression.' , $ expression ) ) ; } $ this -> expression = $ expression ; $ this -> fields = array ( ) ; foreach ( $ expressionParts as $ position => $ value ) { $ this -> fields [ $ position ] = $ this -> getField ( $ position , $ value ) ; } }
|
Set CRON expression .
|
5,137
|
public function matches ( \ DateTime $ date ) { foreach ( $ this -> fields as $ field ) { if ( ! $ field -> matches ( $ date ) ) { return false ; } } return true ; }
|
Checks if the CRON expression matches the given date .
|
5,138
|
private function getField ( $ position , $ value ) { switch ( $ position ) { case 0 : return new MinuteField ( $ value ) ; case 1 : return new HourField ( $ value ) ; case 2 : return new DayOfMonthField ( $ value ) ; case 3 : return new MonthField ( $ value ) ; case 4 : return new DayOfWeekField ( $ value ) ; case 5 : return new YearField ( $ value ) ; default : throw new \ InvalidArgumentException ( sprintf ( '%s is not a valid CRON expression position.' , $ position ) ) ; } }
|
Get the field object for the given position with the given value .
|
5,139
|
protected function configure ( ) { $ this -> setName ( 'scan' ) -> setDescription ( 'scan phpunit test files for static code analysis' ) -> setHelp ( $ this -> getHelpOutput ( ) ) -> addArgument ( 'phpunit-config' , InputArgument :: OPTIONAL , 'the source path of your corresponding phpunit xml config file (e.g. ./tests/phpunit.xml)' ) -> addOption ( 'phpunit-config-suite' , null , InputOption :: VALUE_OPTIONAL , 'name of the target test suite inside your php config xml file, this test suite will be scanned' ) -> addOption ( 'raw-scan-path' , null , InputOption :: VALUE_OPTIONAL , 'raw mode option: the source path of your corresponding phpunit test files or a specific testFile (e.g. tests/), this option will always override phpunit.xml settings!' ) -> addOption ( 'raw-autoload-file' , null , InputOption :: VALUE_OPTIONAL , 'raw-mode option: your application autoload file and path (e.g. ../app/autoload.php for running in symfony context), this option will always override phpunit.xml settings!' ) -> addOption ( 'raw-exclude-path' , null , InputOption :: VALUE_OPTIONAL , 'raw-mode option: exclude a specific path from planned scan' , null ) -> addOption ( 'output-format' , 'f' , InputOption :: VALUE_OPTIONAL , 'output format of scan result (json|text)' , 'text' ) -> addOption ( 'output-level' , 'l' , InputOption :: VALUE_OPTIONAL , 'level of output information (0:minimal, 1: normal (default), 2: detailed)' , 1 ) -> addOption ( 'stop-on-error' , null , InputOption :: VALUE_OPTIONAL , 'stop on first application error raises' , false ) -> addOption ( 'stop-on-failure' , null , InputOption :: VALUE_OPTIONAL , 'stop on first detected coverFish failure raises' , false ) ; }
|
additional options and arguments for our cli application
|
5,140
|
protected function execute ( InputInterface $ input , OutputInterface $ output ) { $ this -> showExecTitle ( $ input , $ output ) ; $ this -> prepareExecute ( $ input ) ; $ cliOptions = array ( 'sys_phpunit_config' => $ input -> getArgument ( 'phpunit-config' ) , 'sys_phpunit_config_test_suite' => $ input -> getOption ( 'phpunit-config-suite' ) , 'sys_stop_on_error' => $ input -> getOption ( 'stop-on-error' ) , 'sys_stop_on_failure' => $ input -> getOption ( 'stop-on-failure' ) , 'raw_scan_source' => $ input -> getOption ( 'raw-scan-path' ) , 'raw_scan_autoload_file' => $ input -> getOption ( 'raw-autoload-file' ) , 'raw_scan_exclude_path' => $ input -> getOption ( 'raw-exclude-path' ) , ) ; $ outOptions = array ( 'out_verbose' => $ input -> getOption ( 'verbose' ) , 'out_format' => $ input -> getOption ( 'output-format' ) , 'out_level' => ( int ) $ input -> getOption ( 'output-level' ) , 'out_no_ansi' => $ input -> getOption ( 'no-ansi' ) , 'out_no_echo' => $ input -> getOption ( 'quiet' ) , ) ; try { $ scanner = new CoverFishScanner ( $ cliOptions , $ outOptions , $ output ) ; $ scanner -> analysePHPUnitFiles ( ) ; } catch ( CoverFishFailExit $ e ) { return CoverFishFailExit :: RETURN_CODE_SCAN_FAIL ; } return 0 ; }
|
exec command scan
|
5,141
|
public function prepareExecute ( InputInterface $ input ) { $ this -> coverFishHelper = new CoverFishHelper ( ) ; $ phpUnitConfigFile = $ input -> getArgument ( 'phpunit-config' ) ; if ( false === empty ( $ phpUnitConfigFile ) && false === $ this -> coverFishHelper -> checkFileOrPath ( $ phpUnitConfigFile ) ) { throw new \ Exception ( sprintf ( 'phpunit config file "%s" not found! please define your phpunit.xml config file to use (e.g. tests/phpunit.xml)' , $ phpUnitConfigFile ) ) ; } $ testPathOrFile = $ input -> getOption ( 'raw-scan-path' ) ; if ( false === empty ( $ testPathOrFile ) && false === $ this -> coverFishHelper -> checkFileOrPath ( $ testPathOrFile ) ) { throw new \ Exception ( sprintf ( 'test path/file "%s" not found! please define test file path (e.g. tests/)' , $ testPathOrFile ) ) ; } }
|
prepare exec of command scan
|
5,142
|
public function migrate ( $ request ) { $ migrationTarget = isset ( $ request [ 'MigrationTarget' ] ) ? $ request [ 'MigrationTarget' ] : '' ; $ fileMigrationTarget = isset ( $ request [ 'FileMigrationTarget' ] ) ? $ request [ 'FileMigrationTarget' ] : '' ; $ includeSelected = isset ( $ request [ 'IncludeSelected' ] ) ? $ request [ 'IncludeSelected' ] : 0 ; $ includeChildren = isset ( $ request [ 'IncludeChildren' ] ) ? $ request [ 'IncludeChildren' ] : 0 ; $ duplicates = isset ( $ request [ 'DuplicateMethod' ] ) ? $ request [ 'DuplicateMethod' ] : ExternalContentTransformer :: DS_OVERWRITE ; $ selected = isset ( $ request [ 'ID' ] ) ? $ request [ 'ID' ] : 0 ; if ( ! $ selected ) { $ messageType = 'bad' ; $ message = _t ( 'ExternalContent.NOITEMSELECTED' , 'No item selected to import.' ) ; } if ( ! $ migrationTarget || ! $ fileMigrationTarget ) { $ messageType = 'bad' ; $ message = _t ( 'ExternalContent.NOTARGETSELECTED' , 'No target to import to selected.' ) ; } if ( $ selected && ( $ migrationTarget || $ fileMigrationTarget ) ) { $ target = null ; $ targetType = 'SiteTree' ; if ( $ migrationTarget ) { $ target = DataObject :: get_by_id ( 'SiteTree' , $ migrationTarget ) ; } else { $ targetType = 'File' ; $ target = DataObject :: get_by_id ( 'File' , $ fileMigrationTarget ) ; } $ from = ExternalContent :: getDataObjectFor ( $ selected ) ; if ( $ from instanceof ExternalContentSource ) { $ selected = false ; } if ( isset ( $ request [ 'Repeat' ] ) && $ request [ 'Repeat' ] > 0 ) { $ job = new ScheduledExternalImportJob ( $ request [ 'Repeat' ] , $ from , $ target , $ includeSelected , $ includeChildren , $ targetType , $ duplicates , $ request ) ; singleton ( 'QueuedJobService' ) -> queueJob ( $ job ) ; $ messageType = 'good' ; $ message = _t ( 'ExternalContent.CONTENTMIGRATEQUEUED' , 'Import job queued.' ) ; } else { $ importer = $ from -> getContentImporter ( $ targetType ) ; if ( $ importer ) { $ result = $ importer -> import ( $ from , $ target , $ includeSelected , $ includeChildren , $ duplicates , $ request ) ; $ messageType = 'good' ; if ( $ result instanceof QueuedExternalContentImporter ) { $ message = _t ( 'ExternalContent.CONTENTMIGRATEQUEUED' , 'Import job queued.' ) ; } else { $ message = _t ( 'ExternalContent.CONTENTMIGRATED' , 'Import Successful.' ) ; } } } } Session :: set ( "FormInfo.Form_EditForm.formError.message" , $ message ) ; Session :: set ( "FormInfo.Form_EditForm.formError.type" , $ messageType ) ; return $ this -> getResponseNegotiator ( ) -> respond ( $ this -> request ) ; }
|
Action to migrate a selected object through to SS
|
5,143
|
public function getRecord ( $ id ) { if ( is_numeric ( $ id ) ) { return parent :: getRecord ( $ id ) ; } else { return ExternalContent :: getDataObjectFor ( $ id ) ; } }
|
Return the record corresponding to the given ID .
|
5,144
|
public function EditForm ( $ request = null ) { HtmlEditorField :: include_js ( ) ; $ cur = $ this -> getCurrentPageID ( ) ; if ( $ cur ) { $ record = $ this -> currentPage ( ) ; if ( ! $ record ) return false ; if ( $ record && ! $ record -> canView ( ) ) return Security :: permissionFailure ( $ this ) ; } if ( $ this -> hasMethod ( 'getEditForm' ) ) { return $ this -> getEditForm ( $ this -> getCurrentPageID ( ) ) ; } return false ; }
|
Return the edit form
|
5,145
|
public function AddForm ( ) { $ classes = ClassInfo :: subclassesFor ( self :: $ tree_class ) ; array_shift ( $ classes ) ; foreach ( $ classes as $ key => $ class ) { if ( ! singleton ( $ class ) -> canCreate ( ) ) unset ( $ classes [ $ key ] ) ; $ classes [ $ key ] = FormField :: name_to_label ( $ class ) ; } $ fields = new FieldList ( new HiddenField ( "ParentID" ) , new HiddenField ( "Locale" , 'Locale' , i18n :: get_locale ( ) ) , $ type = new DropdownField ( "ProviderType" , "" , $ classes ) ) ; $ type -> setAttribute ( 'style' , 'width:150px' ) ; $ actions = new FieldList ( FormAction :: create ( "addprovider" , _t ( 'ExternalContent.CREATE' , "Create" ) ) -> addExtraClass ( 'ss-ui-action-constructive' ) -> setAttribute ( 'data-icon' , 'accept' ) -> setUseButtonTag ( true ) ) ; $ form = new Form ( $ this , "AddForm" , $ fields , $ actions ) ; $ form -> addExtraClass ( 'cms-edit-form ' . $ this -> BaseCSSClasses ( ) ) ; $ this -> extend ( 'updateEditForm' , $ form ) ; return $ form ; }
|
Get the form used to create a new provider
|
5,146
|
function DeleteItemsForm ( ) { $ form = new Form ( $ this , 'DeleteItemsForm' , new FieldList ( new LiteralField ( 'SelectedPagesNote' , sprintf ( '<p>%s</p>' , _t ( 'ExternalContentAdmin.SELECT_CONNECTORS' , 'Select the connectors that you want to delete and then click the button below' ) ) ) , new HiddenField ( 'csvIDs' ) ) , new FieldList ( new FormAction ( 'deleteprovider' , _t ( 'ExternalContentAdmin.DELCONNECTORS' , 'Delete the selected connectors' ) ) ) ) ; $ form -> addExtraClass ( 'actionparams' ) ; return $ form ; }
|
Copied from AssetAdmin ...
|
5,147
|
public function deleteprovider ( ) { $ script = '' ; $ ids = split ( ' *, *' , $ _REQUEST [ 'csvIDs' ] ) ; $ script = '' ; if ( ! $ ids ) return false ; foreach ( $ ids as $ id ) { if ( is_numeric ( $ id ) ) { $ record = ExternalContent :: getDataObjectFor ( $ id ) ; if ( $ record ) { $ script .= $ this -> deleteTreeNodeJS ( $ record ) ; $ record -> delete ( ) ; $ record -> destroy ( ) ; } } } $ size = sizeof ( $ ids ) ; if ( $ size > 1 ) { $ message = $ size . ' ' . _t ( 'AssetAdmin.FOLDERSDELETED' , 'folders deleted.' ) ; } else { $ message = $ size . ' ' . _t ( 'AssetAdmin.FOLDERDELETED' , 'folder deleted.' ) ; } $ script .= "statusMessage('$message');" ; echo $ script ; }
|
Delete a folder
|
5,148
|
public static function calculateHashOfArray ( array $ data ) : string { return self :: calculateHash ( ( string ) json_encode ( $ data , JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) ) ; }
|
Calculates the hash of the specified data array .
|
5,149
|
protected function setPostcode ( string $ postcode ) : void { if ( ! preg_match ( self :: POSTCODE_FORMAT , $ postcode ) ) { throw new InvalidArgumentException ( 'Postcode must match the expected format: ' . self :: POSTCODE_FORMAT ) ; } $ this -> postcode = $ postcode ; }
|
Set postcode .
|
5,150
|
public function merge ( $ entity ) { if ( ! $ this -> merged -> contains ( $ entity ) ) { $ this -> merged -> add ( $ entity ) ; } if ( $ this -> removed -> contains ( $ entity ) ) { $ this -> removed -> removeElement ( $ entity ) ; } if ( $ this -> detached -> contains ( $ entity ) ) { $ this -> detached -> removeElement ( $ entity ) ; } if ( $ this -> delegate ) { return parent :: persist ( $ entity ) ; } }
|
Der Parameter von merge wird nicht im EntityManager persisted
|
5,151
|
protected function substituteVars ( Config $ config , $ prefix = '{' , $ suffix = '}' ) { $ arrayConfig = $ config -> toArray ( ) ; if ( isset ( $ arrayConfig [ 'variables' ] ) ) { $ vars = array_map ( function ( $ x ) use ( $ prefix , $ suffix ) { return $ prefix . $ x . $ suffix ; } , array_keys ( $ arrayConfig [ 'variables' ] ) ) ; $ vals = array_values ( $ arrayConfig [ 'variables' ] ) ; $ tokens = array_combine ( $ vars , $ vals ) ; $ processor = new Token ( ) ; $ processor -> setTokens ( $ tokens ) ; $ processor -> process ( $ config ) ; unset ( $ config -> variables ) ; } return $ config ; }
|
Substitute defined variables if any found and return the new configuration object
|
5,152
|
protected function getCommandConfig ( Config $ config , $ command ) { $ string = '' ; if ( isset ( $ config [ $ command ] ) ) { $ config = $ config [ $ command ] ; if ( $ config -> count ( ) > 0 ) { $ config = $ config -> toArray ( ) ; $ string .= $ this -> commands [ $ command ] . PHP_EOL . '{' . PHP_EOL . "\t" ; $ string .= $ this -> getValuesString ( $ config , true ) ; $ string .= PHP_EOL . '}' . PHP_EOL ; } } return $ string ; }
|
Creates the config part of the specified command
|
5,153
|
private function getValuesString ( array $ values , $ tab = true ) { $ glue = $ tab ? PHP_EOL . "\t" : PHP_EOL ; return implode ( $ glue , array_map ( function ( $ key ) use ( $ values , $ glue ) { if ( ! is_array ( $ values [ $ key ] ) ) { $ return = $ key . ' = ' . $ values [ $ key ] ; } else { $ return = implode ( $ glue , array_map ( function ( $ value ) use ( $ key ) { return $ key . ' = ' . $ value ; } , $ values [ $ key ] ) ) ; } if ( $ key == 'charset_table' ) { $ filter = new SeparatorToSeparator ( ', ' , ', \\' . $ glue ) ; return $ filter -> filter ( $ return ) ; } return $ return ; } , array_keys ( $ values ) ) ) ; }
|
Construct a string representation from configuration associative values
|
5,154
|
protected function getSectionConfig ( Config $ config , $ section ) { $ string = '' ; if ( isset ( $ config [ $ section ] ) ) { $ config = $ config [ $ section ] ; if ( $ config -> count ( ) > 0 ) { foreach ( $ config as $ name => $ values ) { if ( $ values -> count ( ) > 0 ) { $ string .= $ this -> sections [ $ section ] . ' ' . $ name . PHP_EOL . '{' . PHP_EOL . "\t" ; $ string .= $ this -> getValuesString ( $ values -> toArray ( ) ) ; $ string .= PHP_EOL . '}' . PHP_EOL ; } } } } return $ string ; }
|
Creates the config parts of the specified section
|
5,155
|
protected function _arrayInclude ( $ path , array $ options = [ ] , $ type = 'css' ) { $ doc = $ this -> Document ; if ( is_array ( $ path ) ) { $ out = '' ; foreach ( $ path as $ i ) { $ out .= $ this -> { $ type } ( $ i , $ options ) ; } if ( empty ( $ options [ 'block' ] ) ) { return $ out . $ doc -> eol ; } return null ; } return false ; }
|
Include array paths .
|
5,156
|
protected function _getCssOutput ( array $ options , $ url ) { if ( $ options [ 'rel' ] === 'import' ) { return $ this -> formatTemplate ( 'style' , [ 'attrs' => $ this -> templater ( ) -> formatAttributes ( $ options , [ 'rel' , 'block' , 'weight' , 'alias' ] ) , 'content' => '@import url(' . $ url . ');' , ] ) ; } return $ this -> formatTemplate ( 'css' , [ 'rel' => $ options [ 'rel' ] , 'url' => $ url , 'attrs' => $ this -> templater ( ) -> formatAttributes ( $ options , [ 'rel' , 'block' , 'weight' , 'alias' ] ) , ] ) ; }
|
Get current css output .
|
5,157
|
protected function _getCurrentUrlAndOptions ( $ path , array $ options , $ type , $ external ) { if ( strpos ( $ path , '//' ) !== false ) { $ url = $ path ; $ external = true ; unset ( $ options [ 'fullBase' ] ) ; } else { $ url = $ this -> Url -> { $ type } ( $ path , $ options ) ; $ options = array_diff_key ( $ options , [ 'fullBase' => null , 'pathPrefix' => null ] ) ; } return [ $ url , $ options , $ external ] ; }
|
Get current options and url asset .
|
5,158
|
protected function _getScriptOutput ( array $ options , $ url ) { return $ this -> formatTemplate ( 'javascriptlink' , [ 'url' => $ url , 'attrs' => $ this -> templater ( ) -> formatAttributes ( $ options , [ 'block' , 'once' , 'weight' , 'alias' ] ) , ] ) ; }
|
Get current script output .
|
5,159
|
protected function _getTypeOutput ( array $ options , $ url , $ type ) { $ type = Str :: low ( $ type ) ; if ( $ type === 'css' ) { return $ this -> _getCssOutput ( $ options , $ url ) ; } return $ this -> _getScriptOutput ( $ options , $ url ) ; }
|
Get current output by type .
|
5,160
|
protected function _hasAsset ( $ path , $ type , $ external ) { return ! $ this -> Url -> assetPath ( $ path , $ this -> _getAssetType ( $ type ) ) && $ external === false ; }
|
Check has asset .
|
5,161
|
protected function _include ( $ path , array $ options = [ ] , $ type = 'css' ) { $ doc = $ this -> Document ; $ options += [ 'once' => true , 'block' => null , 'fullBase' => true , 'weight' => 10 ] ; $ external = false ; $ assetArray = $ this -> _arrayInclude ( $ path , $ options , $ type ) ; if ( $ assetArray ) { return $ assetArray ; } $ path = $ this -> _getCurrentPath ( $ path , $ assetArray ) ; if ( empty ( $ path ) ) { return null ; } $ options += [ 'alias' => Str :: slug ( $ path ) ] ; list ( $ url , $ options , $ external ) = $ this -> _getCurrentUrlAndOptions ( $ path , $ options , $ type , $ external ) ; if ( ( $ this -> _isOnceIncluded ( $ path , $ type , $ options ) ) || $ this -> _hasAsset ( $ path , $ type , $ external ) ) { return null ; } unset ( $ options [ 'once' ] ) ; $ this -> _includedAssets [ $ type ] [ $ path ] = true ; $ out = $ this -> _getTypeOutput ( $ options , $ url , $ type ) ; $ options [ 'alias' ] = Str :: low ( $ options [ 'alias' ] ) ; if ( $ options [ 'block' ] === 'assets' ) { $ this -> _assets [ $ type ] [ $ options [ 'alias' ] ] = [ 'url' => $ url , 'output' => $ out , 'path' => $ path , 'weight' => $ options [ 'weight' ] , ] ; return null ; } if ( empty ( $ options [ 'block' ] ) ) { return $ out ; } $ options = $ this -> _setFetchBlock ( $ options , $ type ) ; $ this -> _View -> append ( $ options [ 'block' ] , $ out . $ doc -> eol ) ; }
|
Include asset .
|
5,162
|
protected function _isOnceIncluded ( $ path , $ type , array $ options = [ ] ) { return $ options [ 'once' ] && isset ( $ this -> _includedAssets [ $ type ] [ $ path ] ) ; }
|
Check asset on once include .
|
5,163
|
public function finish ( ) { $ response = $ this -> client -> post ( "{$this->uriImport}fullimport/finish" , [ 'query' => [ 'key' => $ this -> config [ 'data' ] [ 'key' ] , ] , ] ) ; $ response = json_decode ( $ response -> getBody ( ) , true ) ; return isset ( $ response [ 'status' ] ) && $ response [ 'status' ] === 'ok' ; }
|
Close import queue .
|
5,164
|
public static function send ( Swift_Message $ message , Swift_SmtpTransport $ transport = NULL , Swift_Mailer $ mailer = NULL ) { if ( ! isset ( $ transport ) && ! isset ( $ mailer ) ) { if ( Config :: req ( 'mail.smtp.user' ) != NULL ) { $ transport = Swift_SmtpTransport :: newInstance ( 'smtprelaypool.ispgateway.de' , 465 , 'ssl' ) -> setUsername ( Config :: req ( 'mail.smtp.user' ) ) -> setPassword ( Config :: req ( 'mail.smtp.password' ) ) ; } else { $ transport = Swift_Mailtransport :: newInstance ( ) ; } } if ( ! isset ( $ mailer ) ) { $ mailer = \ Swift_Mailer :: newInstance ( $ transport ) ; } return $ mailer -> send ( $ message ) ; }
|
Sendet die Message
|
5,165
|
protected function allowHighlightTag ( BladeCompiler $ compiler ) { $ compiler -> directive ( 'highlight' , function ( $ expression ) { if ( is_null ( $ expression ) ) { $ expression = "('php')" ; } return "<?php \$__env->startSection{$expression}; ?>" ; } ) ; $ compiler -> directive ( 'endhighlight' , function ( ) { return <<<'HTML'<?php $last = $__env->stopSection(); echo '<pre><code class="language-', $last, '">', trim($__env->yieldContent($last)), '</code></pre>'; ?>HTML ; } ) ; }
|
Add basic syntax highlighting .
|
5,166
|
protected function getAdapter ( $ context ) { return $ this -> context === $ context || $ context === NULL ? $ this : new static ( $ this -> entityMeta , $ context ) ; }
|
Erstellt einen neuen MetaAdapter im richtigen Context
|
5,167
|
public function getHashtagMessages ( $ name , $ offset = 0 , $ length = 10 ) { if ( ! $ name ) { throw new Exception ( 'Please specify a tag name' ) ; } return $ this -> execute ( 'GET' , '/maniaflash/hashtags/%s/messages/?offset=%d&length=%d' , array ( $ name , $ offset , $ length ) ) ; }
|
Return latest messages of an hashtag
|
5,168
|
public function getMessages ( $ id , $ offset = 0 , $ length = 10 ) { if ( ! $ id ) { throw new Exception ( 'Invalid id' ) ; } return $ this -> execute ( 'GET' , '/maniaflash/channels/%s/messages/?offset=%d&length=%d' , array ( $ id , $ offset , $ length ) ) ; }
|
Return latest messages of a channel
|
5,169
|
public function postMessage ( $ channelId , $ message , $ longMessage = null , $ mediaURL = null ) { return $ this -> execute ( 'POST' , '/maniaflash/channels/%s/' , array ( $ channelId , array ( 'message' => $ message , 'longMessage' => $ longMessage , 'mediaURL' => $ mediaURL ) ) ) ; }
|
Publish a message on a maniaflash channel
|
5,170
|
private function data ( $ view ) { $ data [ 'var' ] = $ this -> module -> get ( 'var' ) ; if ( isset ( $ view [ 'with' ] ) ) { foreach ( ( array ) $ view [ 'with' ] as $ name => $ value ) { $ data [ 'var' ] [ $ name ] = $ value ; } } $ data [ 'file' ] = $ this -> getPath ( $ view , $ this -> module -> get ( 'module' ) ) ; return $ data ; }
|
Prepare the data path for the requested view
|
5,171
|
private function load ( $ view ) { $ data = $ this -> data ( $ view ) ; if ( file_exists ( $ data [ 'file' ] ) ) { extract ( $ data [ 'var' ] ) ; require $ data [ 'file' ] ; } }
|
View the file to the controller
|
5,172
|
private function getPath ( $ view , $ module ) { if ( isset ( $ module ) ) { if ( isset ( $ view [ 'from' ] ) ) { return realpath ( dirname ( $ module [ 'path' ] ) . '/' . $ view [ 'from' ] . '/Views/' . $ view [ 'name' ] . '.php' ) ; } else { return realpath ( $ module [ 'path' ] . '/Views/' . $ view [ 'name' ] . '.php' ) ; } } }
|
Get file path for the requested view name
|
5,173
|
public static function has_action ( $ path , $ action = null ) { $ path = CCStr :: cut ( $ path , '@' ) ; $ path = CCStr :: cut ( $ path , '?' ) ; if ( ! is_string ( $ path ) ) { return false ; } if ( is_null ( $ action ) ) { $ action = static :: $ _default_action ; } if ( ! $ controller = static :: create ( $ path ) ) { return false ; } return method_exists ( $ controller , static :: $ _action_prefix . $ action ) ; }
|
check if a controller implements an action
|
5,174
|
public function checkContainerForWrite ( $ container ) { $ container = static :: addContainerToName ( $ container , '' ) ; if ( ! is_dir ( $ container ) ) { if ( ! mkdir ( $ container , 0777 , true ) ) { throw new InternalServerErrorException ( 'Failed to create container.' ) ; } } }
|
Creates the container for this file management if it does not already exist
|
5,175
|
public function createContainer ( $ properties = [ ] , $ check_exist = false ) { $ container = array_get ( $ properties , 'name' , array_get ( $ properties , 'path' ) ) ; if ( empty ( $ container ) ) { throw new BadRequestException ( 'No name found for container in create request.' ) ; } if ( $ this -> folderExists ( $ container , '' ) ) { if ( $ check_exist ) { throw new BadRequestException ( "Container '$container' already exists." ) ; } } else { $ dir = static :: addContainerToName ( $ container , '' ) ; if ( ! mkdir ( $ dir , 0777 , true ) ) { throw new InternalServerErrorException ( 'Failed to create container.' ) ; } } return [ 'name' => $ container , 'path' => $ container ] ; }
|
Create a container using properties where at least name is required
|
5,176
|
public function createContainers ( $ containers = [ ] , $ check_exist = false ) { if ( empty ( $ containers ) ) { return [ ] ; } $ out = [ ] ; foreach ( $ containers as $ key => $ folder ) { try { $ out [ $ key ] = $ this -> createContainer ( $ folder , $ check_exist ) ; } catch ( \ Exception $ ex ) { $ out [ $ key ] [ 'error' ] = [ 'message' => $ ex -> getMessage ( ) , 'code' => $ ex -> getCode ( ) ] ; } } return $ out ; }
|
Create multiple containers using array of properties where at least name is required
|
5,177
|
public static function listTree ( $ root , $ prefix = '' , $ delimiter = '' ) { $ dir = $ root . ( ( ! empty ( $ prefix ) ) ? $ prefix : '' ) ; $ out = [ ] ; if ( is_dir ( $ dir ) ) { $ files = array_diff ( scandir ( $ dir ) , [ '.' , '..' ] ) ; foreach ( $ files as $ file ) { $ key = $ dir . $ file ; $ local = ( ( ! empty ( $ prefix ) ) ? $ prefix : '' ) . $ file ; if ( is_dir ( $ key ) ) { $ stat = stat ( $ key ) ; $ out [ ] = [ 'path' => str_replace ( DIRECTORY_SEPARATOR , '/' , $ local ) . '/' , 'last_modified' => gmdate ( 'D, d M Y H:i:s \G\M\T' , array_get ( $ stat , 'mtime' , 0 ) ) ] ; if ( empty ( $ delimiter ) ) { $ out = array_merge ( $ out , static :: listTree ( $ root , $ local . DIRECTORY_SEPARATOR ) ) ; } } elseif ( is_file ( $ key ) ) { $ stat = stat ( $ key ) ; $ ext = FileUtilities :: getFileExtension ( $ key ) ; $ out [ ] = [ 'path' => str_replace ( DIRECTORY_SEPARATOR , '/' , $ local ) , 'content_type' => FileUtilities :: determineContentType ( $ ext , '' , $ key ) , 'last_modified' => gmdate ( 'D, d M Y H:i:s \G\M\T' , array_get ( $ stat , 'mtime' , 0 ) ) , 'content_length' => array_get ( $ stat , 'size' , 0 ) ] ; } else { error_log ( $ key ) ; } } } else { throw new NotFoundException ( "Folder '$prefix' does not exist in storage." ) ; } return $ out ; }
|
List folders and files
|
5,178
|
public static function install ( Compiler $ parser ) { $ me = new static ( $ parser ) ; $ callback = array ( $ me , 'macroGettext' ) ; $ me -> addMacro ( '_' , $ callback ) ; $ me -> addMacro ( '_n' , $ callback ) ; $ me -> addMacro ( '_p' , $ callback ) ; $ me -> addMacro ( '_np' , $ callback ) ; }
|
Add gettext macros
|
5,179
|
public static function registerHelpers ( Template $ template , ITranslator $ translator ) { $ template -> registerHelper ( 'gettext' , array ( $ translator , 'gettext' ) ) ; $ template -> registerHelper ( 'ngettext' , array ( $ translator , 'ngettext' ) ) ; $ template -> registerHelper ( 'pgettext' , array ( $ translator , 'pgettext' ) ) ; $ template -> registerHelper ( 'npgettext' , array ( $ translator , 'npgettext' ) ) ; }
|
Add gettext helpers to template .
|
5,180
|
public static function doSelectJoinAll ( Criteria $ criteria , $ con = null , $ join_behavior = Criteria :: LEFT_JOIN ) { $ criteria = clone $ criteria ; if ( $ criteria -> getDbName ( ) == Propel :: getDefaultDB ( ) ) { $ criteria -> setDbName ( UserRolePeer :: DATABASE_NAME ) ; } UserRolePeer :: addSelectColumns ( $ criteria ) ; $ startcol2 = UserRolePeer :: NUM_HYDRATE_COLUMNS ; UserPeer :: addSelectColumns ( $ criteria ) ; $ startcol3 = $ startcol2 + UserPeer :: NUM_HYDRATE_COLUMNS ; RolePeer :: addSelectColumns ( $ criteria ) ; $ startcol4 = $ startcol3 + RolePeer :: NUM_HYDRATE_COLUMNS ; $ criteria -> addJoin ( UserRolePeer :: USER_ID , UserPeer :: ID , $ join_behavior ) ; $ criteria -> addJoin ( UserRolePeer :: ROLE_ID , RolePeer :: ID , $ join_behavior ) ; $ stmt = BasePeer :: doSelect ( $ criteria , $ con ) ; $ results = array ( ) ; while ( $ row = $ stmt -> fetch ( PDO :: FETCH_NUM ) ) { $ key1 = UserRolePeer :: getPrimaryKeyHashFromRow ( $ row , 0 ) ; if ( null !== ( $ obj1 = UserRolePeer :: getInstanceFromPool ( $ key1 ) ) ) { } else { $ cls = UserRolePeer :: getOMClass ( ) ; $ obj1 = new $ cls ( ) ; $ obj1 -> hydrate ( $ row ) ; UserRolePeer :: addInstanceToPool ( $ obj1 , $ key1 ) ; } $ key2 = UserPeer :: getPrimaryKeyHashFromRow ( $ row , $ startcol2 ) ; if ( $ key2 !== null ) { $ obj2 = UserPeer :: getInstanceFromPool ( $ key2 ) ; if ( ! $ obj2 ) { $ cls = UserPeer :: getOMClass ( ) ; $ obj2 = new $ cls ( ) ; $ obj2 -> hydrate ( $ row , $ startcol2 ) ; UserPeer :: addInstanceToPool ( $ obj2 , $ key2 ) ; } $ obj2 -> addUserRole ( $ obj1 ) ; } $ key3 = RolePeer :: getPrimaryKeyHashFromRow ( $ row , $ startcol3 ) ; if ( $ key3 !== null ) { $ obj3 = RolePeer :: getInstanceFromPool ( $ key3 ) ; if ( ! $ obj3 ) { $ cls = RolePeer :: getOMClass ( ) ; $ obj3 = new $ cls ( ) ; $ obj3 -> hydrate ( $ row , $ startcol3 ) ; RolePeer :: addInstanceToPool ( $ obj3 , $ key3 ) ; } $ obj3 -> addUserRole ( $ obj1 ) ; } $ results [ ] = $ obj1 ; } $ stmt -> closeCursor ( ) ; return $ results ; }
|
Selects a collection of UserRole objects pre - filled with all related objects .
|
5,181
|
public static function doUpdate ( $ values , PropelPDO $ con = null ) { if ( $ con === null ) { $ con = Propel :: getConnection ( UserRolePeer :: DATABASE_NAME , Propel :: CONNECTION_WRITE ) ; } $ selectCriteria = new Criteria ( UserRolePeer :: DATABASE_NAME ) ; if ( $ values instanceof Criteria ) { $ criteria = clone $ values ; $ comparison = $ criteria -> getComparison ( UserRolePeer :: USER_ID ) ; $ value = $ criteria -> remove ( UserRolePeer :: USER_ID ) ; if ( $ value ) { $ selectCriteria -> add ( UserRolePeer :: USER_ID , $ value , $ comparison ) ; } else { $ selectCriteria -> setPrimaryTableName ( UserRolePeer :: TABLE_NAME ) ; } $ comparison = $ criteria -> getComparison ( UserRolePeer :: ROLE_ID ) ; $ value = $ criteria -> remove ( UserRolePeer :: ROLE_ID ) ; if ( $ value ) { $ selectCriteria -> add ( UserRolePeer :: ROLE_ID , $ value , $ comparison ) ; } else { $ selectCriteria -> setPrimaryTableName ( UserRolePeer :: TABLE_NAME ) ; } } else { $ criteria = $ values -> buildCriteria ( ) ; $ selectCriteria = $ values -> buildPkeyCriteria ( ) ; } $ criteria -> setDbName ( UserRolePeer :: DATABASE_NAME ) ; return BasePeer :: doUpdate ( $ selectCriteria , $ criteria , $ con ) ; }
|
Performs an UPDATE on the database given a UserRole or Criteria object .
|
5,182
|
public static function retrieveByPK ( $ user_id , $ role_id , PropelPDO $ con = null ) { $ _instancePoolKey = serialize ( array ( ( string ) $ user_id , ( string ) $ role_id ) ) ; if ( null !== ( $ obj = UserRolePeer :: getInstanceFromPool ( $ _instancePoolKey ) ) ) { return $ obj ; } if ( $ con === null ) { $ con = Propel :: getConnection ( UserRolePeer :: DATABASE_NAME , Propel :: CONNECTION_READ ) ; } $ criteria = new Criteria ( UserRolePeer :: DATABASE_NAME ) ; $ criteria -> add ( UserRolePeer :: USER_ID , $ user_id ) ; $ criteria -> add ( UserRolePeer :: ROLE_ID , $ role_id ) ; $ v = UserRolePeer :: doSelect ( $ criteria , $ con ) ; return ! empty ( $ v ) ? $ v [ 0 ] : null ; }
|
Retrieve object using using composite pkey values .
|
5,183
|
public function ddl ( Collection $ collection ) { if ( ! empty ( $ this -> options [ 'autoddl' ] ) ) { $ sql = $ this -> dialect -> grammarDDL ( $ collection , $ this -> options [ 'autoddl' ] ) ; $ this -> execute ( $ sql ) ; } }
|
DDL runner for collection
|
5,184
|
public function write ( $ path , $ contents , Config $ config ) { $ tempfile = tmpfile ( ) ; fwrite ( $ tempfile , $ contents ) ; $ uploaded_metadata = $ this -> writeStream ( $ path , $ tempfile , $ config ) ; return $ uploaded_metadata ; }
|
Write a new file . Create temporary stream with content . Pass to writeStream .
|
5,185
|
public function rename ( $ path , $ newpath ) { $ pathinfo = pathinfo ( $ path ) ; if ( $ pathinfo [ 'dirname' ] != '.' ) { $ path_remote = $ pathinfo [ 'dirname' ] . '/' . $ pathinfo [ 'filename' ] ; } else { $ path_remote = $ pathinfo [ 'filename' ] ; } $ newpathinfo = pathinfo ( $ newpath ) ; if ( $ newpathinfo [ 'dirname' ] != '.' ) { $ newpath_remote = $ newpathinfo [ 'dirname' ] . '/' . $ newpathinfo [ 'filename' ] ; } else { $ newpath_remote = $ newpathinfo [ 'filename' ] ; } $ result = Uploader :: rename ( $ path_remote , $ newpath_remote ) ; return $ result [ 'public_id' ] == $ newpathinfo [ 'filename' ] ; }
|
Rename a file . Paths without extensions .
|
5,186
|
public function copy ( $ path , $ newpath ) { $ url = cloudinary_url_internal ( $ path ) ; $ result = Uploader :: upload ( $ url , [ 'public_id' => $ newpath ] ) ; return is_array ( $ result ) ? $ result [ 'public_id' ] == $ newpath : false ; }
|
Copy a file . Copy content from existing url .
|
5,187
|
public function has ( $ path ) { try { $ this -> api -> resource ( $ path ) ; } catch ( Exception $ e ) { return false ; } return true ; }
|
Check whether a file exists . Using url to check response headers . Maybe I should use api resource?
|
5,188
|
protected function prepareResourceMetadata ( $ resource ) { $ resource [ 'type' ] = 'file' ; $ resource [ 'path' ] = $ resource [ 'public_id' ] ; $ resource = array_merge ( $ resource , $ this -> prepareSize ( $ resource ) ) ; $ resource = array_merge ( $ resource , $ this -> prepareTimestamp ( $ resource ) ) ; $ resource = array_merge ( $ resource , $ this -> prepareMimetype ( $ resource ) ) ; return $ resource ; }
|
Prepare apropriate metadata for resource metadata given from cloudinary .
|
5,189
|
public function init ( ) { $ this -> assets = array ( 'js' => YII_DEBUG ? 'foundation/foundation.section.js' : 'foundation.min.js' ) ; Html :: addCssClass ( $ this -> htmlOptions , Enum :: SECTION_CONTAINER ) ; Html :: addCssClass ( $ this -> htmlOptions , $ this -> style ) ; ArrayHelper :: addValue ( 'data-section' , $ this -> style , $ this -> htmlOptions ) ; $ this -> registerClientScript ( ) ; parent :: init ( ) ; }
|
Initilizes the widget
|
5,190
|
public function renderSection ( ) { $ sections = array ( ) ; foreach ( $ this -> items as $ item ) { $ sections [ ] = $ this -> renderItem ( $ item ) ; } return \ CHtml :: tag ( 'div' , $ this -> htmlOptions , implode ( "\n" , $ sections ) ) ; }
|
Renders the section
|
5,191
|
public function renderItem ( $ item ) { $ sectionItem = array ( ) ; $ sectionItem [ ] = \ CHtml :: tag ( 'p' , array ( 'class' => 'title' , 'data-section-title' => 'data-section-title' ) , \ CHtml :: link ( ArrayHelper :: getValue ( $ item , 'label' , 'Section Title' ) , '#' ) ) ; $ options = ArrayHelper :: getValue ( $ item , 'options' , array ( ) ) ; Html :: addCssClass ( $ options , 'content' ) ; ArrayHelper :: addValue ( 'data-section-content' , 'data-section-content' , $ options ) ; $ sectionOptions = array ( ) ; if ( ArrayHelper :: getValue ( $ item , 'active' ) ) { ArrayHelper :: addValue ( 'class' , 'active' , $ sectionOptions ) ; } $ sectionItem [ ] = \ CHtml :: tag ( 'div' , $ options , ArrayHelper :: getValue ( $ item , 'content' , 'Section Content' ) ) ; return \ CHtml :: tag ( 'section' , $ sectionOptions , implode ( "\n" , $ sectionItem ) ) ; }
|
Renders a section item
|
5,192
|
public function camelToSnake ( ) : Manipulator { $ modifiedString = '' ; foreach ( str_split ( $ this -> string , 1 ) as $ character ) { $ modifiedString .= ctype_upper ( $ character ) ? '_' . $ character : $ character ; } return new static ( mb_strtolower ( $ modifiedString ) ) ; }
|
Convert a camel - case string to snake - case .
|
5,193
|
public function eachCharacter ( \ Closure $ closure ) : Manipulator { $ modifiedString = '' ; foreach ( str_split ( $ this -> string ) as $ character ) { $ modifiedString .= $ closure ( $ character ) ; } return new static ( $ modifiedString ) ; }
|
Perform an action on each character in the string .
|
5,194
|
public function eachWord ( \ Closure $ closure , bool $ preserveSpaces = false ) : Manipulator { $ modifiedString = '' ; foreach ( explode ( ' ' , $ this -> string ) as $ word ) { $ modifiedString .= $ closure ( $ word ) ; $ modifiedString .= $ preserveSpaces ? ' ' : '' ; } return new static ( trim ( $ modifiedString ) ) ; }
|
Perform an action on each word in the string .
|
5,195
|
public function getPossessive ( ) : Manipulator { $ modifiedString = $ this -> trimEnd ( ) ; if ( mb_substr ( $ modifiedString , - 1 ) === 's' ) { $ modifiedString .= '\'' ; } else { $ modifiedString .= '\'s' ; } return new static ( $ modifiedString ) ; }
|
Get Possessive Version of String
|
5,196
|
public function htmlEntitiesDecode ( $ flags = ENT_HTML5 , string $ encoding = 'UTF-8' ) : Manipulator { return new static ( html_entity_decode ( $ this -> string , $ flags , $ encoding ) ) ; }
|
Decode HTML Entities
|
5,197
|
public function htmlSpecialCharacters ( $ flags = ENT_HTML5 , string $ encoding = 'UTF-8' , bool $ doubleEncode = true ) : Manipulator { return new static ( htmlspecialchars ( $ this -> string , $ flags , $ encoding , $ doubleEncode ) ) ; }
|
HTML Special Characters
|
5,198
|
public function nthCharacter ( int $ nth , \ Closure $ closure ) : Manipulator { $ count = 1 ; $ modifiedString = '' ; foreach ( str_split ( $ this -> string ) as $ character ) { $ modifiedString .= $ count === $ nth ? $ closure ( $ character ) : $ character ; $ count ++ ; } return new static ( $ modifiedString ) ; }
|
Perfrom an action on the nth character .
|
5,199
|
public function nthWord ( int $ nth , \ Closure $ closure , bool $ preserveSpaces = true ) : Manipulator { $ count = 1 ; $ modifiedString = '' ; foreach ( explode ( ' ' , $ this -> string ) as $ word ) { $ modifiedString .= $ count === $ nth ? $ closure ( $ word ) : $ word ; $ modifiedString .= $ preserveSpaces ? ' ' : '' ; $ count ++ ; } return new static ( trim ( $ modifiedString ) ) ; }
|
Perform an action on the nth word .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.