idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
47,000
|
public function makeRelationship ( $ name ) { if ( ! $ this -> getRelationship ( $ name ) ) { $ rows = call_user_func_array ( array ( $ this , $ name ) , array ( ) ) -> rows ( ) ; $ this -> addRelationship ( $ name , $ rows ) ; } return $ this ; }
|
Establishes a relationship fetching the rows as needed
|
47,001
|
public function makeAcquaintance ( $ name ) { if ( ! $ this -> getRelationship ( $ name ) ) { $ rows = call_user_func_array ( self :: $ acquaintances [ $ name ] , [ $ this ] ) -> rows ( ) ; $ this -> addRelationship ( $ name , $ rows ) ; } return $ this ; }
|
Establishes a relationship based on the acquaintances fetching the rows as needed
|
47,002
|
public static function introspectRelationships ( ) { $ instance = self :: blank ( ) ; $ methods = [ ] ; $ reflection = new \ ReflectionClass ( $ instance ) ; $ relationship = __NAMESPACE__ . '\\Relationship\\Relationship' ; foreach ( $ reflection -> getMethods ( \ ReflectionMethod :: IS_PUBLIC ) as $ method ) { if ( $ method -> class == __CLASS__ ) { continue ; } $ result = null ; try { $ result = $ method -> invoke ( new $ reflection -> name ) ; } catch ( \ Exception $ e ) { } if ( $ result instanceof $ relationship ) { $ methods [ ] = $ method -> name ; } } $ acquaintances = array_keys ( self :: $ acquaintances ) ; return array_merge ( $ methods , $ acquaintances ) ; }
|
Identifies known relationships on the model
|
47,003
|
public function automaticCreated ( $ data ) { if ( ! isset ( $ data [ 'created' ] ) || ! $ data [ 'created' ] ) { $ now = new Date ( 'now' ) ; $ data [ 'created' ] = $ now -> toSql ( ) ; } return $ data [ 'created' ] ; }
|
Generates automatic created field value
|
47,004
|
public function automaticCreatedBy ( $ data ) { return ( isset ( $ data [ 'created_by' ] ) && $ data [ 'created_by' ] ? ( int ) $ data [ 'created_by' ] : ( int ) \ User :: get ( 'id' ) ) ; }
|
Generates automatic created by field value
|
47,005
|
public function status ( ) { $ arguments = array ( '--porcelain' ) ; $ status = $ this -> call ( 'status' , $ arguments ) ; $ response = '' ; if ( ! empty ( $ status ) ) { $ status = trim ( $ status ) ; $ lines = explode ( "\n" , $ status ) ; $ response = array ( 'added' => array ( ) , 'modified' => array ( ) , 'deleted' => array ( ) , 'renamed' => array ( ) , 'copied' => array ( ) , 'untracked' => array ( ) , 'unmerged' => array ( ) , 'merged' => array ( ) ) ; foreach ( $ lines as $ line ) { $ line = trim ( $ line ) ; preg_match ( '/([A|D|M|U|R|C|?]{1,2})[ ]{1,2}([[:alnum:]_\-\.\/]*)/' , $ line , $ parts ) ; if ( strlen ( $ parts [ 1 ] ) == 2 && $ parts [ 1 ] != '??' && $ parts [ 1 ] != 'UU' ) { $ parts [ 1 ] = 'merged' ; } switch ( $ parts [ 1 ] ) { case 'A' : $ response [ 'added' ] [ ] = $ parts [ 2 ] ; break ; case 'D' : $ response [ 'deleted' ] [ ] = $ parts [ 2 ] ; break ; case 'M' : $ response [ 'modified' ] [ ] = $ parts [ 2 ] ; break ; case 'R' : $ response [ 'renamed' ] [ ] = $ parts [ 2 ] ; break ; case 'C' : $ response [ 'copied' ] [ ] = $ parts [ 2 ] ; break ; case 'UU' : $ response [ 'unmerged' ] [ ] = $ parts [ 2 ] ; break ; case '??' : $ response [ 'untracked' ] [ ] = $ parts [ 2 ] ; break ; case 'merged' : $ response [ 'merged' ] [ ] = $ parts [ 2 ] ; break ; } } } return $ response ; }
|
Get the status of the repository
|
47,006
|
public function log ( $ length = null , $ start = null , $ upcoming = false , $ installed = true , $ search = null , $ format = '%an: %s' , $ count = false ) { $ args = array ( ) ; if ( $ count ) { return $ this -> countLogs ( $ installed , $ upcoming , $ search ) ; } if ( $ upcoming ) { $ args [ 'upcoming' ] = "HEAD..{$this->upstream}" ; } if ( isset ( $ length ) ) { $ args [ 'length' ] = '-' . ( int ) $ length ; } if ( isset ( $ start ) ) { $ args [ 'skip' ] = '--skip=' . ( int ) $ start ; } if ( isset ( $ format ) ) { $ args [ 'format' ] = '--pretty=format:' . escapeshellarg ( $ format ) ; } if ( isset ( $ search ) ) { $ args [ 'case-insensitive' ] = '-i' ; $ args [ 'search' ] = '--grep=' . escapeshellarg ( $ search ) ; } $ upcomingCount = 0 ; $ upcomingTotal = 0 ; if ( $ upcoming ) { $ upcomingLog = $ this -> call ( 'log' , $ args ) ; if ( isset ( $ upcomingLog ) ) { $ upcomingLogs = explode ( "\n" , $ upcomingLog ) ; $ upcomingCount = count ( $ upcomingLogs ) ; } $ upcomingTotal = $ this -> countLogs ( false , true , $ search ) ; } if ( $ upcomingCount < $ length ) { if ( isset ( $ args [ 'upcoming' ] ) ) { unset ( $ args [ 'upcoming' ] ) ; } $ args [ 'length' ] = '-' . ( $ length - $ upcomingCount ) ; $ args [ 'skip' ] = '--skip=' . ( ( ( $ start - $ upcomingTotal ) >= 0 ) ? ( $ start - $ upcomingTotal ) : 0 ) ; $ currentLog = $ this -> call ( 'log' , $ args ) ; $ currentLogs = ( ! empty ( $ currentLog ) ) ? explode ( "\n" , $ currentLog ) : array ( ) ; } $ response = array ( ) ; if ( $ upcomingCount > 0 ) { foreach ( $ upcomingLogs as $ entry ) { $ response [ ] = '* ' . $ entry ; } } if ( isset ( $ currentLogs ) && count ( $ currentLogs ) > 0 && $ installed ) { foreach ( $ currentLogs as $ entry ) { $ response [ ] = $ entry ; } } return $ response ; }
|
Get the log
|
47,007
|
private function countLogs ( $ installed = true , $ upcoming = false , $ search = null ) { $ total = 0 ; $ countArgs = array ( '--count' ) ; if ( isset ( $ search ) ) { $ countArgs [ ] = '-i' ; $ countArgs [ ] = '--grep=' . escapeshellarg ( $ search ) ; } if ( $ installed ) { $ installedArgs = $ countArgs ; array_unshift ( $ installedArgs , 'HEAD' ) ; $ total = $ this -> call ( 'rev-list' , $ installedArgs ) ; $ total = trim ( $ total ) ; } if ( $ upcoming ) { $ upcomingArgs = $ countArgs ; array_unshift ( $ upcomingArgs , "HEAD..{$this->upstream}" ) ; $ upcomingTotal = $ this -> call ( 'rev-list' , $ upcomingArgs ) ; $ upcomingTotal = trim ( $ upcomingTotal ) ; $ total += $ upcomingTotal ; } return trim ( $ total ) ; }
|
Count log entries
|
47,008
|
public function update ( $ dryRun = true , $ allowNonFf = false , $ source = null ) { if ( ! $ dryRun ) { chdir ( $ this -> workTree ) ; $ arguments = array ( ) ; if ( isset ( $ source ) ) { $ arguments [ ] = $ source ; } else { $ arguments [ ] = $ this -> upstream ; } if ( ! $ allowNonFf ) { $ arguments [ ] = '--ff-only' ; } $ autoedit = getenv ( "GIT_MERGE_AUTOEDIT" ) ; putenv ( "GIT_MERGE_AUTOEDIT=no" ) ; $ response = $ this -> call ( 'merge' , $ arguments ) ; if ( $ autoedit ) { putenv ( "GIT_MERGE_AUTOEDIT={$autoedit}" ) ; } else { putenv ( "GIT_MERGE_AUTOEDIT" ) ; } $ response = trim ( $ response ) ; $ return = array ( ) ; if ( substr ( $ response , 0 , 5 ) == 'fatal' ) { $ return [ 'status' ] = 'fatal' ; $ return [ 'message' ] = trim ( substr ( $ response , stripos ( $ response , 'fatal' ) + 6 ) ) ; } else if ( substr ( $ response , 0 , 5 ) == 'error' ) { $ return [ 'status' ] = 'fatal' ; $ return [ 'message' ] = trim ( substr ( $ response , stripos ( $ response , 'error' ) + 6 ) ) ; } else if ( stripos ( $ response , 'automatic merge failed' ) !== false ) { $ return [ 'status' ] = 'fatal' ; $ return [ 'message' ] = $ response ; } else { $ return [ 'status' ] = 'success' ; } $ return [ 'raw' ] = $ response ; } else { $ this -> call ( 'fetch' ) ; $ this -> call ( 'remote update' ) ; $ arguments = array ( '--pretty=format:"%an: \"%s\" (%ar)"' , "HEAD..{$this->upstream}" ) ; $ log = $ this -> call ( 'log' , $ arguments ) ; $ log = trim ( $ log ) ; $ return = array ( ) ; $ logs = explode ( "\n" , $ log ) ; if ( ! empty ( $ log ) && count ( $ logs ) > 0 ) { foreach ( $ logs as $ log ) { $ return [ ] = trim ( $ log ) ; } } } return $ return ; }
|
Pull the latest updates
|
47,009
|
public function push ( $ ref = 'master' , $ remote = 'origin' , $ remoteRef = null ) { $ ref = ( isset ( $ remoteRef ) ) ? $ ref . ':' . $ remoteRef : $ ref ; $ response = $ this -> call ( 'push' , array ( $ remote , $ ref ) ) ; $ response = trim ( $ response ) ; $ return = array ( ) ; if ( stripos ( $ response , 'error: failed to push some refs' ) !== false ) { $ return [ 'status' ] = 'fatal' ; $ return [ 'message' ] = $ response ; } else if ( stripos ( $ response , 'everything up-to-date' ) !== false ) { $ return [ 'status' ] = 'success' ; $ return [ 'message' ] = $ response ; } else { $ return [ 'status' ] = 'success' ; } return $ return ; }
|
Pushes the local repository to the remote destination
|
47,010
|
public function getRollbackPoint ( ) { $ tagList = $ this -> call ( 'tag' ) ; $ tags = explode ( "\n" , $ tagList ) ; $ rbp = 0 ; if ( count ( $ tags ) > 0 ) { foreach ( $ tags as $ tag ) { if ( strstr ( $ tag , 'cmsrollbackpoint-' ) !== false ) { $ tmp_tag = substr ( $ tag , 17 ) ; if ( $ tmp_tag > $ rbp ) { $ rbp = $ tmp_tag ; } } } if ( $ rbp === 0 ) { return false ; } return $ rbp ; } else { return false ; } }
|
Get the latest rollback point
|
47,011
|
public function purgeRollbackPoints ( ) { $ tagList = $ this -> call ( 'tag' ) ; $ tags = explode ( "\n" , $ tagList ) ; $ rollbackPoints = array ( ) ; foreach ( $ tags as $ tag ) { if ( strstr ( $ tag , 'cmsrollbackpoint-' ) !== false ) { $ rollbackPoints [ ] = $ tag ; } } if ( count ( $ rollbackPoints ) > 1 ) { for ( $ i = 0 ; $ i < ( count ( $ rollbackPoints ) - 1 ) ; $ i ++ ) { $ this -> call ( 'tag' , array ( '-d' , $ rollbackPoints [ $ i ] ) ) ; } } }
|
Purge rollback points except for the latest
|
47,012
|
public function isClean ( ) { $ status = $ this -> status ( ) ; $ eligible = true ; if ( ! empty ( $ status ) && is_array ( $ status ) ) { foreach ( $ status as $ type => $ files ) { if ( $ type != 'untracked' && ! empty ( $ files ) ) { $ eligible = false ; break ; } } } return $ eligible ; }
|
Check to see if the repo is clean at least as far as this mechanism is concerned
|
47,013
|
private function call ( $ cmd , $ arguments = array ( ) ) { $ command = "{$this->baseCmd} {$cmd}" . ( ( ! empty ( $ arguments ) ) ? ' ' . implode ( ' ' , $ arguments ) : '' ) . ' 2>&1' ; $ response = shell_exec ( $ command ) ; return $ response ; }
|
Call a git command
|
47,014
|
public static function optgroup ( $ text , $ optKey = 'value' , $ optText = 'text' ) { static $ state = 'open' ; switch ( $ state ) { case 'open' : $ obj = new stdClass ; $ obj -> $ optKey = '<OPTGROUP>' ; $ obj -> $ optText = $ text ; $ state = 'close' ; break ; case 'close' : $ obj = new stdClass ; $ obj -> $ optKey = '</OPTGROUP>' ; $ obj -> $ optText = $ text ; $ state = 'open' ; break ; } return $ obj ; }
|
Create a placeholder for an option group .
|
47,015
|
public static function option ( $ value , $ text = '' , $ optKey = 'value' , $ optText = 'text' , $ disable = false ) { $ options = array ( 'attr' => null , 'disable' => false , 'option.attr' => null , 'option.disable' => 'disable' , 'option.key' => 'value' , 'option.label' => null , 'option.text' => 'text' ) ; if ( is_array ( $ optKey ) ) { $ options = array_merge ( $ options , $ optKey ) ; } else { $ options [ 'option.key' ] = $ optKey ; $ options [ 'option.text' ] = $ optText ; $ options [ 'disable' ] = $ disable ; } $ obj = new Obj ; $ obj -> { $ options [ 'option.key' ] } = $ value ; $ obj -> { $ options [ 'option.text' ] } = trim ( $ text ) ? $ text : $ value ; $ hasProperty = $ options [ 'option.label' ] !== null ; if ( isset ( $ options [ 'label' ] ) ) { $ labelProperty = $ hasProperty ? $ options [ 'option.label' ] : 'label' ; $ obj -> $ labelProperty = $ options [ 'label' ] ; } elseif ( $ hasProperty ) { $ obj -> { $ options [ 'option.label' ] } = '' ; } if ( $ options [ 'attr' ] !== null ) { $ obj -> { $ options [ 'option.attr' ] } = $ options [ 'attr' ] ; } if ( $ options [ 'disable' ] !== null ) { $ obj -> { $ options [ 'option.disable' ] } = $ options [ 'disable' ] ; } return $ obj ; }
|
Create an object that represents an option in an option list .
|
47,016
|
public static function ordering ( $ name , $ query , $ attribs = null , $ selected = null , $ neworder = null , $ chop = null ) { if ( empty ( $ attribs ) ) { $ attribs = 'class="inputbox" size="1"' ; } if ( empty ( $ neworder ) ) { $ db = \ App :: get ( 'db' ) ; $ db -> setQuery ( $ query ) ; $ items = $ db -> loadObjectList ( ) ; if ( empty ( $ items ) ) { $ options [ ] = self :: option ( 1 , Lang :: txt ( 'JOPTION_ORDER_FIRST' ) ) ; } else { $ chop = '30' ; $ options [ ] = self :: option ( 0 , '0 ' . Lang :: txt ( 'JOPTION_ORDER_FIRST' ) ) ; for ( $ i = 0 , $ n = count ( $ items ) ; $ i < $ n ; $ i ++ ) { $ items [ $ i ] -> text = Lang :: txt ( $ items [ $ i ] -> text ) ; if ( strlen ( $ items [ $ i ] -> text ) > $ chop ) { $ text = substr ( $ items [ $ i ] -> text , 0 , $ chop ) . "..." ; } else { $ text = $ items [ $ i ] -> text ; } $ options [ ] = self :: option ( $ items [ $ i ] -> value , $ items [ $ i ] -> value . '. ' . $ text ) ; } $ options [ ] = self :: option ( $ items [ $ i - 1 ] -> value + 1 , ( $ items [ $ i - 1 ] -> value + 1 ) . ' ' . Lang :: txt ( 'JOPTION_ORDER_LAST' ) ) ; } $ html = self :: genericlist ( $ options , $ name , array ( 'list.attr' => $ attribs , 'list.select' => ( int ) $ selected ) ) ; } else { if ( $ neworder > 0 ) { $ text = Lang :: txt ( 'JGLOBAL_NEWITEMSLAST_DESC' ) ; } elseif ( $ neworder <= 0 ) { $ text = Lang :: txt ( 'JGLOBAL_NEWITEMSFIRST_DESC' ) ; } $ html = '<input type="hidden" name="' . $ name . '" value="' . ( int ) $ selected . '" />' . '<span class="readonly">' . $ text . '</span>' ; } return $ html ; }
|
Build the select list for Ordering derived from a query
|
47,017
|
public static function access ( ) { $ lines = array ( '<label id="batch-access-lbl" for="batch-access" class="hasTip" title="' . Lang :: txt ( 'JLIB_HTML_BATCH_ACCESS_LABEL' ) . '::' . Lang :: txt ( 'JLIB_HTML_BATCH_ACCESS_LABEL_DESC' ) . '">' , Lang :: txt ( 'JLIB_HTML_BATCH_ACCESS_LABEL' ) , '</label>' , Access :: assetgrouplist ( 'batch[assetgroup_id]' , '' , 'class="inputbox"' , array ( 'title' => Lang :: txt ( 'JLIB_HTML_BATCH_NOCHANGE' ) , 'id' => 'batch-access' ) ) ) ; return implode ( "\n" , $ lines ) ; }
|
Display a batch widget for the access level selector .
|
47,018
|
public static function item ( $ extension ) { $ options = array ( Select :: option ( 'c' , Lang :: txt ( 'JLIB_HTML_BATCH_COPY' ) ) , Select :: option ( 'm' , Lang :: txt ( 'JLIB_HTML_BATCH_MOVE' ) ) ) ; $ lines = array ( '<label id="batch-choose-action-lbl" for="batch-choose-action">' , Lang :: txt ( 'JLIB_HTML_BATCH_MENU_LABEL' ) , '</label>' , '<fieldset id="batch-choose-action" class="combo">' , '<select name="batch[category_id]" class="inputbox" id="batch-category-id">' , '<option value="">' . Lang :: txt ( 'JSELECT' ) . '</option>' , Select :: options ( Category :: options ( $ extension ) ) , '</select>' , Select :: radiolist ( $ options , 'batch[move_copy]' , '' , 'value' , 'text' , 'm' ) , '</fieldset>' ) ; return implode ( "\n" , $ lines ) ; }
|
Displays a batch widget for moving or copying items .
|
47,019
|
public static function language ( ) { $ lines = array ( '<label id="batch-language-lbl" for="batch-language" class="hasTip" title="' . Lang :: txt ( 'JLIB_HTML_BATCH_LANGUAGE_LABEL' ) . '::' . Lang :: txt ( 'JLIB_HTML_BATCH_LANGUAGE_LABEL_DESC' ) . '">' , Lang :: txt ( 'JLIB_HTML_BATCH_LANGUAGE_LABEL' ) , '</label>' , '<select name="batch[language_id]" class="inputbox" id="batch-language-id">' , '<option value="">' . Lang :: txt ( 'JLIB_HTML_BATCH_LANGUAGE_NOCHANGE' ) . '</option>' , Select :: options ( ContentLanguage :: existing ( true , true ) , 'value' , 'text' ) , '</select>' ) ; return implode ( "\n" , $ lines ) ; }
|
Display a batch widget for the language selector .
|
47,020
|
public static function user ( $ noUser = true ) { $ optionNo = '' ; if ( $ noUser ) { $ optionNo = '<option value="0">' . Lang :: txt ( 'JLIB_HTML_BATCH_USER_NOUSER' ) . '</option>' ; } $ db = \ App :: get ( 'db' ) ; $ query = $ db -> getQuery ( ) -> select ( 'a.id' , 'value' ) -> select ( 'a.name' , 'text' ) -> from ( '#__users' , 'a' ) -> whereEquals ( 'a.block' , '0' ) -> order ( 'a.name' , 'asc' ) ; $ db -> setQuery ( $ query -> toString ( ) ) ; $ items = $ db -> loadObjectList ( ) ; $ lines = array ( '<label id="batch-user-lbl" for="batch-user" class="hasTip" title="' . Lang :: txt ( 'JLIB_HTML_BATCH_USER_LABEL' ) . '::' . Lang :: txt ( 'JLIB_HTML_BATCH_USER_LABEL_DESC' ) . '">' , Lang :: txt ( 'JLIB_HTML_BATCH_USER_LABEL' ) , '</label>' , '<select name="batch[user_id]" class="inputbox" id="batch-user-id">' , '<option value="">' . Lang :: txt ( 'JLIB_HTML_BATCH_USER_NOCHANGE' ) . '</option>' , $ optionNo , Select :: options ( $ items , 'value' , 'text' ) , '</select>' ) ; return implode ( "\n" , $ lines ) ; }
|
Display a batch widget for the user selector .
|
47,021
|
public function render ( ) { $ html = array ( ) ; $ html [ ] = '<div class="toolbar-list" id="' . $ this -> _name . '">' ; $ html [ ] = '<ul>' ; foreach ( $ this -> _bar as $ key => $ button ) { $ this -> _bar [ $ key ] [ 9 ] = array ( ) ; if ( $ button [ 0 ] == 'Separator' ) { continue ; } if ( ! isset ( $ this -> _bar [ $ key - 1 ] ) || $ this -> _bar [ $ key - 1 ] [ 0 ] == 'Separator' ) { $ this -> _bar [ $ key ] [ 9 ] [ ] = 'first' ; } if ( ! isset ( $ this -> _bar [ $ key + 1 ] ) || $ this -> _bar [ $ key + 1 ] [ 0 ] == 'Separator' ) { $ this -> _bar [ $ key ] [ 9 ] [ ] = 'last' ; } } foreach ( $ this -> _bar as $ button ) { $ html [ ] = $ this -> renderButton ( $ button ) ; } $ html [ ] = '</ul>' ; $ html [ ] = '</div>' ; return implode ( "\n" , $ html ) ; }
|
Render a tool bar .
|
47,022
|
public function loadButtonType ( $ type , $ new = false ) { $ signature = md5 ( $ type ) ; if ( isset ( $ this -> _buttons [ $ signature ] ) && $ new === false ) { return $ this -> _buttons [ $ signature ] ; } $ buttonClass = __NAMESPACE__ . '\\Toolbar\\Button\\' . $ type ; if ( ! class_exists ( $ buttonClass ) ) { $ dirs = isset ( $ this -> _buttonPath ) ? $ this -> _buttonPath : array ( ) ; $ file = preg_replace ( '/[^A-Z0-9_\.-]/i' , '' , str_replace ( '_' , DIRECTORY_SEPARATOR , strtolower ( $ type ) ) ) . '.php' ; if ( $ buttonFile = $ this -> find ( $ dirs , $ file ) ) { include_once $ buttonFile ; } else { throw new \ InvalidArgumentException ( \ Lang :: txt ( 'JLIB_HTML_BUTTON_NO_LOAD' , $ buttonClass , $ buttonFile ) , 500 ) ; } } if ( ! class_exists ( $ buttonClass ) ) { throw new \ Exception ( "Module file $buttonFile does not contain class $buttonClass." , 500 ) ; } $ this -> _buttons [ $ signature ] = new $ buttonClass ( $ this ) ; return $ this -> _buttons [ $ signature ] ; }
|
Loads a button type .
|
47,023
|
public function addButtonPath ( $ path ) { settype ( $ path , 'array' ) ; foreach ( $ path as $ dir ) { $ dir = trim ( $ dir ) ; if ( substr ( $ dir , - 1 ) != DIRECTORY_SEPARATOR ) { $ dir .= DIRECTORY_SEPARATOR ; } array_unshift ( $ this -> _buttonPath , $ dir ) ; } }
|
Add a directory where ToolBar should search for button types in LIFO order .
|
47,024
|
public function send ( $ message = null , $ status = null , $ reason = null ) { $ this -> response -> setContent ( $ message ) ; $ this -> response -> setStatusCode ( $ status ? $ status : 200 ) ; }
|
Set response content
|
47,025
|
public function readTask ( ) { $ model = $ this -> resolveModel ( ) ; $ model = $ model -> whereEquals ( $ model -> getPrimaryKey ( ) , Request :: getVar ( $ model -> getPrimaryKey ( ) ) ) -> row ( ) ; if ( $ model -> isNew ( ) ) { App :: abort ( 404 , Lang :: txt ( 'JLIB_APPLICATION_ERROR_ITEM_NOT_FOUND' ) ) ; } $ properties = $ model -> getStructure ( ) -> getTableColumns ( $ model -> getTableName ( ) ) ; $ properties = $ this -> normalizeProperties ( $ properties ) ; foreach ( $ properties as $ property => $ type ) { if ( $ type == 'date' && $ model -> get ( $ property ) && $ model -> get ( $ property ) != '0000-00-00 00:00:00' ) { $ model -> set ( $ property , with ( new Date ( $ model -> get ( $ property ) ) ) -> format ( 'Y-m-d\TH:i:s\Z' ) ) ; } } $ this -> send ( $ model -> toObject ( ) ) ; }
|
Read an entry
|
47,026
|
public function deleteTask ( ) { $ this -> requiresAuthentication ( ) ; $ model = $ this -> resolveModel ( ) ; $ model = $ model -> whereEquals ( $ model -> getPrimaryKey ( ) , Request :: getVar ( $ model -> getPrimaryKey ( ) ) ) -> row ( ) ; if ( $ model -> isNew ( ) ) { App :: abort ( 404 , Lang :: txt ( 'JLIB_APPLICATION_ERROR_ITEM_NOT_FOUND' ) ) ; } if ( ! $ model -> destroy ( ) ) { App :: abort ( 500 , Lang :: txt ( 'JLIB_APPLICATION_ERROR_DELETE_FAILED' , $ model -> getError ( ) ) ) ; } $ recipients = array ( ) ; if ( $ model -> hasAttribute ( 'created_by' ) ) { $ recipients [ ] = $ model -> get ( 'created_by' ) ; } if ( $ model -> hasAttribute ( 'modified_by' ) ) { $ recipients [ ] = $ model -> get ( 'modified_by' ) ; } Event :: trigger ( 'system.logActivity' , [ 'activity' => [ 'action' => 'deleted' , 'scope' => $ this -> _name . '.' . $ model -> getModelName ( ) , 'scope_id' => $ model -> get ( $ model -> getPrimaryKey ( ) ) , 'description' => Lang :: txt ( 'JLIB_ACTIVITY_ITEM_DELETED' , $ model -> getModelName ( ) . ' #' . $ model -> get ( $ model -> getPrimaryKey ( ) ) ) , 'details' => $ model -> toArray ( ) ] , 'recipients' => $ recipients ] ) ; $ this -> send ( null , 204 ) ; }
|
Delete an entry
|
47,027
|
protected function normalizeProperties ( $ properties ) { foreach ( $ properties as $ property => $ type ) { if ( preg_match ( '/(.*?)\(\d+\).*/i' , $ type , $ matches ) ) { $ type = $ matches [ 1 ] ; $ properties [ $ property ] = $ type ; } switch ( $ type ) { case 'text' : case 'tinytext' : case 'mediumtext' : case 'longtext' : case 'blob' : $ properties [ $ property ] = 'text' ; break ; case 'int' : case 'integer' : case 'smallint' : case 'tinyint' : case 'bigint' : case 'mediumint' : case 'year' : $ properties [ $ property ] = 'integer' ; break ; case 'datetime' : case 'date' : case 'timestamp' : case 'time' : $ properties [ $ property ] = 'date' ; break ; case 'varchar' : case 'char' : default : $ properties [ $ property ] = 'string' ; break ; } } return $ properties ; }
|
Reduce field types to a couple generic types
|
47,028
|
public static function fire ( $ name ) { $ args = func_get_args ( ) ; unset ( $ args [ 0 ] ) ; if ( isset ( self :: $ events [ $ name ] ) ) { foreach ( self :: $ events [ $ name ] as $ event ) { if ( is_callable ( $ event ) ) { call_user_func_array ( $ event , $ args ) ; } } } }
|
Fires registered event callbacks for a given event name
|
47,029
|
public static function init ( $ namespace , $ total , $ start = 'start' , $ limit = 'limit' ) { $ instance = new self ; $ instance -> total = $ total ; $ instance -> start = \ Request :: getInt ( $ start , \ User :: getState ( $ namespace . '.start' , 0 ) ) ; $ instance -> limit = \ Request :: getInt ( $ limit , \ User :: getState ( $ namespace . '.limit' , \ Config :: get ( 'list_limit' ) ) ) ; $ instance -> start = ( $ instance -> limit != 0 ? ( floor ( $ instance -> start / $ instance -> limit ) * $ instance -> limit ) : 0 ) ; \ User :: setState ( $ namespace . '.start' , $ instance -> start ) ; \ User :: setState ( $ namespace . '.limit' , $ instance -> limit ) ; return $ instance ; }
|
Initializes pagination object
|
47,030
|
protected function getPaginator ( ) { if ( ! isset ( $ this -> paginator ) ) { $ this -> paginator = new \ Hubzero \ Pagination \ Paginator ( $ this -> total , $ this -> start , $ this -> limit ) ; } return $ this -> paginator ; }
|
Gets the HUBzero paginator or creates a new one
|
47,031
|
public function getLogs ( ) { if ( file_exists ( $ this -> logPath ) ) { $ log = Filesystem :: read ( $ this -> logPath ) ; $ levels = array ( ) ; $ this -> logs = explode ( "\n" , $ log ) ; } else { return array ( ) ; } return $ this -> logs ; }
|
getLogs - Returns an array of search engine query log entries
|
47,032
|
public function lastInsert ( ) { $ query = $ this -> connection -> createSelect ( ) ; $ query -> setQuery ( '*:*' ) ; $ query -> setFields ( array ( 'timestamp' ) ) ; $ query -> addSort ( 'timestamp' , 'DESC' ) ; $ query -> setRows ( 1 ) ; $ query -> setStart ( 0 ) ; $ results = $ this -> connection -> execute ( $ query ) ; foreach ( $ results as $ document ) { foreach ( $ document as $ field => $ value ) { $ result = $ value ; return $ result ; } } }
|
lastInsert - Returns the timestamp of the last document indexed
|
47,033
|
public function status ( ) { try { $ pingRequest = $ this -> connection -> createPing ( ) ; $ ping = $ this -> connection -> ping ( $ pingRequest ) ; $ pong = $ ping -> getData ( ) ; $ alive = false ; if ( isset ( $ pong [ 'status' ] ) && $ pong [ 'status' ] === "OK" ) { return true ; } } catch ( \ Solarium \ Exception $ e ) { return false ; } }
|
status - Checks whether or not the search engine is responding
|
47,034
|
public function optimize ( ) { $ update = $ this -> connection -> createUpdate ( ) ; $ update -> addOptimize ( ) ; return $ this -> connection -> update ( $ update ) ; }
|
optimize - Defragment the index
|
47,035
|
public function initBufferAdd ( $ overwrite = null , $ commitWithin = null , $ buffer = null ) { if ( ! isset ( $ this -> bufferAdd ) ) { $ this -> bufferAdd = $ this -> connection -> getPlugin ( 'bufferedadd' ) ; $ this -> commitWithin = $ commitWithin ; $ this -> overwrite = $ overwrite ; $ buffer ++ ; $ this -> bufferAdd -> setBufferSize ( $ buffer ) ; } return $ this -> bufferAdd ; }
|
Initialize Solarium bufferAdd plugin
|
47,036
|
public function delete ( $ query ) { $ deleteQuery = $ this -> parseQuery ( $ query ) ; if ( ! empty ( $ deleteQuery ) ) { try { $ update = $ this -> connection -> createUpdate ( ) ; $ update -> addDeleteQuery ( $ deleteQuery ) ; $ update -> addCommit ( ) ; $ response = $ this -> connection -> update ( $ update ) ; return null ; } catch ( \ Solarium \ Exception \ HttpException $ e ) { $ body = json_decode ( $ e -> getBody ( ) ) ; $ message = isset ( $ body -> error -> msg ) ? $ body -> error -> msg : $ e -> getStatusMessage ( ) ; return $ message ; } } else { return false ; } }
|
deleteById - Removes a single document from the search index
|
47,037
|
public function updateIndex ( $ document , $ commitWithin = 3000 ) { $ this -> index ( $ document , true , $ commitWithin ) ; return $ this -> finalize ( ) ; }
|
updateIndex - Updates a document existing in the search index
|
47,038
|
private function parseQuery ( $ query ) { $ string = '' ; if ( is_array ( $ query ) ) { foreach ( $ query as $ index => $ value ) { $ string .= ! empty ( $ string ) ? ' AND ' : '' ; $ string .= $ index . ':' . $ value ; } } else { $ string = 'id:' . $ query ; } return $ string ; }
|
parseQuery - Translates symbols from query string
|
47,039
|
public function finalize ( ) { try { if ( isset ( $ this -> bufferAdd ) ) { $ this -> bufferAdd -> flush ( $ this -> overwrite , $ this -> commitWithin ) ; } return null ; } catch ( \ Solarium \ Exception \ HttpException $ e ) { $ body = json_decode ( $ e -> getBody ( ) ) ; $ message = isset ( $ body -> error -> msg ) ? $ body -> error -> msg : $ e -> getStatusMessage ( ) ; return $ message ; } }
|
Automatically flushes any remaining documents in the buffer
|
47,040
|
static function & getInstance ( $ key = null ) { static $ instances ; if ( ! isset ( $ instances ) ) { $ instances = array ( ) ; } if ( ! isset ( $ instances [ $ key ] ) ) { $ instances [ $ key ] = new static ( $ key ) ; } return $ instances [ $ key ] ; }
|
Get Instance of Page Archive
|
47,041
|
public function imports ( $ rtrn = 'list' , $ filters = array ( ) , $ clear = false ) { $ model = Import :: all ( ) ; if ( isset ( $ filters [ 'state' ] ) && $ filters [ 'state' ] ) { if ( ! is_array ( $ filters [ 'state' ] ) ) { $ filters [ 'state' ] = array ( $ filters [ 'state' ] ) ; } $ filters [ 'state' ] = array_map ( 'intval' , $ filters [ 'state' ] ) ; $ model -> whereIn ( 'state' , $ filters [ 'state' ] ) ; } if ( ! isset ( $ filters [ 'type' ] ) ) { $ filters [ 'type' ] = $ this -> type ; } if ( isset ( $ filters [ 'type' ] ) && $ filters [ 'type' ] ) { $ model -> whereEquals ( 'type' , $ filters [ 'type' ] ) ; } if ( isset ( $ filters [ 'created_by' ] ) && $ filters [ 'created_by' ] >= 0 ) { $ model -> whereEquals ( 'created_by' , $ filters [ 'created_by' ] ) ; } if ( strtolower ( $ rtrn ) == 'count' ) { return $ model -> total ( ) ; } return $ model -> ordered ( ) -> paginated ( ) -> rows ( ) ; }
|
Get a list or count of imports
|
47,042
|
protected function expiration ( $ key ) { $ lifetime = ini_get ( "session.gc_maxlifetime" ) ; $ expire = $ this -> engine -> get ( $ key . '_expire' ) ; if ( $ expire + $ lifetime < time ( ) ) { $ this -> engine -> delete ( $ key ) ; $ this -> engine -> delete ( $ key . '_expire' ) ; } else { $ this -> engine -> replace ( $ key . '_expire' , time ( ) ) ; } }
|
Set expire time on each call since memcached sets it on cache creation .
|
47,043
|
public function setMessages ( $ messages ) { if ( ! is_array ( $ messages ) ) { throw new InvalidArgumentException ( sprintf ( 'Messages must be an array. Type of "%s" passed.' , gettype ( $ messages ) ) ) ; } $ this -> _messages = $ messages ; return $ this ; }
|
Set the list of messages
|
47,044
|
public function getCurrentUser ( ) { $ instance = $ this -> app [ 'session' ] -> get ( 'user' ) ; if ( ! ( $ instance instanceof User ) ) { $ instance = new User ; } return $ instance ; }
|
Get the default user
|
47,045
|
public function getInstance ( $ id = null ) { $ current = $ this -> getCurrentUser ( ) ; if ( is_null ( $ id ) ) { return $ current ; } if ( is_numeric ( $ id ) ) { $ id = ( int ) $ id ; } if ( $ id === ( int ) $ current -> get ( 'id' ) || $ id === ( string ) $ current -> get ( 'username' ) ) { return $ current ; } if ( ! is_numeric ( $ id ) ) { $ user = $ this -> resolveUser ( $ id ) ; $ id = $ user -> get ( 'id' , 0 ) ; if ( $ id ) { $ this -> users [ $ id ] = $ user ; } } if ( $ id === 0 ) { return new User ; } if ( ! isset ( $ this -> users [ $ id ] ) ) { $ this -> users [ $ id ] = $ this -> resolveUser ( $ id ) ; } return $ this -> users [ $ id ] ; }
|
Get a user instance
|
47,046
|
protected function resolveUser ( $ id ) { if ( ! is_numeric ( $ id ) ) { if ( strstr ( $ id , '@' ) ) { $ user = User :: oneByEmail ( $ id ) ; } else { $ user = User :: oneByUsername ( $ id ) ; } } else { $ user = User :: oneOrNew ( $ id ) ; } return $ user ; }
|
Create a new user instance .
|
47,047
|
protected function getInput ( ) { $ html = array ( ) ; $ attr = '' ; $ attr .= $ this -> element [ 'class' ] ? ' class="combobox ' . ( string ) $ this -> element [ 'class' ] . '"' : ' class="combobox"' ; $ attr .= ( ( string ) $ this -> element [ 'readonly' ] == 'true' ) ? ' readonly="readonly"' : '' ; $ attr .= ( ( string ) $ this -> element [ 'disabled' ] == 'true' ) ? ' disabled="disabled"' : '' ; $ attr .= $ this -> element [ 'size' ] ? ' size="' . ( int ) $ this -> element [ 'size' ] . '"' : '' ; $ attr .= $ this -> element [ 'onchange' ] ? ' onchange="' . ( string ) $ this -> element [ 'onchange' ] . '"' : '' ; $ options = $ this -> getOptions ( ) ; Behavior :: combobox ( ) ; $ html [ ] = '<input type="text" name="' . $ this -> name . '" id="' . $ this -> id . '"' . ' value="' . htmlspecialchars ( $ this -> value , ENT_COMPAT , 'UTF-8' ) . '"' . $ attr . '/>' ; $ html [ ] = '<ul id="combobox-' . $ this -> id . '" style="display:none;">' ; foreach ( $ options as $ option ) { $ html [ ] = '<li>' . $ option -> text . '</li>' ; } $ html [ ] = '</ul>' ; return implode ( $ html ) ; }
|
Method to get the field input markup for a combo box field .
|
47,048
|
protected function createRouter ( $ client ) { $ prefix = $ this -> app [ 'request' ] -> getHttpHost ( ) ; $ router = new Router ( array ( ) , $ prefix ) ; $ routes = array ( ) ; foreach ( $ this -> paths as $ path ) { $ routes [ ] = $ path . DIRECTORY_SEPARATOR . 'bootstrap' . DIRECTORY_SEPARATOR . $ client ; $ routes [ ] = $ path . DIRECTORY_SEPARATOR . 'bootstrap' . DIRECTORY_SEPARATOR . ucfirst ( $ client ) ; } foreach ( $ routes as $ route ) { $ path = $ route . DIRECTORY_SEPARATOR . 'routes.php' ; if ( file_exists ( $ path ) ) { require $ path ; } } return $ router ; }
|
Create a new client instance .
|
47,049
|
public function objectToString ( $ object , $ options = array ( ) ) { if ( is_string ( $ object ) ) { return $ object ; } $ format = 'object' ; if ( isset ( $ options [ 'format' ] ) && $ options [ 'format' ] ) { $ format = $ options [ 'format' ] ; } $ vars = '' ; foreach ( get_object_vars ( $ object ) as $ k => $ v ) { if ( is_scalar ( $ v ) ) { switch ( $ format ) { case 'object' : $ vars .= "\tvar $" . $ k . " = '" . addcslashes ( $ v , '\\\'' ) . "';\n" ; break ; case 'array' : $ vars .= "\t'" . $ k . "' => '" . addcslashes ( $ v , '\\\'' ) . "',\n" ; break ; } } elseif ( is_array ( $ v ) || is_object ( $ v ) ) { switch ( $ format ) { case 'object' : $ vars .= "\tvar $" . $ k . " = " . $ this -> getArrayString ( ( array ) $ v ) . ";\n" ; break ; case 'array' : $ vars .= "\t'" . $ k . "' => " . $ this -> getArrayString ( ( array ) $ v ) . ",\n" ; break ; } } elseif ( is_null ( $ v ) ) { switch ( $ format ) { case 'object' : $ vars .= "\tvar $" . $ k . " = '';\n" ; break ; case 'array' : $ vars .= "\t'" . $ k . "' => '',\n" ; break ; } } } $ str = "<?php\n" ; switch ( $ format ) { case 'object' : if ( ! isset ( $ options [ 'class' ] ) || ! $ options [ 'class' ] ) { $ options [ 'class' ] = 'Config' ; } $ str .= "class " . $ options [ 'class' ] . "\n" ; $ str .= "{\n" ; $ str .= $ vars ; $ str .= "}" ; break ; case 'array' : $ str .= "return array(\n" ; $ str .= $ vars ; $ str .= ");" ; break ; } if ( isset ( $ options [ 'closingtag' ] ) && $ options [ 'closingtag' ] ) { $ str .= "\n?>" ; } return $ str ; }
|
Converts an object into a php class or array string .
|
47,050
|
public function clear ( $ clause = '' ) { if ( ! $ clause ) { $ this -> reset ( ) ; } else { $ clause = 'reset' . ucfirst ( strtolower ( $ clause ) ) ; $ this -> syntax -> $ clause ( ) ; } return $ this ; }
|
Empties a query clause of current values
|
47,051
|
public function select ( $ column , $ as = null , $ count = false ) { $ this -> syntax -> setSelect ( $ column , $ as , $ count ) ; $ this -> type = 'select' ; return $ this ; }
|
Applies a select field to the pending query
|
47,052
|
public function insert ( $ table , $ ignore = false ) { $ this -> syntax -> setInsert ( $ table , $ ignore ) ; $ this -> type = 'insert' ; return $ this ; }
|
Applies an insert statement to the pending query
|
47,053
|
public function from ( $ table , $ as = null ) { $ this -> syntax -> setFrom ( $ table , $ as ) ; return $ this ; }
|
Defines the table from which data should be retrieved
|
47,054
|
public function join ( $ table , $ leftKey , $ rightKey , $ type = 'inner' ) { $ this -> syntax -> setJoin ( $ table , $ leftKey , $ rightKey , $ type ) ; return $ this ; }
|
Defines a table join to be performed for the query
|
47,055
|
public function joinRaw ( $ table , $ raw , $ type = 'inner' ) { $ this -> syntax -> setRawJoin ( $ table , $ raw , $ type ) ; return $ this ; }
|
Defines a table join to be performed for the query using a raw expression
|
47,056
|
public function innerJoin ( $ table , $ leftKey , $ rightKey ) { $ this -> syntax -> setJoin ( $ table , $ leftKey , $ rightKey , 'inner' ) ; return $ this ; }
|
Defines a table INNER join to be performed for the query
|
47,057
|
public function fullJoin ( $ table , $ leftKey , $ rightKey ) { $ this -> syntax -> setJoin ( $ table , $ leftKey , $ rightKey , 'full' ) ; return $ this ; }
|
Defines a table FULL OUTER join to be performed for the query
|
47,058
|
public function leftJoin ( $ table , $ leftKey , $ rightKey ) { $ this -> syntax -> setJoin ( $ table , $ leftKey , $ rightKey , 'left' ) ; return $ this ; }
|
Defines a table LEFT join to be performed for the query
|
47,059
|
public function rightJoin ( $ table , $ leftKey , $ rightKey ) { $ this -> syntax -> setJoin ( $ table , $ leftKey , $ rightKey , 'right' ) ; return $ this ; }
|
Defines a table RIGHT join to be performed for the query
|
47,060
|
public function orWhere ( $ column , $ operator , $ value , $ depth = 0 ) { $ this -> where ( $ column , $ operator , $ value , 'or' , $ depth ) ; return $ this ; }
|
Applies a where clause to the pending query
|
47,061
|
public function having ( $ column , $ operator , $ value ) { $ this -> syntax -> setHaving ( $ column , $ operator , $ value ) ; return $ this ; }
|
Sets the having element on the query
|
47,062
|
public function fetch ( $ structure = 'rows' , $ noCache = false ) { $ query = $ this -> buildQuery ( ) ; $ key = hash ( 'md5' , $ structure . $ query . serialize ( $ this -> syntax -> getBindings ( ) ) ) ; if ( $ noCache || ! isset ( self :: $ cache [ $ key ] ) ) { self :: $ cache [ $ key ] = $ this -> query ( $ query , $ structure ) ; } $ this -> reset ( ) ; return self :: $ cache [ $ key ] ; }
|
Retrieves all applicable data
|
47,063
|
public function push ( $ table , $ data , $ ignore = false ) { $ this -> insert ( $ table , $ ignore ) -> values ( $ data ) ; $ result = $ this -> execute ( ) ; return ! $ result ? : $ this -> connection -> insertid ( ) ; }
|
Inserts a new row using data provided into given table
|
47,064
|
public function alter ( $ table , $ pkField , $ pkValue , $ data ) { $ this -> update ( $ table ) -> set ( $ data ) ; $ this -> whereEquals ( $ pkField , $ pkValue ) ; return $ this -> execute ( ) ; }
|
Updates an existing item in the database using the provided data
|
47,065
|
public function remove ( $ table , $ pkField , $ pkValue ) { if ( is_null ( $ pkValue ) || empty ( $ pkValue ) ) { return false ; } $ this -> delete ( $ table ) -> whereEquals ( $ pkField , $ pkValue ) ; return $ this -> execute ( ) ; }
|
Removes a record by its primary key
|
47,066
|
public function execute ( ) { $ result = $ this -> query ( $ this -> buildQuery ( $ this -> type ) ) ; $ this -> reset ( ) ; return $ result ; }
|
Builds and executes the current query based on the elements present
|
47,067
|
public function query ( $ query , $ structure = null ) { list ( $ type ) = explode ( ' ' , $ query , 2 ) ; $ type = strtolower ( $ type ) ; if ( $ type == 'select' && is_null ( $ structure ) ) { $ structure = 'rows' ; } $ this -> connection -> prepare ( $ query ) -> bind ( $ this -> syntax -> getBindings ( ) ) ; $ result = ( isset ( $ structure ) ) ? $ this -> connection -> { constant ( 'self::' . strtoupper ( $ structure ) ) } ( ) : $ this -> connection -> query ( ) ; return $ result ; }
|
Performs the actual query and returns the results
|
47,068
|
private function buildQuery ( $ type = 'select' ) { $ pieces = array ( ) ; foreach ( $ this -> $ type as $ piece ) { if ( $ element = $ this -> syntax -> build ( $ piece ) ) { $ pieces [ ] = $ element ; } } return implode ( "\n" , $ pieces ) ; }
|
Builds query based on the current query elements established
|
47,069
|
private function reset ( ) { $ syntax = '\\Hubzero\\Database\\Syntax\\' . ucfirst ( $ this -> connection -> getSyntax ( ) ) ; $ this -> syntax = new $ syntax ( $ this -> connection ) ; }
|
Resets the query elements
|
47,070
|
public function spellCheck ( $ terms ) { $ scQuery = $ this -> connection -> createSelect ( ) ; $ scQuery -> setRows ( 0 ) -> getSpellcheck ( ) -> setQuery ( $ terms ) -> setCount ( '5' ) ; $ spellcheckResults = $ this -> connection -> select ( $ scQuery ) -> getSpellcheck ( ) ; return $ spellcheckResults ; }
|
spellCheck Returns terms suggestions
|
47,071
|
public function getSuggestions ( $ terms ) { $ config = $ this -> config [ 'endpoint' ] [ 'hubsearch' ] ; $ url = rtrim ( Request :: Root ( ) , '/\\' ) ; $ url .= ':' . $ config [ 'port' ] ; $ url .= '/solr/' . $ config [ 'core' ] ; $ url .= '/select?fl=id' ; $ this -> restrictAccess ( ) ; $ userPerms = $ this -> query -> getFilterQuery ( 'userPerms' ) -> getQuery ( ) ; $ url .= '&fq=' . $ userPerms ; $ url .= '&rows=0' ; $ url .= '&q=*:*' ; $ url .= '&facet=true&facet.field=author_auto&facet.field=tags_auto&facet.field=title_auto' ; $ url .= '&facet.mincount=1' ; $ url .= '&facet.prefix=' . strtolower ( $ terms ) ; $ url .= '&wt=json' ; $ client = new \ GuzzleHttp \ Client ( ) ; $ res = $ client -> get ( $ url ) ; $ resultSet = $ res -> json ( ) [ 'facet_counts' ] [ 'facet_fields' ] ; $ suggestions = array ( ) ; foreach ( $ resultSet as $ results ) { $ x = 0 ; foreach ( $ results as $ i => $ result ) { if ( $ i % 2 == 0 ) { if ( $ x >= 10 ) { break ; } array_push ( $ suggestions , $ result ) ; $ x ++ ; } } } return $ suggestions ; }
|
getSuggestions Returns indexed terms
|
47,072
|
public function available ( ) { $ package = $ this -> arguments -> getOpt ( 'package' ) ; if ( ! empty ( $ package ) ) { $ versions = Composer :: findRemotePackages ( $ package , '*' ) ; $ this -> output -> addRawFromAssocArray ( $ versions ) ; } else { $ available = Composer :: getAvailablePackages ( ) ; $ this -> output -> addRawFromAssocArray ( $ available ) ; } }
|
Show available packages
|
47,073
|
public function install ( ) { if ( $ this -> arguments -> getOpt ( 'package' ) ) { $ package = $ this -> arguments -> getOpt ( 'package' ) ; } if ( $ this -> arguments -> getOpt ( 'version' ) ) { $ version = $ this -> arguments -> getOpt ( 'version' ) ; } if ( ! isset ( $ package ) || ! isset ( $ version ) ) { $ this -> output -> error ( 'A package name and version is required' ) ; } try { Composer :: installPackage ( $ package , $ version ) ; } catch ( Exception $ e ) { } $ this -> output -> addLine ( "Done. $package($version) installed." ) ; }
|
Add a package
|
47,074
|
public function update ( ) { $ package = $ this -> arguments -> getOpt ( 'package' ) ; if ( empty ( $ package ) ) { $ this -> output -> error ( 'A package name is required' ) ; } Composer :: updatePackage ( $ package ) ; $ this -> output -> addLine ( "Done. $package updated to latest version" ) ; }
|
Update a package
|
47,075
|
public function validateToken ( ) { if ( $ this -> token !== $ this -> getToken ( ) ) { $ this -> session_id = 'public' ; } return ( $ this -> token === $ this -> getToken ( ) ) ; }
|
Validates the given token against the session date
|
47,076
|
private function decompose ( $ identifier ) { $ identifier = base64_decode ( $ identifier ) ; if ( strstr ( $ identifier , ':' ) ) { list ( $ token , $ path ) = explode ( ':' , $ identifier , 2 ) ; $ this -> token = $ token ; $ this -> path = $ path ; } }
|
Unpacks the token into meaninful bits
|
47,077
|
public function addHeader ( $ headerFieldNameOrLine , $ fieldValue = null ) { $ this -> getHeaders ( ) -> addTextHeader ( $ headerFieldNameOrLine , $ fieldValue ) ; return $ this ; }
|
Check if message needs to be sent as multipart MIME message or if it has only one part .
|
47,078
|
public function setPriority ( $ priority ) { if ( is_string ( $ priority ) ) { switch ( strtolower ( $ priority ) ) { case 'high' : $ priority = 1 ; break ; case 'normal' : $ priority = 3 ; break ; case 'low' : $ priority = 5 ; break ; default : $ priority = 3 ; break ; } } return parent :: setPriority ( $ priority ) ; }
|
Set the priority of this message . The value is an integer where 1 is the highest priority and 5 is the lowest .
|
47,079
|
public function send ( $ transporter = '' , $ options = array ( ) ) { $ transporter = $ transporter ? $ transporter : \ Config :: get ( 'mailer' ) ; if ( is_object ( $ transporter ) && ( $ transporter instanceof \ Swift_Transport ) ) { $ transport = $ transporter ; } elseif ( is_string ( $ transporter ) && self :: hasTrasporter ( $ transporter ) ) { $ transport = self :: getTrasporter ( $ transporter ) ; } else { switch ( strtolower ( $ transporter ) ) { case 'smtp' : if ( ! isset ( $ options [ 'host' ] ) ) { $ options [ 'host' ] = \ Config :: get ( 'smtphost' ) ; } if ( ! isset ( $ options [ 'port' ] ) ) { $ options [ 'port' ] = \ Config :: get ( 'smtpport' ) ; } if ( ! isset ( $ options [ 'username' ] ) ) { $ options [ 'username' ] = \ Config :: get ( 'smtpuser' ) ; } if ( ! isset ( $ options [ 'password' ] ) ) { $ options [ 'password' ] = \ Config :: get ( 'smtppass' ) ; } if ( ! empty ( $ options ) ) { $ transport = \ Swift_SmtpTransport :: newInstance ( $ options [ 'host' ] , $ options [ 'port' ] ) ; $ transport -> setUsername ( $ options [ 'username' ] ) -> setPassword ( $ options [ 'password' ] ) ; } break ; case 'sendmail' : if ( ! isset ( $ options [ 'command' ] ) ) { $ options [ 'command' ] = '/usr/sbin/exim -bs' ; } $ transport = \ Swift_SendmailTransport :: newInstance ( $ options [ 'command' ] ) ; break ; case 'mail' : default : $ transport = \ Swift_MailTransport :: newInstance ( ) ; break ; } if ( ! ( $ transport instanceof \ Swift_Transport ) ) { throw new \ InvalidArgumentException ( 'Invalid transport specified' ) ; } } $ mailer = \ Swift_Mailer :: newInstance ( $ transport ) ; $ result = $ mailer -> send ( $ this , $ this -> _failures ) ; if ( $ result ) { \ Log :: info ( sprintf ( 'Mail sent to %s' , json_encode ( $ this -> getTo ( ) ) ) ) ; } else { \ Log :: error ( sprintf ( 'Failed to mail %s' , json_encode ( $ this -> getTo ( ) ) ) ) ; } return $ result ; }
|
Send the message
|
47,080
|
public function removeAttachment ( $ attachment ) { if ( ! ( $ attachment instanceof Swift_Mime_MimeEntity ) ) { $ attachment = \ Swift_Attachment :: fromPath ( $ attachment ) ; } return $ this -> detach ( $ attachment ) ; }
|
Remove an attachment
|
47,081
|
public function getEmbed ( $ attachment ) { if ( ! ( $ attachment instanceof \ Swift_Image ) ) { $ attachment = \ Swift_Image :: fromPath ( $ attachment ) ; } return $ this -> embed ( $ attachment ) ; }
|
Get an embed string for an attachment
|
47,082
|
public function write ( $ file , $ format = 'json' , $ options = array ( ) ) { return with ( new Filesystem ( new Local ) ) -> write ( $ file , $ this -> processor ( $ format ) -> objectToString ( $ this -> data , $ options ) ) ; }
|
Write the contents of the registry to a file
|
47,083
|
public function getFields ( ) { static $ cache = null ; if ( $ cache === null ) { $ name = $ this -> _tbl ; $ fields = $ this -> _db -> getTableColumns ( $ name , false ) ; if ( empty ( $ fields ) ) { $ e = new Exception ( Lang :: txt ( 'JLIB_DATABASE_ERROR_COLUMNS_NOT_FOUND' ) ) ; $ this -> setError ( $ e ) ; return false ; } $ cache = $ fields ; } return $ cache ; }
|
Get the columns from database table .
|
47,084
|
public static function addIncludePath ( $ path = null ) { static $ _paths ; if ( ! isset ( $ _paths ) ) { $ _paths = array ( __DIR__ . '/table' ) ; } settype ( $ path , 'array' ) ; if ( ! empty ( $ path ) && ! in_array ( $ path , $ _paths ) ) { foreach ( $ path as $ dir ) { $ dir = trim ( $ dir ) ; array_unshift ( $ _paths , $ dir ) ; } } return $ _paths ; }
|
Add a filesystem path where Table should search for table class files . You may either pass a string or an array of paths .
|
47,085
|
protected function _getAssetParentId ( $ table = null , $ id = null ) { $ rootId = \ Hubzero \ Access \ Asset :: getRootId ( ) ; if ( ! empty ( $ rootId ) ) { return $ rootId ; } return 1 ; }
|
Method to get the parent asset under which to register this one . By default all assets are registered to the ROOT node with ID which will default to 1 if none exists . The extended class can define a table and id to lookup . If the asset does not exist it will be created .
|
47,086
|
public function setDBO ( & $ db ) { if ( ! ( $ db instanceof \ Hubzero \ Database \ Driver ) ) { return false ; } $ this -> _db = & $ db ; return true ; }
|
Method to set the Database connector object .
|
47,087
|
public function setRules ( $ input ) { if ( $ input instanceof \ Hubzero \ Access \ Rules ) { $ this -> _rules = $ input ; } else { $ this -> _rules = new \ Hubzero \ Access \ Rules ( $ input ) ; } }
|
Method to set rules for the record .
|
47,088
|
public function bind ( $ src , $ ignore = array ( ) ) { if ( ! is_object ( $ src ) && ! is_array ( $ src ) ) { $ e = new Exception ( Lang :: txt ( 'JLIB_DATABASE_ERROR_BIND_FAILED_INVALID_SOURCE_ARGUMENT' , get_class ( $ this ) ) ) ; $ this -> setError ( $ e ) ; return false ; } if ( is_object ( $ src ) ) { $ src = get_object_vars ( $ src ) ; } if ( ! is_array ( $ ignore ) ) { $ ignore = explode ( ' ' , $ ignore ) ; } foreach ( $ this -> getProperties ( ) as $ k => $ v ) { if ( ! in_array ( $ k , $ ignore ) ) { if ( isset ( $ src [ $ k ] ) ) { $ this -> $ k = $ src [ $ k ] ; } } } return true ; }
|
Method to bind an associative array or object to the Table instance . This method only binds properties that are publicly accessible and optionally takes an array of properties to ignore when binding .
|
47,089
|
public function load ( $ keys = null , $ reset = true ) { if ( empty ( $ keys ) ) { $ keyName = $ this -> _tbl_key ; $ keyValue = $ this -> $ keyName ; if ( empty ( $ keyValue ) ) { return true ; } $ keys = array ( $ keyName => $ keyValue ) ; } elseif ( ! is_array ( $ keys ) ) { $ keys = array ( $ this -> _tbl_key => $ keys ) ; } if ( $ reset ) { $ this -> reset ( ) ; } $ query = $ this -> _db -> getQuery ( ) ; $ query -> select ( '*' ) ; $ query -> from ( $ this -> _tbl ) ; $ fields = array_keys ( $ this -> getProperties ( ) ) ; foreach ( $ keys as $ field => $ value ) { if ( ! in_array ( $ field , $ fields ) ) { $ e = new Exception ( Lang :: txt ( 'JLIB_DATABASE_ERROR_CLASS_IS_MISSING_FIELD' , get_class ( $ this ) , $ field ) ) ; $ this -> setError ( $ e ) ; return false ; } $ query -> whereEquals ( $ field , $ value ) ; } $ this -> _db -> setQuery ( $ query -> toString ( ) ) ; try { $ row = $ this -> _db -> loadAssoc ( ) ; } catch ( Exception $ e ) { $ je = new Exception ( $ e -> getMessage ( ) ) ; $ this -> setError ( $ je ) ; return false ; } if ( empty ( $ row ) ) { $ e = new Exception ( Lang :: txt ( 'JLIB_DATABASE_ERROR_EMPTY_ROW_RETURNED' ) ) ; $ this -> setError ( $ e ) ; return false ; } return $ this -> bind ( $ row ) ; }
|
Method to load a row from the database by primary key and bind the fields to the Table instance properties .
|
47,090
|
public function save ( $ src , $ orderingFilter = '' , $ ignore = '' ) { if ( ! $ this -> bind ( $ src , $ ignore ) ) { return false ; } if ( ! $ this -> check ( ) ) { return false ; } if ( ! $ this -> store ( ) ) { return false ; } if ( ! $ this -> checkin ( ) ) { return false ; } if ( $ orderingFilter ) { $ filterValue = $ this -> $ orderingFilter ; $ this -> reorder ( $ orderingFilter ? $ this -> _db -> quoteName ( $ orderingFilter ) . ' = ' . $ this -> _db -> Quote ( $ filterValue ) : '' ) ; } $ this -> setError ( '' ) ; return true ; }
|
Method to provide a shortcut to binding checking and storing a Table instance to the database table . The method will check a row in once the data has been stored and if an ordering filter is present will attempt to reorder the table rows based on the filter . The ordering filter is an instance property name . The rows that will be reordered are those whose value matches the Table instance for the property specified .
|
47,091
|
public function getNextOrder ( $ where = '' ) { if ( ! property_exists ( $ this , 'ordering' ) ) { $ e = new Exception ( Lang :: txt ( 'JLIB_DATABASE_ERROR_CLASS_DOES_NOT_SUPPORT_ORDERING' , get_class ( $ this ) ) ) ; $ this -> setError ( $ e ) ; return false ; } $ query = $ this -> _db -> getQuery ( ) ; $ query -> select ( 'MAX(ordering)' ) ; $ query -> from ( $ this -> _tbl ) ; if ( $ where ) { $ query -> whereRaw ( $ where ) ; } $ this -> _db -> setQuery ( $ query -> toString ( ) ) ; $ max = ( int ) $ this -> _db -> loadResult ( ) ; if ( $ this -> _db -> getErrorNum ( ) ) { $ e = new Exception ( Lang :: txt ( 'JLIB_DATABASE_ERROR_GET_NEXT_ORDER_FAILED' , get_class ( $ this ) , $ this -> _db -> getErrorMsg ( ) ) ) ; $ this -> setError ( $ e ) ; return false ; } return ( $ max + 1 ) ; }
|
Method to get the next ordering value for a group of rows defined by an SQL WHERE clause . This is useful for placing a new item last in a group of items in the table .
|
47,092
|
public function reorder ( $ where = '' ) { if ( ! property_exists ( $ this , 'ordering' ) ) { $ e = new Exception ( Lang :: txt ( 'JLIB_DATABASE_ERROR_CLASS_DOES_NOT_SUPPORT_ORDERING' , get_class ( $ this ) ) ) ; $ this -> setError ( $ e ) ; return false ; } $ k = $ this -> _tbl_key ; $ query = $ this -> _db -> getQuery ( ) ; $ query -> select ( $ this -> _tbl_key ) ; $ query -> select ( 'ordering' ) ; $ query -> from ( $ this -> _tbl ) ; $ query -> where ( 'ordering' , '>=' , '0' ) ; $ query -> order ( 'ordering' , 'asc' ) ; if ( $ where ) { $ query -> whereRaw ( $ where ) ; } $ this -> _db -> setQuery ( $ query -> toString ( ) ) ; $ rows = $ this -> _db -> loadObjectList ( ) ; if ( $ this -> _db -> getErrorNum ( ) ) { $ e = new Exception ( Lang :: txt ( 'JLIB_DATABASE_ERROR_REORDER_FAILED' , get_class ( $ this ) , $ this -> _db -> getErrorMsg ( ) ) ) ; $ this -> setError ( $ e ) ; return false ; } foreach ( $ rows as $ i => $ row ) { if ( $ row -> ordering >= 0 ) { if ( $ row -> ordering != $ i + 1 ) { $ query = $ this -> _db -> getQuery ( ) ; $ query -> update ( $ this -> _tbl ) ; $ query -> set ( array ( 'ordering' => ( $ i + 1 ) ) ) ; $ query -> whereEquals ( $ this -> _tbl_key , $ row -> $ k ) ; $ this -> _db -> setQuery ( $ query -> toString ( ) ) ; if ( ! $ this -> _db -> execute ( ) ) { $ e = new Exception ( Lang :: txt ( 'JLIB_DATABASE_ERROR_REORDER_UPDATE_ROW_FAILED' , get_class ( $ this ) , $ i , $ this -> _db -> getErrorMsg ( ) ) ) ; $ this -> setError ( $ e ) ; return false ; } } } } return true ; }
|
Method to compact the ordering values of rows in a group of rows defined by an SQL WHERE clause .
|
47,093
|
public function publish ( $ pks = null , $ state = 1 , $ userId = 0 ) { $ k = $ this -> _tbl_key ; \ Hubzero \ Utility \ Arr :: toInteger ( $ pks ) ; $ userId = ( int ) $ userId ; $ state = ( int ) $ state ; if ( empty ( $ pks ) ) { if ( $ this -> $ k ) { $ pks = array ( $ this -> $ k ) ; } else { $ e = new Exception ( Lang :: txt ( 'JLIB_DATABASE_ERROR_NO_ROWS_SELECTED' ) ) ; $ this -> setError ( $ e ) ; return false ; } } $ query = $ this -> _db -> getQuery ( ) ; $ query -> update ( $ this -> _tbl ) ; $ query -> set ( array ( 'published' => ( int ) $ state ) ) ; if ( property_exists ( $ this , 'checked_out' ) || property_exists ( $ this , 'checked_out_time' ) ) { $ query -> whereEquals ( 'checked_out' , 0 , 1 ) -> orWhereEquals ( 'checked_out' , ( int ) $ userId , 1 ) -> resetDepth ( ) ; $ checkin = true ; } else { $ checkin = false ; } $ query -> whereRaw ( $ k . ' = ' . implode ( ' OR ' . $ k . ' = ' , $ pks ) ) ; $ this -> _db -> setQuery ( $ query -> toString ( ) ) ; if ( ! $ this -> _db -> execute ( ) ) { $ e = new Exception ( Lang :: txt ( 'JLIB_DATABASE_ERROR_PUBLISH_FAILED' , get_class ( $ this ) , $ this -> _db -> getErrorMsg ( ) ) ) ; $ this -> setError ( $ e ) ; return false ; } if ( $ checkin && ( count ( $ pks ) == $ this -> _db -> getAffectedRows ( ) ) ) { foreach ( $ pks as $ pk ) { $ this -> checkin ( $ pk ) ; } } if ( in_array ( $ this -> $ k , $ pks ) ) { $ this -> published = $ state ; } $ this -> setError ( '' ) ; return true ; }
|
Method to set the publishing state for a row or list of rows in the database table . The method respects checked out rows by other users and will attempt to checkin rows that it can after adjustments are made .
|
47,094
|
public function canDelete ( $ pk = null , $ joins = null ) { Log :: debug ( 'Hubzero\Database\Table::canDelete() is deprecated.' ) ; $ k = $ this -> _tbl_key ; $ pk = ( is_null ( $ pk ) ) ? $ this -> $ k : $ pk ; if ( $ pk === null ) { return false ; } if ( is_array ( $ joins ) ) { $ query = $ this -> _db -> getQuery ( ) ; $ query -> select ( $ this -> _tbl_key ) ; $ query -> from ( $ this -> _tbl ) ; $ query -> whereEquals ( $ this -> _tbl_key , $ this -> $ k ) ; $ query -> group ( $ this -> _tbl_key ) ; foreach ( $ joins as $ table ) { $ query -> select ( 'COUNT(DISTINCT ' . $ table [ 'idfield' ] . ')' , $ table [ 'idfield' ] ) ; $ query -> join ( $ table [ 'name' ] , $ table [ 'joinfield' ] , $ k , 'left' ) ; } $ this -> _db -> setQuery ( ( string ) $ query -> toString ( ) , 0 , 1 ) ; $ row = $ this -> _db -> loadObject ( ) ; if ( $ this -> _db -> getErrorNum ( ) ) { $ this -> setError ( $ this -> _db -> getErrorMsg ( ) ) ; return false ; } $ msg = array ( ) ; $ i = 0 ; foreach ( $ joins as $ table ) { $ k = $ table [ 'idfield' ] . $ i ; if ( $ row -> $ k ) { $ msg [ ] = Lang :: txt ( $ table [ 'label' ] ) ; } $ i ++ ; } if ( count ( $ msg ) ) { $ this -> setError ( "noDeleteRecord" . ": " . implode ( ', ' , $ msg ) ) ; return false ; } else { return true ; } } return true ; }
|
Generic check for whether dependencies exist for this object in the database schema
|
47,095
|
public function toXML ( $ mapKeysToText = false ) { Log :: debug ( 'Hubzero\Database\Table::toXML() is deprecated.' ) ; $ xml = array ( ) ; $ map = $ mapKeysToText ? ' mapkeystotext="true"' : '' ; $ xml [ ] = '<record table="' . $ this -> _tbl . '"' . $ map . '>' ; foreach ( get_object_vars ( $ this ) as $ k => $ v ) { if ( ! is_scalar ( $ v ) || ( $ v === null ) || ( $ k [ 0 ] == '_' ) ) { continue ; } $ xml [ ] = ' <' . $ k . '><![CDATA[' . $ v . ']]></' . $ k . '>' ; } $ xml [ ] = '</record>' ; return implode ( "\n" , $ xml ) ; }
|
Method to export the Table instance properties to an XML string .
|
47,096
|
protected function _lock ( ) { $ this -> _db -> lockTable ( $ this -> _tbl ) ; $ this -> _locked = true ; return true ; }
|
Method to lock the database table for writing .
|
47,097
|
public function check ( $ data ) { $ results = array ( ) ; $ data = $ this -> prepareData ( $ data ) ; foreach ( $ data as $ datum ) { $ results [ ] = array ( 'data' => $ datum , 'tests' => $ this -> process ( $ datum ) ) ; } if ( $ this -> log ) { $ this -> log ( $ results ) ; } return $ results ; }
|
Process data against a series of tests
|
47,098
|
public function process ( array $ datum ) { $ results = array ( ) ; foreach ( $ this -> tests as $ key => $ tester ) { $ result = $ tester -> examine ( $ datum ) ; $ result -> set ( 'scope' , $ this -> scope ) ; $ result -> set ( 'test_id' , $ key ) ; $ results [ $ tester -> name ( ) ] = $ result ; } return $ results ; }
|
Run the tests against a single data point
|
47,099
|
public function install ( ) { $ configuration = $ this -> arguments -> getOpt ( 3 , 'production' ) ; $ args = [ ] ; switch ( $ configuration ) { case 'development' : case 'staging' : $ args [ ] = '--prefer-source' ; break ; case 'production' : default : $ args [ ] = '--no-dev' ; break ; } if ( $ this -> output -> getMode ( ) != 'minimal' ) { $ this -> output -> addString ( 'Installing any missing libraries from composer...' , 'info' ) ; } $ cmd = 'php ' . PATH_CORE . DS . 'bin' . DS . 'composer --working-dir=' . PATH_CORE . ' install ' . implode ( ' ' , $ args ) . ' 2>&1' ; exec ( $ cmd , $ output , $ status ) ; if ( $ this -> output -> getMode ( ) != 'minimal' ) { if ( $ status === 0 ) { $ this -> output -> addLine ( 'complete' , 'success' ) ; } else { $ this -> output -> error ( 'failed' ) ; } } else { if ( $ status !== 0 ) { $ this -> output -> error ( 'Failed to update package repository!' ) ; } } if ( $ configuration == 'development' || $ configuration == 'staging' ) { $ this -> configure ( ) ; } if ( $ this -> output -> getMode ( ) != 'minimal' ) { $ this -> output -> addLine ( 'Installation complete!' , 'success' ) ; } }
|
Installs the package repository
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.