idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
29,500
public function addIndex ( $ columnName , $ type = Table :: INDEX_REGULAR ) { if ( ! array_key_exists ( $ columnName , $ this -> getIndexes ( ) ) && ! array_key_exists ( $ columnName , $ this -> newIndexes ) ) $ this -> newIndexes [ $ columnName ] = $ type ; return $ this ; }
Adds an index to a column
29,501
public function dropIndex ( $ columnName ) { if ( ! in_array ( $ columnName , $ this -> dropIndexes ) ) $ this -> dropIndexes [ ] = $ columnName ; if ( array_key_exists ( $ columnName , $ this -> getReferences ( ) ) ) $ this -> dropReference ( $ columnName ) ; return $ this ; }
Removes index from a column
29,502
public function dropColumn ( $ columnName ) { $ this -> dropColumns [ ] = $ columnName ; if ( array_key_exists ( $ columnName , $ this -> references ) ) { $ this -> dropReference ( $ columnName ) ; } return $ this ; }
Removes a column
29,503
public function addReference ( $ columnName , $ refTable , $ refColumn , $ onDelete = 'RESTRICT' , $ onUpdate = 'RESTRICT' ) { $ this -> addIndex ( $ columnName ) ; $ this -> newReferences [ $ columnName ] = array ( 'table' => $ refTable , 'column' => $ refColumn , 'onDelete' => $ onDelete , 'onUpdate' => $ onUpdate , ) ; return $ this ; }
Add reference to a column
29,504
public function alterReference ( $ columnName , $ refTable , $ refColumn , $ onDelete = 'RESTRICT' , $ onUpdate = 'RESTRICT' ) { $ this -> dropReference ( $ columnName ) ; $ this -> addReference ( $ columnName , $ refTable , $ refColumn , $ onDelete , $ onUpdate ) ; return $ this ; }
Alter references of the table column
29,505
private function fetchBackReferences ( ) { $ qry = "SELECT k.COLUMN_NAME as refColumn, k.TABLE_SCHEMA as refDB, k.TABLE_NAME as refTable, k.REFERENCED_COLUMN_NAME as columnName" . " FROM information_schema.KEY_COLUMN_USAGE k" . " WHERE k.TABLE_SCHEMA = '" . $ this -> connection -> getDBName ( ) . "' AND k.REFERENCED_TABLE_NAME = '" . $ this -> name . "'" ; $ backRef = $ this -> connection -> doPrepare ( $ qry ) ; if ( is_bool ( $ backRef ) ) return ; foreach ( $ backRef as & $ info ) { $ name = $ info [ 'columnName' ] ; unset ( $ info [ 'columnName' ] ) ; $ this -> backReferences [ $ name ] [ ] = $ info ; } }
Fetches the tables that reference this table and their columns
29,506
private function fetchReferences ( ) { $ qry = "SELECT i.CONSTRAINT_NAME as constraintName, i.CONSTRAINT_TYPE as constraintType, j.COLUMN_NAME as columnName, j.REFERENCED_TABLE_SCHEMA as refDB, j.REFERENCED_TABLE_NAME as refTable, j.REFERENCED_COLUMN_NAME as refColumn, k.UPDATE_RULE as onUpdate, k.DELETE_RULE as onDelete" . " FROM information_schema.TABLE_CONSTRAINTS i" . " LEFT JOIN information_schema.KEY_COLUMN_USAGE j ON i.CONSTRAINT_NAME = j.CONSTRAINT_NAME AND j.TABLE_SCHEMA = '" . $ this -> connection -> getDBName ( ) . "' AND j.TABLE_NAME = '" . $ this -> name . "'" . " LEFT JOIN information_schema.REFERENTIAL_CONSTRAINTS k ON i.CONSTRAINT_NAME = k.CONSTRAINT_NAME AND j.CONSTRAINT_SCHEMA = k.CONSTRAINT_SCHEMA AND k.TABLE_NAME = '" . $ this -> name . "'" . " WHERE i.TABLE_SCHEMA = '" . $ this -> connection -> getDBName ( ) . "' AND i.TABLE_NAME = '" . $ this -> name . "'" ; $ define = $ this -> connection -> doPrepare ( $ qry ) ; if ( is_bool ( $ define ) ) return ; foreach ( $ define as $ info ) { if ( isset ( $ info [ 'constraintType' ] ) && $ info [ 'constraintType' ] === 'PRIMARY KEY' ) { if ( isset ( $ info [ 'columnName' ] ) ) $ this -> primaryKey = $ info [ 'columnName' ] ; } else if ( $ info [ 'refTable' ] ) { if ( isset ( $ info [ 'constraintType' ] ) ) unset ( $ info [ 'constraintType' ] ) ; if ( isset ( $ info [ 'columnName' ] ) ) { $ name = $ info [ 'columnName' ] ; unset ( $ info [ 'columnName' ] ) ; } $ this -> references [ $ name ] = $ info ; } } }
Fetches all tables and columns that this table references
29,507
private function fetchColumns ( ) { $ qry = 'SELECT c.column_name as colName, c.column_default as colDefault, c.is_nullable as nullable, c.column_type as colType, c.extra, c.column_key as colKey, c.character_set_name as charset, c.collation_name as collation' ; $ qry .= ', d.index_name as indexName' ; $ qry .= ' FROM INFORMATION_SCHEMA.COLUMNS c ' . 'LEFT JOIN INFORMATION_SCHEMA.STATISTICS d' . ' ON c.column_name = d.column_name AND d.table_schema="' . $ this -> connection -> getDBName ( ) . '" AND d.table_name="' . $ this -> name . '" ' . 'WHERE c.table_schema="' . $ this -> connection -> getDBName ( ) . '" AND c.table_name="' . $ this -> name . '"' ; $ columns = $ this -> connection -> doPrepare ( $ qry ) ; if ( is_bool ( $ columns ) ) return ; foreach ( $ columns as $ column ) { $ this -> columns [ $ column [ 'colName' ] ] = $ column ; if ( in_array ( $ column [ 'colKey' ] , array ( 'MUL' , 'UNI' , 'PRI' , 'SPA' , 'FUL' ) ) ) { $ this -> indexes [ $ column [ 'colName' ] ] = $ column [ 'indexName' ] ; } } }
Fetches all columns of the table and their information
29,508
public function getTableRelationships ( $ table ) { $ table = $ this -> connection -> getTablePrefix ( ) . Util :: camelTo_ ( $ table ) ; $ relationships = array ( ) ; foreach ( $ this -> references as $ columnName => $ info ) { if ( $ info [ 'constraintName' ] == 'PRIMARY' || $ info [ 'refTable' ] != $ table ) continue ; $ this -> setupRelationship ( $ columnName , $ info [ 'refColumn' ] , $ info [ 'refTable' ] , $ relationships , false ) ; } foreach ( $ this -> backReferences as $ columnName => $ infoArray ) { foreach ( $ infoArray as $ info ) { if ( $ info [ 'refTable' ] != $ table ) continue ; $ this -> setupRelationship ( $ columnName , $ info [ 'refColumn' ] , $ info [ 'refTable' ] , $ relationships , true ) ; } } return $ relationships [ $ table ] ; }
Fetches the relationships between the columns in this table and the give table
29,509
public function targetColumns ( $ columns ) { $ this -> targetColumns = is_array ( $ columns ) ? $ columns : explode ( ',' , $ columns ) ; return $ this ; }
This targets the query at the given columns
29,510
public function selectColumns ( $ columns , array $ criteria = array ( ) , $ return = Table :: RETURN_MODEL ) { $ this -> targetColumns ( $ columns ) ; return $ this -> select ( $ criteria , $ return ) ; }
Selects the given columns from rows with the given criteria Many rows can be passed in as criteria
29,511
public function select ( array $ criteria = array ( ) , $ return = Table :: RETURN_MODEL ) { if ( ! $ this -> checkExists ( ) ) { return ( $ this -> delayExecute ) ? $ this : new ArrayCollection ( ) ; } $ this -> current = self :: OP_SELECT ; $ this -> query = 'SELECT ' . $ this -> prepareColumns ( ) ; $ this -> query .= ' FROM `' . $ this -> name . '`' . $ this -> processJoins ( ) ; $ this -> where ( $ criteria ) ; $ this -> setExpectedResult ( $ return , true ) ; if ( $ this -> delayExecute ) { return $ this ; } return $ this -> execute ( ) ; }
Selects rows from database Many rows can be passed in as criteria
29,512
private function getCached ( ) { if ( isset ( $ _GET [ 'noCache' ] ) ) return null ; $ cacheDir = DATA . 'select' . DIRECTORY_SEPARATOR ; if ( ! is_dir ( $ cacheDir ) ) mkdir ( $ cacheDir , 0777 , true ) ; $ cache = $ cacheDir . base64_encode ( $ this -> getName ( ) ) . '.php' ; if ( ! is_readable ( $ cache ) ) return null ; $ cached = include $ cache ; return $ this -> decode ( $ cached [ $ this -> encode ( $ this -> query . serialize ( $ this -> values ) ) ] ) ; }
Fetches the results from cache if available
29,513
private function saveCache ( $ result ) { if ( ! $ result ) return false ; $ cache = DATA . 'select' . DIRECTORY_SEPARATOR . $ this -> encode ( $ this -> getName ( ) ) . '.php' ; return Util :: updateConfig ( $ cache , array ( $ this -> encode ( $ this -> query . serialize ( $ this -> values ) ) => $ this -> encode ( serialize ( $ result ) ) ) ) ; }
Saves the given result if valid to cache for future uses
29,514
public function setExpectedResult ( $ expected = Table :: RETURN_MODEL , $ checkNotSet = false ) { if ( ! $ checkNotSet || ( $ checkNotSet && is_null ( $ this -> expected ) ) ) $ this -> expected = $ expected ; return $ this ; }
Sets the type of result expected
29,515
public function where ( array $ criteria , $ joinWithAnd = true , $ notEqual = false , $ valuesAreColumns = false ) { if ( count ( $ criteria ) ) { if ( ! $ this -> where ) { $ this -> where = ' WHERE (' ; $ opened = true ; } if ( substr ( $ this -> where , strlen ( $ this -> where ) - 1 ) != '(' ) { $ this -> where .= $ joinWithAnd ? ' AND ' : ' OR ' ; } foreach ( $ criteria as $ ky => $ row ) { if ( $ ky ) $ this -> where .= ' OR (' ; $ rowArray = $ this -> checkModel ( $ row ) ; $ cnt = 1 ; foreach ( $ rowArray as $ column => $ value ) { if ( ! is_array ( $ value ) ) { $ this -> where .= '`' . $ this -> name . '`.`' . Util :: camelTo_ ( $ column ) . '` ' ; $ this -> where .= ( $ notEqual ) ? '!=' : '=' ; if ( $ valuesAreColumns ) $ this -> where .= '`' . $ this -> name . '`.`' . Util :: camelTo_ ( $ value ) . '` ' ; else { $ this -> where .= ' ?' ; $ this -> values [ ] = $ value ; } if ( count ( $ rowArray ) > $ cnt ) $ this -> where .= ' AND ' ; } else { $ this -> where .= '`' . $ this -> name . '`.`' . Util :: camelTo_ ( $ column ) . '` ' ; $ this -> where .= ( $ notEqual ) ? 'NOT IN' : 'IN' ; $ this -> where .= ' (' ; if ( $ valuesAreColumns ) { $ n = 0 ; foreach ( $ value as $ val ) { if ( $ n ) $ this -> where .= ', ' ; $ this -> where .= '`' . $ this -> name . '`.`' . Util :: camelTo_ ( $ val ) . '`' ; $ n ++ ; } } else { $ this -> where .= '?' . str_repeat ( ',?' , count ( $ value ) - 1 ) ; $ this -> values = $ this -> values ? array_merge ( $ this -> values , $ value ) : $ value ; } $ this -> where .= ')' ; } $ cnt ++ ; } if ( $ opened ) $ this -> where .= ')' ; } } return $ this ; }
Create the where part of the query
29,516
public function notLike ( $ column , $ value , $ logicalAnd = true ) { $ this -> customWhere ( '`:TBL:`.`' . Util :: camelTo_ ( $ column ) . '` NOT LIKE "' . $ value . '"' , $ logicalAnd ? 'AND' : 'OR' ) ; return $ this ; }
Select a column where it is NOT LIKE the value i . e . it does not contain the given value
29,517
public function lessThan ( $ column , $ value , $ logicalAnd = true , $ valueIsColumn = false ) { $ value = $ valueIsColumn ? '`:TBL:`.`' . \ Util :: camelTo_ ( $ value ) . '`' : '"' . $ value . '"' ; $ this -> customWhere ( '`:TBL:`.`' . Util :: camelTo_ ( $ column ) . '` < ' . $ value , $ logicalAnd ? 'AND' : 'OR' ) ; return $ this ; }
Select a column where it is less than the given value
29,518
public function between ( $ column , $ value1 , $ value2 , $ logicalAnd = true ) { $ this -> customWhere ( '`:TBL:`.`' . Util :: camelTo_ ( $ column ) . '` BETWEEN "' . $ value1 . '" AND "' . $ value2 . '" ' , $ logicalAnd ? 'AND' : 'OR' ) ; }
Finds rows that matches the given range of values in the required column
29,519
public function equal ( array $ criteria , $ joinWithAnd = true , $ valuesAreColumns = false ) { $ this -> where ( $ criteria , $ joinWithAnd , false , $ valuesAreColumns ) ; return $ this ; }
Query the table where the given values are equal to the corresponding column value in the table
29,520
public function notEqual ( array $ criteria , $ joinWithAnd = true , $ valuesAreColumns = false ) { $ this -> where ( $ criteria , $ joinWithAnd , true , $ valuesAreColumns ) ; return $ this ; }
Query the table where the given values are not equal to the corresponding column value in the table
29,521
public function isNull ( $ column , $ logicalAnd = true ) { $ this -> customWhere ( '`:TBL:`.`' . Util :: camelTo_ ( $ column ) . '` IS NULL' , $ logicalAnd ? 'AND' : 'OR' ) ; return $ this ; }
Select a column where the value is null
29,522
public function isNotNull ( $ column , $ logicalAnd = true ) { $ this -> customWhere ( '`:TBL:`.`' . Util :: camelTo_ ( $ column ) . '` IS NOT NULL' , $ logicalAnd ? 'AND' : 'OR' ) ; return $ this ; }
Select a column where the value is not null
29,523
public function areNull ( array $ columns , $ logicalAnd = true ) { foreach ( $ columns as $ column ) { $ this -> isNull ( $ column , $ logicalAnd ) ; } return $ this ; }
Select a column where the values of the given columns are null
29,524
public function areNotNull ( array $ columns , $ logicalAnd = true ) { foreach ( $ columns as $ column ) { $ this -> isNotNull ( $ column , $ logicalAnd ) ; } return $ this ; }
Select a column where the values of the given columns are not null
29,525
public function startGroup ( $ logicalAnd = true ) { if ( $ this -> where ) $ this -> where .= ' ' . ( $ logicalAnd ? 'AND' : 'OR' ) . ' (' ; else $ this -> where = ' WHERE (' ; return $ this ; }
Start grouping criteria with a parenthesis
29,526
public function customWhere ( $ custom , $ logicalConnector = 'AND' , $ tablePlaceholder = ':TBL:' ) { if ( $ this -> where && substr ( $ this -> where , strlen ( $ this -> where ) - 1 ) != '(' ) $ this -> where .= ' ' . $ logicalConnector ; else if ( ! $ this -> where ) $ this -> where = ' WHERE ' ; $ this -> where .= trim ( str_replace ( $ tablePlaceholder , $ this -> name , $ custom ) ) ; return $ this ; }
Adds a custom query to the existing query . If no query exists it serves as the query .
29,527
public function having ( $ condition , $ tablePlaceholder = ':TBL:' ) { $ this -> having = trim ( str_replace ( $ tablePlaceholder , $ this -> name , $ condition ) ) ; return $ this ; }
Fetch rows that fulfill the given condition
29,528
public function in ( $ column , array $ values , $ logicalAnd = true , $ valuesAreColumns = false ) { $ this -> where ( array ( array ( $ column => $ values ) ) , $ logicalAnd , false , $ valuesAreColumns ) ; return $ this ; }
Fetch results whose data in the given column is in the given array of values
29,529
final public function seekJoin ( $ tableName , array $ columns , Row $ object = null , array $ options = array ( ) ) { if ( ! $ this -> joinQuery ) return false ; $ prefix = $ this -> connection -> getTablePrefix ( ) . $ tableName . '_' ; if ( ! $ object ) { $ object = new Row ( ) ; } $ array = array ( ) ; foreach ( $ this -> relationshipData as $ data ) { foreach ( $ columns as $ column => $ value ) { $ compare = $ prefix . $ column ; if ( $ data [ $ compare ] === null ) continue ; $ found = true ; if ( ( ! is_array ( $ value ) && @ $ data [ $ compare ] != $ value ) || ( is_array ( $ value ) && ! in_array ( @ $ data [ $ compare ] , $ value ) ) ) { $ found = false ; } if ( ! $ found ) break ; } if ( $ found ) { $ d = array ( ) ; foreach ( $ data as $ col => $ val ) { $ d [ str_replace ( $ prefix , '' , $ col ) ] = $ val ; } $ ob = clone $ object ; $ array [ ] = $ ob -> populate ( $ d ) ; } } $ this -> parseWithOptions ( $ array , $ options ) ; return count ( $ array ) ? new ArrayCollection ( $ array ) : false ; }
Checks the joined data for rows that have the value needed in a column
29,530
private function checkModel ( $ row , $ preSave = false ) { if ( ! is_array ( $ row ) && ! is_object ( $ row ) ) throw new Exception ( 'Each element of param $where must be an object of, or one that extends, "DBScribe\Row", or an array of [column => value]: ' . print_r ( $ row , true ) ) ; if ( empty ( $ this -> columns ) ) return array ( ) ; if ( is_array ( $ row ) ) { return $ row ; } elseif ( is_object ( $ row ) && get_class ( $ row ) === 'DBScribe\Row' || in_array ( 'DBScribe\Row' , class_parents ( $ row ) ) ) { if ( $ preSave ) $ row -> preSave ( ) ; $ this -> rowModelInUse = $ row ; return $ row -> toArray ( ( $ this -> current !== self :: OP_SELECT ) ) ; } }
Checks if the row is a valid \ DBScribe \ Row row
29,531
public function orderBy ( $ column , $ direction = Table :: ORDER_ASC ) { $ this -> orderBy [ ] = '`' . Util :: camelTo_ ( $ column ) . '` ' . $ direction ; return $ this ; }
Orders the returned rows
29,532
public function count ( $ column = '*' , $ criteria = array ( ) , $ return = Table :: RETURN_DEFAULT ) { $ this -> query = 'SELECT COUNT(' . Util :: camelTo_ ( $ column ) . ') as rows FROM `' . $ this -> name . '`' ; $ this -> where ( $ criteria ) ; $ this -> setExpectedResult ( $ return , true ) ; if ( $ ret = $ this -> execute ( ) ) { return ( $ ret ) ? $ ret [ 0 ] [ 'rows' ] : 0 ; } return 0 ; }
Counts the number of rows in the table based on a column
29,533
public function distinct ( $ column , array $ criteria = array ( ) , $ return = Table :: RETURN_MODEL ) { $ this -> current = self :: OP_SELECT ; $ this -> setExpectedResult ( $ return , true ) ; $ this -> targetColumns ( $ column ) ; $ this -> query = 'SELECT DISTINCT `' . $ this -> name . '`.`' . Util :: camelTo_ ( $ column ) . '` as ' . Util :: _toCamel ( $ column ) . ' FROM `' . $ this -> name . '` ' . $ this -> joinQuery ; $ this -> where ( $ criteria ) ; return $ this -> execute ( ) ; }
Gets the distinct values of a column
29,534
public function upsert ( array $ values , $ whereColumn = 'id' , $ generateIds = true ) { if ( ! is_array ( $ whereColumn ) ) $ whereColumn = array ( $ whereColumn ) ; if ( ! $ this -> checkExists ( ) ) return false ; $ this -> current = self :: OP_INSERT ; $ this -> query = 'INSERT INTO `' . $ this -> name . '` (' ; $ columns = array ( ) ; $ noOfColumns = 0 ; $ update = '' ; foreach ( array_values ( $ values ) as $ ky => $ row ) { $ rowArray = $ this -> checkModel ( $ row , true ) ; if ( $ ky === 0 ) $ noOfColumns = count ( $ rowArray ) ; if ( count ( $ rowArray ) === 0 ) throw new Exception ( 'You cannot insert an empty row into table "' . $ this -> name . '"' ) ; if ( $ generateIds ) { $ id = is_string ( $ generateIds ) ? $ generateIds : 'id' ; if ( ! array_key_exists ( $ id , $ rowArray ) ) $ rowArray [ $ id ] = Util :: createGUID ( ) ; } if ( $ generateIds ) { $ id = is_string ( $ generateIds ) ? $ generateIds : 'id' ; if ( ! array_key_exists ( $ id , $ rowArray ) ) $ rowArray [ $ id ] = Util :: createGUID ( ) ; } foreach ( $ rowArray as $ column => & $ value ) { if ( empty ( $ value ) && $ value != 0 ) continue ; $ column = Util :: camelTo_ ( $ column ) ; if ( ! $ ky && ! in_array ( $ column , $ whereColumn ) ) { if ( $ update ) $ update .= ', ' ; $ update .= '`' . $ column . '`=VALUES(' . $ column . ')' ; } if ( ! in_array ( $ column , $ columns ) ) $ columns [ ] = $ column ; $ this -> values [ $ ky ] [ ':' . $ column ] = $ value ; } } $ this -> query .= '`' . join ( '`, `' , $ columns ) . '`' ; $ this -> query .= ') VALUES (' ; $ this -> query .= ':' . join ( ', :' , $ columns ) ; $ this -> query .= ') ON DUPLICATE KEY UPDATE ' ; $ this -> query .= $ update ; $ this -> multiple = true ; $ this -> doPost = self :: OP_INSERT ; if ( $ this -> delayExecute ) { return $ this ; } return $ this -> execute ( ) ; }
Updates rows that exist and creates those that don t
29,535
public function execute ( ) { if ( ! $ this -> checkExists ( ) ) { if ( $ this -> current === self :: OP_SELECT ) { return new ArrayCollection ( ) ; } return false ; } $ this -> createQuery ( ) ; $ model = ( $ this -> expected ) ? $ this -> getRowModel ( ) : null ; if ( $ this -> current === self :: OP_SELECT && $ this -> isCached ( ) ) { $ result = $ this -> getCached ( ) ; } if ( ! $ result ) { if ( $ this -> preserveQueries && $ this -> current !== self :: OP_SELECT ) $ this -> doPreserveQueries ( ) ; $ result = $ this -> connection -> doPrepare ( $ this -> query , $ this -> values , array ( 'multipleRows' => $ this -> multiple , 'model' => $ model ) ) ; if ( $ this -> current === self :: OP_SELECT ) $ this -> saveCache ( $ result ) ; else $ this -> removeCache ( ) ; } if ( $ this -> current === self :: OP_SELECT ) $ result = $ this -> returnSelect ( $ result ) ; $ this -> lastQuery = $ this -> query . '<pre><code>' . print_r ( $ this -> values , true ) . '</code></pre>' ; $ this -> resetQuery ( ) ; return $ result ; }
Executes the delayed database operation
29,536
public function getQuery ( $ withValues = false ) { return $ withValues ? $ this -> createQuery ( ) . '<pre><code>' . print_r ( $ this -> getQueryValues ( ) , true ) . '</code></pre>' : $ this -> createQuery ( ) ; }
Fetches the query to execute
29,537
public function index ( $ teamId ) { $ team = Team :: findOrFail ( $ teamId ) ; $ this -> authorize ( 'view' , $ team ) ; return $ this -> respondRelatedAddresses ( $ teamId , 'address' ) ; }
Produce a list of Addresss related to a selected Team
29,538
public function lookup ( $ string , $ uuid = null , $ arguments = null ) { $ id = md5 ( $ string ) ; $ string = ( isset ( self :: $ translationTables [ $ uuid ] [ $ id ] ) ) ? self :: $ translationTables [ $ uuid ] [ $ id ] : $ string ; if ( $ arguments !== null ) { $ string = vsprintf ( $ string , $ arguments ) ; } return $ string ; }
Looks for the passed looks up the translation of the given combination of values .
29,539
protected function buildTranslationtable ( $ locale , array $ namespaces ) { $ result = [ ] ; $ fresh = false ; if ( ! isset ( self :: $ translations [ $ locale ] ) ) { self :: $ translations [ $ locale ] = [ ] ; $ fresh = true ; } foreach ( $ namespaces as $ namespace ) { if ( ! $ fresh && isset ( self :: $ translations [ $ locale ] [ $ namespace ] ) ) { $ result = array_merge ( $ result , self :: $ translations [ $ locale ] [ $ namespace ] ) ; } else { $ translationFile = $ this -> path . $ locale . DIRECTORY_SEPARATOR . self :: TRANSLATION_FILES_DIRECTORY . DIRECTORY_SEPARATOR . $ this -> normalizeLocale ( $ locale ) . DIRECTORY_SEPARATOR . 'LC_MESSAGES' . DIRECTORY_SEPARATOR . $ namespace . '.' . self :: TRANSLATION_FILES_EXTENSION ; $ result = array_merge ( $ result , $ this -> parseTranslationfile ( $ translationFile ) ) ; } } return $ result ; }
builds a translation - tables for giving locale and namespace .
29,540
public function p ( $ name ) { $ msg = $ this -> raw ( $ name ) ; if ( ! $ msg ) { return '' ; } return sprintf ( $ this -> format , $ msg ) ; }
prints out error message in a format .
29,541
public function duplicateAction ( ) { $ id = $ this -> getRequest ( ) -> get ( $ this -> admin -> getIdParameter ( ) ) ; $ object = $ this -> admin -> getObject ( $ id ) ; $ new = clone $ object ; $ this -> duplicateFiles ( $ object , $ new ) ; $ preResponse = $ this -> preDuplicate ( $ new ) ; if ( $ preResponse !== null ) { return $ preResponse ; } return $ this -> createAction ( $ new ) ; }
Duplicate action .
29,542
protected function handleFiles ( $ object ) { $ request = $ this -> getRequest ( ) ; $ rc = new \ ReflectionClass ( $ object ) ; $ className = $ rc -> getShortName ( ) ; $ repo = $ this -> manager -> getRepository ( 'LibrinfoMediaBundle:File' ) ; if ( $ remove = $ request -> get ( 'remove_files' ) ) { foreach ( $ remove as $ key => $ id ) { $ file = $ repo -> find ( $ id ) ; if ( $ file ) { if ( method_exists ( $ object , 'removeLibrinfoFile' ) ) { $ object -> removeLibrinfoFile ( $ file ) ; $ this -> manager -> remove ( $ file ) ; } elseif ( method_exists ( $ object , 'setLibrinfoFile' ) ) { $ object -> setLibrinfoFile ( ) ; $ this -> manager -> remove ( $ file ) ; } else { throw new \ Exception ( 'You must define ' . $ className . '::removeLibrinfoFile() method or ' . $ className . '::setFile() in case of a one to one' ) ; } } } } if ( $ ids = $ request -> get ( 'add_files' ) ) { foreach ( $ ids as $ key => $ id ) { $ file = $ repo -> find ( $ id ) ; if ( $ file ) { if ( method_exists ( $ object , 'addLibrinfoFile' ) ) { $ object -> addLibrinfoFile ( $ file ) ; $ file -> setOwned ( true ) ; } elseif ( method_exists ( $ object , 'setLibrinfoFile' ) ) { $ object -> setLibrinfoFile ( $ file ) ; $ file -> setOwned ( true ) ; } else { throw new \ Exception ( 'You must define ' . $ className . '::addLibrinfoFile() method or ' . $ className . '::setLibrinfoFile() in case of a one to one' ) ; } } } } }
Binds the uploaded file to its owner on creation .
29,543
protected function isRegexpLiteral ( ) { if ( strpos ( "\n{;(,=:[!&|?" , $ this -> a ) !== false ) { return true ; } if ( $ this -> a === ' ' ) { $ length = strlen ( $ this -> output ) ; if ( $ length < 2 ) { return true ; } if ( preg_match ( '/(?:case|else|in|return|typeof)$/' , $ this -> output , $ m ) ) { if ( $ this -> output === $ m [ 0 ] ) { return true ; } $ charBeforeKeyword = substr ( $ this -> output , $ length - strlen ( $ m [ 0 ] ) - 1 , 1 ) ; if ( ! $ this -> isAlphaNum ( $ charBeforeKeyword ) ) { return true ; } } } return false ; }
Utility conditional check .
29,544
protected function get ( ) { $ c = $ this -> lookAhead ; $ this -> lookAhead = null ; if ( $ c === null ) { if ( $ this -> inputIndex < $ this -> inputLength ) { $ c = $ this -> input [ $ this -> inputIndex ] ; $ this -> inputIndex += 1 ; } else { return ; } } if ( $ c === "\r" || $ c === "\n" ) { return "\n" ; } if ( ord ( $ c ) < self :: ORD_SPACE ) { return ' ' ; } return $ c ; }
Get next character .
29,545
protected function singleLineComment ( ) { $ comment = '' ; while ( true ) { $ get = $ this -> get ( ) ; $ comment .= $ get ; if ( ord ( $ get ) <= self :: ORD_LF ) { if ( preg_match ( '/^\\/@(?:cc_on|if|elif|else|end)\\b/' , $ comment ) ) { return '/' . $ comment ; } return $ get ; } } return ; }
Single - line comment handler .
29,546
protected function multipleLineComment ( ) { $ this -> get ( ) ; $ comment = '' ; while ( true ) { $ get = $ this -> get ( ) ; if ( $ get === '*' ) { if ( $ this -> peek ( ) === '/' ) { $ this -> get ( ) ; if ( strpos ( $ comment , '!' ) === 0 ) { return "\n/*!" . substr ( $ comment , 1 ) . "*/\n" ; } if ( preg_match ( '/^@(?:cc_on|if|elif|else|end)\\b/' , $ comment ) ) { return '/*' . $ comment . '*/' ; } return ' ' ; } } elseif ( $ get === null ) { throw new \ Exception ( 'Unterminated comment at byte: ' . $ this -> inputIndex . ': /*' . $ comment ) ; } $ comment .= $ get ; } return ; }
Multi - line comment handler .
29,547
public static function fromCode ( $ code ) { $ calculateCodeHashRefl = new \ ReflectionMethod ( BaseTokens :: class , 'calculateCodeHash' ) ; $ calculateCodeHashRefl -> setAccessible ( true ) ; $ hasCacheRefl = new \ ReflectionMethod ( BaseTokens :: class , 'hasCache' ) ; $ hasCacheRefl -> setAccessible ( true ) ; $ getCacheRefl = new \ ReflectionMethod ( BaseTokens :: class , 'getCache' ) ; $ getCacheRefl -> setAccessible ( true ) ; $ codeHash = $ calculateCodeHashRefl -> invoke ( null , $ code ) ; if ( $ hasCacheRefl -> invoke ( null , $ codeHash ) ) { $ tokens = $ getCacheRefl -> invoke ( null , $ codeHash ) ; $ tokens -> generateCode ( ) ; if ( $ codeHash === $ tokens -> getCodeHash ( ) ) { $ tokens -> clearEmptyTokens ( ) ; $ tokens -> clearChanged ( ) ; return $ tokens ; } } $ tokens = new static ( ) ; $ tokens -> setCode ( $ code ) ; $ tokens -> clearChanged ( ) ; return $ tokens ; }
Create token collection directly from code .
29,548
static public function attributes ( $ attributes ) { $ compiled = '' ; foreach ( $ attributes as $ key => $ value ) { if ( $ value === NULL ) { continue ; } if ( is_numeric ( $ key ) ) { $ key = $ value ; } $ compiled .= ' ' . $ key . '="' . htmlspecialchars ( ( string ) $ value , ENT_QUOTES , self :: $ charset , true ) . '"' ; } return $ compiled ; }
create html attributes
29,549
public static function style ( $ file , array $ attributes = NULL , $ protocol = NULL , $ index = FALSE ) { if ( strpos ( $ file , '://' ) === FALSE ) { $ file = Ioc :: url ( $ file ) ; } $ attributes [ 'href' ] = $ file ; $ attributes [ 'rel' ] = 'stylesheet' ; $ attributes [ 'type' ] = 'text/css' ; return '<link' . self :: attributes ( $ attributes ) . ' />' ; }
html style link
29,550
public function setParams ( $ params ) { foreach ( $ params as $ name => $ value ) { $ this -> setParam ( $ name , $ value ) ; } return $ this ; }
Set multiple params
29,551
public function first ( ) { $ oldLimit = $ this -> limit ; $ this -> limit = 1 ; $ rows = $ this -> get ( ) ; $ this -> limit = $ oldLimit ; return isset ( $ rows [ 0 ] ) ? $ rows [ 0 ] : null ; }
Returns a single row as assoc array
29,552
public function next ( ) { if ( $ this -> limit && $ this -> currentPos >= $ this -> limit ) { return null ; } $ oldLimit = $ this -> limit ; $ oldOffset = $ this -> offset ; $ this -> limit = 1 ; $ this -> offset += $ this -> currentPos ; $ rows = $ this -> get ( ) ; $ this -> limit = $ oldLimit ; $ this -> offset = $ oldOffset ; $ this -> currentPos ++ ; return isset ( $ rows [ 0 ] ) ? $ rows [ 0 ] : null ; }
Return results one by one . If a limit is set it won t go further than the selected limit . Also it will start from the selected offset if one is set .
29,553
public function get ( ) { $ q = "SELECT " . $ this -> fields . " FROM `" . $ this -> table . "` " . $ this -> join ; if ( $ this -> condition ) { $ q .= " WHERE {$this->condition}" ; } if ( $ this -> group ) { $ q .= " GROUP BY {$this->group}" ; if ( $ this -> having ) { $ q .= " HAVING {$this->having}" ; } } if ( $ this -> order ) { $ q .= " ORDER BY {$this->order}" ; } if ( $ this -> limit ) { $ q .= " LIMIT {$this->limit}" ; } if ( $ this -> offset ) { $ q .= " OFFSET {$this->offset}" ; } if ( $ this -> procedure ) { $ q .= " PROCEDURE {$this->procedure}" ; } if ( $ this -> into ) { $ q .= " INTO {$this->into}" ; } if ( $ this -> for_update ) { $ q .= " FOR UPDATE" ; } if ( $ this -> lock_in_share_mode ) { $ q .= " LOCK IN SHARE MODE" ; } return $ this -> connection -> queryAssoc ( $ q , $ this -> params ) ; }
Creates select query executes it and returns the result as assoc array .
29,554
public function count ( ) { $ oldFields = $ this -> fields ; $ this -> fields = 'COUNT(*) as number' ; $ number = $ this -> get ( ) ; $ number = $ number [ 0 ] [ 'number' ] ; $ this -> fields = $ oldFields ; return $ number ; }
Return number of rows for current options .
29,555
public function increment ( $ column , $ value ) { $ this -> params [ ':column' ] = $ value ; $ query = "UPDATE `{$this->table}` {$this->join} SET `$column` = `$column` + :$column" ; if ( $ this -> condition ) { $ query .= " WHERE {$this->condition}" ; } if ( $ this -> limit ) { $ query .= " LIMIT {$this->limit}" ; } return $ this -> connection -> execQuery ( $ query , $ this -> params ) ; }
Updates a single column and increments it with selected value . Returns number of affected rows .
29,556
public function insert ( $ columns , $ duplicateKey = null , $ params = [ ] ) { if ( is_string ( $ duplicateKey ) && 'ignore' == strtolower ( $ duplicateKey ) ) { $ q = "INSERT IGNORE INTO {$this->table} " ; } else { $ q = "INSERT INTO {$this->table} " ; } $ cols = array ( ) ; $ vals = array ( ) ; $ this -> params = $ params ; foreach ( $ columns as $ name => $ value ) { $ cols [ ] = '`' . $ name . '`' ; $ vals [ ] = ":$name" ; $ this -> params [ ":$name" ] = $ value ; } $ q .= "(" . implode ( ", " , $ cols ) . ") VALUES (" . implode ( ", " , $ vals ) . ")" ; if ( is_array ( $ duplicateKey ) && count ( $ duplicateKey ) ) { $ q .= " ON DUPLICATE KEY UPDATE " ; $ updates = [ ] ; foreach ( $ duplicateKey as $ column => $ value ) { $ updates [ ] = "`$column` = :dp_{$column}" ; $ this -> params [ ':dp_' . $ column ] = $ value ; } $ q .= implode ( ", " , $ updates ) ; } elseif ( $ duplicateKey && is_string ( $ duplicateKey ) && ( 'ignore' != strtolower ( $ duplicateKey ) ) ) { $ q .= " ON DUPLICATE KEY UPDATE " . $ duplicateKey ; } if ( $ this -> connection -> execQuery ( $ q , $ this -> params ) ) { return $ this -> connection -> lastInsertId ( ) ? $ this -> connection -> lastInsertId ( ) : true ; } else { return false ; } }
Inserts a new row and returns the id or false if failed .
29,557
public function update ( $ columns ) { $ update = array ( ) ; foreach ( $ columns as $ k => $ v ) { $ update [ ] = "`$k` = :$k" ; $ this -> params [ ":$k" ] = $ v ; } $ update = implode ( ", " , $ update ) ; $ q = "UPDATE {$this->table} as `t` {$this->join} SET $update WHERE {$this->condition}" ; if ( $ this -> limit ) { $ q .= " LIMIT {$this->limit}" ; } return $ this -> connection -> execQuery ( $ q , $ this -> params ) ; }
Update selected columns and return the number of affected rows .
29,558
public function delete ( ) { $ query = "DELETE FROM `{$this->table}` {$this->join}" ; if ( $ this -> condition ) { $ query .= " WHERE {$this->condition}" ; } if ( $ this -> limit ) { $ query .= " LIMIT {$this->limit}" ; } return $ this -> connection -> execQuery ( $ query , $ this -> params ) ; }
Deletes rows that match condition . It will return number of affected rows .
29,559
protected function _getValueTypeError ( $ value , $ type ) { if ( ! ( $ type instanceof ReflectionType ) ) { throw $ this -> _createInvalidArgumentException ( $ this -> __ ( 'Type criterion is invalid' ) , null , null , $ type ) ; } $ typeName = method_exists ( $ type , 'getName' ) ? $ type -> getName ( ) : $ type -> __toString ( ) ; $ isOfType = null ; if ( $ type -> isBuiltin ( ) ) { $ testFunc = sprintf ( 'is_%1$s' , $ typeName ) ; $ isOfType = call_user_func_array ( $ testFunc , [ $ value ] ) ; } else { $ isOfType = $ value instanceof $ typeName ; } if ( ! $ isOfType ) { return $ this -> __ ( 'Value must be of type "%1$s"' , [ $ typeName ] ) ; } return ; }
Generates a list of reasons for a value failing validation against a type spec .
29,560
public function generateNext ( BillingAgreementInterface $ billingAgreement ) { $ billingPeriodStart = null ; $ billingPeriodEnd = null ; $ billingRequest = null ; $ nextBillingPeriod = $ this -> getNextBillingPeriod ( $ billingAgreement ) ; if ( null !== $ nextBillingPeriod ) { list ( $ billingPeriodStart , $ billingPeriodEnd ) = $ nextBillingPeriod ; $ billingRequest = $ this -> billingManager -> generateBillingRequest ( $ billingAgreement ) ; $ billingRequest -> setPeriodStart ( $ billingPeriodStart ) ; $ billingRequest -> setPeriodEnd ( $ billingPeriodEnd ) ; if ( $ this -> config [ 'billing_request_payment_phase' ] == 'end' ) { $ plannedBillingDate = $ billingPeriodEnd -> add ( new \ DateInterval ( 'P1D' ) ) ; } else if ( $ this -> config [ 'billing_request_payment_phase' ] == 'start' ) { $ plannedBillingDate = $ billingPeriodStart ; } else { throw new \ Exception ( 'billing_request_payment_phase option "' . $ this -> config [ 'billing_request_payment_phase' ] . '" is unknown' ) ; } $ billingRequest -> setPlannedBillingDate ( $ plannedBillingDate ) ; $ billingAgreement -> setBilledToDate ( $ billingPeriodEnd ) ; } return $ billingRequest ; }
Generate the next billing request for provided billing agreement
29,561
public function getNumberProspectsPerDay ( $ maxDays = 30 ) { $ select = $ this -> tableGateway -> getSql ( ) -> select ( ) ; $ select -> columns ( array ( new \ Zend \ Db \ Sql \ Expression ( 'COUNT("pros_id") AS nb' ) , "pros_contact_date" ) ) ; $ select -> group ( "pros_contact_date" ) ; $ select -> limit ( $ maxDays ) ; $ resultSet = $ this -> tableGateway -> selectWith ( $ select ) ; return $ resultSet ; }
Gets the number of prospect per day
29,562
public function fromEmail ( Email $ emailEntity ) { $ message = ( new \ Swift_Message ( ) ) -> setSubject ( $ emailEntity -> getSubject ( ) ) -> setTo ( [ $ emailEntity -> getTargetMail ( ) ] ) -> setFrom ( $ emailEntity -> getFrom ( ) ) -> setBody ( $ emailEntity -> getBodyHtml ( ) , 'text/html' ) -> addPart ( $ emailEntity -> getBodyText ( ) , 'text/plain' ) ; foreach ( $ emailEntity -> getAttachments ( ) as $ name => $ attachment ) { $ message -> attach ( AttachmentManager :: buildSwift ( $ attachment , $ name ) ) ; } return $ message ; }
Transforms an Email entity to a Swift_Message .
29,563
public static function count ( $ request , $ match ) { $ userId = $ request -> user ? $ request -> user -> id : 0 ; $ sql = new Pluf_SQL ( 'account_id=%s' , array ( $ userId ) ) ; $ message = new User_Message ( ) ; $ res = $ message -> getList ( array ( 'count' => true , 'filter' => $ sql -> gen ( ) ) ) ; return $ res [ 0 ] [ 'nb_items' ] ; }
Retruns messages count
29,564
private function & getCollection ( ) { if ( null === $ this -> collection ) { $ qb = $ this -> createAndFilterQueryBuilder ( $ this -> getEntityAlias ( ) ) ; if ( $ this -> isHydrationDisabled ( ) ) { $ this -> collection = $ qb -> getQuery ( ) -> getScalarResult ( ) ; } else { $ this -> collection = $ qb -> getQuery ( ) -> getResult ( ) ; } } return $ this -> collection ; }
Load data if not already and return it . Important to call by reference to avoid array copies
29,565
public function paginate ( $ page = 1 , $ itemsPerPage = 20 ) { $ query = $ this -> createAndFilterQueryBuilder ( $ this -> getEntityAlias ( ) ) ; $ query -> setFirstResult ( ( $ page - 1 ) * $ itemsPerPage ) ; $ query -> setMaxResults ( $ itemsPerPage ) ; return new Paginator ( $ query ) ; }
Paginate results in current filter scope
29,566
protected function getEntityAlias ( ) { $ entityName = $ this -> getRepository ( ) -> getClassName ( ) ; if ( false !== strpos ( $ entityName , '\\' ) ) { $ entityName = substr ( $ entityName , strrpos ( $ entityName , '\\' ) + 1 ) ; } $ matches = array ( ) ; preg_match_all ( '/[A-Z]/' , $ entityName , $ matches ) ; return strtolower ( implode ( '' , $ matches [ 0 ] ) ) ; }
Returns all uppercase letters of the entity name without the namespace lowercased
29,567
public function findPublishedTreeForMenu ( $ slug ) { $ builder = $ this -> createQueryBuilder ( 'm' ) -> where ( 'm.slug = :slug' ) -> setParameter ( 'slug' , $ slug ) -> andWhere ( 'm.lvl = 0' ) ; $ menu = $ builder -> andWhere ( $ builder -> expr ( ) -> andX ( $ builder -> expr ( ) -> isNotNull ( 'm.startedAt' ) , $ builder -> expr ( ) -> lte ( 'm.startedAt' , ':now' ) , $ builder -> expr ( ) -> orX ( $ builder -> expr ( ) -> isNull ( 'm.endedAt' ) , $ builder -> expr ( ) -> gte ( 'm.endedAt' , ':now' ) ) ) ) -> setParameter ( 'now' , new \ DateTime ( ) ) -> getQuery ( ) -> setMaxResults ( 1 ) -> getOneOrNullResult ( ) ; if ( $ menu ) { return ; } $ builder = $ this -> createQueryBuilder ( 'm' ) -> where ( 'm.root = :root' ) -> setParameter ( 'root' , $ menu -> getId ( ) ) -> leftJoin ( 'm.article' , 'a' ) -> addSelect ( 'a' ) -> orderBy ( 'm.lft' , 'ASC' ) ; $ builder -> andWhere ( $ builder -> expr ( ) -> andX ( $ builder -> expr ( ) -> isNotNull ( 'm.startedAt' ) , $ builder -> expr ( ) -> lte ( 'm.startedAt' , ':now' ) , $ builder -> expr ( ) -> orX ( $ builder -> expr ( ) -> isNull ( 'm.endedAt' ) , $ builder -> expr ( ) -> gte ( 'm.endedAt' , ':now' ) ) ) ) -> setParameter ( 'now' , new \ DateTime ( ) ) ; return $ this -> buildTree ( $ builder -> getQuery ( ) -> getArrayResult ( ) ) ; }
Find a published Menu by its slug
29,568
public function setName ( $ name ) { $ this -> name = $ name ; $ arg = pathinfo ( $ name , PATHINFO_EXTENSION ) ; if ( ! empty ( $ arg ) ) { $ this -> extension = $ arg ; } return $ this ; }
SET REAL NAME
29,569
public function touch ( $ modifyTime = null , $ accessTime = null ) { return touch ( $ this -> fullName , $ modifyTime , $ accessTime ) ; }
UPDATE FILE MODIFY TIME AND ACCESS TIME IF NOT EXIST WILL CREATE
29,570
public function write ( $ data , $ lock = false ) { if ( ! is_string ( $ data ) && ! is_integer ( $ data ) ) { $ data = var_export ( $ data , true ) ; } if ( is_bool ( $ lock ) ) { $ lock = $ lock ? LOCK_EX : 0 ; } return file_put_contents ( $ this -> fullName , $ data , $ lock ) ; }
PUT FILE CONTENT
29,571
public function getDashboardStats ( ) { $ limit = 10 ; $ success = 1 ; $ values = array ( ) ; if ( $ this -> getController ( ) -> getRequest ( ) -> isPost ( ) ) { $ chartFor = get_object_vars ( $ this -> getController ( ) -> getRequest ( ) -> getPost ( ) ) ; $ chartFor = isset ( $ chartFor [ 'chartFor' ] ) ? $ chartFor [ 'chartFor' ] : 'monthly' ; $ melisProspectsService = $ this -> getServiceLocator ( ) -> get ( 'MelisProspectsService' ) ; $ curdate = date ( 'Y-m-d' ) ; for ( $ ctr = $ limit ; $ ctr > 0 ; $ ctr -- ) { $ nb = $ melisProspectsService -> getProspectsDataByDate ( $ chartFor , $ curdate ) ; switch ( $ chartFor ) { case 'daily' : $ values [ ] = array ( $ curdate , $ nb ) ; $ curdate = date ( 'Y-m-d' , strtotime ( $ curdate . ' -1 days' ) ) ; break ; case 'monthly' : $ values [ ] = array ( $ curdate , $ nb ) ; $ curdate = date ( 'Y-m-d' , strtotime ( $ curdate . ' -1 months' ) ) ; break ; case 'yearly' : $ values [ ] = array ( $ curdate , $ nb ) ; $ curdate = date ( 'Y-m-d' , strtotime ( $ curdate . ' -1 years' ) ) ; break ; default : break ; } } } return new JsonModel ( array ( 'date' => date ( 'Y-m-d' ) , 'success' => $ success , 'values' => $ values , ) ) ; }
Returns JSon datas for the graphs on the dashboard
29,572
public function getTheme ( $ name ) { $ key = $ this -> normalizeKey ( $ name ) ; return ( array_key_exists ( $ key , $ this -> themes ) ) ? $ this -> themes [ $ key ] : null ; }
Returns the template from its name
29,573
static function ToHtml ( $ string , HtmlQuoteMode $ mode = null ) { self :: InitEncoding ( ) ; if ( ! $ mode ) $ mode = HtmlQuoteMode :: DoubleQuotes ( ) ; return htmlspecialchars ( $ string , $ mode -> Flag ( ) , self :: GetEncoding ( ) -> Code ( ) ) ; }
Escapes special chars .
29,574
static function ToJavascript ( $ string , $ htmlEncode = true ) { if ( $ htmlEncode ) { $ string = self :: ToHtml ( $ string ) ; } return '\'' . addcslashes ( $ string , "'\r\n\\" ) . '\'' ; }
Creates a single quoted string that can be put into javascript variables .
29,575
static function Part ( $ string , $ start , $ length = null ) { self :: InitEncoding ( ) ; if ( $ length !== null ) return mb_substr ( $ string , $ start , $ length ) ; return mb_substr ( $ string , $ start ) ; }
Returns length of string .
29,576
static function End ( $ string , $ length = 0 ) { self :: InitEncoding ( ) ; $ pos = max ( 0 , self :: Length ( $ string ) - $ length ) ; return self :: Part ( $ string , $ pos ) ; }
Gets the end part of the string with the given length
29,577
static function StartsWith ( $ needle , $ haystack , $ ignoreCase = false ) { self :: InitEncoding ( ) ; $ start = self :: Start ( $ haystack , self :: Length ( $ needle ) ) ; return self :: Compare ( $ start , $ needle , $ ignoreCase ) ; }
Checks if haystack starts with needle
29,578
static function Trim ( $ string , $ chars = null ) { self :: InitEncoding ( ) ; if ( ! $ chars ) return trim ( $ string ) ; return trim ( $ string , $ chars ) ; }
Trims leading and trailing chars .
29,579
static function TrimRight ( $ string , $ chars = null ) { self :: InitEncoding ( ) ; if ( ! $ chars ) return rtrim ( $ chars ) ; return rtrim ( $ string , $ chars ) ; }
Trims trailing chars .
29,580
static function TrimLeft ( $ string , $ chars = null ) { self :: InitEncoding ( ) ; if ( ! $ chars ) return ltrim ( $ chars ) ; return ltrim ( $ string , $ chars ) ; }
Trims leading chars .
29,581
private static function AddSpecialCharsToMap ( $ specialChars , $ mapped ) { $ reader = new StringReader ( $ specialChars ) ; while ( $ ch = $ reader -> ReadChar ( ) ) { self :: $ specialWesternCharMap [ $ ch ] = $ mapped ; } }
Maps all special chars to the given string
29,582
private function getParser ( ) { if ( null === $ this -> parser ) { $ this -> parser = new Parser ; $ this -> fixUniqueHeaders ( ) ; $ this -> parser -> setText ( $ this -> toString ( ) ) ; } return $ this -> parser ; }
Return mail parser
29,583
public function getBody ( ) { if ( $ this -> getAttachments ( ) ) { try { return $ this -> getParser ( ) -> getMessageBody ( 'html' ) ; } catch ( \ Throwable $ exc ) { error_log ( $ exc ) ; } } return parent :: getBody ( ) ; }
Return the message body
29,584
private function fixUniqueHeaders ( ) { $ headers = $ this -> getHeaders ( ) ; $ headersCopy = clone $ headers ; $ headers -> clearHeaders ( ) ; foreach ( $ headersCopy as $ header ) { $ name = $ header -> getFieldName ( ) ; $ headers -> has ( $ name ) or $ headers -> addHeader ( $ header ) ; } }
Fixing headers uniqueness
29,585
public static function fromFile ( $ path ) { $ message = static :: fromString ( join ( PHP_EOL , file ( $ path , FILE_IGNORE_NEW_LINES ) ) ) ; return $ message ; }
Create mail object from file
29,586
public function addContent ( $ content , $ type = 'text' ) { $ element = $ this -> addChild ( 'atom:content' , 'content' ) ; $ element -> setContent ( $ content , $ type ) ; return $ element ; }
Add content .
29,587
public function getEventManager ( ) : EventManagerInterface { if ( null === $ this -> events ) { $ this -> setEventManager ( new EventManager ( ) ) ; } return $ this -> events ; }
Returns the EventManager
29,588
protected function setEventManager ( EventManagerInterface $ events ) : self { $ events -> setIdentifiers ( [ __CLASS__ , get_called_class ( ) ] ) ; $ this -> events = $ events ; return $ this ; }
Sets the EventManager
29,589
protected function beforeSave ( EntityInterface $ entity ) : EntityInterface { $ argv = compact ( 'entity' ) ; $ argv = $ this -> getEventManager ( ) -> prepareArgs ( $ argv ) ; $ this -> getEventManager ( ) -> trigger ( "{$this->event_prefix}_save_before" , $ this , $ argv ) ; if ( $ this -> entity_event_prefix ) { $ this -> getEventManager ( ) -> trigger ( "{$this->entity_event_prefix}_save_before" , $ this , $ argv ) ; } return $ argv [ 'entity' ] ; }
Events to fire before an Entity is saved
29,590
protected function afterSave ( EntityInterface $ entity ) : void { $ argv = compact ( 'entity' ) ; $ argv = $ this -> getEventManager ( ) -> prepareArgs ( $ argv ) ; $ this -> getEventManager ( ) -> trigger ( "{$this->event_prefix}_save_after" , $ this , $ argv ) ; if ( $ this -> entity_event_prefix ) { $ this -> getEventManager ( ) -> trigger ( "{$this->entity_event_prefix}_save_after" , $ this , $ argv ) ; } }
Events to fire after an Entity is saved
29,591
function RemoveItem ( $ idx ) { $ result = array ( ) ; foreach ( $ this -> items as $ currentIdx => $ item ) { if ( $ currentIdx != $ idx ) $ result [ ] = $ item ; } $ this -> items = $ result ; }
Removes an item from the items list
29,592
public function index ( ) { $ locations = Location :: with ( 'upcoming_jobs_count' ) -> onTeam ( ) -> orderBy ( 'name' , 'asc' ) -> paginate ( config ( 'app.pagination_default' ) ) ; return fractal ( $ locations , new LocationTransformer ( ) ) -> withResourceName ( 'location' ) -> respond ( ) ; }
Fetch a paginated list of Locations for a selected Team
29,593
public function store ( Request $ request ) { $ this -> authorize ( 'store' , Location :: class ) ; $ request -> validate ( [ 'name' => 'required|max:128' ] ) ; $ location = new Location ( ) ; $ location -> team_id = $ this -> userContext ( ) -> team_id ; $ location -> name = $ request -> name ; $ location -> save ( ) ; return fractal ( $ location , new LocationTransformer ( ) ) -> withResourceName ( 'location' ) -> respond ( ) ; }
Store a new Location
29,594
public function update ( Request $ request , $ id ) { $ request -> validate ( [ 'name' => 'required|max:128' ] ) ; $ location = Location :: findOrFail ( $ id ) ; $ location -> name = $ request -> name ; $ this -> authorize ( 'update' , $ location ) ; $ location -> save ( ) ; return fractal ( $ location , new LocationTransformer ( ) ) -> withResourceName ( 'location' ) -> respond ( ) ; }
Store an updated Location
29,595
function _connect ( $ dsn ) { if ( is_string ( $ dsn ) || is_array ( $ dsn ) ) { if ( ! $ this -> db ) { $ this -> db = ADONewConnection ( $ dsn ) ; if ( $ err = ADODB_Pear_error ( ) ) { return PEAR :: raiseError ( $ err ) ; } } } else { return PEAR :: raiseError ( 'The given dsn was not valid in file ' . __FILE__ . ' at line ' . __LINE__ , 41 , PEAR_ERROR_RETURN , null , null ) ; } if ( ! $ this -> db ) { return PEAR :: raiseError ( ADODB_Pear_error ( ) ) ; } else { return true ; } }
Connect to database by using the given DSN string
29,596
function query ( $ query ) { $ err = $ this -> _prepare ( ) ; if ( $ err !== true ) { return $ err ; } return $ this -> db -> query ( $ query ) ; }
Prepare query to the database
29,597
function _setDefaults ( ) { $ this -> options [ 'db_type' ] = 'mysql' ; $ this -> options [ 'table' ] = 'auth' ; $ this -> options [ 'usernamecol' ] = 'username' ; $ this -> options [ 'passwordcol' ] = 'password' ; $ this -> options [ 'dsn' ] = '' ; $ this -> options [ 'db_fields' ] = '' ; $ this -> options [ 'cryptType' ] = 'md5' ; }
Set some default options
29,598
function _parseOptions ( $ array ) { foreach ( $ array as $ key => $ value ) { if ( isset ( $ this -> options [ $ key ] ) ) { $ this -> options [ $ key ] = $ value ; } } if ( ! empty ( $ this -> options [ 'db_fields' ] ) ) { if ( is_array ( $ this -> options [ 'db_fields' ] ) ) { $ this -> options [ 'db_fields' ] = join ( $ this -> options [ 'db_fields' ] , ', ' ) ; } $ this -> options [ 'db_fields' ] = ', ' . $ this -> options [ 'db_fields' ] ; } }
Parse options passed to the container class
29,599
function fetchData ( $ username , $ password ) { $ err = $ this -> _prepare ( ) ; if ( $ err !== true ) { return PEAR :: raiseError ( $ err -> getMessage ( ) , $ err -> getCode ( ) ) ; } if ( strstr ( $ this -> options [ 'db_fields' ] , '*' ) ) { $ sql_from = "*" ; } else { $ sql_from = $ this -> options [ 'usernamecol' ] . ", " . $ this -> options [ 'passwordcol' ] . $ this -> options [ 'db_fields' ] ; } $ query = "SELECT " . $ sql_from . " FROM " . $ this -> options [ 'table' ] . " WHERE " . $ this -> options [ 'usernamecol' ] . " = " . $ this -> db -> Quote ( $ username ) ; $ ADODB_FETCH_MODE = ADODB_FETCH_ASSOC ; $ rset = $ this -> db -> Execute ( $ query ) ; $ res = $ rset -> fetchRow ( ) ; if ( DB :: isError ( $ res ) ) { return PEAR :: raiseError ( $ res -> getMessage ( ) , $ res -> getCode ( ) ) ; } if ( ! is_array ( $ res ) ) { $ this -> activeUser = '' ; return false ; } if ( $ this -> verifyPassword ( trim ( $ password , "\r\n" ) , trim ( $ res [ $ this -> options [ 'passwordcol' ] ] , "\r\n" ) , $ this -> options [ 'cryptType' ] ) ) { foreach ( $ res as $ key => $ value ) { if ( $ key == $ this -> options [ 'passwordcol' ] || $ key == $ this -> options [ 'usernamecol' ] ) { continue ; } if ( is_object ( $ this -> _auth_obj ) ) { $ this -> _auth_obj -> setAuthData ( $ key , $ value ) ; } else { Auth :: setAuthData ( $ key , $ value ) ; } } return true ; } $ this -> activeUser = $ res [ $ this -> options [ 'usernamecol' ] ] ; return false ; }
Get user information from database