idx
int64
0
60.3k
question
stringlengths
99
4.85k
target
stringlengths
5
718
46,200
private function createEventListener ( ) : self { $ aFields = $ this -> getArguments ( ) ; $ aCreated = [ ] ; try { $ aToCreate = [ ] ; $ aListeners = array_filter ( array_map ( function ( $ sListener ) { return implode ( '/' , array_map ( 'ucfirst' , explode ( '/' , ucfirst ( trim ( $ sListener ) ) ) ) ) ; } , explode...
Create the Listener
46,201
protected function generateFilePath ( array $ aServiceBits ) : string { $ sClassName = array_pop ( $ aServiceBits ) ; return implode ( DIRECTORY_SEPARATOR , array_map ( function ( $ sItem ) { return rtrim ( $ sItem , DIRECTORY_SEPARATOR ) ; } , array_merge ( [ static :: APP_PATH ] , $ aServiceBits , [ $ sClassName . '....
Generate the class file path
46,202
public function display_error ( $ error = '' , $ swap = '' , $ native = false ) { if ( is_array ( $ error ) ) { $ error = implode ( '; ' , $ error ) ; } throw new QueryException ( $ error ) ; }
Display an error message using an exception rather than a view
46,203
protected function _compile_join ( ) { $ sSql = '' ; if ( count ( $ this -> qb_join ) > 0 ) { $ sSql .= "\n" . implode ( "\n" , $ this -> qb_join ) ; } return $ sSql ; }
Compiles the JOIN string
46,204
protected function determineModuleState ( $ sModuleName , $ sMigrationsPath ) : ? \ stdClass { $ oModule = ( object ) [ 'name' => $ sModuleName , 'start' => null , 'end' => null , ] ; $ aDirMap = $ this -> mapDir ( $ sMigrationsPath ) ; if ( ! empty ( $ aDirMap ) ) { $ aMigrations = [ ] ; foreach ( $ aDirMap as $ dir )...
Determines whether or not the module needs to migration and if so between what versions
46,205
protected function findEnabledModules ( ) : array { $ aModules = Components :: available ( false ) ; $ aOut = [ ] ; foreach ( $ aModules as $ oModule ) { $ aOut [ ] = $ this -> determineModuleState ( $ oModule -> slug , $ oModule -> path . 'migrations/' ) ; } return array_filter ( $ aOut ) ; }
Looks for enabled Nails modules which support migration
46,206
protected function doMigration ( $ oModule ) : bool { $ oOutput = $ this -> oOutput ; $ sPath = $ oModule -> name == 'APP' ? 'application/migrations/' : 'vendor/' . $ oModule -> name . '/migrations/' ; $ aDirMap = $ this -> mapDir ( $ sPath ) ; $ iCurrent = is_null ( $ oModule -> start ) ? - 1 : $ oModule -> start ; fo...
Executes a migration
46,207
private function executeMigration ( $ oModule , $ aMigration ) : bool { $ oOutput = $ this -> oOutput ; require_once $ aMigration [ 'path' ] ; $ sPattern = '[^a-zA-Z0-9' . preg_quote ( DIRECTORY_SEPARATOR , '/\-' ) . ']' ; $ sModuleName = strtolower ( $ oModule -> name ) ; $ sModuleName = preg_replace ( '/' . $ sPatter...
Executes an individual migration
46,208
private function mapDir ( $ sDir ) : ? array { if ( is_dir ( $ sDir ) ) { $ aOut = [ ] ; foreach ( new \ DirectoryIterator ( $ sDir ) as $ oFileInfo ) { if ( $ oFileInfo -> isDot ( ) ) { continue ; } if ( preg_match ( static :: VALID_MIGRATION_PATTERN , $ oFileInfo -> getFilename ( ) , $ aMatches ) ) { $ aOut [ $ aMatc...
Generates an array of files in a directory
46,209
private function buildContentTypeFilterParameters ( ParameterBuilderInterface $ builder , array $ groups = [ ] ) : void { $ builder -> add ( 'filter_by_content_type' , ParameterType \ Compound \ BooleanType :: class , [ 'groups' => $ groups , ] ) ; $ builder -> get ( 'filter_by_content_type' ) -> add ( 'content_types' ...
Builds the parameters for filtering by content types .
46,210
private function getContentTypeFilterCriteria ( ParameterCollectionInterface $ parameterCollection ) : ? Criterion { if ( $ parameterCollection -> getParameter ( 'filter_by_content_type' ) -> getValue ( ) !== true ) { return null ; } $ contentTypes = $ parameterCollection -> getParameter ( 'content_types' ) -> getValue...
Returns the criteria used to filter content by content type .
46,211
public function read ( string $ sKey ) : ? Resource \ Cookie { return ArrayHelper :: getFromArray ( $ sKey , $ this -> aCookies , null ) ; }
Returns a specific cookie
46,212
public function write ( string $ sKey , string $ sValue , int $ iTTL = null , string $ sPath = '' , string $ sDomain = '' , bool $ bSecure = false , bool $ bHttpOnly = false ) : bool { if ( setcookie ( $ sKey , $ sValue , $ iTTL ? time ( ) + $ iTTL : 0 , $ sPath , $ sDomain , $ bSecure , $ bHttpOnly ) ) { $ this -> aCo...
Writes a cookie or overwrites an existing one
46,213
public function view ( $ view , $ vars = [ ] , $ return = false ) { if ( strpos ( $ view , '/' ) === 0 ) { if ( substr ( $ view , strlen ( EXT ) * - 1 ) != EXT ) { $ view .= EXT ; } $ pathInfo = pathinfo ( $ view ) ; $ path = $ pathInfo [ 'dirname' ] . '/' ; $ view = $ pathInfo [ 'filename' ] ; $ this -> _ci_view_paths...
Loads a view . If an absolute path is provided then that view will be used otherwise the system will search the modules
46,214
public function viewExists ( $ view ) { list ( $ path , $ view ) = Modules :: find ( $ view , $ this -> _module , 'views/' ) ; return ( bool ) trim ( $ path ) ; }
Determines whether or not a view exists
46,215
public function getBody ( $ bIsJSON = true ) { if ( $ bIsJSON ) { return json_decode ( $ this -> oResponse -> getBody ( ) ) ; } else { return ( string ) $ this -> oResponse -> getBody ( ) ; } }
Return the response s body optionally parsed as JSON
46,216
public static function property ( string $ sPropertyName , ? string $ sComponentName = '' ) { $ mProperty = self :: getService ( 'properties' , $ sPropertyName , $ sComponentName ) ; if ( is_callable ( $ mProperty ) ) { return $ mProperty ( ) ; } else { return $ mProperty ; } }
Return a property from the container .
46,217
public static function setProperty ( string $ sPropertyName , $ mPropertyValue , ? string $ sComponentName = '' ) : void { $ sComponentName = empty ( $ sComponentName ) ? 'nails/common' : $ sComponentName ; if ( ! self :: $ aContainers [ $ sComponentName ] [ 'properties' ] -> offsetExists ( $ sPropertyName ) ) { throw ...
Sets a new value for a property
46,218
public static function service ( string $ sServiceName , ? string $ sComponentName = '' ) : object { return static :: getServiceOrModel ( static :: $ aLoadedItems [ 'SERVICES' ] , 'services' , $ sServiceName , $ sComponentName , array_slice ( func_get_args ( ) , 2 ) ) ; }
Return a service from the container .
46,219
public static function model ( string $ sModelName , ? string $ sComponentName = '' ) : Base { return static :: getServiceOrModel ( static :: $ aLoadedItems [ 'MODELS' ] , 'models' , $ sModelName , $ sComponentName , array_slice ( func_get_args ( ) , 2 ) ) ; }
Return a model from the container .
46,220
private static function getServiceOrModel ( array & $ aTrackerArray , string $ sType , string $ sName , string $ sComponent , array $ aParamaters ) : object { $ sKey = md5 ( $ sComponent . $ sName ) ; if ( ! array_key_exists ( $ sKey , $ aTrackerArray ) ) { $ aTrackerArray [ $ sKey ] = call_user_func_array ( self :: ge...
Loads a servie or a model from the tracker array
46,221
public static function factory ( string $ sFactoryName , ? string $ sComponentName = '' ) : object { return call_user_func_array ( self :: getService ( 'factories' , $ sFactoryName , $ sComponentName ) , array_slice ( func_get_args ( ) , 2 ) ) ; }
Return a factory from the container .
46,222
public static function resource ( string $ sResourceName , ? string $ sComponentName = '' ) : Resource { return call_user_func_array ( self :: getService ( 'resources' , $ sResourceName , $ sComponentName ) , array_slice ( func_get_args ( ) , 2 ) ) ; }
Return a resource from the container .
46,223
public static function helper ( string $ sHelperName , ? string $ sComponentName = '' ) : void { $ sComponentName = empty ( $ sComponentName ) ? 'nails/common' : $ sComponentName ; if ( empty ( self :: $ aLoadedHelpers [ $ sComponentName ] [ $ sHelperName ] ) ) { if ( empty ( self :: $ aLoadedHelpers [ $ sComponentName...
Load a helper file
46,224
private static function getService ( string $ sServiceType , string $ sServiceName , ? string $ sComponentName = '' ) { $ sComponentName = empty ( $ sComponentName ) ? 'nails/common' : $ sComponentName ; if ( ! array_key_exists ( $ sComponentName , self :: $ aContainers ) ) { throw new FactoryException ( 'No containers...
Returns a service from the namespaced container
46,225
public static function autoload ( ) : void { require_once BASEPATH . 'core/Common.php' ; $ aComponents = [ ] ; foreach ( Components :: available ( ) as $ oModule ) { $ aComponents [ ] = ( object ) [ 'slug' => $ oModule -> slug , 'autoload' => $ oModule -> autoload , ] ; } foreach ( $ aComponents as $ oModule ) { if ( !...
Auto - loads items at startup
46,226
protected static function extractAutoLoadItemsFromComposerJson ( string $ sPath ) : \ stdClass { $ oOut = ( object ) [ 'helpers' => [ ] , 'services' => [ ] ] ; if ( file_exists ( $ sPath ) ) { $ oAppComposer = json_decode ( file_get_contents ( $ sPath ) ) ; if ( ! empty ( $ oAppComposer -> extra -> nails -> autoload ->...
Extracts the autoload elements from a composer . json file
46,227
public static function destroyService ( string $ sServiceName , ? string $ sComponentName = '' ) : bool { return static :: destroyServiceOrModel ( static :: $ aLoadedItems [ 'SERVICES' ] , null , $ sServiceName , $ sComponentName ) ; }
Allows for a service to be destroyed so that a subsequent request will yeild a new instance
46,228
public static function destroyModel ( string $ sModelName , ? string $ sComponentName = '' ) : bool { return static :: destroyServiceOrModel ( static :: $ aLoadedItems [ 'MODELS' ] , null , $ sModelName , $ sComponentName ) ; }
Allows for a model to be destroyed so that a subsequent request will yeild a new instance
46,229
public static function destroy ( object $ oInstance ) : bool { foreach ( static :: $ aLoadedItems [ 'SERVICES' ] as $ sKey => $ oItem ) { if ( $ oItem === $ oInstance ) { return static :: destroyServiceOrModel ( static :: $ aLoadedItems [ 'SERVICES' ] , $ sKey ) ; } } foreach ( static :: $ aLoadedItems [ 'MODELS' ] as ...
Destroys an object by its instance
46,230
private static function destroyServiceOrModel ( array & $ aTrackerArray , string $ sKey , string $ sName = null , string $ sComponent = null ) : bool { if ( ! $ sKey ) { $ sKey = md5 ( $ sComponent . $ sName ) ; } if ( array_key_exists ( $ sKey , $ aTrackerArray ) ) { unset ( $ aTrackerArray [ $ sKey ] ) ; return true ...
Destroys an item in the tracker array
46,231
public function load ( $ langfile , $ lang = '' , $ return = false , $ add_suffix = true , $ alt_path = '' , $ _module = '' ) { if ( is_array ( $ langfile ) ) { foreach ( $ langfile as $ _lang ) { $ this -> load ( $ _lang ) ; } return $ this -> language ; } $ _default = CI :: $ APP -> config -> item ( 'language' ) ; $ ...
Loads a lang file
46,232
protected function setErrorReporting ( ) { error_reporting ( E_ALL ^ E_STRICT ^ E_ERROR ) ; if ( function_exists ( 'ini_set' ) ) { switch ( Environment :: get ( ) ) { case Environment :: ENV_PROD : ini_set ( 'display_errors' , false ) ; break ; default : ini_set ( 'display_errors' , true ) ; break ; } } }
Sets the appropriate error reporting values and handlers
46,233
protected function maintenanceMode ( $ force = false , $ sTitle = '' , $ sBody = '' ) { if ( $ force || file_exists ( NAILS_APP_PATH . '.MAINTENANCE' ) ) { $ oInput = Factory :: service ( 'Input' ) ; $ oUri = Factory :: service ( 'Uri' ) ; try { $ this -> load -> add_package_path ( NAILS_COMMON_PATH ) ; Factory :: serv...
Checks if Maintenance Mode is enabled shows the holding page if so .
46,234
protected function passwordProtected ( ) { $ oInput = Factory :: service ( 'Input' ) ; $ sConstantName = 'APP_USER_PASS_' . Environment :: get ( ) ; $ sConstantNameWhitelist = 'APP_USER_PASS_WHITELIST_' . Environment :: get ( ) ; if ( ! $ oInput :: isCli ( ) && defined ( $ sConstantName ) ) { if ( defined ( $ sConstant...
Checks if credentials should be requested for staging environments
46,235
protected function passwordProtectedRequest ( ) { $ oInput = Factory :: service ( 'Input' ) ; header ( 'WWW-Authenticate: Basic realm="' . APP_NAME . ' - Restricted Area"' ) ; header ( $ oInput -> server ( 'SERVER_PROTOCOL' ) . ' 401 Unauthorized' ) ; $ oErrorHandler = Factory :: service ( 'ErrorHandler' ) ; $ oErrorHa...
Requests staging credentials
46,236
protected function instantiateDateTime ( ) { $ oDateTimeService = Factory :: service ( 'DateTime' ) ; $ oDefaultDateFormat = $ oDateTimeService -> getDateFormatDefault ( ) ; if ( empty ( $ oDefaultDateFormat ) ) { throw new NailsException ( 'No default date format has been set, or it\'s been set incorrectly.' , 1 ) ; }...
Sets up date & time handling
46,237
protected function generateRoutes ( ) { if ( defined ( 'NAILS_STARTUP_GENERATE_APP_ROUTES' ) && NAILS_STARTUP_GENERATE_APP_ROUTES ) { $ oRoutesService = Factory :: service ( 'Routes' ) ; if ( ! $ oRoutesService -> update ( ) ) { throw new NailsException ( 'Failed to generate routes_app.php. ' . $ oRoutesService -> last...
Checks if routes need to be generated as part of the startup request
46,238
protected function instantiateLanguages ( ) { $ oLanguageService = Factory :: service ( 'Language' ) ; $ oDefault = $ oLanguageService -> getDefault ( ) ; if ( empty ( $ oDefault ) ) { throw new NailsException ( 'No default language has been set, or it\'s been set incorrectly.' ) ; } Functions :: define ( 'APP_DEFAULT_...
Sets up language handling
46,239
protected function definePackages ( ) { $ oConfig = Factory :: service ( 'Config' ) ; $ oConfig -> _config_paths = [ ] ; $ aPaths = [ ] ; $ aPaths [ ] = NAILS_COMMON_PATH ; $ aAvailableModules = Components :: modules ( ) ; foreach ( $ aAvailableModules as $ oModule ) { $ aPaths [ ] = $ oModule -> path ; } $ aPaths [ ] ...
Defines all the package paths
46,240
protected function isUserSuspended ( ) { if ( isLoggedIn ( ) && activeUser ( 'is_suspended' ) ) { $ oAuthModel = Factory :: model ( 'Auth' , 'nails/module-auth' ) ; $ this -> lang -> load ( 'auth/auth' ) ; $ oAuthModel -> logout ( ) ; $ oSession = Factory :: service ( 'Session' , 'nails/module-auth' ) ; $ oSession -> s...
Determines whether the active user is suspended and if so logs them out .
46,241
public static function backwardsCompatibility ( & $ oBindTo ) { $ oBindTo -> db = Factory :: service ( 'Database' ) ; $ oBindTo -> input = Factory :: service ( 'Input' ) ; $ oBindTo -> output = Factory :: service ( 'Output' ) ; $ oBindTo -> meta = Factory :: service ( 'Meta' ) ; $ oBindTo -> asset = Factory :: service ...
Provides some backwards compatability
46,242
public static function populateUserFeedback ( array & $ aData ) { $ oSession = Factory :: service ( 'Session' , 'nails/module-auth' ) ; $ oUserFeedback = Factory :: service ( 'UserFeedback' ) ; $ aData [ 'error' ] = $ oUserFeedback -> get ( 'error' ) ? : $ oSession -> getFlashData ( 'error' ) ; $ aData [ 'negative' ] =...
Populates an array from the UserFeedback and session classes
46,243
public static function populatePageData ( array & $ aData ) { $ oLocale = Factory :: service ( 'Locale' ) ; $ aData [ 'page' ] = ( object ) [ 'title' => '' , 'html_lang' => $ oLocale -> get ( ) -> getLanguage ( ) , 'seo' => ( object ) [ 'title' => '' , 'description' => '' , 'keywords' => '' , ] , ] ; }
Populates an array with a default object for page and SEO
46,244
protected function setCommonMeta ( array $ aMeta = [ ] ) { $ oMeta = Factory :: service ( 'Meta' ) ; $ oMeta -> addRaw ( [ 'charset' => 'utf-8' , ] ) -> addRaw ( [ 'name' => 'viewport' , 'content' => 'width=device-width, initial-scale=1' , ] ) ; foreach ( $ aMeta as $ aItem ) { $ oMeta -> addRaw ( $ aItem ) ; } }
Sets some common meta for every page load
46,245
public static function setNailsJs ( ) { $ oAsset = Factory :: service ( 'Asset' ) ; $ aVariables = [ 'ENVIRONMENT' => Environment :: get ( ) , 'SITE_URL' => site_url ( '' , Functions :: isPageSecure ( ) ) , 'NAILS' => ( object ) [ 'URL' => NAILS_ASSETS_URL , 'LANG' => ( object ) [ ] , 'USER' => ( object ) [ 'ID' => act...
Sets a global Nails JS object
46,246
protected function setGlobalJs ( ) { $ oAsset = Factory :: service ( 'Asset' ) ; $ sCustomJs = appSetting ( 'site_custom_js' , 'site' ) ; if ( ! empty ( $ sCustomJs ) ) { $ oAsset -> inline ( $ sCustomJs , 'JS' ) ; } $ sGoogleAnalyticsProfile = appSetting ( 'google_analytics_account' ) ; if ( ! empty ( $ sGoogleAnalyti...
Sets global JS
46,247
protected function setGlobalCss ( ) { $ oAsset = Factory :: service ( 'Asset' ) ; $ sCustomCss = appSetting ( 'site_custom_css' , 'site' ) ; if ( ! empty ( $ sCustomCss ) ) { $ oAsset -> inline ( $ sCustomCss , 'CSS' ) ; } }
Sets global CSS
46,248
protected function writeFile ( ) { $ sData = '<?php' . "\n\n" ; $ sData .= '/**' . "\n" ; $ sData .= ' * THIS FILE IS CREATED/MODIFIED AUTOMATICALLY' . "\n" ; $ sData .= ' * ===========================================' . "\n" ; $ sData .= ' *' . "\n" ; $ sData .= ' * Any changes you make in this file will be overwritte...
Write the routes file
46,249
public function canWriteRoutes ( ) { if ( ! is_null ( $ this -> bCanWriteRoutes ) ) { return $ this -> bCanWriteRoutes ; } if ( file_exists ( static :: ROUTES_DIR . static :: ROUTES_FILE ) ) { if ( is_writable ( static :: ROUTES_DIR . static :: ROUTES_FILE ) ) { $ this -> bCanWriteRoutes = true ; return true ; } else {...
Determine whether or not the routes can be written
46,250
protected function getCountCommonCompileSelect ( array & $ aData ) { if ( ! empty ( $ aData [ 'select' ] ) ) { $ oDb = Factory :: service ( 'Database' ) ; $ oDb -> select ( $ aData [ 'select' ] ) ; } }
Compiles the select statement
46,251
protected function getCountCommonCompileFiltersString ( $ sColumn , $ mValue , $ bIsQuery ) { if ( is_object ( $ mValue ) && ( $ mValue instanceof \ Closure ) ) { $ mValue = $ mValue ( ) ; } $ oDb = Factory :: service ( 'Database' ) ; if ( $ bIsQuery ) { $ aBits = [ $ mValue ] ; } elseif ( ! is_array ( $ mValue ) ) { $...
Compile the filter string
46,252
protected function getCountCommonCompileSort ( array & $ aData ) { $ oDb = Factory :: service ( 'Database' ) ; if ( ! empty ( $ aData [ 'sort' ] ) ) { if ( is_string ( $ aData [ 'sort' ] ) ) { $ oDb -> order_by ( $ aData [ 'sort' ] ) ; } elseif ( is_array ( $ aData [ 'sort' ] ) ) { $ mFirst = reset ( $ aData [ 'sort' ]...
Compiles the sort element into the query
46,253
protected function getCountCommonParseSort ( $ mSort ) { $ aOut = [ 'column' => null , 'order' => null ] ; if ( is_string ( $ mSort ) ) { $ aOut [ 'column' ] = $ mSort ; return $ aOut ; } elseif ( isset ( $ mSort [ 'column' ] ) ) { $ aOut [ 'column' ] = $ mSort [ 'column' ] ; } else { $ aOut [ 'column' ] = reset ( $ mS...
Parse the sort variable
46,254
private function buildParentLocationParameters ( ParameterBuilderInterface $ builder , array $ groups = [ ] ) : void { $ builder -> add ( 'use_current_location' , ParameterType \ Compound \ BooleanType :: class , [ 'reverse' => true , 'groups' => $ groups , ] ) ; $ builder -> get ( 'use_current_location' ) -> add ( 'pa...
Builds the parameters for filtering by parent location .
46,255
private function getParentLocation ( ParameterCollectionInterface $ parameterCollection ) : ? Location { if ( $ parameterCollection -> getParameter ( 'use_current_location' ) -> getValue ( ) === true ) { return $ this -> contentProvider -> provideLocation ( ) ; } $ parentLocationId = $ parameterCollection -> getParamet...
Returns the parent location to use for the parameter collection .
46,256
public function addHook ( $ hookwhere , $ hook ) { if ( is_array ( $ hook ) ) { if ( isset ( $ hook [ 'classref' ] ) && isset ( $ hook [ 'method' ] ) && isset ( $ hook [ 'params' ] ) ) { if ( is_object ( $ hook [ 'classref' ] ) && method_exists ( $ hook [ 'classref' ] , $ hook [ 'method' ] ) ) { $ this -> aCustomHooks ...
Adds a particular hook
46,257
public function call_hook ( $ sWhich = '' ) { if ( ! isset ( $ this -> aCustomHooks [ $ sWhich ] ) ) { return parent :: call_hook ( $ sWhich ) ; } if ( isset ( $ this -> aCustomHooks [ $ sWhich ] [ 0 ] ) && is_array ( $ this -> aCustomHooks [ $ sWhich ] [ 0 ] ) ) { foreach ( $ this -> aCustomHooks [ $ sWhich ] as $ aCu...
Call a particular hook
46,258
protected function runCustomHook ( $ aData ) { if ( ! is_array ( $ aData ) ) { return false ; } if ( $ this -> bCustomHooksInProgress == true ) { return ; } $ oClass = null ; $ sMethod = null ; $ aParams = [ ] ; if ( isset ( $ aData [ 'classref' ] ) ) { $ oClass = & $ aData [ 'classref' ] ; } if ( isset ( $ aData [ 'me...
Execute a cusotm hook
46,259
public function create ( array $ aData = [ ] , $ bReturnObject = false ) { $ mResult = parent :: create ( $ aData , $ bReturnObject ) ; if ( $ mResult ) { $ this -> saveBreadcrumbs ( $ bReturnObject ? $ mResult -> id : $ mResult ) ; $ this -> saveOrder ( ) ; if ( $ bReturnObject ) { $ mResult = $ this -> getById ( $ mR...
Generates breadcrumbs after creating an object
46,260
public function update ( $ mIds , array $ aData = [ ] ) : bool { $ mResult = parent :: update ( $ mIds , $ aData ) ; if ( $ mResult ) { $ aIds = ( array ) $ mIds ; foreach ( $ aIds as $ iId ) { $ this -> saveBreadcrumbs ( $ iId ) ; } $ this -> saveOrder ( ) ; } return $ mResult ; }
Generates breadcrumbs after updating an object
46,261
protected function saveBreadcrumbs ( $ iItemId ) { $ oItem = $ this -> getById ( $ iItemId ) ; if ( ! empty ( $ oItem ) ) { $ aBreadcrumbs = [ ] ; $ iParentId = ( int ) $ oItem -> parent_id ; while ( $ iParentId ) { $ oParentItem = $ this -> getById ( $ iParentId ) ; if ( $ oParentItem ) { $ iParentId = $ oParentItem -...
Generates breadcrumbs for the item
46,262
protected function buildTree ( array & $ aItems , int $ iParentId = null ) : array { $ aTemp = [ ] ; $ sIdColumn = $ this -> getColumn ( 'id' ) ; $ sParentColumn = $ this -> getColumn ( 'parent_id' , 'parent_id' ) ; foreach ( $ aItems as $ oItem ) { if ( $ oItem -> { $ sParentColumn } == $ iParentId ) { $ oItem -> chil...
Builds a tree of objects
46,263
protected function flattenTree ( array $ aItems , & $ aOutput = [ ] ) : array { foreach ( $ aItems as $ oItem ) { $ aOutput [ ] = $ oItem ; $ this -> flattenTree ( $ oItem -> children , $ aOutput ) ; unset ( $ oItem -> children ) ; } return $ aOutput ; }
Flattens a tree of objects
46,264
public function generateUrl ( $ oObj ) { if ( empty ( $ oObj -> breadcrumbs ) ) { return null ; } $ aBreadcrumbs = json_decode ( $ oObj -> breadcrumbs ) ; if ( is_null ( $ aBreadcrumbs ) ) { return null ; } $ aUrl = arrayExtractProperty ( $ aBreadcrumbs , 'slug' ) ; $ aUrl [ ] = $ oObj -> slug ; $ sUrl = implode ( '/' ...
Generates the URL for nestable objects ; optionally place under a URL namespace
46,265
public function getChildren ( $ iId , $ bRecursive = false , array $ aData = [ ] ) { $ aQueryData = $ aData ; if ( ! array_key_exists ( 'where' , $ aQueryData ) ) { $ aQueryData [ 'where' ] = [ ] ; } $ aQueryData [ 'where' ] [ ] = [ 'parent_id' , $ iId ] ; $ aChildren = $ this -> getAll ( $ aQueryData ) ; foreach ( $ a...
Retrieves the immediate children of an item
46,266
private function getContentType ( EzLocation $ location ) : ContentType { if ( method_exists ( $ location , 'getContent' ) && method_exists ( $ location -> getContent ( ) , 'getContentType' ) ) { return $ location -> getContent ( ) -> getContentType ( ) ; } return $ this -> repository -> getContentTypeService ( ) -> lo...
Loads the content type for provided location .
46,267
public function getAll ( $ iPage = null , $ iPerPage = null , array $ aData = [ ] , $ bIncludeDeleted = false ) : array { $ aResult = parent :: getAll ( $ iPage , $ iPerPage , $ aData , $ bIncludeDeleted ) ; $ this -> addLocaleToResources ( $ aResult ) ; return $ aResult ; }
Overloads the getAll to add a Locale object to each resource
46,268
protected function addLocaleToResource ( Resource $ oResource ) : void { $ oLocale = Factory :: service ( 'Locale' ) ; $ oResource -> locale = $ this -> getLocale ( $ oResource -> { static :: $ sColumnLanguage } , $ oResource -> { static :: $ sColumnRegion } ) ; $ oResource -> available_locales = array_map ( function (...
Adds a Locale object to a Resource and removes the language and region properties
46,269
public function getTableName ( $ bIncludeAlias = false ) : string { $ sTable = parent :: getTableName ( ) . static :: $ sLocalisedTableSuffix ; return $ bIncludeAlias ? trim ( $ sTable . ' as `' . $ this -> getTableAlias ( ) . '`' ) : $ sTable ; }
Returns the localised table name
46,270
public function create ( array $ aData = [ ] , $ bReturnObject = false , \ Nails \ Common \ Factory \ Locale $ oLocale = null ) { $ oDb = Factory :: service ( 'Database' ) ; if ( empty ( $ oLocale ) ) { throw new ModelException ( self :: class . ': A locale must be defined when creating a localised item' ) ; } $ aData ...
Create a new localised item
46,271
public static function siteUrl ( $ sUri , $ bUseSecure = false ) { if ( preg_match ( '/^(https?:\/\/|#)/' , $ sUri ) ) { return $ sUri ; } else { if ( $ bUseSecure && defined ( 'SECURE_BASE_URL' ) ) { $ sBaseUrl = rtrim ( SECURE_BASE_URL , '/' ) . '/' ; } else { $ sBaseUrl = rtrim ( BASE_URL , '/' ) . '/' ; } if ( is_f...
Prepends BASE_URL or SECURE_BASE_URL to a string
46,272
public function createMany ( array $ aData ) { $ oDb = Factory :: service ( 'Database' ) ; try { $ oDb -> trans_begin ( ) ; foreach ( $ aData as $ aDatum ) { if ( ! $ this -> create ( $ aDatum ) ) { throw new ModelException ( 'Failed to create item with data: ' . json_encode ( $ aDatum ) ) ; } } $ oDb -> trans_commit (...
Inserts a batch of data into the table
46,273
public function updateMany ( array $ aIds , array $ aData = [ ] ) : bool { $ oDb = Factory :: service ( 'Database' ) ; try { $ oDb -> trans_begin ( ) ; foreach ( $ aIds as $ iId ) { if ( ! $ this -> update ( $ iId , $ aData ) ) { throw new ModelException ( 'Failed to update item with ID ' . $ iId ) ; } } $ oDb -> trans...
Update many items with the same data
46,274
public function deleteMany ( array $ aIds ) : bool { $ oDb = Factory :: service ( 'Database' ) ; try { $ oDb -> trans_begin ( ) ; foreach ( $ aIds as $ iId ) { if ( ! $ this -> delete ( $ iId ) ) { throw new ModelException ( 'Failed to delete item with ID ' . $ iId ) ; } } $ oDb -> trans_commit ( ) ; return true ; } ca...
Deletes many items
46,275
public function getAllFlat ( $ iPage = null , $ iPerPage = null , array $ aData = [ ] , $ bIncludeDeleted = false ) { $ aItems = $ this -> getAll ( $ iPage , $ iPerPage , $ aData , $ bIncludeDeleted ) ; $ aOut = [ ] ; if ( ! $ aItems ) { return [ ] ; } $ oTest = reset ( $ aItems ) ; if ( ! property_exists ( $ oTest , $...
Fetches all objects as a flat array
46,276
public function getById ( $ iId , array $ aData = [ ] ) { if ( ! $ this -> tableIdColumn ) { throw new ModelException ( static :: class . '::getById() Column variable not set.' , 1 ) ; } return $ this -> getByColumn ( $ this -> tableIdColumn , $ iId , $ aData ) ; }
Fetch an object by it s ID
46,277
public function getByIds ( $ aIds , array $ aData = [ ] , $ bMaintainInputOrder = false ) { if ( ! $ this -> tableIdColumn ) { throw new ModelException ( static :: class . '::getByIds() Column variable not set.' , 1 ) ; } $ aItems = $ this -> getByColumn ( $ this -> tableIdColumn , $ aIds , $ aData , true ) ; if ( $ bM...
Fetch objects by their IDs
46,278
public function getBySlug ( $ sSlug , array $ aData = [ ] ) { if ( ! $ this -> tableSlugColumn ) { throw new ModelException ( static :: class . '::getBySlug() Column variable not set.' , 1 ) ; } return $ this -> getByColumn ( $ this -> tableSlugColumn , $ sSlug , $ aData ) ; }
Fetch an object by it s slug
46,279
public function getBySlugs ( $ aSlugs , array $ aData = [ ] , $ bMaintainInputOrder = false ) { if ( ! $ this -> tableSlugColumn ) { throw new ModelException ( static :: class . '::getBySlugs() Column variable not set.' , 1 ) ; } $ aItems = $ this -> getByColumn ( $ this -> tableSlugColumn , $ aSlugs , $ aData , true )...
Fetch objects by their slugs
46,280
public function getByIdOrSlug ( $ mIdSlug , array $ aData = [ ] ) { if ( is_numeric ( $ mIdSlug ) ) { return $ this -> getById ( $ mIdSlug , $ aData ) ; } else { return $ this -> getBySlug ( $ mIdSlug , $ aData ) ; } }
Fetch an object by it s id or slug
46,281
public function getByToken ( $ sToken , array $ aData = [ ] ) { if ( ! $ this -> tableTokenColumn ) { throw new ModelException ( static :: class . '::getByToken() Column variable not set.' , 1 ) ; } return $ this -> getByColumn ( $ this -> tableTokenColumn , $ sToken , $ aData ) ; }
Fetch an object by its token
46,282
public function getByTokens ( $ aTokens , array $ aData = [ ] , $ bMaintainInputOrder = false ) { if ( ! $ this -> tableTokenColumn ) { throw new ModelException ( static :: class . '::getByTokens() Column variable not set.' , 1 ) ; } $ aItems = $ this -> getByColumn ( $ this -> tableTokenColumn , $ aTokens , $ aData , ...
Fetch objects by an array of tokens
46,283
protected function sortItemsByColumn ( array $ aItems , array $ aInputOrder , $ sColumn ) { $ aOut = [ ] ; foreach ( $ aInputOrder as $ sInputItem ) { foreach ( $ aItems as $ oItem ) { if ( $ oItem -> { $ sColumn } == $ sInputItem ) { $ aOut [ ] = $ oItem ; } } } return $ aOut ; }
Sorts items into a specific order based on a specific column
46,284
protected function getManyAssociatedItems ( array & $ aItems , $ sItemProperty , $ sAssociatedItemIdColumn , $ sAssociatedModel , $ sAssociatedModelProvider , array $ aAssociatedModelData = [ ] ) { if ( ! empty ( $ aItems ) ) { $ oAssociatedModel = Factory :: model ( $ sAssociatedModel , $ sAssociatedModelProvider ) ; ...
Get associated content for the items in the result set where the the relationship is 1 to many
46,285
protected function countManyAssociatedItems ( array & $ aItems , $ sItemProperty , $ sAssociatedItemIdColumn , $ sAssociatedModel , $ sAssociatedModelProvider , array $ aAssociatedModelData = [ ] ) { if ( ! empty ( $ aItems ) ) { $ oAssociatedModel = Factory :: model ( $ sAssociatedModel , $ sAssociatedModelProvider ) ...
Count associated content for the items in the result set where the the relationship is 1 to many
46,286
protected function getManyAssociatedItemsWithTaxonomy ( array & $ aItems , $ sItemProperty , $ sTaxonomyModel , $ sTaxonomyModelProvider , $ sAssociatedModel , $ sAssociatedModelProvider , array $ aAssociatedModelData = [ ] , $ sTaxonomyItemIdColumn = 'item_id' , $ sTaxonomyAssociatedIdColumn = 'associated_id' ) { if (...
Get associated content for the items in the result set using a taxonomy table
46,287
protected function saveAssociatedItems ( $ iItemId , array $ aAssociatedItems , $ sAssociatedItemIdColumn , $ sAssociatedModel , $ sAssociatedModelProvider ) { $ oAssociatedItemModel = Factory :: model ( $ sAssociatedModel , $ sAssociatedModelProvider ) ; $ aTouchedIds = [ ] ; $ aExistingItemIds = [ ] ; $ aData = [ 'wh...
Save associated items for an object
46,288
public function search ( $ sKeywords , $ iPage = null , $ iPerPage = null , array $ aData = [ ] , $ bIncludeDeleted = false ) { if ( is_array ( $ iPage ) ) { $ aData = $ iPage ; $ iPage = null ; } $ this -> applySearchConditionals ( $ aData , $ sKeywords ) ; return ( object ) [ 'page' => $ iPage , 'perPage' => $ iPerPa...
Searches for objects optionally paginated .
46,289
protected function applySearchConditionals ( array & $ aData , $ sKeywords ) { if ( empty ( $ aData [ 'or_like' ] ) ) { $ aData [ 'or_like' ] = [ ] ; } $ sAlias = $ this -> getTableAlias ( true ) ; foreach ( $ this -> searchableFields as $ mField ) { if ( is_array ( $ mField ) ) { $ sMappedFields = array_map ( function...
Mutates the data array and adds the conditionals for searching
46,290
protected function generateToken ( $ sMask = null , $ sTable = null , $ sColumn = null ) { if ( is_null ( $ sMask ) ) { $ sMask = $ this -> sTokenMask ; } if ( is_null ( $ sTable ) ) { $ sTable = $ this -> getTableName ( ) ; } if ( is_null ( $ sColumn ) ) { if ( ! $ this -> tableTokenColumn ) { throw new ModelException...
Generates a unique token for a record
46,291
protected function addExpandableField ( array $ aOptions ) { if ( ! array_key_exists ( 'trigger' , $ aOptions ) ) { throw new ModelException ( 'Expandable fields must define a "trigger".' ) ; } if ( ! array_key_exists ( 'type' , $ aOptions ) ) { $ aOptions [ 'type' ] = static :: EXPANDABLE_TYPE_SINGLE ; } if ( $ aOptio...
Define expandable objects
46,292
protected function autoSaveExpandableFieldsExtract ( array & $ aData ) { $ aFields = [ ] ; $ aOut = [ ] ; $ aExpandableFields = $ this -> getExpandableFields ( ) ; foreach ( $ aExpandableFields as $ oField ) { if ( $ oField -> auto_save ) { $ aFields [ $ oField -> trigger ] = $ oField ; } } foreach ( $ aData as $ sKey ...
Extracts any autosaveable expandable fields and unsets them from the main array
46,293
protected function autoSaveExpandableFieldsSave ( $ iId , array $ aExpandableFields ) { foreach ( $ aExpandableFields as $ oField ) { $ aData = array_filter ( ( array ) $ oField -> data ) ; $ this -> saveAssociatedItems ( $ iId , $ aData , $ oField -> id_column , $ oField -> model , $ oField -> provider ) ; } }
Saves extracted expandable fields
46,294
public function getColumn ( $ sColumn , $ sDefault = null ) { $ sColumn = ucfirst ( trim ( $ sColumn ) ) ; if ( property_exists ( $ this , 'table' . $ sColumn . 'Column' ) ) { return $ this -> { 'table' . $ sColumn . 'Column' } ; } return $ sDefault ; }
Returns the column name for specific columns of interest
46,295
public function describeFields ( $ sTable = null ) { $ sTable = $ sTable ? : $ this -> getTableName ( ) ; $ oDb = Factory :: service ( 'Database' ) ; $ aResult = $ oDb -> query ( 'DESCRIBE `' . $ sTable . '`;' ) -> result ( ) ; $ aFields = [ ] ; if ( classUses ( $ this , Localised :: class ) ) { $ oLocale = Factory :: ...
Describes the fields for this model automatically and with some guesswork ; for more fine grained control models should overload this method .
46,296
protected function describeFieldsPrepareLabel ( $ sLabel ) { $ aPatterns = [ '/\bid\b/i' => 'ID' , '/\burl\b/i' => 'URL' , '/\bhtml\b/i' => 'HTML' , '/\bpdf\b/i' => 'PDF' , ] ; $ sLabel = ucwords ( preg_replace ( '/[\-_]/' , ' ' , $ sLabel ) ) ; $ sLabel = preg_replace ( array_keys ( $ aPatterns ) , array_values ( $ aP...
Generates a human friendly label from the field s key
46,297
protected function describeFieldsGuessType ( & $ oField , $ sType ) { preg_match ( '/^(.*?)(\((.+?)\)(.*))?$/' , $ sType , $ aMatches ) ; $ sType = ArrayHelper :: getFromArray ( 1 , $ aMatches , 'text' ) ; $ sTypeConfig = trim ( ArrayHelper :: getFromArray ( 3 , $ aMatches ) ) ; $ iLength = is_numeric ( $ sTypeConfig )...
Guesses the field s type and sets it accordingly
46,298
protected function describeFieldsGuessValidation ( & $ oField , $ sType ) { preg_match ( '/^(.*?)(\((.+?)\)(.*))?$/' , $ sType , $ aMatches ) ; $ sType = ArrayHelper :: getFromArray ( 1 , $ aMatches , 'text' ) ; $ iLength = ArrayHelper :: getFromArray ( 3 , $ aMatches ) ; $ sExtra = trim ( strtolower ( ArrayHelper :: g...
Guesses the field s validation rules based on it s type
46,299
private function getSections ( Options $ options ) : array { $ allSections = [ ] ; $ sections = $ this -> sectionService -> loadSections ( ) ; $ configuredSections = $ options [ 'sections' ] ; foreach ( $ sections as $ section ) { if ( count ( $ configuredSections ) > 0 && ! in_array ( $ section -> identifier , $ confi...
Returns the allowed sections from eZ Platform .