idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
18,200 | private function getClassDiscriminatorValues ( ClassMetadata $ metadata ) { $ discriminatorValues = array ( $ metadata -> discriminatorValue ) ; foreach ( $ metadata -> subClasses as $ className ) { if ( $ key = array_search ( $ className , $ metadata -> discriminatorMap ) ) { $ discriminatorValues [ ] = $ key ; } } return $ discriminatorValues ; } | Gets the array of discriminator values for the given ClassMetadata |
18,201 | private function guardMissingShardKey ( $ document , $ shardKeyField , $ actualDocumentData ) { $ dcs = $ this -> uow -> getDocumentChangeSet ( $ document ) ; $ isUpdate = $ this -> uow -> isScheduledForUpdate ( $ document ) ; $ fieldMapping = $ this -> class -> getFieldMappingByDbFieldName ( $ shardKeyField ) ; $ fieldName = $ fieldMapping [ 'fieldName' ] ; if ( $ isUpdate && isset ( $ dcs [ $ fieldName ] ) && isset ( $ dcs [ $ fieldName ] [ 0 ] ) && $ dcs [ $ fieldName ] [ 0 ] != $ dcs [ $ fieldName ] [ 1 ] ) { throw MongoDBException :: shardKeyFieldCannotBeChanged ( $ shardKeyField , $ this -> class -> getName ( ) , $ dcs ) ; } if ( ! isset ( $ actualDocumentData [ $ fieldName ] ) ) { throw MongoDBException :: shardKeyFieldMissing ( $ shardKeyField , $ this -> class -> getName ( ) ) ; } } | If the document is new ignore shard key field value otherwise throw an exception . Also shard key field should be presented in actual document data . |
18,202 | public function classify ( array $ classes , DocumentInterface $ d ) { list ( $ token , $ before , $ after ) = $ d -> getDocumentData ( ) ; $ dotcnt = count ( explode ( '.' , $ token ) ) - 1 ; $ lastdot = substr ( $ token , - 1 ) == '.' OR substr ( $ token , - 1 ) == '?' OR substr ( $ token , - 1 ) == '!' ; if ( ! $ lastdot ) return 'O' ; if ( $ dotcnt > 1 && $ dotcnt < 3 ) return 'O' ; return 'EOW' ; } | Splits up a certain text into a sentence array |
18,203 | public static function invalidMappingType ( $ itemClass , $ attributeName , $ type , $ ownerName = null ) { return new self ( 'The mapping attribute "' . $ attributeName . ( isset ( $ ownerName ) ? ' of "' . $ ownerName . '"' : '' ) . ' is not a valid "' . $ type . '" in "' . $ itemClass . '".' ) ; } | Return MappingException with invalid type mapping message |
18,204 | public static function requiredMapping ( $ itemClass , $ attributeName , $ ownerName = null ) { return new self ( 'The mapping attribute "' . $ attributeName . '"' . ( isset ( $ ownerName ) ? ' of "' . $ ownerName . '"' : '' ) . ' is required in "' . $ itemClass . '".' ) ; } | Return MappingException with required mapping message |
18,205 | public static function filter ( $ alias , $ value ) { $ filter = self :: create ( $ alias ) ; return $ filter -> filter ( $ value ) ; } | Creates the filter in the alias or class name and applies it to the provided value . |
18,206 | protected static function getClass ( $ alias ) { if ( array_key_exists ( $ alias , self :: $ filters ) ) { return self :: $ filters [ $ alias ] ; } if ( ! class_exists ( $ alias ) ) { throw new InvalidArgumentException ( "Class {$alias} does not exists." ) ; } return $ alias ; } | Returns the class name for provided alias |
18,207 | protected function queryXml ( $ apiUrl , $ apiServiceFilter = null ) { $ useCache = self :: $ useCache ; if ( $ apiServiceFilter ) { $ url = $ apiUrl . $ apiServiceFilter -> getURLQuery ( ) ; } else { $ url = $ apiUrl ; } if ( ! $ useCache || $ this -> cacheManager -> has ( md5 ( $ url ) ) == false ) { $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_URL , $ url ) ; curl_setopt ( $ ch , CURLOPT_HEADER , true ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; $ headers = [ 'User-Agent: ' . \ RGU \ Dvoconnector \ Utility \ EmConfiguration :: getSettings ( ) -> getHttpUserAgent ( ) , ] ; if ( ! $ useCache ) { $ headers [ ] = 'Cache-Control: no-cache' ; } curl_setopt ( $ ch , CURLOPT_HTTPHEADER , $ headers ) ; $ response = curl_exec ( $ ch ) ; list ( $ header , $ body ) = explode ( "\r\n\r\n" , $ response , 2 ) ; $ headers = explode ( "\r\n" , $ header ) ; $ responseCode = preg_replace ( '/HTTP\/.* ([0-9]+) .*/' , '${1}' , $ headers [ 0 ] ) ; if ( $ responseCode { 0 } != '2' ) { throw new \ Exception ( 'Unexpected HTTP response code: ' . $ responseCode . '|' . $ url ) ; } if ( ! preg_match ( '/.*Cache-Control: .*no-cache.*/sm' , $ header ) ) { $ maxAge = preg_replace ( '/.*Cache-Control: .*max-age=(\d+).*/sm' , '${1}' , $ header ) ; $ this -> writeCache ( md5 ( $ url ) , $ body , ( $ maxAge == '' ) ? \ RGU \ Dvoconnector \ Utility \ EmConfiguration :: getSettings ( ) -> getCachetime ( ) : ( int ) $ maxAge ) ; } } elseif ( $ useCache && $ this -> cacheManager -> has ( md5 ( $ url ) ) == true ) { $ body = $ this -> readCache ( md5 ( $ url ) ) ; } try { $ xml = new \ SimpleXMLElement ( $ body ) ; } catch ( \ Exception $ e ) { throw $ e ; } return $ xml ; } | Queries XML data from server or cache |
18,208 | protected function writeCache ( $ key , & $ data , $ lifetime ) { $ this -> cacheManager -> set ( $ key , $ data , [ ] , $ lifetime ) ; } | Caches the HTTP response body into database |
18,209 | public static function Gd2gce ( $ a , $ f , $ elong , $ phi , $ height , array & $ xyz ) { $ sp ; $ cp ; $ w ; $ d ; $ ac ; $ as ; $ r ; $ sp = sin ( $ phi ) ; $ cp = cos ( $ phi ) ; $ w = 1.0 - $ f ; $ w = $ w * $ w ; $ d = $ cp * $ cp + $ w * $ sp * $ sp ; if ( $ d <= 0.0 ) return - 1 ; $ ac = $ a / sqrt ( $ d ) ; $ as = $ w * $ ac ; $ r = ( $ ac + $ height ) * $ cp ; $ xyz [ 0 ] = $ r * cos ( $ elong ) ; $ xyz [ 1 ] = $ r * sin ( $ elong ) ; $ xyz [ 2 ] = ( $ as + $ height ) * $ sp ; return 0 ; } | - - - - - - - - - - i a u G d 2 g c e - - - - - - - - - - |
18,210 | function checkLink ( $ link , $ id ) { $ result = $ this -> db -> query ( 'SELECT link FROM ' . $ this -> articleTable . ' WHERE link = :link AND id != :id' , [ ':link' => $ link , ':id' => 0 + $ id ] ) ; if ( isset ( $ result [ 0 ] ) ) { return $ result [ 0 ] -> get ( 'link' ) ; } $ this -> db -> query ( 'UPDATE ' . $ this -> articleTable . ' SET link = :link WHERE id = :id' , [ ':link' => $ link , ':id' => 0 + $ id ] ) ; return false ; } | Check link and if ID is diferent |
18,211 | function getCategory ( $ id ) { $ result = $ this -> db -> query ( 'SELECT * FROM category WHERE id = :id' , [ ':id' => ( 0 + $ id ) ] ) ; if ( isset ( $ result [ 0 ] ) ) { return [ 'name' => $ result [ 0 ] -> get ( 'name' ) , 'description' => $ result [ 0 ] -> get ( 'description' ) ] ; } return false ; } | Get Category by id |
18,212 | private function comList ( $ result ) { foreach ( $ result as $ res ) { $ data [ $ res -> get ( 'id' ) ] [ 'title' ] = $ res -> get ( 'title' ) ; $ data [ $ res -> get ( 'id' ) ] [ 'resume' ] = $ res -> get ( 'resume' ) ; $ data [ $ res -> get ( 'id' ) ] [ 'author' ] = $ res -> get ( 'author' ) ; $ data [ $ res -> get ( 'id' ) ] [ 'autor' ] = $ res -> get ( 'autor' ) ; $ data [ $ res -> get ( 'id' ) ] [ 'category' ] = $ res -> get ( 'category' ) ; $ data [ $ res -> get ( 'id' ) ] [ 'categoria' ] = $ res -> get ( 'categoria' ) ; $ data [ $ res -> get ( 'id' ) ] [ 'link' ] = $ res -> get ( 'link' ) ; $ data [ $ res -> get ( 'id' ) ] [ 'pubdate' ] = $ res -> get ( 'pubdate' ) ; $ media = json_decode ( $ res -> get ( 'media' ) ) ; foreach ( $ media as $ img ) { if ( isset ( $ img -> type ) && $ img -> type == 'image' ) { $ data [ $ res -> get ( 'id' ) ] [ 'image' ] = '/media/article/' . $ res -> get ( 'id' ) . '/mini_' . basename ( $ img -> src ) ; break ; } if ( isset ( $ img -> type ) && $ img -> type == 'video' ) { $ data [ $ res -> get ( 'id' ) ] [ 'image' ] = '/media/v.png' ; } } } return $ data ; } | Private util function |
18,213 | public function listByCategory ( $ cat = null ) { $ result = $ this -> db -> query ( 'SELECT id, title, resume, category, author, link FROM ' . $ this -> articleTable . ' WHERE category = :cat' , [ ':cat' => $ cat ] ) ; if ( isset ( $ result [ 0 ] ) ) { return $ this -> comList ( $ result ) ; } return false ; } | List ao article in this category |
18,214 | public function Index ( ) { $ this -> Permission ( 'Garden.Settings.Manage' ) ; $ this -> AddSideMenu ( 'dashboard/statistics' ) ; $ this -> Title ( T ( 'Vanilla Statistics' ) ) ; $ this -> EnableSlicing ( $ this ) ; if ( $ this -> Form -> IsPostBack ( ) ) { $ Flow = TRUE ; if ( $ Flow && $ this -> Form -> GetFormValue ( 'Reregister' ) ) { Gdn :: Statistics ( ) -> Register ( ) ; } if ( $ Flow && $ this -> Form -> GetFormValue ( 'Save' ) ) { Gdn :: InstallationID ( $ this -> Form -> GetFormValue ( 'InstallationID' ) ) ; Gdn :: InstallationSecret ( $ this -> Form -> GetFormValue ( 'InstallationSecret' ) ) ; $ this -> InformMessage ( T ( "Your settings have been saved." ) ) ; } if ( $ Flow && $ this -> Form -> GetFormValue ( 'AllowLocal' ) ) { SaveToConfig ( 'Garden.Analytics.AllowLocal' , TRUE ) ; } if ( $ Flow && $ this -> Form -> GetFormValue ( 'Allow' ) ) { SaveToConfig ( 'Garden.Analytics.Enabled' , TRUE ) ; } if ( $ Flow && $ this -> Form -> GetFormValue ( 'ClearCredentials' ) ) { Gdn :: InstallationID ( FALSE ) ; Gdn :: InstallationSecret ( FALSE ) ; Gdn :: Statistics ( ) -> Tick ( ) ; $ Flow = FALSE ; } } $ AnalyticsEnabled = Gdn_Statistics :: CheckIsEnabled ( ) ; if ( $ AnalyticsEnabled ) { $ ConfFile = PATH_CONF . '/config.php' ; $ this -> SetData ( 'ConfWritable' , $ ConfWritable = is_writable ( $ ConfFile ) ) ; if ( ! $ ConfWritable ) $ AnalyticsEnabled = FALSE ; } $ this -> SetData ( 'AnalyticsEnabled' , $ AnalyticsEnabled ) ; $ NotifyMessage = Gdn :: Get ( 'Garden.Analytics.Notify' , FALSE ) ; $ this -> SetData ( 'NotifyMessage' , $ NotifyMessage ) ; if ( $ NotifyMessage !== FALSE ) Gdn :: Set ( 'Garden.Analytics.Notify' , NULL ) ; $ this -> Form -> SetFormValue ( 'InstallationID' , Gdn :: InstallationID ( ) ) ; $ this -> Form -> SetFormValue ( 'InstallationSecret' , Gdn :: InstallationSecret ( ) ) ; $ this -> Render ( ) ; } | Statistics setup & configuration . |
18,215 | public function Verify ( ) { $ CredentialsValid = Gdn :: Statistics ( ) -> ValidateCredentials ( ) ; $ this -> SetData ( 'StatisticsVerified' , $ CredentialsValid ) ; $ this -> Render ( ) ; } | Verify connection credentials . |
18,216 | public function has ( string $ name ) : bool { $ parts = explode ( '[' , $ name ) ; $ lastKey = trim ( array_pop ( $ parts ) , ']' ) ; $ current = & $ this -> parameters ; foreach ( $ parts as $ part ) { $ target = trim ( $ part , ']' ) ; if ( ! is_array ( $ current ) || ! array_key_exists ( $ target , $ current ) ) { return false ; } $ current = & $ current [ $ target ] ; } if ( ! array_key_exists ( $ lastKey , $ current ) ) { return false ; } return true ; } | Checks if a parameter exists . |
18,217 | public function get ( string $ name , $ default = null ) { $ parts = explode ( '[' , $ name ) ; $ lastKey = trim ( array_pop ( $ parts ) , ']' ) ; $ current = & $ this -> parameters ; foreach ( $ parts as $ part ) { $ target = trim ( $ part , ']' ) ; if ( ! is_array ( $ current ) || ! array_key_exists ( $ target , $ current ) ) { return $ default ; } $ current = & $ current [ $ target ] ; } if ( ! array_key_exists ( $ lastKey , $ current ) ) { return $ default ; } return $ current [ $ lastKey ] ; } | Returns the value of a parameter . |
18,218 | protected function requestProjects ( $ name , \ Closure $ finder , $ nameKey ) { $ projects = [ ] ; if ( $ this -> repoParser -> isConcrete ( $ name ) ) { $ project = $ this -> getProject ( $ name ) ; $ projects [ $ project -> getName ( ) ] = $ project ; } else { $ repos = $ finder ( $ name ) ; if ( true === $ this -> repoParser -> isWildcard ( $ name ) ) { foreach ( ( array ) $ repos as $ repo ) { $ project = $ this -> getProject ( $ repo [ $ nameKey ] ) ; $ projects [ $ project -> getName ( ) ] = $ project ; } } else { foreach ( ( array ) $ repos as $ repo ) { if ( false === $ this -> repoParser -> matchesRegex ( $ name , $ repo [ $ nameKey ] ) ) { continue ; } $ project = $ this -> getProject ( $ repo [ $ nameKey ] ) ; $ projects [ $ project -> getName ( ) ] = $ project ; } } } return $ projects ; } | searches for projects . |
18,219 | public static function getViewHelper ( $ appName = null , bool $ layout = false ) { if ( $ appName === false ) { $ class = '\Osf\View\Helper' ; $ instance = 'osf' ; } else { $ appName = $ appName === null ? Router :: getDefaultControllerName ( true ) : $ appName ; $ class = "\\App\\" . $ appName . '\View\Helper' ; $ instance = $ appName ; } $ viewName = $ layout ? 'layout' : 'view' ; $ instance .= $ layout ? '_l' : '_v' ; return self :: buildObject ( $ class , [ $ viewName ] ) ; } | Get a view helpers object with a context |
18,220 | public static function getCrypt ( $ cryptKey = Crypt :: DEFAULT_KEY , $ mode = Crypt :: MODE_ASCII ) : \ Osf \ Crypt \ Crypt { return self :: buildObject ( '\Osf\Crypt\Crypt' , [ $ cryptKey , $ mode ] ) ; } | Get Osf Crypt object . Parameters are usefull ONLY for the first call |
18,221 | public function thumbnail ( $ width , $ height = null ) { if ( $ this -> type != 'image' ) { throw new \ LogicException ( "Tried to create thumbnail for not image file." , 500 ) ; } $ thumbnail = new \ Routegroup \ Media \ Helpers \ Thumbnail ( $ this ) ; $ filename = $ thumbnail -> name ( $ width , $ height ) ; if ( $ thumbnail -> exists ( $ filename ) ) { return $ this -> storage -> url ( $ this -> path ( $ filename ) ) ; } return $ thumbnail -> create ( $ filename , $ width , $ height ) ; } | Gets thumbnail for given sizes . |
18,222 | public static function argsValidation ( $ cacheDir , $ cacheTTL , $ caching , $ cacheForever , $ charset ) { if ( ! self :: validateDirName ( $ cacheDir ) ) throw new \ Franzip \ SerpFetcher \ Exceptions \ InvalidArgumentException ( 'Invalid SerpFetcher $cacheDir: please supply a valid non-empty string.' ) ; if ( ! self :: validateExpirationTime ( $ cacheTTL ) ) throw new \ Franzip \ SerpFetcher \ Exceptions \ InvalidArgumentException ( 'Invalid SerpFetcher $cacheTTL: please supply a positive integer.' ) ; if ( ! self :: validateCacheOpt ( $ caching ) ) throw new \ Franzip \ SerpFetcher \ Exceptions \ InvalidArgumentException ( 'Invalid SerpFetcher $caching: please supply a boolean value.' ) ; if ( ! self :: validateCacheOpt ( $ cacheForever ) ) throw new \ Franzip \ SerpFetcher \ Exceptions \ InvalidArgumentException ( 'Invalid SerpFetcher $cacheForever: please supply a boolean value.' ) ; if ( ! self :: validateCharset ( $ charset ) ) throw new \ Franzip \ SerpFetcher \ Exceptions \ InvalidArgumentException ( 'Invalid SerpFetcher $charset: please supply a valid non-empty string.' ) ; } | Perform validation on SerpFetcher constructor arguments . |
18,223 | public function tableExists ( $ tableName ) { if ( is_null ( $ this -> dbh ) ) { throw new NoConnectionException ( ) ; } $ mrSql = "SHOW TABLES LIKE :table_name" ; $ mrStmt = $ this -> dbh -> prepare ( $ mrSql ) ; $ mrStmt -> bindParam ( ":table_name" , $ tableName , \ PDO :: PARAM_STR ) ; $ sqlResult = $ mrStmt -> execute ( ) ; if ( $ sqlResult ) { $ row = $ mrStmt -> fetch ( \ PDO :: FETCH_NUM ) ; if ( $ row [ 0 ] ) { return true ; } } return false ; } | This function checks if the table exists in the passed PDO database connection |
18,224 | public static function deleteCrops ( $ originalFilePath , $ cropsFolder = null ) { $ self = static :: create ( $ originalFilePath , $ cropsFolder ) ; return $ self -> removeCrops ( ) ; } | Quickly remove crops |
18,225 | public function removeCrops ( ) { $ justTheName = pathinfo ( $ this -> originalImagePath , PATHINFO_FILENAME ) ; $ filesToRemove = glob ( sprintf ( '%s/%s-*' , $ this -> cropsFolder , $ justTheName ) ) ; foreach ( $ filesToRemove as $ file ) { if ( is_file ( $ file ) ) unlink ( $ file ) ; } return $ this ; } | Reset all created crops for the image |
18,226 | public function server ( string $ key , $ default = null ) { return $ this -> server -> has ( $ key ) ? $ this -> server -> get ( $ key ) : $ default ; } | Shortcut to fetch a SERVER - parameter with optional default value |
18,227 | public function cookie ( string $ key , $ default = null ) { return $ this -> cookie -> has ( $ key ) ? $ this -> cookie -> get ( $ key ) : $ default ; } | Shortcut to fetch a COOKIE - parameter with optional default value |
18,228 | public function session ( string $ key , $ default = null ) { if ( null === $ this -> session ) { throw new \ Exception ( 'No session object set. Use \'Request::setSession\'.' ) ; } return $ this -> session -> has ( $ key ) ? $ this -> session -> get ( $ key ) : $ default ; } | Shortcut to fetch a SESSION - parameter with optional default value . The session object must me manualy set and started! |
18,229 | public function header ( string $ key , $ default = null ) { return $ this -> header -> has ( $ key ) ? $ this -> header -> get ( $ key ) : $ default ; } | Shortcut to fetch a HEADER - parameter with optional default value . |
18,230 | public function getMethod ( ) : ? int { switch ( $ this -> server ( 'REQUEST_METHOD' ) ) { case 'GET' : return self :: HTTP_GET ; case 'POST' : return self :: HTTP_POST ; case 'HEAD' : return self :: HTTP_HEAD ; case 'PUT' : return self :: HTTP_PUT ; case 'DELETE' : return self :: HTTP_DELETE ; case 'TRACE' : return self :: HTTP_TRACE ; case 'OPTIONS' : return self :: HTTP_OPTIONS ; case 'CONNECT' : return self :: HTTP_CONNECT ; } return null ; } | Returns the bit - code of the request method or null if the method is unknown . |
18,231 | protected function protocolWithActiveSsl ( $ protocol ) : bool { $ protocol = strtolower ( ( string ) $ protocol ) ; return in_array ( $ protocol , [ 'on' , '1' , 'https' , 'ssl' ] , true ) ; } | Detects an active SSL protocol value . |
18,232 | public function getPort ( ) : string { $ port = self :: server ( 'HTTP_X_FORWARDED_PORT' ) ; if ( $ port ) { return ( string ) $ port ; } $ protocol = ( string ) self :: server ( 'HTTP_X_FORWARDED_PROTO' ) ; if ( $ protocol === 'https' ) { return '443' ; } return ( string ) self :: server ( 'SERVER_PORT' ) ; } | Get the port of this request as string . |
18,233 | public function getUrl ( ) : Url { return Url :: from ( $ this -> getHttpScheme ( ) . '://' . $ this -> getHost ( ) . $ this -> server ( 'REQUEST_URI' ) ) ; } | Gets a new ieu \ Http \ Url object based on the request URL |
18,234 | public function getResults ( EntityManager $ em , Request $ request , $ page ) { $ query = $ this -> buildResultQuery ( $ em , $ request , $ page ) ; return $ query -> getResult ( ) ; } | Get results for request |
18,235 | public function getCount ( EntityManager $ em , Request $ request ) { $ stmt = $ this -> buildCountQuery ( $ em , $ request ) ; $ stmt -> execute ( ) ; return ( int ) $ stmt -> fetchColumn ( ) ; } | Get result count for request |
18,236 | protected function buildResultQuery ( EntityManager $ em , Request $ request , $ page ) { $ searchWords = preg_split ( '/[^[:alnum:]]+/' , $ request -> getSearchText ( ) ) ; $ offset = $ request -> getLimit ( ) * ( $ page - 1 ) ; $ limit = $ request -> getLimit ( ) ; $ selects = array ( ) ; foreach ( $ this -> databaseMapping as $ key => $ tableMapping ) { $ tableMapping [ 'columns' ] [ $ this -> scorePos ] = $ this -> buildScoreColumn ( $ tableMapping [ 'columns' ] , count ( $ searchWords ) ) ; ksort ( $ tableMapping [ 'columns' ] ) ; $ hitExpressions = $ this -> buildHitExpressions ( $ tableMapping [ 'columns' ] ) ; $ joinsExpressions = $ this -> buildJoinExpressions ( $ tableMapping [ 'joins' ] ) ; $ selects [ ] = 'SELECT * FROM (SELECT ' . implode ( $ hitExpressions , ', ' ) . ' ' . 'FROM ' . $ tableMapping [ 'table' ] . ' ' . $ tableMapping [ 'tableAlias' ] . ' ' . implode ( ' ' , $ joinsExpressions ) . ' ' . 'ORDER BY c' . $ this -> scorePos . ' DESC ' . 'LIMIT ' . ( $ offset + $ limit ) . ') AS DT' . $ key . ' ' . 'WHERE c' . $ this -> scorePos . '<>0 ' ; } $ bigSelect = '' . implode ( $ selects , ' UNION ' ) . ' ' . 'ORDER BY c' . $ this -> scorePos . ' DESC ' . 'LIMIT ' . $ limit . ' ' . 'OFFSET ' . $ offset ; $ query = $ em -> createNativeQuery ( $ bigSelect , $ this -> rsm ) ; foreach ( $ searchWords as $ key => $ searchWord ) { $ query -> setParameter ( 'p' . $ key , $ searchWord ) ; } return $ query ; } | Build result query |
18,237 | protected function buildCountQuery ( EntityManager $ em , Request $ request ) { $ searchWords = preg_split ( '/[^[:alnum:]]+/' , $ request -> getSearchText ( ) ) ; $ selects = array ( ) ; foreach ( $ this -> databaseMapping as $ tableMapping ) { $ score = $ this -> buildScoreColumn ( $ tableMapping [ 'columns' ] , count ( $ searchWords ) ) ; $ joinsExpressions = $ this -> buildJoinExpressions ( $ tableMapping [ 'joins' ] ) ; $ selects [ ] = 'SELECT COUNT(*) ' . 'FROM ' . $ tableMapping [ 'table' ] . ' ' . $ tableMapping [ 'tableAlias' ] . ' ' . implode ( ' ' , $ joinsExpressions ) . ' ' . 'WHERE ' . $ score [ 'expression' ] . '<>0 ' ; } $ bigSelect = 'SELECT (' . implode ( ')+(' , $ selects ) . ')' ; $ stmt = $ em -> getConnection ( ) -> prepare ( $ bigSelect ) ; foreach ( $ searchWords as $ key => $ searchWord ) { $ stmt -> bindValue ( 'p' . $ key , $ searchWord ) ; } return $ stmt ; } | Build count query |
18,238 | protected function buildScoreColumn ( array $ columns , $ searchWordsCount ) { $ scoreExpression = $ this -> buildScore ( $ columns , $ searchWordsCount ) ; return array ( 'expression' => $ scoreExpression , 'type' => Type :: INTEGER ) ; } | Build score column with same structure as hit |
18,239 | protected function buildScore ( array $ columns , $ searchWordsCount ) { $ scores = array ( ) ; foreach ( $ columns as $ column ) { if ( $ column [ 'scoreFactor' ] != 0 && isset ( $ column [ 'expression' ] ) ) { $ stringConvertedExpression = $ this -> convertToString ( $ column [ 'type' ] , $ column [ 'expression' ] ) ; $ score = $ column [ 'scoreFactor' ] . '*(' . $ searchWordsCount . '*LENGTH(IFNULL(' . $ stringConvertedExpression . ', \'\'))' ; for ( $ i = 0 ; $ i < $ searchWordsCount ; $ i ++ ) { $ score .= ' - LENGTH(REPLACE(LOWER(IFNULL(' . $ stringConvertedExpression . ', \'\')), LOWER(:p' . $ i . '), \'\'))' ; } $ score .= ')' ; $ scores [ ] = $ score ; } } return '' . implode ( $ scores , '+' ) . '' ; } | Build score expression |
18,240 | protected function buildJoinExpressions ( array $ joins ) { $ joinExpressions = array ( ) ; foreach ( $ joins as $ joins ) { $ joinExpressions [ ] = 'LEFT JOIN ' . $ joins [ 'table' ] . ' ' . $ joins [ 'tableAlias' ] . ' ON ' . $ joins [ 'onClause' ] ; } return $ joinExpressions ; } | Build joins expression |
18,241 | protected function convertToString ( $ type , $ expression ) { switch ( $ type ) { case Type :: STRING : case Type :: TEXT : return $ expression ; case Type :: BIGINT : case Type :: DECIMAL : case Type :: FLOAT : case Type :: INTEGER : case Type :: SMALLINT : case Type :: DATE : case Type :: DATETIME : case Type :: DATETIMETZ : case Type :: TIME : return 'CAST(' . $ expression . ' AS CHAR)' ; default : return '\'\'' ; } } | Return string string converted column |
18,242 | public function mapDatabase ( array $ databaseMapping , $ itemClass , array $ hitPositions ) { $ this -> databaseMapping = $ databaseMapping ; $ this -> loadFinalType ( $ hitPositions ) ; $ this -> loadResultSetMappingAndScorePosition ( $ itemClass , $ hitPositions ) ; $ this -> finalTypes [ $ this -> scorePos ] = Type :: INTEGER ; } | Loads and complete databaseMapping |
18,243 | function isUTF8 ( $ str ) { if ( is_array ( $ str ) ) { $ str = implode ( '' , $ str ) ; return ! ( ( ord ( $ str [ 0 ] ) != 239 ) && ( ord ( $ str [ 1 ] ) != 187 ) && ( ord ( $ str [ 2 ] ) != 191 ) ) ; } else { return ( utf8_encode ( utf8_decode ( $ str ) ) == $ str ) ; } } | Fonction permettant de savoir s il y a des caracteres en utf8 dans la chaine |
18,244 | function encodeToUTF8 ( $ str ) { $ encodage = mb_detect_encoding ( $ str , "UTF-8, ISO-8859-1, ISO-8859-15, windows-1252" , true ) ; $ str_utf8 = mb_convert_encoding ( $ str , "UTF-8" , $ encodage ) ; return $ str_utf8 ; } | Fonction d encodage en utf8 a partir d autre encodage pratique = > detection |
18,245 | public function getTexteDifferences ( $ params = array ( ) ) { $ retour = "" ; if ( isset ( $ params [ 'nouveau' ] ) && isset ( $ params [ 'ancien' ] ) ) { $ fd = new filediff ( ) ; $ fd -> set_textes ( $ params [ 'nouveau' ] , $ params [ 'ancien' ] ) ; $ fd -> execute ( ) ; $ retour [ 'html' ] = $ fd -> display ( ) ; } return $ retour ; } | Permet de comparer 2 fichiers |
18,246 | protected function view ( $ file , $ param = array ( ) ) { extract ( $ param ) ; if ( ! is_array ( $ file ) ) { $ path = explode ( '\\' , get_class ( $ this ) ) ; if ( count ( $ path ) > 2 ) { $ view_path = '' ; for ( $ i = 0 ; $ i < count ( $ path ) - 2 ; $ i ++ ) { $ view_path .= strtolower ( $ path [ $ i ] ) . '/' ; } $ view_path = Config :: get ( 'path.mvc' ) . '/' . $ view_path ; } else { $ view_path = Config :: get ( 'path.mvc' ) ; } if ( php_sapi_name ( ) == 'cli' ) $ view_path = Config :: get ( 'path.basepath' ) . '/' . $ view_path ; } else { $ view_path = Config :: get ( 'path.mvc' ) ; if ( isset ( $ file [ 1 ] ) ) { $ view_path .= '/' . $ file [ 0 ] ; $ file = $ file [ 1 ] ; } else $ file = $ file [ 0 ] ; if ( php_sapi_name ( ) == 'cli' ) $ view_path = Config :: get ( 'path.basepath' ) . '/' . $ view_path ; } ob_start ( ) ; include $ view_path . '/views/' . $ file . '.php' ; return ob_get_clean ( ) ; } | view Funngsi untuk menampilkan view |
18,247 | public function setQuestion ( $ question ) { if ( false === is_string ( $ question ) ) { throw new \ InvalidArgumentException ( 'Question should be a string' ) ; } $ this -> question = trim ( $ question ) . " " ; return $ this ; } | Sets the value of question . |
18,248 | protected function doFindAndRemove ( array $ query , array $ options = array ( ) ) { $ document = parent :: doFindAndRemove ( $ query , $ options ) ; if ( isset ( $ document ) ) { $ this -> riakCollection -> chunks -> remove ( array ( 'files_id' => $ document [ '_id' ] ) , $ options ) ; } return $ document ; } | Execute the findAndModify command with the remove option and delete any chunks for the document . |
18,249 | protected function doInsert ( array & $ a , array $ options = array ( ) ) { if ( ! isset ( $ a [ 'file' ] ) ) { parent :: doInsert ( $ a , $ options ) ; return ; } $ file = $ a [ 'file' ] ; unset ( $ a [ 'file' ] ) ; if ( $ file -> isDirty ( ) ) { $ this -> storeFile ( $ file , $ a , $ options ) ; } else { parent :: doInsert ( $ a , $ options ) ; } $ a [ 'file' ] = $ file ; return $ a ; } | Execute the insert query and persist the GridFSFile if necessary . |
18,250 | protected function doSave ( array & $ a , array $ options = array ( ) ) { if ( isset ( $ a [ '_id' ] ) ) { return $ this -> doUpdate ( array ( '_id' => $ a [ '_id' ] ) , $ a , $ options ) ; } else { return $ this -> doInsert ( $ a , $ options ) ; } } | Execute the save query and persist the GridFSFile if necessary . |
18,251 | public static function parse ( $ path ) { $ path = explode ( ':' , $ path , 2 ) ; if ( count ( $ path ) == 2 ) { if ( head ( $ path ) == 'app' ) { $ path = app_path ( last ( $ path ) ) ; } elseif ( head ( $ path ) == 'base' ) { $ path = base_path ( last ( $ path ) ) ; } elseif ( head ( $ path ) == 'config' ) { $ path = config_path ( last ( $ path ) ) ; } elseif ( head ( $ path ) == 'database' ) { $ path = database_path ( last ( $ path ) ) ; } elseif ( head ( $ path ) == 'public' ) { $ path = public_path ( last ( $ path ) ) ; } elseif ( head ( $ path ) == 'storage' ) { $ path = storage_path ( last ( $ path ) ) ; } else { $ path = head ( $ path ) ; } } else { $ path = head ( $ path ) ; } return $ path ; } | Parse a path . |
18,252 | public function reset ( ) { $ this -> class = null ; $ this -> with = [ ] ; $ this -> flags = [ ] ; $ this -> columns = [ ] ; $ this -> from = [ ] ; $ this -> join = [ ] ; $ this -> where = [ ] ; $ this -> groupBy = [ ] ; $ this -> having = [ ] ; $ this -> orderBy = [ ] ; $ this -> limit = null ; $ this -> offset = null ; $ this -> bindings = [ 'select' => [ ] , 'from' => [ ] , 'join' => [ ] , 'where' => [ ] , 'group' => [ ] , 'having' => [ ] , 'order' => [ ] , ] ; return $ this ; } | Reset the query . |
18,253 | protected function quoteColumn ( $ column ) { if ( ( $ pos = strpos ( $ column , '.' ) ) !== false ) { return $ this -> db -> quoteName ( substr ( $ column , 0 , $ pos ) ) . '.' . $ this -> db -> quoteName ( substr ( $ column , $ pos + 1 ) ) ; } return $ this -> db -> quoteName ( $ column ) ; } | Quote a column . |
18,254 | protected function eagerLoadRelations ( array $ entities ) { if ( empty ( $ entities ) ) { return ; } if ( $ this -> class === null ) { throw new LogicException ( 'A class must be specified for Eager Loading using the `asClass` method.' ) ; } foreach ( $ this -> with as $ method ) { $ relation = $ this -> getRelation ( $ entities [ 0 ] , $ method ) ; $ relation -> addEagerConstraints ( $ entities ) ; $ relationEntities = $ relation -> getEager ( ) ; foreach ( $ entities as $ entity ) { $ id = $ entity -> getId ( ) ; $ entity -> setRelationEntities ( $ method , isset ( $ relationEntities [ $ id ] ) ? $ relationEntities [ $ id ] : null ) ; } } } | Eager load the relationships . |
18,255 | protected function getRelation ( $ entity , $ method ) { if ( ! method_exists ( $ entity , $ method ) ) { throw new LogicException ( 'Call to undefined relationship "' . $ method . '" on model "' . get_class ( $ entity ) . '".' ) ; } $ relation = \ Core \ Models \ Relation :: noConstraints ( function ( ) use ( $ entity , $ method ) { return $ entity -> $ method ( ) ; } ) ; if ( ! $ relation instanceof Relation ) { throw new LogicException ( 'Relationship method "' . $ method . '" must return an object of type Core\Models\Contracts\Relation.' ) ; } return $ relation ; } | Get the relation instance for the given relationship method . |
18,256 | private function hasExactlyOneColumn ( ) { if ( count ( $ this -> columns ) != 1 || strpos ( $ this -> columns [ 0 ] , '*' ) !== false ) { return false ; } if ( strpos ( $ this -> columns [ 0 ] , ',' ) === false ) { return true ; } $ column = $ this -> columns [ 0 ] ; $ n = strlen ( $ column ) ; $ braces = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ ch = $ column [ $ i ] ; if ( $ braces == 0 && $ ch == ',' ) { return false ; } else if ( $ ch == '(' ) { $ braces ++ ; } else if ( $ ch == ')' ) { $ braces -- ; } } return true ; } | Determine if the statement has exactly one column . |
18,257 | protected function aggregate ( $ function , $ column = null ) { if ( $ column === null ) { if ( $ this -> hasExactlyOneColumn ( ) ) { if ( ( $ pos = strpos ( $ this -> columns [ 0 ] , ' AS ' ) ) !== false ) { $ column = substr ( $ this -> columns [ 0 ] , 0 , $ pos ) ; } else { $ column = $ this -> columns [ 0 ] ; } $ bindings = $ this -> bindings [ 'select' ] ; } else { $ column = '*' ; $ bindings = [ ] ; } } else { $ column = $ this -> db -> quoteName ( $ column ) ; $ bindings = [ ] ; } $ flags = ! empty ( $ this -> flags ) ? implode ( ' ' , $ this -> flags ) . ' ' : '' ; $ query = 'SELECT ' . $ function . '(' . $ flags . $ column . ')' . $ this -> buildFrom ( ) . $ this -> buildJoin ( ) . $ this -> buildWhere ( ) ; foreach ( [ 'from' , 'join' , 'where' ] as $ clause ) { if ( ! empty ( $ this -> bindings [ $ clause ] ) ) { $ bindings = array_merge ( $ bindings , $ this -> bindings [ $ clause ] ) ; } } $ result = $ this -> db -> scalar ( $ query , $ bindings ) ; return $ result ? : 0 ; } | Execute an aggregate function . |
18,258 | protected function doInsert ( array $ data = [ ] ) { if ( empty ( $ data ) ) { $ this -> insertEmptyRecord ( ) ; return $ this -> db -> lastInsertId ( ) ; } if ( ! is_int ( key ( $ data ) ) ) { $ columns = implode ( ', ' , array_map ( [ $ this -> db , 'quoteName' ] , array_keys ( $ data ) ) ) ; $ params = implode ( ', ' , array_fill ( 0 , count ( $ data ) , '?' ) ) ; $ bindings = array_values ( $ data ) ; } else { $ keys = [ ] ; foreach ( $ data as $ row ) { if ( empty ( $ row ) ) { throw new InvalidArgumentException ( 'Cannot insert an empty record on bulk mode.' ) ; } $ keys = array_merge ( $ keys , $ row ) ; } $ keys = array_keys ( $ keys ) ; $ columns = implode ( ', ' , array_map ( [ $ this -> db , 'quoteName' ] , $ keys ) ) ; $ params = implode ( ', ' , array_fill ( 0 , count ( $ keys ) , '?' ) ) ; $ bindings = [ ] ; $ temp = [ ] ; foreach ( $ data as $ i => $ row ) { foreach ( $ keys as $ key ) { $ bindings [ ] = isset ( $ row [ $ key ] ) ? $ row [ $ key ] : null ; } $ temp [ ] = $ params ; } $ params = implode ( '), (' , $ temp ) ; } $ table = implode ( ', ' , $ this -> from ) ; $ query = "INSERT INTO $table ($columns) VALUES ($params)" ; $ this -> db -> exec ( $ query , $ bindings ) ; return $ this -> db -> lastInsertId ( ) ; } | Insert rows to the table and return the inserted autoincrement sequence value . |
18,259 | protected function doUpdate ( array $ data ) { if ( empty ( $ data ) ) { throw new InvalidArgumentException ( 'Cannot update an empty record.' ) ; } $ bindings = array_merge ( $ this -> bindings [ 'join' ] , $ this -> bindings [ 'where' ] ) ; $ settings = [ ] ; $ values = [ ] ; if ( empty ( $ bindings ) || is_int ( key ( $ bindings ) ) ) { foreach ( $ data as $ column => $ value ) { $ settings [ ] = $ this -> quoteColumn ( $ column ) . ' = ?' ; $ values [ ] = $ value ; } } else { foreach ( $ data as $ column => $ value ) { $ key = $ column ; if ( isset ( $ bindings [ $ key ] ) ) { $ i = 0 ; do { $ key = $ column . '_' . ( ++ $ i ) ; } while ( isset ( $ bindings [ $ key ] ) || isset ( $ data [ $ key ] ) ) ; } $ settings [ ] = $ this -> quoteColumn ( $ column ) . ' = :' . $ key ; $ values [ $ key ] = $ value ; } } $ from = ' ' . implode ( ', ' , $ this -> from ) ; $ bindings = array_merge ( $ this -> bindings [ 'join' ] , $ values , $ this -> bindings [ 'where' ] ) ; $ settings = ' SET ' . implode ( ', ' , $ settings ) ; $ query = 'UPDATE' . $ from . $ this -> buildJoin ( ) . $ settings . $ this -> buildWhere ( ) ; return $ this -> db -> exec ( $ query , $ bindings ) ; } | Update all records of the query result with th given data and return the number of affected rows . |
18,260 | protected function doDelete ( ) { $ bindings = array_merge ( $ this -> bindings [ 'join' ] , $ this -> bindings [ 'where' ] ) ; $ query = 'DELETE' . $ this -> buildFrom ( ) . $ this -> buildJoin ( ) . $ this -> buildWhere ( ) ; return $ this -> db -> exec ( $ query , $ bindings ) ; } | Delete all records of the query result and return the number of affected rows . |
18,261 | protected function putBindings ( $ clause , array $ bindings ) { if ( ! empty ( $ bindings ) ) { $ this -> bindings [ $ clause ] = array_merge ( $ this -> bindings [ $ clause ] , $ bindings ) ; } } | Put the bindings into the list . |
18,262 | protected function compileColumns ( $ columns , $ clause ) { $ list = [ ] ; foreach ( ( array ) $ columns as $ alias => $ column ) { if ( is_string ( $ column ) && preg_match ( '/^(?:([0-9a-zA-Z$_]+)\.)?([0-9a-zA-Z$_]+)$/s' , trim ( $ column ) , $ match ) ) { $ column = ( ! empty ( $ match [ 1 ] ) ? $ this -> db -> quoteName ( $ match [ 1 ] ) . '.' : '' ) . $ this -> db -> quoteName ( $ match [ 2 ] ) ; } else { if ( is_callable ( $ column ) ) { $ column = $ column ( new static ( $ this -> db ) ) ; } if ( $ column instanceof BuilderContract ) { $ this -> putBindings ( $ clause , $ column -> bindings ( ) ) ; $ column = $ column -> toSql ( ) ; } $ column = $ this -> compileExpression ( $ column ) ; } if ( is_string ( $ alias ) ) { if ( strncasecmp ( $ column , 'SELECT ' , 7 ) === 0 ) { $ column = "($column)" ; } $ column .= ' AS ' . $ this -> db -> quoteName ( $ alias ) ; } $ list [ ] = $ column ; } return $ list ; } | Render the column list . |
18,263 | protected function buildLimit ( ) { return $ this -> limit !== null ? ' LIMIT ' . $ this -> limit . ( $ this -> offset ? ' OFFSET ' . $ this -> offset : '' ) : '' ; } | Builds the LIMIT ... OFFSET clause . |
18,264 | public function initialize ( ) { if ( $ this -> riakClient !== null ) { return ; } if ( $ this -> eventManager -> hasListeners ( Events :: preConnect ) ) { $ this -> eventManager -> dispatchEvent ( Events :: preConnect , new EventArgs ( $ this ) ) ; } $ server = $ this -> server ? : 'http://localhost:8098' ; $ options = $ this -> options ; $ options = isset ( $ options [ 'timeout' ] ) ? $ this -> convertConnectTimeout ( $ options ) : $ options ; $ options = isset ( $ options [ 'wTimeout' ] ) ? $ this -> convertWriteTimeout ( $ options ) : $ options ; $ this -> riakClient = $ this -> retry ( function ( ) use ( $ server , $ options ) { return new RiakClient ( $ server , $ options ) ; } ) ; if ( $ this -> eventManager -> hasListeners ( Events :: postConnect ) ) { $ this -> eventManager -> dispatchEvent ( Events :: postConnect , new EventArgs ( $ this ) ) ; } } | Construct the wrapped RiakClient instance if necessary . |
18,265 | protected function convertConnectTimeout ( array $ options ) { if ( version_compare ( phpversion ( 'mongo' ) , '1.4.0' , '<' ) ) { return $ options ; } if ( isset ( $ options [ 'timeout' ] ) && ! isset ( $ options [ 'connectTimeoutMS' ] ) ) { $ options [ 'connectTimeoutMS' ] = $ options [ 'timeout' ] ; unset ( $ options [ 'timeout' ] ) ; } return $ options ; } | Converts timeout RiakClient constructor option to connectTimeoutMS for driver versions 1 . 4 . 0 + . |
18,266 | protected function convertWriteTimeout ( array $ options ) { if ( version_compare ( phpversion ( 'mongo' ) , '1.4.0' , '<' ) ) { return $ options ; } if ( isset ( $ options [ 'wTimeout' ] ) && ! isset ( $ options [ 'wTimeoutMS' ] ) ) { $ options [ 'wTimeoutMS' ] = $ options [ 'wTimeout' ] ; unset ( $ options [ 'wTimeout' ] ) ; } return $ options ; } | Converts wTimeout RiakClient constructor option to wTimeoutMS for driver versions 1 . 4 . 0 + . |
18,267 | public static function createRole ( $ name , $ description ) { $ auth = Yii :: $ app -> authManager ; $ role = $ auth -> createRole ( $ name ) ; $ role -> description = $ description ; $ auth -> add ( $ role ) ; return $ role ; } | Creates role with a given name and description and adds it to RBAC system . |
18,268 | public static function createChildPermission ( $ role , $ name , $ description ) { $ auth = Yii :: $ app -> authManager ; $ permission = $ auth -> createPermission ( $ name ) ; $ permission -> description = $ description ; $ auth -> add ( $ permission ) ; $ auth -> addChild ( $ role , $ permission ) ; return $ permission ; } | Creates permission with a given name and description and adds it to RBAC system assigning permission to the role . |
18,269 | public static function removeRuleByName ( $ name ) { $ auth = Yii :: $ app -> authManager ; $ rule = $ auth -> getRule ( $ name ) ; return $ auth -> remove ( $ rule ) ; } | Removes rule from RBAC system by name . |
18,270 | public static function removePermissionByName ( $ name ) { $ auth = Yii :: $ app -> authManager ; $ permission = $ auth -> getPermission ( $ name ) ; return $ auth -> remove ( $ permission ) ; } | Removes permission from RBAC system by name . |
18,271 | public static function removeRoleByName ( $ name ) { $ auth = Yii :: $ app -> authManager ; $ role = $ auth -> getRole ( $ name ) ; return $ auth -> remove ( $ role ) ; } | Removes role from RBAC system by name . |
18,272 | protected function buildListExpression ( ClassProfile $ entity , $ index = null , $ group = null ) { $ expr = 'obj:' . $ entity -> getReflectionClass ( ) -> getName ( ) ; if ( isset ( $ group ) ) $ expr .= '<' . $ group . '>' ; if ( isset ( $ index ) ) $ expr .= '[' . $ index . ']' ; else $ expr .= '[]' ; return $ expr ; } | Obtains a list mapping expression for the give profile |
18,273 | private function vulgarize ( $ string ) { return trim ( preg_replace ( '/(-+)/' , '-' , preg_replace ( '/([^a-z0-9-]*)/' , '' , preg_replace ( '/((\s|\.|\'|\/)+)/' , '-' , html_entity_decode ( preg_replace ( '/&(a|o)elig;/' , '$1e' , preg_replace ( '/&([a-z])(uml|acute|grave|circ|tilde|ring|cedil|slash);/' , '$1' , strtolower ( htmlentities ( $ string , ENT_COMPAT , 'utf-8' ) ) ) ) , ENT_COMPAT , 'utf-8' ) ) ) ) , '-' ) ; } | Makes a string URL - compatible |
18,274 | protected function isNameUnique ( $ association ) { $ associations = $ this -> determineAssociationsByName ( $ association -> getName ( ) ) ; return $ associations -> getAssociations ( ) -> count ( ) == 1 ; } | determine if the association is unique by the name |
18,275 | protected function determineAssociationsByName ( $ name ) { $ associationsFilter = new AssociationsFilter ( ) ; $ associationsFilter -> setName ( $ name ) ; $ associations = $ this -> associationRepository -> findAssociationsByRootAssociations ( $ associationsFilter ) ; return $ associations ; } | determine offset for association |
18,276 | public function setData ( $ data ) { try { parent :: setData ( $ data ) ; $ this -> invalidData = null ; $ this -> invalidDataTypeException = null ; } catch ( InputFilterInvalidArgumentException $ e ) { $ this -> invalidData = $ data ; $ this -> invalidDataTypeException = $ e ; } return $ this ; } | Set data to use when validating and filtering |
18,277 | public function isValid ( $ context = null ) { if ( $ this -> invalidDataTypeException !== null ) { return false ; } if ( ! $ this -> data && ! $ this -> isRequired ( ) ) { return true ; } if ( ! $ this -> needsFiltering ( ) ) { return true ; } return parent :: isValid ( $ context ) ; } | Is the data set valid? |
18,278 | public function getMessages ( ) { if ( $ this -> invalidDataTypeException !== null ) { return array ( 'invalidType' => sprintf ( 'Value must be an array or Traversable object; received %s' , is_object ( $ this -> invalidData ) ? get_class ( $ this -> invalidData ) : gettype ( $ this -> invalidData ) ) ) ; } return parent :: getMessages ( ) ; } | Return a list of validation failure messages . |
18,279 | public function getValues ( ) { if ( ! $ this -> data && ! $ this -> isRequired ( ) ) { return null ; } if ( ! $ this -> needsFiltering ( ) ) { return array ( ) ; } return parent :: getValues ( ) ; } | Return a list of filtered values . |
18,280 | protected function needsFiltering ( array $ inputs = null ) { $ inputsToFilter = $ inputs ? : $ this -> getInputsToFilter ( ) ; return ! ( is_array ( $ inputsToFilter ) && count ( $ inputsToFilter ) === 0 ) ; } | Do we have to filter at all? |
18,281 | public function upload ( $ filename , $ destination ) { if ( isset ( $ this [ $ filename ] ) ) { $ file = $ this [ $ filename ] ; if ( is_uploaded_file ( $ file [ static :: TMP_NAME ] ) ) { try { return move_uploaded_file ( $ file [ static :: TMP_NAME ] , $ destination ) ; } catch ( \ Exception $ e ) { var_dump ( $ e -> getMessage ( ) ) ; exit ( ) ; } } } return false ; } | Upload a file to the destination on the server |
18,282 | public function pregGet ( string $ pattern , $ match = 0 ) : string { preg_match ( $ pattern , ltrim ( $ this -> content , "\t" ) , $ matches ) ; return $ matches [ $ match ] ?? '' ; } | Matching a preg pattern and return the all or one of groups of matchment . |
18,283 | public function pregMap ( string $ pattern , callable $ callback ) : array { preg_match_all ( $ pattern , ltrim ( $ this -> content , "\t" ) , $ matches ) ; return array_map ( $ callback , ... $ matches ) ; } | Multiple matching a preg pattern and map result with a callback . |
18,284 | public function set ( array $ parameters ) { foreach ( $ parameters as $ parameter => $ value ) { $ this -> add ( $ parameter , $ value ) ; } return $ this ; } | Set all parameters at once |
18,285 | public function getReleases ( $ moduleName , $ coreVersion ) { $ request = $ this -> httpClient -> get ( [ '{module_name}/{core_version}' , [ 'module_name' => $ moduleName , 'core_version' => $ coreVersion ] ] ) ; if ( $ request -> getStatusCode ( ) != 200 ) { throw new \ Exception ( sprintf ( 'Status code was not OK. %d returned instead.' , $ request -> getStatusCode ( ) ) ) ; } $ response = ( string ) $ request -> getBody ( ) ; return $ this -> xmlToArray ( $ response ) ; } | Fetch releases according to given module and core version |
18,286 | public function createDb ( array $ aOptions = array ( ) ) { if ( isset ( $ aOptions [ 'a' ] ) ) { $ sSqlJsonFile = $ aOptions [ 'a' ] ; } else { $ sSqlJsonFile = false ; } if ( isset ( $ aOptions [ 'b' ] ) ) { $ sSqlJson = $ aOptions [ 'b' ] ; } else { $ sSqlJson = false ; $ sSqlJsonFile = str_replace ( 'Batch' , '' , __DIR__ ) . 'Db.conf' ; } if ( isset ( $ aOptions [ 'i' ] ) ) { $ oConstJson = json_decode ( file_get_contents ( $ aOptions [ 'i' ] ) ) ; } else { $ oConstJson = '../Const.conf' ; } if ( is_object ( $ oConstJson ) ) { foreach ( $ oConstJson as $ sKey => $ mValue ) { if ( is_string ( $ mValue ) || is_int ( $ mValue ) || is_float ( $ mValue ) ) { if ( ! defined ( strtoupper ( $ sKey ) ) ) { define ( strtoupper ( $ sKey ) , $ mValue ) ; } } } } if ( $ sSqlJsonFile !== false ) { $ oJson = json_decode ( file_get_contents ( $ sSqlJsonFile ) ) ; } else { $ oJson = json_decode ( $ sSqlJson ) ; } $ oConnection = $ oJson -> configuration ; $ oContainer = new DbContainer ; $ oContainer -> setHost ( $ oConnection -> host ) -> setName ( $ oConnection -> db ) -> setPassword ( $ oConnection -> password ) -> setType ( $ oConnection -> type ) -> setUser ( $ oConnection -> user ) ; $ oPdo = Db :: connect ( $ oContainer ) ; $ oPdo -> query ( "CREATE DATABASE " . $ oConnection -> db ) ; echo "\n\n" ; echo Bash :: setBackground ( " " , 'green' ) ; echo Bash :: setBackground ( " [OK] Success " , 'green' ) ; echo Bash :: setBackground ( " " , 'green' ) ; echo "\n\n" ; } | run the batch to create entity |
18,287 | public function one ( $ query ) { $ authSession = $ this -> repositoryDispatcher -> getCookieAuthSession ( ) ; $ url = null ; $ options = [ RequestOptions :: HEADERS => [ 'Cookie' => $ authSession -> getName ( ) . '=' . $ authSession -> getValue ( ) , ] , ] ; if ( is_scalar ( $ query ) ) { $ url = $ this -> endpoint . '/rest/api/2/issue/' . $ query ; } elseif ( is_array ( $ query ) && ( array_key_exists ( 'id' , $ query ) || array_key_exists ( 'key' , $ query ) ) ) { if ( isset ( $ query [ 'id' ] ) ) { $ url = $ this -> endpoint . '/rest/api/2/issue/' . $ query [ 'id' ] ; unset ( $ query [ 'id' ] ) ; } elseif ( isset ( $ query [ 'key' ] ) ) { $ url = $ this -> endpoint . '/rest/api/2/issue/' . $ query [ 'key' ] ; unset ( $ query [ 'key' ] ) ; } foreach ( $ query as $ param => $ value ) { if ( 'fields' === $ param ) { if ( is_array ( $ value ) ) { $ query [ $ param ] = implode ( ',' , $ value ) ; } } elseif ( 'expand' === $ param ) { if ( is_array ( $ value ) ) { $ query [ $ param ] = implode ( ',' , $ value ) ; } } else { unset ( $ query [ $ param ] ) ; } } $ options [ RequestOptions :: QUERY ] = $ query ; } else { throw new \ Exception ( 'Bad params' ) ; } $ response = $ this -> client -> request ( 'GET' , $ url , $ options ) ; $ body = $ response -> getBody ( ) ; $ body -> seek ( 0 ) ; $ contents = $ body -> getContents ( ) ; $ issue = $ this -> createInstance ( json_decode ( $ contents , true ) ) ; return $ issue ; } | Returns issue of Jira |
18,288 | public function all ( $ query ) { $ authSession = $ this -> repositoryDispatcher -> getCookieAuthSession ( ) ; $ response = $ this -> client -> request ( 'POST' , $ this -> endpoint . '/rest/api/2/search' , [ RequestOptions :: HEADERS => [ 'Cookie' => $ authSession -> getName ( ) . '=' . $ authSession -> getValue ( ) , ] , RequestOptions :: JSON => $ query , ] ) ; $ body = $ response -> getBody ( ) ; $ body -> seek ( 0 ) ; $ contents = $ body -> getContents ( ) ; $ decodedContents = json_decode ( $ contents , true ) ; $ issues = [ ] ; if ( isset ( $ decodedContents [ 'issues' ] ) && is_array ( $ decodedContents [ 'issues' ] ) ) { foreach ( $ decodedContents [ 'issues' ] as $ issue ) { $ issues [ ] = $ this -> createInstance ( $ issue ) ; } } return $ issues ; } | Returns issues of Jira |
18,289 | public function setPropertyValue ( $ property , $ value = NULL , $ objectId = NULL ) { $ property = strtolower ( $ property ) ; if ( ! array_key_exists ( $ property , $ this -> propertyModel ) ) return false ; if ( empty ( $ value ) ) : if ( isset ( $ this -> propertyModel [ $ property ] [ 3 ] ) ) $ value = $ this -> propertyModel [ $ property ] [ 3 ] ; endif ; if ( empty ( $ objectId ) || ( int ) $ objectId == $ this -> objectId ) : $ this -> propertyData [ $ property ] = $ value ; endif ; return $ this ; } | Sets the property Value before save |
18,290 | public function getPropertyValue ( $ propertyName , $ objectId = null ) { if ( in_array ( $ propertyName , array ( "objectId" , "objectType" , "objectURI" ) ) && isset ( $ this -> $ propertyName ) ) { return $ this -> $ propertyName ; } $ property = strtolower ( $ propertyName ) ; if ( ! array_key_exists ( $ property , $ this -> propertyModel ) ) return false ; if ( ( ! empty ( $ objectId ) && ( int ) $ objectId == $ this -> objectId ) || empty ( $ objectId ) ) { if ( ! isset ( $ this -> propertyData [ $ property ] ) ) { return ; } return $ this -> propertyData [ $ property ] ; } return ; } | Returns an entity property value by propery name if exists |
18,291 | public function getObjectsByPropertyValueBetween ( $ property , $ valueA , $ valueB , array $ select , $ objectType = NULL , $ objectURI = NULL , $ objectId = NULL ) { if ( empty ( $ property ) || empty ( $ valueA ) || empty ( $ valueB ) || empty ( $ select ) ) return false ; $ query = static :: getObjectQuery ( $ select , "?{$this->valueGroup}property_values" , $ objectId , $ objectType , $ objectURI ) ; $ query .= "\nGROUP BY o.object_id" ; $ query .= "\nHAVING {$property} BETWEEN {$valueA} AND {$valueB}" ; $ results = $ this -> database -> prepare ( $ query ) -> execute ( ) ; return $ results ; } | Return Object lists with matched properties between two values |
18,292 | public function getObjectsByPropertyValueMatch ( array $ properties , array $ values , array $ select = array ( ) , $ objectType = NULL , $ objectURI = NULL , $ objectId = NULL ) { if ( empty ( $ properties ) || empty ( $ values ) ) return false ; $ select = array_merge ( $ properties , $ select ) ; $ query = static :: getObjectQuery ( $ select , "?{$this->valueGroup}property_values" , $ objectId , $ objectType , $ objectType ) ; $ query .= "\nGROUP BY o.object_id" ; $ p = count ( $ properties ) ; $ v = count ( $ values ) ; if ( ! empty ( $ properties ) && ! empty ( $ values ) && $ p === $ v ) : $ query .= "\nHAVING\t" ; $ having = false ; for ( $ i = 0 ; $ i < $ p ; $ i ++ ) : $ query .= ( $ having ) ? "\tAND\t" : "" ; $ query .= "{$properties[$i]} = " . $ this -> database -> quote ( $ values [ $ i ] ) ; $ having = true ; endfor ; endif ; $ results = $ this -> database -> prepare ( $ query ) -> execute ( ) ; return $ results ; } | Return Object lists with properties matching the given value |
18,293 | final public function setListOrderBy ( $ fields , $ direction = "ASC" ) { $ direction = ( in_array ( strtoupper ( trim ( $ direction ) ) , array ( 'ASC' , 'DESC' ) , TRUE ) ) ? ' ' . $ direction : ' ASC' ; $ orderby = NULL ; if ( ! empty ( $ fields ) && ! is_array ( $ fields ) ) { $ temp = array ( ) ; foreach ( explode ( ',' , $ fields ) as $ part ) { $ part = trim ( $ part ) ; $ temp [ ] = $ part ; } $ orderby = implode ( ', ' , $ temp ) ; } else if ( is_array ( $ fields ) ) { $ temp = array ( ) ; foreach ( $ fields as $ field ) { $ part = trim ( $ field ) ; $ temp [ ] = $ part ; } $ orderby = implode ( ', ' , $ temp ) ; } if ( ! empty ( $ orderby ) ) { $ this -> listOrderByStatement = "\nORDER BY " . $ orderby . $ direction ; } return $ this ; } | Sets the list order direction |
18,294 | final public function setListLookUpConditions ( $ key , $ value = NULL , $ type = 'AND' , $ exact = FALSE , $ escape = TRUE , $ comparison = "LIKE" ) { if ( empty ( $ key ) ) { return $ this ; } if ( ! is_array ( $ key ) ) { if ( is_null ( $ value ) ) { return $ this ; } $ key = array ( $ key => $ value ) ; } $ dataModel = $ this -> getPropertyModel ( ) ; foreach ( $ key as $ k => $ v ) { if ( array_key_exists ( $ k , $ dataModel ) ) : $ this -> listLookUpConditionProperties [ ] = $ k ; endif ; $ prefix = ( count ( $ this -> listLookUpConditions ) == 0 AND count ( $ this -> listLookUpConditions ) == 0 ) ? '' : $ type . "\t" ; if ( $ escape === TRUE ) { $ v = $ this -> database -> escape ( $ v ) ; } if ( empty ( $ v ) ) { $ v = " IS NULL" ; } else { if ( is_array ( $ v ) ) : $ _values = array_map ( array ( $ this -> database , "quote" ) , $ v ) ; $ values = implode ( ',' , $ _values ) ; $ v = " IN ($values)" ; else : $ v = ( strtoupper ( $ comparison ) == "LIKE" ) ? " LIKE '%{$v}%'" : " {$comparison} '{$v}'" ; endif ; } if ( $ exact && is_array ( $ this -> listLookUpConditions ) && ! empty ( $ this -> listLookUpConditions ) ) : $ conditions = implode ( "\t" , $ this -> listLookUpConditions ) ; $ this -> listLookUpConditions = array ( ) ; $ this -> listLookUpConditions [ ] = "(" . $ conditions . ")" ; endif ; $ this -> listLookUpConditions [ ] = $ prefix . $ k . $ v ; } return $ this ; } | Sets lookup conditions for entity table search |
18,295 | public function getListLookUpConditionsClause ( ) { $ query = null ; if ( is_array ( $ this -> listLookUpConditions ) && ! empty ( $ this -> listLookUpConditions ) ) : $ query .= "\nHAVING\t" ; $ query .= implode ( "\t" , $ this -> listLookUpConditions ) ; endif ; return $ query ; } | Returns the list select clause additional conditions |
18,296 | final public function getObjectsList ( $ objectType , $ properties = array ( ) , $ objectURI = NULL , $ objectId = NULL ) { if ( empty ( $ properties ) ) : if ( ! empty ( $ this -> propertyModel ) ) $ properties = array_keys ( $ this -> propertyModel ) ; endif ; $ query = static :: getObjectQuery ( $ properties , "?{$this->valueGroup}property_values" , NULL , $ objectType , $ objectURI , $ objectId ) ; $ query .= "\nGROUP BY o.object_id" ; $ query .= $ this -> getListLookUpConditionsClause ( ) ; $ query .= $ this -> getListOrderByStatement ( ) ; $ query .= $ this -> getLimitClause ( ) ; $ total = $ this -> getObjectsListCount ( $ objectType , $ properties , $ objectURI , $ objectId ) ; $ results = $ this -> database -> prepare ( $ query ) -> execute ( ) ; $ this -> resetListLookUpConditions ( ) ; $ this -> setListTotal ( $ total ) ; return $ results ; } | Returns objects lists table with attributes list and values |
18,297 | final public function getObjectsListCount ( $ objectType , $ properties = array ( ) , $ objectURI = NULL , $ objectId = NULL ) { if ( empty ( $ properties ) ) : if ( ! empty ( $ this -> propertyModel ) ) $ properties = array_keys ( $ this -> propertyModel ) ; endif ; $ query = $ this -> getObjectCountQuery ( $ properties , "?{$this->valueGroup}property_values" , $ objectId , $ objectType , $ objectURI ) ; $ query .= "\nGROUP BY o.object_id" ; $ query .= $ this -> getListLookUpConditionsClause ( ) ; $ query .= $ this -> getListOrderByStatement ( ) ; $ cquery = "SELECT COUNT(total_objects) as count FROM ($query) AS total_entities" ; $ results = $ this -> database -> prepare ( $ cquery ) -> execute ( ) ; $ count = 0 ; while ( $ row = $ results -> fetchAssoc ( ) ) { $ count = $ row [ 'count' ] ; } return $ count ; } | Gets the object List Count |
18,298 | final private static function getObjectQuery ( $ properties , $ vtable = '?property_values' , $ objectId = NULL , $ objectType = NULL , $ objectURI = NULL ) { $ query = "SELECT o.object_id, o.object_uri, o.object_type, o.object_created_on, o.object_updated_on, o.object_status" ; if ( ! empty ( $ properties ) ) : $ i = 0 ; $ count = \ sizeof ( $ properties ) ; $ query .= "," ; foreach ( $ properties as $ alias => $ attribute ) : $ alias = ( is_int ( $ alias ) ) ? $ attribute : $ alias ; $ query .= "\nMAX(IF(p.property_name = '{$attribute}', v.value_data, null)) AS {$alias}" ; if ( $ i + 1 < $ count ) : $ query .= "," ; $ i ++ ; endif ; endforeach ; $ query .= "\nFROM {$vtable} v" . "\nLEFT JOIN ?properties p ON p.property_id = v.property_id" . "\nLEFT JOIN ?objects o ON o.object_id=v.object_id" ; else : $ query .= "\nFROM ?objects o" ; endif ; static :: $ withConditions = false ; if ( ! empty ( $ objectId ) || ! empty ( $ objectURI ) || ! empty ( $ objectType ) ) : $ query .= "\nWHERE" ; if ( ! empty ( $ objectType ) ) : $ query .= "\to.object_type='{$objectType}'" ; static :: $ withConditions = TRUE ; endif ; if ( ! empty ( $ objectURI ) ) : $ query .= ( static :: $ withConditions ) ? "\t AND" : "" ; $ query .= "\to.object_uri='{$objectURI}'" ; static :: $ withConditions = TRUE ; endif ; if ( ! empty ( $ objectId ) ) : $ query .= ( static :: $ withConditions ) ? "\t AND \t" : "" ; $ query .= "\to.object_id='{$objectId}'" ; static :: $ withConditions = TRUE ; endif ; endif ; return $ query ; } | Builds the original portion of the Object Query without conditions |
18,299 | final private function getObjectCountQuery ( $ properties , $ vtable = '?property_values' , $ objectId = NULL , $ objectType = NULL , $ objectURI = NULL ) { $ query = "SELECT DISTINCT o.object_id as total_objects" ; $ hasProperties = FALSE ; if ( ! empty ( $ properties ) ) : $ i = 0 ; $ count = \ sizeof ( $ properties ) ; foreach ( $ properties as $ alias => $ attribute ) : if ( in_array ( $ attribute , $ this -> listLookUpConditionProperties ) ) : if ( $ i + 1 < $ count ) : $ query .= "," ; $ i ++ ; endif ; $ alias = ( is_int ( $ alias ) ) ? $ attribute : $ alias ; $ query .= "\nMAX(IF(p.property_name = '{$attribute}', v.value_data, null)) AS {$alias}" ; $ hasProperties = TRUE ; endif ; endforeach ; $ query .= "\nFROM {$vtable} v" ; $ query .= ( $ hasProperties ) ? "\nLEFT JOIN ?properties p ON p.property_id = v.property_id" : NULL ; $ query .= "\nLEFT JOIN ?objects o ON o.object_id=v.object_id" ; else : $ query .= "\nFROM ?objects o" ; endif ; static :: $ withConditions = false ; if ( ! empty ( $ objectId ) || ! empty ( $ objectURI ) || ! empty ( $ objectType ) ) : $ query .= "\nWHERE" ; if ( ! empty ( $ objectType ) ) : $ query .= "\to.object_type='{$objectType}'" ; static :: $ withConditions = TRUE ; endif ; if ( ! empty ( $ objectURI ) ) : $ query .= ( static :: $ withConditions ) ? "\t AND" : "" ; $ query .= "\to.object_uri='{$objectURI}'" ; static :: $ withConditions = TRUE ; endif ; if ( ! empty ( $ objectId ) ) : $ query .= ( static :: $ withConditions ) ? "\t AND \t" : "" ; $ query .= "\to.object_id='{$objectId}'" ; static :: $ withConditions = TRUE ; endif ; endif ; return $ query ; } | Get the final count |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.