idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
55,800
|
public function snippet ( $ field , $ tag = 'b' , $ separator = '...' , $ maxSize = 200 , $ maxNumber = 1 , $ fragmenter = self :: SNIPPET_NO_FRAGMENTER ) { if ( empty ( $ this -> data [ 'snippets' ] ) ) { $ this -> data [ 'snippets' ] = array ( ) ; } $ this -> data [ 'snippets' ] [ ] = array ( 'field' => $ field , 'tag' => $ tag , 'separator' => $ separator , 'maxSize' => $ maxSize , 'maxNumber' => $ maxNumber , 'fragmenter' => $ fragmenter , ) ; return $ this ; }
|
Add one snippet
|
55,801
|
public function scoring ( $ field = null , $ weight = 1 , $ ascending = false , $ type = self :: SCORING_FIELD_ORDER ) { if ( empty ( $ this -> data [ 'scorings' ] ) ) { $ this -> data [ 'scorings' ] = array ( ) ; } $ newScoring = array ( 'ascending' => ( boolean ) $ ascending , 'type' => $ type , 'weight' => $ weight ) ; if ( ! empty ( $ field ) ) { $ newScoring [ 'field' ] = $ field ; } $ this -> data [ 'scorings' ] [ ] = $ newScoring ; return $ this ; }
|
Add one level of scoring
|
55,802
|
public function boostingQuery ( $ query , $ boost = 1 ) { if ( empty ( $ this -> data [ 'boostingQueries' ] ) ) { $ this -> data [ 'boostingQueries' ] = array ( ) ; } $ newBoosting = array ( 'patternQuery' => $ query , 'boost' => $ boost ) ; $ this -> data [ 'boostingQueries' ] [ ] = $ newBoosting ; return $ this ; }
|
Add one boosting query
|
55,803
|
public function join ( $ indexName , $ queryTemplate , $ queryString , $ localField , $ foreignField , $ type = self :: JOIN_INNER , $ returnFields = true , $ returnScores = false , $ returnFacets = false ) { if ( empty ( $ this -> data [ 'joins' ] ) ) { $ this -> data [ 'joins' ] = array ( ) ; } $ this -> data [ 'joins' ] [ ] = array ( 'indexName' => $ indexName , 'queryTemplate' => $ queryTemplate , 'queryString' => $ queryString , 'localField' => $ localField , 'foreignField' => $ foreignField , 'type' => $ type , 'returnFields' => $ returnFields , 'returnScores' => $ returnScores , 'returnFacets' => $ returnFacets ) ; return $ this ; }
|
Add one join
|
55,804
|
private function normalizeTagCounts ( & $ tagsArray , $ tagCounts ) { $ maxFontSize = 200 ; $ minFontSize = 100 ; $ maxCount = max ( $ tagCounts ) ; $ minCount = min ( $ tagCounts ) ; $ spread = $ maxCount - $ minCount ; if ( $ spread == 0 ) $ spread = 1 ; $ step = ( $ maxFontSize - $ minFontSize ) / ( $ spread ) ; foreach ( $ tagsArray as $ index => $ tagItem ) { $ tagsArray [ $ index ] [ 'font_size' ] = $ minFontSize + ( ( $ tagItem [ 'count' ] - $ minCount ) * $ step ) ; } }
|
Normalizes the count of tags to be able to be displayed properly on the page
|
55,805
|
public function connect ( $ host , $ ssl = false , $ port = 21 , $ timeout = 90 ) { if ( $ ssl ) { $ this -> connection = @ ftp_ssl_connect ( $ host , $ port , $ timeout ) ; } else { $ this -> connection = @ ftp_connect ( $ host , $ port , $ timeout ) ; } if ( $ this -> connection == null ) { throw new Exception ( 'Unable to connect' ) ; } else { return $ this ; } }
|
Opens a FTP connection
|
55,806
|
public function login ( $ username = 'anonymous' , $ password = '' ) { $ result = @ ftp_login ( $ this -> connection , $ username , $ password ) ; if ( $ result === false ) { throw new Exception ( 'Login incorrect' ) ; } else { if ( ! is_null ( $ this -> passive ) ) { $ this -> passive ( $ this -> passive ) ; } return $ this ; } }
|
Logins to FTP Server
|
55,807
|
public function passive ( $ passive = true ) { $ this -> passive = $ passive ; if ( $ this -> connection ) { $ result = ftp_pasv ( $ this -> connection , $ passive ) ; if ( $ result === false ) { throw new Exception ( 'Unable to change passive mode' ) ; } } return $ this ; }
|
Changes passive mode
|
55,808
|
public function changeDirectory ( $ directory ) { $ result = @ ftp_chdir ( $ this -> connection , $ directory ) ; if ( $ result === false ) { throw new Exception ( 'Unable to change directory' ) ; } return $ this ; }
|
Changes the current directory to the specified one
|
55,809
|
public function delete ( $ path ) { $ result = @ ftp_delete ( $ this -> connection , $ path ) ; if ( $ result === false ) { throw new Exception ( 'Unable to get parent folder' ) ; } return $ this ; }
|
Deletes a file on the FTP server
|
55,810
|
public function size ( $ remoteFile ) { $ size = @ ftp_size ( $ this -> connection , $ remoteFile ) ; if ( $ size === - 1 ) { throw new Exception ( 'Unable to get file size' ) ; } return $ size ; }
|
Returns the size of the given file . Return - 1 on error
|
55,811
|
public function rename ( $ currentName , $ newName ) { $ result = @ ftp_rename ( $ this -> connection , $ currentName , $ newName ) ; return $ result ; }
|
Renames a file or a directory on the FTP server
|
55,812
|
public function getOption ( $ option ) { switch ( $ option ) { case FTPClient :: TIMEOUT_SEC : case FTPClient :: AUTOSEEK : $ result = @ ftp_get_option ( $ this -> connection , $ option ) ; return $ result ; break ; default : throw new Exception ( 'Unsupported option' ) ; break ; } }
|
Retrieves various runtime behaviours of the current FTP stream TIMEOUT_SEC | AUTOSEEK
|
55,813
|
public function setOption ( $ option , $ value ) { switch ( $ option ) { case FTPClient :: TIMEOUT_SEC : if ( $ value <= 0 ) { throw new Exception ( 'Timeout value must be greater than zero' ) ; } break ; case FTPClient :: AUTOSEEK : if ( ! is_bool ( $ value ) ) { throw new Exception ( 'Autoseek value must be boolean' ) ; } break ; default : throw new Exception ( 'Unsupported option' ) ; break ; } return @ ftp_set_option ( $ this -> connection , $ option , $ value ) ; }
|
Set miscellaneous runtime FTP options TIMEOUT_SEC | AUTOSEEK
|
55,814
|
public function chmod ( $ mode , $ filename ) { $ result = @ ftp_chmod ( $ this -> connection , $ mode , $ filename ) ; if ( $ result === false ) { throw new Exception ( 'Unable to change permissions' ) ; } return $ this ; }
|
Set permissions on a file via FTP
|
55,815
|
public function exec ( $ command ) { $ result = @ ftp_exec ( $ this -> connection , $ command ) ; if ( $ result === false ) { throw new Exception ( 'Unable to exec command' ) ; } return $ this ; }
|
Requests execution of a command on the FTP server
|
55,816
|
public function find ( $ key ) { if ( isset ( $ this -> payload [ $ key ] ) ) { return $ this -> payload [ $ key ] ; } return null ; }
|
Find a value from array with given key .
|
55,817
|
public function getIssues ( ) : array { usort ( $ this -> issues , function ( Issue $ a , Issue $ b ) { return $ a -> getLine ( ) - $ b -> getLine ( ) ; } ) ; return $ this -> issues ; }
|
Gets all issues for this file . The issues will be sorted by line numbers not by order of addition to this report .
|
55,818
|
public function getIssuesBySeverity ( string $ severity ) : array { return array_values ( array_filter ( $ this -> getIssues ( ) , function ( Issue $ i ) use ( $ severity ) { return $ i -> getSeverity ( ) === $ severity ; } ) ) ; }
|
Gets all issues for this file that have a certain severity .
|
55,819
|
public function merge ( File $ other ) : self { $ new = new static ( $ this -> filename ) ; $ new -> issues = array_merge ( $ this -> issues , $ other -> issues ) ; return $ new ; }
|
Merges this file report with another file report
|
55,820
|
public function execute ( ) { $ methods = array_values ( $ this -> implementedEvents ( ) ) ; foreach ( $ methods as $ method ) { $ this -> dispatchEvent ( sprintf ( 'Bake.%s' , $ method ) , null , $ this -> event -> subject ) ; } }
|
Dispatches all the attached events
|
55,821
|
public function isType ( $ type ) { $ template = sprintf ( 'Bake/%s.ctp' , $ type ) ; return strpos ( $ this -> event -> getData ( '0' ) , $ template ) !== false ; }
|
Check whether or not a bake call is a certain type .
|
55,822
|
public function implementedEvents ( ) { $ methodMap = [ 'config/routes' => 'beforeRenderRoutes' , 'Controller/component' => 'beforeRenderComponent' , 'Controller/controller' => 'beforeRenderController' , 'Model/behavior' => 'beforeRenderBehavior' , 'Model/entity' => 'beforeRenderEntity' , 'Model/table' => 'beforeRenderTable' , 'Shell/shell' => 'beforeRenderShell' , 'View/cell' => 'beforeRenderCell' , 'View/helper' => 'beforeRenderHelper' , 'tests/test_case' => 'beforeRenderTestCase' , ] ; $ events = [ ] ; foreach ( $ methodMap as $ template => $ method ) { if ( $ this -> isType ( $ template ) && method_exists ( $ this , $ method ) ) { $ events [ sprintf ( 'Bake.%s' , $ method ) ] = $ method ; } } return $ events ; }
|
Get the callbacks this class is interested in .
|
55,823
|
public function version ( $ versionId , $ reset = false ) { $ versions = $ this -> versions ( $ reset ) ; if ( empty ( $ versions [ $ versionId ] ) ) { return null ; } return $ versions [ $ versionId ] ; }
|
Retrieves a specified version for the current entity
|
55,824
|
public function versions ( $ reset = false ) { if ( $ reset === false && $ this -> has ( '_versions' ) ) { return $ this -> get ( '_versions' ) ; } $ table = TableRegistry :: get ( $ this -> getSource ( ) ) ; $ versions = $ table -> getVersions ( $ this ) ; $ this -> set ( '_versions' , $ versions ) ; return $ this -> get ( '_versions' ) ; }
|
Retrieves the related versions for the current entity
|
55,825
|
public function getSourceFieldName ( $ media_type ) { $ bundle = $ this -> entityTypeManager -> getStorage ( 'media_type' ) -> load ( $ media_type ) ; if ( ! $ bundle ) { throw new NotFoundHttpException ( "Bundle $media_type does not exist" ) ; } $ type_configuration = $ bundle -> get ( 'source_configuration' ) ; if ( ! isset ( $ type_configuration [ 'source_field' ] ) ) { return NULL ; } return $ type_configuration [ 'source_field' ] ; }
|
Gets the name of a source field for a Media .
|
55,826
|
public function getSourceFile ( MediaInterface $ media ) { $ source_field = $ this -> getSourceFieldName ( $ media -> bundle ( ) ) ; if ( empty ( $ source_field ) ) { throw new NotFoundHttpException ( "Source field not set for {$media->bundle()} media" ) ; } $ files = $ media -> get ( $ source_field ) -> referencedEntities ( ) ; $ file = reset ( $ files ) ; return $ file ; }
|
Gets the value of a source field for a Media .
|
55,827
|
public function updateSourceField ( MediaInterface $ media , $ resource , $ mimetype ) { $ source_field = $ this -> getSourceFieldName ( $ media -> bundle ( ) ) ; $ file = $ this -> getSourceFile ( $ media ) ; $ this -> updateFile ( $ file , $ resource , $ mimetype ) ; $ file -> save ( ) ; foreach ( $ media -> bundle -> entity -> getFieldMap ( ) as $ source => $ destination ) { if ( $ media -> hasField ( $ destination ) && $ value = $ media -> getSource ( ) -> getMetadata ( $ media , $ source ) ) { $ media -> set ( $ destination , $ value ) ; } if ( $ source == 'width' || $ source == 'height' ) { $ media -> get ( $ source_field ) -> first ( ) -> set ( $ source , $ value ) ; } } $ media -> save ( ) ; }
|
Updates a media s source field with the supplied resource .
|
55,828
|
protected function updateFile ( FileInterface $ file , $ resource , $ mimetype = NULL ) { $ uri = $ file -> getFileUri ( ) ; $ destination = fopen ( $ uri , 'wb' ) ; if ( ! $ destination ) { throw new HttpException ( 500 , "File $uri could not be opened to write." ) ; } $ content_length = stream_copy_to_stream ( $ resource , $ destination ) ; fclose ( $ destination ) ; if ( $ content_length === FALSE ) { throw new HttpException ( 500 , "Request body could not be copied to $uri" ) ; } if ( $ content_length === 0 ) { unlink ( $ uri ) ; throw new HttpException ( 400 , "No bytes were copied to $uri" ) ; } if ( ! empty ( $ mimetype ) ) { $ file -> setMimeType ( $ mimetype ) ; } image_path_flush ( $ uri ) ; }
|
Updates a File s binary contents on disk .
|
55,829
|
public function putToNode ( NodeInterface $ node , MediaTypeInterface $ media_type , TermInterface $ taxonomy_term , $ resource , $ mimetype , $ content_location ) { $ existing = $ this -> islandoraUtils -> getMediaReferencingNodeAndTerm ( $ node , $ taxonomy_term ) ; if ( ! empty ( $ existing ) ) { $ media = $ this -> entityTypeManager -> getStorage ( 'media' ) -> load ( reset ( $ existing ) ) ; $ this -> updateSourceField ( $ media , $ resource , $ mimetype ) ; return FALSE ; } else { $ bundle = $ media_type -> id ( ) ; $ source_field = $ this -> getSourceFieldName ( $ bundle ) ; if ( empty ( $ source_field ) ) { throw new NotFoundHttpException ( "Source field not set for $bundle media" ) ; } $ file = $ this -> entityTypeManager -> getStorage ( 'file' ) -> create ( [ 'uid' => $ this -> account -> id ( ) , 'uri' => $ content_location , 'filename' => $ this -> fileSystem -> basename ( $ content_location ) , 'filemime' => $ mimetype , 'status' => FILE_STATUS_PERMANENT , ] ) ; $ source_field_config = $ this -> entityTypeManager -> getStorage ( 'field_config' ) -> load ( "media.$bundle.$source_field" ) ; $ valid_extensions = $ source_field_config -> getSetting ( 'file_extensions' ) ; $ errors = file_validate_extensions ( $ file , $ valid_extensions ) ; if ( ! empty ( $ errors ) ) { throw new BadRequestHttpException ( "Invalid file extension. Valid types are $valid_extensions" ) ; } $ directory = $ this -> fileSystem -> dirname ( $ content_location ) ; if ( ! file_prepare_directory ( $ directory , FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS ) ) { throw new HttpException ( 500 , "The destination directory does not exist, could not be created, or is not writable" ) ; } $ this -> updateFile ( $ file , $ resource , $ mimetype ) ; $ file -> save ( ) ; $ media_struct = [ 'bundle' => $ bundle , 'uid' => $ this -> account -> id ( ) , 'name' => $ file -> getFilename ( ) , 'langcode' => $ this -> languageManager -> getDefaultLanguage ( ) -> getId ( ) , "$source_field" => [ 'target_id' => $ file -> id ( ) , ] , IslandoraUtils :: MEDIA_OF_FIELD => [ 'target_id' => $ node -> id ( ) , ] , IslandoraUtils :: MEDIA_USAGE_FIELD => [ 'target_id' => $ taxonomy_term -> id ( ) , ] , ] ; if ( $ source_field_config -> getSetting ( 'alt_field' ) && $ source_field_config -> getSetting ( 'alt_field_required' ) ) { $ media_struct [ $ source_field ] [ 'alt' ] = $ file -> getFilename ; } $ media = $ this -> entityTypeManager -> getStorage ( 'media' ) -> create ( $ media_struct ) ; $ media -> save ( ) ; return $ media ; } }
|
Creates a new Media using the provided resource adding it to a Node .
|
55,830
|
protected function generateTypeList ( $ entity_type , $ bundle_type , $ entity_add_form , $ bundle_add_form , NodeInterface $ node , $ field ) { $ type_definition = $ this -> entityTypeManager -> getDefinition ( $ bundle_type ) ; $ build = [ '#theme' => 'entity_add_list' , '#bundles' => [ ] , '#cache' => [ 'tags' => $ type_definition -> getListCacheTags ( ) ] , ] ; $ bundles = $ this -> entityTypeManager -> getStorage ( $ bundle_type ) -> loadMultiple ( ) ; $ access_control_handler = $ this -> entityTypeManager -> getAccessControlHandler ( $ entity_type ) ; foreach ( array_keys ( $ bundles ) as $ bundle_id ) { $ bundle = $ bundles [ $ bundle_id ] ; $ fields = $ this -> entityFieldManager -> getFieldDefinitions ( $ entity_type , $ bundle_id ) ; if ( ! isset ( $ fields [ $ field ] ) ) { continue ; } $ build [ '#bundles' ] [ $ bundle_id ] = [ 'label' => $ bundle -> label ( ) , 'description' => $ bundle -> getDescription ( ) , 'add_link' => Link :: createFromRoute ( $ bundle -> label ( ) , $ entity_add_form , [ $ bundle_type => $ bundle -> id ( ) ] , [ 'query' => [ "edit[$field][widget][0][target_id]" => $ node -> id ( ) ] ] ) , ] ; } foreach ( array_keys ( $ bundles ) as $ bundle_id ) { $ access = $ access_control_handler -> createAccess ( $ bundle_id , NULL , [ ] , TRUE ) ; if ( ! $ access -> isAllowed ( ) ) { unset ( $ build [ '#bundles' ] [ $ bundle_id ] ) ; } $ this -> renderer -> addCacheableDependency ( $ build , $ access ) ; } $ type_label = $ type_definition -> getLowercaseLabel ( ) ; $ link_text = $ this -> t ( 'Add a new @entity_type.' , [ '@entity_type' => $ type_label ] ) ; $ build [ '#add_bundle_message' ] = $ this -> t ( 'There is no @entity_type yet. @add_link' , [ '@entity_type' => $ type_label , '@add_link' => Link :: createFromRoute ( $ link_text , $ bundle_add_form ) -> toString ( ) , ] ) ; return $ build ; }
|
Renders a list of content types to add as members .
|
55,831
|
protected function getFaceList ( ) { if ( ! function_exists ( 'face_detect' ) ) { $ msg = 'PHP Facedetect extension must be installed. See http://www.xarg.org/project/php-facedetect/ for more details' ; throw new \ Exception ( $ msg ) ; } if ( $ this -> maxExecutionTime ) { $ timeBefore = microtime ( true ) ; } $ faceList = $ this -> getFaceListFromClassifier ( self :: CLASSIFIER_FACE ) ; if ( $ this -> maxExecutionTime ) { $ timeSpent = microtime ( true ) - $ timeBefore ; } if ( ! $ this -> maxExecutionTime || $ timeSpent < ( $ this -> maxExecutionTime / 2 ) ) { $ profileList = $ this -> getFaceListFromClassifier ( self :: CLASSIFIER_PROFILE ) ; $ faceList = array_merge ( $ faceList , $ profileList ) ; } return $ faceList ; }
|
getFaceList get faces positions and sizes
|
55,832
|
protected function getMetadataFromHeaders ( Response $ response ) { $ last_modified = \ DateTime :: createFromFormat ( \ DateTime :: RFC1123 , $ response -> getHeader ( 'Last-Modified' ) [ 0 ] ) ; $ type = 'dir' ; $ links = Psr7 \ parse_header ( $ response -> getHeader ( 'Link' ) ) ; foreach ( $ links as $ link ) { if ( $ link [ 'rel' ] == 'type' && $ link [ 0 ] == '<http://www.w3.org/ns/ldp#NonRDFSource>' ) { $ type = 'file' ; break ; } } $ meta = [ 'type' => $ type , 'timestamp' => $ last_modified -> getTimestamp ( ) , ] ; if ( $ type == 'file' ) { $ meta [ 'size' ] = $ response -> getHeader ( 'Content-Length' ) [ 0 ] ; $ meta [ 'mimetype' ] = $ response -> getHeader ( 'Content-Type' ) [ 0 ] ; } return $ meta ; }
|
Gets metadata from response headers .
|
55,833
|
private function deleteTombstone ( $ path ) { $ response = $ this -> fedora -> getResourceHeaders ( $ path ) ; $ return = NULL ; if ( $ response -> getStatusCode ( ) == 410 ) { $ return = FALSE ; $ link_headers = Psr7 \ parse_header ( $ response -> getHeader ( 'Link' ) ) ; if ( $ link_headers ) { $ tombstones = array_filter ( $ link_headers , function ( $ o ) { return ( isset ( $ o [ 'rel' ] ) && $ o [ 'rel' ] == 'hasTombstone' ) ; } ) ; foreach ( $ tombstones as $ tombstone ) { $ url = rtrim ( ltrim ( $ tombstone [ 0 ] , '<' ) , '>' ) ; $ response = $ this -> fedora -> deleteResource ( $ url ) ; if ( $ response -> getStatusCode ( ) == 204 ) { $ return = TRUE ; } } } } return $ return ; }
|
Delete a tombstone for a path if it exists .
|
55,834
|
public function put ( MediaInterface $ media , Request $ request ) { $ content_type = $ request -> headers -> get ( 'Content-Type' , "" ) ; if ( empty ( $ content_type ) ) { throw new BadRequestHttpException ( "Missing Content-Type header" ) ; } $ transaction = $ this -> database -> startTransaction ( ) ; try { $ this -> service -> updateSourceField ( $ media , $ request -> getContent ( TRUE ) , $ content_type ) ; return new Response ( "" , 204 ) ; } catch ( HttpException $ e ) { $ transaction -> rollBack ( ) ; throw $ e ; } catch ( \ Exception $ e ) { $ transaction -> rollBack ( ) ; throw new HttpException ( 500 , $ e -> getMessage ( ) ) ; } }
|
Updates a source file for a Media .
|
55,835
|
public function putToNode ( NodeInterface $ node , MediaTypeInterface $ media_type , TermInterface $ taxonomy_term , Request $ request ) { $ content_type = $ request -> headers -> get ( 'Content-Type' , "" ) ; if ( empty ( $ content_type ) ) { throw new BadRequestHttpException ( "Missing Content-Type header" ) ; } $ content_location = $ request -> headers -> get ( 'Content-Location' , "" ) ; $ transaction = $ this -> database -> startTransaction ( ) ; try { $ media = $ this -> service -> putToNode ( $ node , $ media_type , $ taxonomy_term , $ request -> getContent ( TRUE ) , $ content_type , $ content_location ) ; if ( $ media ) { $ response = new Response ( "" , 201 ) ; $ response -> headers -> set ( "Location" , $ media -> url ( 'canonical' , [ 'absolute' => TRUE ] ) ) ; } else { $ response = new Response ( "" , 204 ) ; } return $ response ; } catch ( HttpException $ e ) { $ transaction -> rollBack ( ) ; throw $ e ; } catch ( \ Exception $ e ) { $ transaction -> rollBack ( ) ; throw new HttpException ( 500 , $ e -> getMessage ( ) ) ; } }
|
Adds a Media to a Node using the specified field .
|
55,836
|
public function putToNodeAccess ( AccountInterface $ account , RouteMatch $ route_match ) { $ node = $ route_match -> getParameter ( 'node' ) ; return AccessResult :: allowedIf ( $ node -> access ( 'update' , $ account ) && $ account -> hasPermission ( 'create media' ) ) ; }
|
Checks for permissions to update a node and create media .
|
55,837
|
public static function addJwt ( JwtAuth $ jwt ) { return function ( callable $ handler ) use ( $ jwt ) { return function ( RequestInterface $ request , array $ options ) use ( $ handler , $ jwt ) { $ request = $ request -> withHeader ( 'Authorization' , 'Bearer ' . $ jwt -> generateToken ( ) ) ; return $ handler ( $ request , $ options ) ; } ; } ; }
|
Guzzle middleware to add a header to outgoing requests .
|
55,838
|
protected function generateData ( EntityInterface $ entity ) { $ data = parent :: generateData ( $ entity ) ; $ source_term = $ this -> utils -> getTermForUri ( $ this -> configuration [ 'source_term_uri' ] ) ; if ( ! $ source_term ) { throw new \ RuntimeException ( "Could not locate source term with uri" . $ this -> configuration [ 'source_term_uri' ] , 500 ) ; } $ source_media = $ this -> utils -> getMediaWithTerm ( $ entity , $ source_term ) ; if ( ! $ source_media ) { throw new \ RuntimeException ( "Could not locate source media" , 500 ) ; } $ source_file = $ this -> mediaSource -> getSourceFile ( $ source_media ) ; if ( ! $ source_file ) { throw new \ RuntimeException ( "Could not locate source file for media {$source_media->id()}" , 500 ) ; } $ data [ 'source_uri' ] = $ source_file -> url ( 'canonical' , [ 'absolute' => TRUE ] ) ; $ derivative_term = $ this -> utils -> getTermForUri ( $ this -> configuration [ 'derivative_term_uri' ] ) ; if ( ! $ source_term ) { throw new \ RuntimeException ( "Could not locate derivative term with uri" . $ this -> configuration [ 'derivative_term_uri' ] , 500 ) ; } $ route_params = [ 'node' => $ entity -> id ( ) , 'media_type' => $ this -> configuration [ 'destination_media_type' ] , 'taxonomy_term' => $ derivative_term -> id ( ) , ] ; $ data [ 'destination_uri' ] = Url :: fromRoute ( 'islandora.media_source_put_to_node' , $ route_params ) -> setAbsolute ( ) -> toString ( ) ; $ token_data = [ 'node' => $ entity , 'media' => $ source_media , 'term' => $ derivative_term , ] ; $ path = $ this -> token -> replace ( $ data [ 'path' ] , $ token_data ) ; $ data [ 'file_upload_uri' ] = $ data [ 'scheme' ] . '://' . $ path ; unset ( $ data [ 'source_term_uri' ] ) ; unset ( $ data [ 'derivative_term_uri' ] ) ; unset ( $ data [ 'path' ] ) ; unset ( $ data [ 'scheme' ] ) ; unset ( $ data [ 'destination_media_type' ] ) ; return $ data ; }
|
Override this to return arbitrary data as an array to be json encoded .
|
55,839
|
protected function getEntityById ( $ entity_id ) { $ entity_ids = $ this -> entityTypeManager -> getStorage ( 'media_type' ) -> getQuery ( ) -> condition ( 'id' , $ entity_id ) -> execute ( ) ; $ id = reset ( $ entity_ids ) ; if ( $ id !== FALSE ) { return $ this -> entityTypeManager -> getStorage ( 'media_type' ) -> load ( $ id ) ; } return '' ; }
|
Find a media_type by id and return it or nothing .
|
55,840
|
static public function definition ( ) { return array ( 'fields' => array ( 'id' => array ( 'name' => 'ID' , 'datatype' => 'integer' , 'default' => 0 , 'required' => true ) , 'parent_id' => array ( 'name' => 'ParentID' , 'datatype' => 'integer' , 'default' => null , 'required' => false ) , 'main_tag_id' => array ( 'name' => 'MainTagID' , 'datatype' => 'integer' , 'default' => null , 'required' => false ) , 'keyword' => array ( 'name' => 'Keyword' , 'datatype' => 'string' , 'default' => '' , 'required' => false ) , 'depth' => array ( 'name' => 'Depth' , 'datatype' => 'integer' , 'default' => 1 , 'required' => false ) , 'path_string' => array ( 'name' => 'PathString' , 'datatype' => 'string' , 'default' => '' , 'required' => false ) , 'modified' => array ( 'name' => 'Modified' , 'datatype' => 'integer' , 'default' => 0 , 'required' => false ) , 'remote_id' => array ( 'name' => 'RemoteID' , 'datatype' => 'string' , 'default' => '' , 'required' => true ) , 'main_language_id' => array ( 'name' => 'MainLanguageID' , 'datatype' => 'integer' , 'default' => 0 , 'required' => false ) , 'language_mask' => array ( 'name' => 'LanguageMask' , 'datatype' => 'integer' , 'default' => 0 , 'required' => false ) ) , 'function_attributes' => array ( 'parent' => 'getParent' , 'children' => 'getChildren' , 'children_count' => 'getChildrenCount' , 'related_objects' => 'getRelatedObjects' , 'related_objects_count' => 'getRelatedObjectsCount' , 'subtree_limitations' => 'getSubTreeLimitations' , 'subtree_limitations_count' => 'getSubTreeLimitationsCount' , 'main_tag' => 'getMainTag' , 'synonyms' => 'getSynonyms' , 'synonyms_count' => 'getSynonymsCount' , 'is_synonym' => 'isSynonym' , 'icon' => 'getIcon' , 'url' => 'getUrl' , 'clean_url' => 'getCleanUrl' , 'path' => 'getPath' , 'path_count' => 'getPathCount' , 'keyword' => 'getKeyword' , 'available_languages' => 'getAvailableLanguages' , 'current_language' => 'getCurrentLanguage' , 'language_name_array' => 'languageNameArray' , 'main_translation' => 'getMainTranslation' , 'translations' => 'getTranslations' , 'translations_count' => 'getTranslationsCount' , 'always_available' => 'isAlwaysAvailable' ) , 'keys' => array ( 'id' ) , 'increment_key' => 'id' , 'class_name' => 'eZTagsObject' , 'name' => 'eztags' ) ; }
|
Returns the definition array for eZTagsObject
|
55,841
|
public function updatePathString ( ) { $ parentTag = $ this -> getParent ( true ) ; $ pathStringPrefix = $ parentTag instanceof self ? $ parentTag -> attribute ( 'path_string' ) : '/' ; $ this -> setAttribute ( 'path_string' , $ pathStringPrefix . $ this -> attribute ( 'id' ) . '/' ) ; $ this -> store ( ) ; foreach ( $ this -> getSynonyms ( true ) as $ s ) { $ s -> setAttribute ( 'path_string' , $ pathStringPrefix . $ s -> attribute ( 'id' ) . '/' ) ; $ s -> store ( ) ; } foreach ( $ this -> getChildren ( 0 , null , true ) as $ c ) { $ c -> updatePathString ( ) ; } }
|
Updates path string of the tag and all of it s children and synonyms .
|
55,842
|
public function updateDepth ( ) { $ parentTag = $ this -> getParent ( true ) ; $ depth = $ parentTag instanceof self ? $ parentTag -> attribute ( 'depth' ) + 1 : 1 ; $ this -> setAttribute ( 'depth' , $ depth ) ; $ this -> store ( ) ; foreach ( $ this -> getSynonyms ( true ) as $ s ) { $ s -> setAttribute ( 'depth' , $ depth ) ; $ s -> store ( ) ; } foreach ( $ this -> getChildren ( 0 , null , true ) as $ c ) { $ c -> updateDepth ( ) ; } }
|
Updates depth of the tag and all of it s children and synonyms .
|
55,843
|
public function getParent ( $ mainTranslation = false ) { if ( $ mainTranslation ) return self :: fetchWithMainTranslation ( $ this -> attribute ( 'parent_id' ) ) ; return self :: fetch ( $ this -> attribute ( 'parent_id' ) ) ; }
|
Returns tag parent
|
55,844
|
public function getChildren ( $ offset = 0 , $ limit = null , $ mainTranslation = false ) { return self :: fetchByParentID ( $ this -> attribute ( 'id' ) , $ offset , $ limit , $ mainTranslation ) ; }
|
Returns first level children tags
|
55,845
|
public function getRelatedObjects ( ) { $ tagID = ( int ) $ this -> attribute ( 'id' ) ; $ db = eZDB :: instance ( ) ; $ result = $ db -> arrayQuery ( "SELECT DISTINCT(o.id) AS object_id FROM eztags_attribute_link l INNER JOIN ezcontentobject o ON l.object_id = o.id AND l.objectattribute_version = o.current_version AND o.status = " . eZContentObject :: STATUS_PUBLISHED . " WHERE l.keyword_id = $tagID" ) ; if ( ! is_array ( $ result ) || empty ( $ result ) ) return array ( ) ; $ objectIDArray = array ( ) ; foreach ( $ result as $ r ) { $ objectIDArray [ ] = $ r [ 'object_id' ] ; } return eZContentObject :: fetchIDArray ( $ objectIDArray ) ; }
|
Returns objects related to this tag
|
55,846
|
public function getRelatedObjectsCount ( ) { $ tagID = ( int ) $ this -> attribute ( 'id' ) ; $ db = eZDB :: instance ( ) ; $ result = $ db -> arrayQuery ( "SELECT COUNT(DISTINCT o.id) AS count FROM eztags_attribute_link l INNER JOIN ezcontentobject o ON l.object_id = o.id AND l.objectattribute_version = o.current_version AND o.status = " . eZContentObject :: STATUS_PUBLISHED . " WHERE l.keyword_id = $tagID" ) ; if ( is_array ( $ result ) && ! empty ( $ result ) ) return ( int ) $ result [ 0 ] [ 'count' ] ; return 0 ; }
|
Returns the count of objects related to this tag
|
55,847
|
public function isInsideSubTreeLimit ( ) { $ path = $ this -> getPath ( true , true ) ; if ( is_array ( $ path ) && ! empty ( $ path ) ) { foreach ( $ path as $ tag ) { if ( $ tag -> getSubTreeLimitationsCount ( ) > 0 ) return true ; } } return false ; }
|
Checks if any of the parents have subtree limits defined
|
55,848
|
public function getMainTag ( $ mainTranslation = false ) { if ( $ mainTranslation ) return self :: fetchWithMainTranslation ( $ this -> attribute ( 'main_tag_id' ) ) ; return self :: fetch ( $ this -> attribute ( 'main_tag_id' ) ) ; }
|
Returns the main tag for synonym
|
55,849
|
public function getIcon ( ) { $ ini = eZINI :: instance ( 'eztags.ini' ) ; $ iconMap = $ ini -> variable ( 'Icons' , 'IconMap' ) ; $ defaultIcon = $ ini -> variable ( 'Icons' , 'Default' ) ; if ( $ this -> attribute ( 'main_tag_id' ) > 0 ) $ tag = $ this -> getMainTag ( true ) ; else $ tag = $ this ; $ tagID = $ tag -> attribute ( 'id' ) ; if ( array_key_exists ( $ tagID , $ iconMap ) && ! empty ( $ iconMap [ $ tagID ] ) ) return $ iconMap [ $ tagID ] ; $ path = $ tag -> getPath ( true , true ) ; if ( is_array ( $ path ) && ! empty ( $ path ) ) { foreach ( $ path as $ pathElement ) { $ pathElementID = $ pathElement -> attribute ( 'id' ) ; if ( array_key_exists ( $ pathElementID , $ iconMap ) && ! empty ( $ iconMap [ $ pathElementID ] ) ) return $ iconMap [ $ pathElementID ] ; } } return $ defaultIcon ; }
|
Returns icon associated with the tag while respecting hierarchy structure
|
55,850
|
public function getPath ( $ reverseSort = false , $ mainTranslation = false ) { $ pathArray = explode ( '/' , trim ( $ this -> attribute ( 'path_string' ) , '/' ) ) ; if ( ! is_array ( $ pathArray ) || empty ( $ pathArray ) || count ( $ pathArray ) == 1 ) return array ( ) ; $ pathArray = array_slice ( $ pathArray , 0 , count ( $ pathArray ) - 1 ) ; return self :: fetchList ( array ( 'id' => array ( $ pathArray ) ) , null , array ( 'path_string' => $ reverseSort != false ? 'desc' : 'asc' ) , $ mainTranslation ) ; }
|
Returns the array of eZTagsObject objects which are parents of this tag
|
55,851
|
public function getPathCount ( $ mainTranslation = false ) { $ pathArray = explode ( '/' , trim ( $ this -> attribute ( 'path_string' ) , '/' ) ) ; if ( ! is_array ( $ pathArray ) || empty ( $ pathArray ) || count ( $ pathArray ) == 1 ) return 0 ; $ pathArray = array_slice ( $ pathArray , 0 , count ( $ pathArray ) - 1 ) ; return self :: fetchListCount ( array ( 'id' => array ( $ pathArray ) ) , $ mainTranslation ) ; }
|
Returns the count of eZTagsObject objects which are parents of this tag
|
55,852
|
public function getParentString ( ) { $ keywordsArray = array ( ) ; $ path = $ this -> getPath ( false , true ) ; if ( is_array ( $ path ) && ! empty ( $ path ) ) { foreach ( $ path as $ tag ) { $ synonymsCount = $ tag -> getSynonymsCount ( true ) ; $ keywordsArray [ ] = $ synonymsCount > 0 ? $ tag -> attribute ( 'keyword' ) . ' (+' . $ synonymsCount . ')' : $ tag -> attribute ( 'keyword' ) ; } } $ synonymsCount = $ this -> getSynonymsCount ( true ) ; $ keywordsArray [ ] = $ synonymsCount > 0 ? $ this -> attribute ( 'keyword' ) . ' (+' . $ synonymsCount . ')' : $ this -> attribute ( 'keyword' ) ; return implode ( ' / ' , $ keywordsArray ) ; }
|
Returns the parent string of the tag
|
55,853
|
public function updateModified ( ) { $ pathArray = explode ( '/' , trim ( $ this -> attribute ( 'path_string' ) , '/' ) ) ; if ( $ this -> attribute ( 'main_tag_id' ) > 0 ) array_push ( $ pathArray , $ this -> attribute ( 'main_tag_id' ) ) ; if ( ! empty ( $ pathArray ) ) { $ db = eZDB :: instance ( ) ; $ db -> query ( "UPDATE eztags SET modified = " . time ( ) . " WHERE " . $ db -> generateSQLINStatement ( $ pathArray , 'id' , false , true , 'int' ) ) ; } }
|
Updates modified timestamp on current tag and all of its parents Expensive to run through API so SQL takes care of it
|
55,854
|
public function registerSearchObjects ( $ relatedObjects = null ) { $ eZTagsINI = eZINI :: instance ( 'eztags.ini' ) ; if ( eZINI :: instance ( 'site.ini' ) -> variable ( 'SearchSettings' , 'DelayedIndexing' ) !== 'disabled' || $ eZTagsINI -> variable ( 'SearchSettings' , 'ReindexWhenDelayedIndexingDisabled' ) == 'enabled' ) { if ( $ relatedObjects === null ) { $ relatedObjects = $ this -> getRelatedObjects ( ) ; } foreach ( $ relatedObjects as $ relatedObject ) { eZContentOperationCollection :: registerSearchObject ( $ relatedObject -> attribute ( 'id' ) , $ relatedObject -> attribute ( 'current_version' ) ) ; } return ; } eZHTTPTool :: instance ( ) -> setSessionVariable ( 'eZTagsShowReindexMessage' , 1 ) ; }
|
Registers all objects related to this tag to search engine for processing
|
55,855
|
static public function fetch ( $ id , $ locale = false ) { if ( is_string ( $ locale ) ) $ tags = self :: fetchList ( array ( 'id' => $ id ) , null , null , false , $ locale ) ; else $ tags = self :: fetchList ( array ( 'id' => $ id ) ) ; if ( is_array ( $ tags ) && ! empty ( $ tags ) ) return $ tags [ 0 ] ; return false ; }
|
Returns eZTagsObject for given ID
|
55,856
|
static public function fetchWithMainTranslation ( $ id ) { $ tags = self :: fetchList ( array ( 'id' => $ id ) , null , null , true ) ; if ( is_array ( $ tags ) && ! empty ( $ tags ) ) return $ tags [ 0 ] ; return false ; }
|
Returns eZTagsObject for given ID using the main translation of the tag
|
55,857
|
static public function fetchList ( $ params , $ limits = null , $ sorts = null , $ mainTranslation = false , $ locale = false ) { $ customConds = self :: fetchCustomCondsSQL ( $ params , $ mainTranslation , $ locale ) ; if ( is_array ( $ params ) ) { $ newParams = array ( ) ; foreach ( $ params as $ key => $ value ) { if ( $ key != 'keyword' ) $ newParams [ $ key ] = $ value ; else $ newParams [ 'eztags_keyword.keyword' ] = $ value ; } $ params = $ newParams ; } if ( is_array ( $ sorts ) ) { $ newSorts = array ( ) ; foreach ( $ sorts as $ key => $ value ) { if ( $ key != 'keyword' ) $ newSorts [ $ key ] = $ value ; else $ newSorts [ 'eztags_keyword.keyword' ] = $ value ; } $ sorts = $ newSorts ; } else if ( $ sorts == null ) { $ sorts = array ( 'eztags_keyword.keyword' => 'asc' ) ; } $ tagsList = parent :: fetchObjectList ( self :: definition ( ) , array ( ) , $ params , $ sorts , $ limits , true , false , array ( 'DISTINCT eztags.*' , array ( 'operation' => 'eztags_keyword.keyword' , 'name' => 'keyword' ) , array ( 'operation' => 'eztags_keyword.locale' , 'name' => 'locale' ) ) , array ( 'eztags_keyword' ) , $ customConds ) ; return $ tagsList ; }
|
Returns array of eZTagsObject objects for given params
|
55,858
|
static public function fetchListCount ( $ params , $ mainTranslation = false , $ locale = false ) { $ customConds = self :: fetchCustomCondsSQL ( $ params , $ mainTranslation , $ locale ) ; if ( is_array ( $ params ) ) { $ newParams = array ( ) ; foreach ( $ params as $ key => $ value ) { if ( $ key != 'keyword' ) $ newParams [ $ key ] = $ value ; else $ newParams [ 'eztags_keyword.keyword' ] = $ value ; } $ params = $ newParams ; } $ tagsList = parent :: fetchObjectList ( self :: definition ( ) , array ( ) , $ params , array ( ) , null , false , false , array ( array ( 'operation' => 'COUNT( * )' , 'name' => 'row_count' ) ) , array ( 'eztags_keyword' ) , $ customConds ) ; return $ tagsList [ 0 ] [ 'row_count' ] ; }
|
Returns count of eZTagsObject objects for given params
|
55,859
|
static public function fetchCustomCondsSQL ( $ params , $ mainTranslation = false , $ locale = false ) { $ customConds = is_array ( $ params ) && ! empty ( $ params ) ? " AND " : " WHERE " ; $ customConds .= " eztags.id = eztags_keyword.keyword_id " ; if ( $ mainTranslation !== false ) { $ customConds .= " AND eztags.main_language_id + MOD( eztags.language_mask, 2 ) = eztags_keyword.language_id " ; } else if ( is_string ( $ locale ) ) { $ db = eZDB :: instance ( ) ; $ customConds .= " AND " . eZContentLanguage :: languagesSQLFilter ( 'eztags' ) . " " ; $ customConds .= " AND eztags_keyword.locale = '" . $ db -> escapeString ( $ locale ) . "' " ; } else { $ customConds .= " AND " . eZContentLanguage :: languagesSQLFilter ( 'eztags' ) . " " ; $ customConds .= " AND " . eZContentLanguage :: sqlFilter ( 'eztags_keyword' , 'eztags' ) . " " ; } return $ customConds ; }
|
Returns the SQL for custom fetching of tags with eZPersistentObject
|
55,860
|
static public function fetchLimitations ( ) { $ tags = self :: fetchList ( array ( 'parent_id' => 0 , 'main_tag_id' => 0 ) , null , null , true ) ; if ( ! is_array ( $ tags ) ) return array ( ) ; $ returnArray = array ( ) ; foreach ( $ tags as $ tag ) { $ returnArray [ ] = array ( 'name' => $ tag -> attribute ( 'keyword' ) , 'id' => $ tag -> attribute ( 'id' ) ) ; } return $ returnArray ; }
|
Returns the list of limitations that eZ Tags support
|
55,861
|
static public function fetchByParentID ( $ parentID , $ offset = 0 , $ limit = null , $ mainTranslation = false ) { if ( $ offset === 0 && $ limit === null ) { $ limits = null ; } else { $ limits = array ( 'offset' => $ offset , 'limit' => $ limit ) ; } return self :: fetchList ( array ( 'parent_id' => $ parentID , 'main_tag_id' => 0 ) , $ limits , null , $ mainTranslation ) ; }
|
Returns array of eZTagsObject objects for given parent ID
|
55,862
|
static public function fetchSynonyms ( $ mainTagID , $ mainTranslation = false ) { return self :: fetchList ( array ( 'main_tag_id' => $ mainTagID ) , null , null , $ mainTranslation ) ; }
|
Returns array of eZTagsObject objects that are synonyms of provided tag ID
|
55,863
|
static public function fetchByKeyword ( $ keyword , $ mainTranslation = false ) { return self :: fetchList ( array ( 'keyword' => $ keyword ) , null , null , $ mainTranslation ) ; }
|
Returns array of eZTagsObject objects for given keyword
|
55,864
|
static public function fetchByPathString ( $ pathString , $ mainTranslation = false ) { return self :: fetchList ( array ( 'path_string' => array ( 'like' , $ pathString . '%' ) , 'main_tag_id' => 0 ) , null , null , $ mainTranslation ) ; }
|
Returns the array of eZTagsObject objects for given path string
|
55,865
|
static public function fetchByRemoteID ( $ remoteID , $ mainTranslation = false ) { $ tagsList = self :: fetchList ( array ( 'remote_id' => $ remoteID ) , null , null , $ mainTranslation ) ; if ( is_array ( $ tagsList ) && ! empty ( $ tagsList ) ) return $ tagsList [ 0 ] ; return null ; }
|
Fetches tag by remote ID
|
55,866
|
static public function fetchByUrl ( $ url , $ mainTranslation = false ) { $ urlArray = is_array ( $ url ) ? $ url : explode ( '/' , ltrim ( $ url , '/' ) ) ; if ( ! is_array ( $ urlArray ) || empty ( $ urlArray ) ) return null ; $ parentID = 0 ; for ( $ i = 0 ; $ i < count ( $ urlArray ) - 1 ; $ i ++ ) { $ tags = self :: fetchList ( array ( 'parent_id' => $ parentID , 'main_tag_id' => 0 , 'keyword' => urldecode ( trim ( $ urlArray [ $ i ] ) ) ) , null , null , $ mainTranslation ) ; if ( ! is_array ( $ tags ) || empty ( $ tags ) ) return null ; $ parentID = $ tags [ 0 ] -> attribute ( 'id' ) ; } $ tags = self :: fetchList ( array ( 'parent_id' => $ parentID , 'keyword' => urldecode ( trim ( $ urlArray [ count ( $ urlArray ) - 1 ] ) ) ) , null , null , $ mainTranslation ) ; if ( ! is_array ( $ tags ) || empty ( $ tags ) ) return null ; return $ tags [ 0 ] ; }
|
Fetches tag by URL
|
55,867
|
public function recursivelyDeleteTag ( ) { foreach ( $ this -> getChildren ( 0 , null , true ) as $ child ) { $ child -> recursivelyDeleteTag ( ) ; } $ relatedObjects = $ this -> getRelatedObjects ( ) ; foreach ( $ this -> getSynonyms ( true ) as $ synonym ) { $ synonym -> remove ( ) ; } $ this -> remove ( ) ; $ this -> registerSearchObjects ( $ relatedObjects ) ; }
|
Recursively deletes all tags below this tag including self
|
55,868
|
public function moveChildrenBelowAnotherTag ( eZTagsObject $ targetTag ) { $ currentTime = time ( ) ; $ children = $ this -> getChildren ( 0 , null , true ) ; foreach ( $ children as $ child ) { $ childSynonyms = $ child -> getSynonyms ( true ) ; foreach ( $ childSynonyms as $ childSynonym ) { $ childSynonym -> setAttribute ( 'parent_id' , $ targetTag -> attribute ( 'id' ) ) ; $ childSynonym -> store ( ) ; } $ child -> setAttribute ( 'parent_id' , $ targetTag -> attribute ( 'id' ) ) ; $ child -> setAttribute ( 'modified' , $ currentTime ) ; $ child -> store ( ) ; $ child -> updatePathString ( $ targetTag ) ; $ child -> updateDepth ( $ targetTag ) ; } }
|
Moves all children of this tag below another tag
|
55,869
|
public function transferObjectsToAnotherTag ( $ destination ) { if ( ! $ destination instanceof self ) { $ destination = self :: fetchWithMainTranslation ( ( int ) $ destination ) ; if ( ! $ destination instanceof self ) return ; } foreach ( $ this -> getTagAttributeLinks ( ) as $ tagAttributeLink ) { $ link = eZTagsAttributeLinkObject :: fetchByObjectAttributeAndKeywordID ( $ tagAttributeLink -> attribute ( 'objectattribute_id' ) , $ tagAttributeLink -> attribute ( 'objectattribute_version' ) , $ tagAttributeLink -> attribute ( 'object_id' ) , $ destination -> attribute ( 'id' ) ) ; if ( ! $ link instanceof eZTagsAttributeLinkObject ) { $ tagAttributeLink -> setAttribute ( 'keyword_id' , $ destination -> attribute ( 'id' ) ) ; $ tagAttributeLink -> store ( ) ; } else { $ tagAttributeLink -> remove ( ) ; } } }
|
Transfers all objects related to this tag to another tag
|
55,870
|
public function remove ( $ conditions = null , $ extraConditions = null ) { foreach ( $ this -> getTagAttributeLinks ( ) as $ tagAttributeLink ) { $ tagAttributeLink -> remove ( ) ; } foreach ( $ this -> getTranslations ( ) as $ translation ) { $ translation -> remove ( ) ; } parent :: remove ( $ conditions , $ extraConditions ) ; }
|
Removes self while also removing related translations and links to objects
|
55,871
|
static public function exists ( $ tagID , $ keyword , $ parentID ) { $ db = eZDB :: instance ( ) ; $ sql = "SELECT COUNT(*) AS row_count FROM eztags, eztags_keyword WHERE eztags.id = eztags_keyword.keyword_id AND eztags.parent_id = " . ( int ) $ parentID . " AND eztags.id <> " . ( int ) $ tagID . " AND eztags_keyword.keyword LIKE '" . $ db -> escapeString ( $ keyword ) . "'" ; $ result = $ db -> arrayQuery ( $ sql ) ; if ( is_array ( $ result ) && ! empty ( $ result ) ) { if ( ( int ) $ result [ 0 ] [ 'row_count' ] > 0 ) return true ; } return false ; }
|
Returns if tag with provided keyword and parent ID already exists not counting tag with provided tag ID
|
55,872
|
static public function generateModuleResultPath ( $ tag = false , $ urlToGenerate = null , $ textPart = false , $ mainTranslation = true ) { $ moduleResultPath = array ( ) ; if ( is_string ( $ textPart ) ) { $ moduleResultPath [ ] = array ( 'text' => $ textPart , 'url' => false ) ; } if ( $ tag instanceof self ) { $ moduleResultPath [ ] = array ( 'tag_id' => $ tag -> attribute ( 'id' ) , 'text' => $ tag -> attribute ( 'keyword' ) , 'url' => false ) ; $ path = $ tag -> getPath ( true , $ mainTranslation ) ; if ( is_array ( $ path ) && ! empty ( $ path ) ) { foreach ( $ path as $ pathElement ) { $ url = false ; if ( $ urlToGenerate !== null ) { if ( $ urlToGenerate ) $ url = $ pathElement -> getUrl ( ) ; else $ url = 'tags/id/' . $ pathElement -> attribute ( 'id' ) ; } $ moduleResultPath [ ] = array ( 'tag_id' => $ pathElement -> attribute ( 'id' ) , 'text' => $ pathElement -> attribute ( 'keyword' ) , 'url' => $ url ) ; } } } return array_reverse ( $ moduleResultPath ) ; }
|
Generates module result path for this tag used in all module views
|
55,873
|
public function getMainTranslation ( ) { $ language = eZContentLanguage :: fetch ( $ this -> attribute ( 'main_language_id' ) ) ; if ( $ language instanceof eZContentLanguage ) return $ this -> translationByLocale ( $ language -> attribute ( 'locale' ) ) ; return false ; }
|
Returns the main translation of this tag
|
55,874
|
public function translationByLanguageID ( $ languageID ) { $ language = eZContentLanguage :: fetch ( $ languageID ) ; if ( $ language instanceof eZContentLanguage ) return $ this -> translationByLocale ( $ language -> attribute ( 'locale' ) ) ; return false ; }
|
Returns translation of the tag for provided language ID
|
55,875
|
public function getKeyword ( $ locale = false ) { if ( $ this -> attribute ( 'id' ) == null ) return $ this -> Keyword ; $ translation = $ this -> translationByLocale ( $ locale === false ? $ this -> CurrentLanguage : $ locale ) ; if ( $ translation instanceof eZTagsKeyword ) return $ translation -> attribute ( 'keyword' ) ; return '' ; }
|
Returns the tag keyword locale aware
|
55,876
|
public function updateMainTranslation ( $ locale ) { $ trans = $ this -> translationByLocale ( $ locale ) ; $ language = eZContentLanguage :: fetchByLocale ( $ locale ) ; if ( ! $ trans instanceof eZTagsKeyword || ! $ language instanceof eZContentLanguage ) return false ; $ this -> setAttribute ( 'main_language_id' , $ language -> attribute ( 'id' ) ) ; $ keyword = $ this -> getKeyword ( $ locale ) ; $ this -> setAttribute ( 'keyword' , $ keyword ) ; $ this -> store ( ) ; $ isAlwaysAvailable = $ this -> isAlwaysAvailable ( ) ; foreach ( $ this -> getTranslations ( ) as $ translation ) { if ( ! $ isAlwaysAvailable ) $ languageID = ( int ) $ translation -> attribute ( 'language_id' ) & ~ 1 ; else { if ( $ translation -> attribute ( 'locale' ) != $ language -> attribute ( 'locale' ) ) $ languageID = ( int ) $ translation -> attribute ( 'language_id' ) & ~ 1 ; else $ languageID = ( int ) $ translation -> attribute ( 'language_id' ) | 1 ; } $ translation -> setAttribute ( 'language_id' , $ languageID ) ; $ translation -> store ( ) ; } return true ; }
|
Sets the main translation of the tag to provided locale
|
55,877
|
public function updateLanguageMask ( $ mask = false ) { if ( $ mask === false ) { $ locales = array ( ) ; foreach ( $ this -> getTranslations ( ) as $ translation ) { $ locales [ ] = $ translation -> attribute ( 'locale' ) ; } $ mask = eZContentLanguage :: maskByLocale ( $ locales , $ this -> isAlwaysAvailable ( ) ) ; } $ this -> setAttribute ( 'language_mask' , $ mask ) ; $ this -> store ( ) ; }
|
Updates language mask of the tag based on current translations or provided language mask
|
55,878
|
public function lookup ( EntityInterface $ entity ) { if ( $ entity -> id ( ) != NULL ) { $ drupal_uri = $ entity -> toUrl ( ) -> setAbsolute ( ) -> toString ( ) ; $ drupal_uri .= '?_format=jsonld' ; $ token = "Bearer " . $ this -> jwtProvider -> generateToken ( ) ; $ linked_uri = $ this -> geminiClient -> findByUri ( $ drupal_uri , $ token ) ; if ( ! is_null ( $ linked_uri ) ) { if ( is_array ( $ linked_uri ) ) { $ linked_uri = reset ( $ linked_uri ) ; } return $ linked_uri ; } } return NULL ; }
|
Lookup this entity s URI in the Gemini db and return the other URI .
|
55,879
|
static public function autocomplete ( $ args ) { $ http = eZHTTPTool :: instance ( ) ; $ searchString = trim ( $ http -> postVariable ( 'search_string' ) , '' ) ; $ autoCompleteType = eZINI :: instance ( 'eztags.ini' ) -> variable ( 'GeneralSettings' , 'AutoCompleteType' ) ; if ( empty ( $ searchString ) ) return array ( 'status' => 'success' , 'message' => '' , 'tags' => array ( ) ) ; $ trans = eZCharTransform :: instance ( ) ; $ searchString = $ trans -> transformByGroup ( $ http -> postVariable ( 'search_string' ) , 'lowercase' ) ; $ searchString = $ searchString . '%' ; if ( $ autoCompleteType === 'any' ) { $ searchString = '%' . $ searchString ; } return self :: generateOutput ( array ( 'LOWER( eztags_keyword.keyword )' => array ( 'like' , $ searchString ) ) , $ http -> postVariable ( 'subtree_limit' , 0 ) , $ http -> postVariable ( 'hide_root_tag' , '0' ) , $ http -> postVariable ( 'locale' , '' ) ) ; }
|
Provides auto complete results when adding tags to object
|
55,880
|
static public function suggest ( $ args ) { $ http = eZHTTPTool :: instance ( ) ; $ searchEngine = eZINI :: instance ( ) -> variable ( 'SearchSettings' , 'SearchEngine' ) ; if ( ! class_exists ( 'eZSolr' ) || $ searchEngine != 'ezsolr' ) return array ( 'status' => 'success' , 'message' => '' , 'tags' => array ( ) ) ; $ tagIDs = $ http -> postVariable ( 'tag_ids' , '' ) ; if ( empty ( $ tagIDs ) ) return array ( 'status' => 'success' , 'message' => '' , 'tags' => array ( ) ) ; if ( is_array ( $ tagIDs ) ) { $ tagIDs = implode ( '|#' , $ tagIDs ) ; } $ tagIDs = array_values ( array_unique ( explode ( '|#' , $ tagIDs ) ) ) ; $ solrSearch = new eZSolr ( ) ; $ params = array ( 'SearchOffset' => 0 , 'SearchLimit' => 0 , 'Facet' => array ( array ( 'field' => 'ezf_df_tag_ids' , 'limit' => 5 + count ( $ tagIDs ) , 'mincount' => 1 ) ) , 'Filter' => array ( 'ezf_df_tag_ids' => implode ( ' OR ' , $ tagIDs ) ) , 'QueryHandler' => 'ezpublish' , 'AsObjects' => false ) ; $ searchResult = $ solrSearch -> search ( '' , $ params ) ; if ( ! isset ( $ searchResult [ 'SearchExtras' ] ) || ! $ searchResult [ 'SearchExtras' ] instanceof ezfSearchResultInfo ) { eZDebug :: writeWarning ( 'There was an error fetching tag suggestions from Solr. Maybe server is not running or using unpatched schema?' , __METHOD__ ) ; return array ( 'status' => 'success' , 'message' => '' , 'tags' => array ( ) ) ; } $ facetResult = $ searchResult [ 'SearchExtras' ] -> attribute ( 'facet_fields' ) ; if ( ! is_array ( $ facetResult ) || ! is_array ( $ facetResult [ 0 ] [ 'nameList' ] ) ) { eZDebug :: writeWarning ( 'There was an error fetching tag suggestions from Solr. Maybe server is not running or using unpatched schema?' , __METHOD__ ) ; return array ( 'status' => 'success' , 'message' => '' , 'tags' => array ( ) ) ; } $ facetResult = array_values ( $ facetResult [ 0 ] [ 'nameList' ] ) ; $ tagsToSuggest = array ( ) ; foreach ( $ facetResult as $ result ) { if ( ! in_array ( $ result , $ tagIDs ) ) $ tagsToSuggest [ ] = $ result ; } if ( empty ( $ tagsToSuggest ) ) return array ( 'status' => 'success' , 'message' => '' , 'tags' => array ( ) ) ; return self :: generateOutput ( array ( 'id' => array ( $ tagsToSuggest ) ) , $ http -> postVariable ( 'subtree_limit' , 0 ) , false , $ http -> postVariable ( 'locale' , '' ) ) ; }
|
Provides suggestion results when adding tags to object
|
55,881
|
static public function children ( $ args ) { $ ezTagsINI = eZINI :: instance ( 'eztags.ini' ) ; $ params = array ( ) ; return self :: generateOutput ( $ params , $ args [ 0 ] , $ args [ 1 ] , $ args [ 2 ] ) ; }
|
Provides children in a specific tree
|
55,882
|
static public function tagtranslations ( $ args ) { $ returnArray = array ( 'status' => 'success' , 'message' => '' , 'translations' => false ) ; $ http = eZHTTPTool :: instance ( ) ; $ tagID = ( int ) $ http -> postVariable ( 'tag_id' , 0 ) ; $ tag = eZTagsObject :: fetchWithMainTranslation ( $ tagID ) ; if ( ! $ tag instanceof eZTagsObject ) return $ returnArray ; $ returnArray [ 'translations' ] = array ( ) ; $ tagTranslations = $ tag -> getTranslations ( ) ; if ( ! is_array ( $ tagTranslations ) || empty ( $ tagTranslations ) ) return $ returnArray ; foreach ( $ tagTranslations as $ translation ) { $ returnArray [ 'translations' ] [ ] = array ( 'locale' => $ translation -> attribute ( 'locale' ) , 'translation' => $ translation -> attribute ( 'keyword' ) ) ; } return $ returnArray ; }
|
Returns requested tag translations
|
55,883
|
static public function treeConfig ( $ args ) { $ returnArray = array ( 'status' => 'success' , 'message' => '' , 'config' => array ( 'hideRootTag' => false , 'rootTag' => array ( ) ) ) ; if ( ! isset ( $ args [ 1 ] ) ) { return $ returnArray ; } $ attributeID = ( int ) $ args [ 0 ] ; $ version = ( int ) $ args [ 1 ] ; $ contentAttribute = eZContentObjectAttribute :: fetch ( $ attributeID , $ version ) ; if ( ! $ contentAttribute instanceof eZContentObjectAttribute || $ contentAttribute -> attribute ( 'data_type_string' ) !== 'eztags' ) { return $ returnArray ; } $ tagsIni = eZINI :: instance ( 'eztags.ini' ) ; $ classAttribute = $ contentAttribute -> attribute ( 'contentclass_attribute' ) ; $ rootTagID = ( int ) $ classAttribute -> attribute ( 'data_int1' ) ; if ( $ rootTagID > 0 ) { $ rootTag = eZTagsObject :: fetch ( $ rootTagID ) ; if ( ! $ rootTag instanceof eZTagsObject ) { return $ returnArray ; } $ returnArray [ 'config' ] [ 'rootTag' ] = array ( 'id' => ( int ) $ rootTag -> attribute ( 'id' ) , 'parent' => '#' , 'text' => $ rootTag -> attribute ( 'keyword' ) , 'icon' => eZTagsTemplateFunctions :: getTagIcon ( $ rootTag -> getIcon ( ) ) , 'children' => $ rootTag -> getChildrenCount ( ) > 0 ? true : false , 'a_attr' => array ( 'data-id' => ( int ) $ rootTag -> attribute ( 'id' ) , 'data-name' => $ rootTag -> attribute ( 'keyword' ) , 'data-parent_id' => ( int ) $ rootTag -> attribute ( 'parent_id' ) , 'data-locale' => $ rootTag -> attribute ( 'current_language' ) ) , 'state' => array ( 'opened' => true , 'selected' => false ) ) ; } else { $ returnArray [ 'config' ] [ 'rootTag' ] = array ( 'id' => 0 , 'parent' => '#' , 'text' => ezpI18n :: tr ( 'extension/eztags/tags/treemenu' , 'Top level tags' ) , 'icon' => eZTagsTemplateFunctions :: getTagIcon ( $ tagsIni -> variable ( 'Icons' , 'Default' ) ) , 'children' => true , 'state' => array ( 'opened' => true , 'disabled' => true , 'selected' => false ) ) ; } $ returnArray [ 'config' ] [ 'hideRootTag' ] = ( int ) $ classAttribute -> attribute ( 'data_int3' ) > 0 ; return $ returnArray ; }
|
Returns config for tree view plugin
|
55,884
|
static public function tree ( $ args ) { $ returnArray = array ( 'status' => 'success' , 'message' => '' , 'children' => array ( ) ) ; $ tagID = 0 ; if ( isset ( $ args [ 0 ] ) && is_numeric ( $ args [ 0 ] ) ) { $ tagID = ( int ) $ args [ 0 ] ; } $ children = eZTagsObject :: fetchList ( array ( 'parent_id' => $ tagID , 'main_tag_id' => 0 ) ) ; if ( empty ( $ children ) ) { return $ returnArray ; } foreach ( $ children as $ child ) { $ returnArray [ 'children' ] [ ] = array ( 'id' => ( int ) $ child -> attribute ( 'id' ) , 'parent' => ( int ) $ child -> attribute ( 'parent_id' ) , 'text' => $ child -> attribute ( 'keyword' ) , 'icon' => eZTagsTemplateFunctions :: getTagIcon ( $ child -> getIcon ( ) ) , 'children' => $ child -> getChildrenCount ( ) > 0 ? true : false , 'state' => array ( 'opened' => false , 'selected' => false ) , 'a_attr' => array ( 'data-id' => ( int ) $ child -> attribute ( 'id' ) , 'data-name' => $ child -> attribute ( 'keyword' ) , 'data-parent_id' => ( int ) $ child -> attribute ( 'parent_id' ) , 'data-locale' => $ child -> attribute ( 'current_language' ) ) ) ; } return $ returnArray ; }
|
Returns children tags formatted for tree view plugin
|
55,885
|
static protected function generateOutput ( array $ params , $ subTreeLimit , $ hideRootTag , $ locale ) { $ subTreeLimit = ( int ) $ subTreeLimit ; $ hideRootTag = ( bool ) $ hideRootTag ; $ locale = ( string ) $ locale ; if ( empty ( $ locale ) ) return array ( 'status' => 'success' , 'message' => '' , 'tags' => array ( ) ) ; if ( $ subTreeLimit > 0 ) { if ( $ hideRootTag ) $ params [ 'id' ] = array ( '<>' , $ subTreeLimit ) ; $ params [ 'path_string' ] = array ( 'like' , '%/' . $ subTreeLimit . '/%' ) ; } $ tags = eZTagsObject :: fetchList ( $ params , null , null , false , $ locale ) ; if ( ! is_array ( $ tags ) ) $ tags = array ( ) ; $ tagsIDsToExclude = array_map ( function ( $ tag ) { return ( int ) $ tag -> attribute ( 'id' ) ; } , $ tags ) ; $ customConds = eZTagsObject :: fetchCustomCondsSQL ( $ params , true ) ; if ( ! empty ( $ tagsIDsToExclude ) ) $ customConds .= " AND " . eZDB :: instance ( ) -> generateSQLINStatement ( $ tagsIDsToExclude , 'eztags.id' , true , true , 'int' ) . " " ; $ tagsRest = eZPersistentObject :: fetchObjectList ( eZTagsObject :: definition ( ) , array ( ) , $ params , null , null , true , false , array ( 'DISTINCT eztags.*' , array ( 'operation' => 'eztags_keyword.keyword' , 'name' => 'keyword' ) , array ( 'operation' => 'eztags_keyword.locale' , 'name' => 'locale' ) ) , array ( 'eztags_keyword' ) , $ customConds ) ; if ( ! is_array ( $ tagsRest ) ) $ tagsRest = array ( ) ; $ tags = array_merge ( $ tags , $ tagsRest ) ; $ returnArray = array ( 'status' => 'success' , 'message' => '' , 'tags' => array ( ) ) ; foreach ( $ tags as $ tag ) { $ returnArrayChild = array ( ) ; $ returnArrayChild [ 'parent_id' ] = $ tag -> attribute ( 'parent_id' ) ; $ returnArrayChild [ 'parent_name' ] = $ tag -> hasParent ( true ) ? $ tag -> getParent ( true ) -> attribute ( 'keyword' ) : '' ; $ returnArrayChild [ 'name' ] = $ tag -> attribute ( 'keyword' ) ; $ returnArrayChild [ 'id' ] = $ tag -> attribute ( 'id' ) ; $ returnArrayChild [ 'main_tag_id' ] = $ tag -> attribute ( 'main_tag_id' ) ; $ returnArrayChild [ 'locale' ] = $ tag -> attribute ( 'current_language' ) ; $ returnArray [ 'tags' ] [ ] = $ returnArrayChild ; } return $ returnArray ; }
|
Generates output for use with autocomplete and suggest methods
|
55,886
|
static public function generateParentString ( $ tagID ) { $ tag = eZTagsObject :: fetchWithMainTranslation ( $ tagID ) ; if ( ! $ tag instanceof eZTagsObject ) return '(' . ezpI18n :: tr ( 'extension/eztags/tags/edit' , 'no parent' ) . ')' ; return $ tag -> getParentString ( ) ; }
|
Generates tag hierarchy string for given tag ID
|
55,887
|
static public function tagsChildren ( $ args ) { $ http = eZHTTPTool :: instance ( ) ; $ filter = urldecode ( trim ( $ http -> getVariable ( 'filter' , '' ) ) ) ; if ( ! isset ( $ args [ 0 ] ) || ! is_numeric ( $ args [ 0 ] ) ) return array ( 'count' => 0 , 'offset' => false , 'filter' => $ filter , 'data' => array ( ) ) ; $ offset = false ; $ limits = null ; if ( $ http -> hasGetVariable ( 'offset' ) ) { $ offset = ( int ) $ http -> getVariable ( 'offset' ) ; if ( $ http -> hasGetVariable ( 'limit' ) ) $ limit = ( int ) $ http -> getVariable ( 'limit' ) ; else $ limit = 10 ; $ limits = array ( 'offset' => $ offset , 'limit' => $ limit ) ; } $ sorts = null ; if ( $ http -> hasGetVariable ( 'sortby' ) ) { $ sortBy = trim ( $ http -> getVariable ( 'sortby' ) ) ; $ sortDirection = 'asc' ; if ( $ http -> hasGetVariable ( 'sortdirection' ) && trim ( $ http -> getVariable ( 'sortdirection' ) ) == 'desc' ) $ sortDirection = 'desc' ; $ sorts = array ( $ sortBy => $ sortDirection ) ; } $ fetchParams = array ( 'parent_id' => ( int ) $ args [ 0 ] , 'main_tag_id' => 0 ) ; if ( ! empty ( $ filter ) ) $ fetchParams [ 'keyword' ] = array ( 'like' , '%' . $ filter . '%' ) ; $ children = eZTagsObject :: fetchList ( $ fetchParams , $ limits , $ sorts ) ; $ childrenCount = eZTagsObject :: fetchListCount ( $ fetchParams ) ; if ( ! is_array ( $ children ) || empty ( $ children ) ) return array ( 'count' => 0 , 'offset' => false , 'filter' => $ filter , 'data' => array ( ) ) ; $ dataArray = array ( ) ; foreach ( $ children as $ child ) { $ tagArray = array ( ) ; $ tagArray [ 'id' ] = $ child -> attribute ( 'id' ) ; $ tagArray [ 'keyword' ] = htmlspecialchars ( $ child -> attribute ( 'keyword' ) , ENT_QUOTES ) ; $ tagArray [ 'modified' ] = $ child -> attribute ( 'modified' ) ; $ tagArray [ 'translations' ] = array ( ) ; foreach ( $ child -> getTranslations ( ) as $ translation ) { $ tagArray [ 'translations' ] [ ] = htmlspecialchars ( $ translation -> attribute ( 'locale' ) , ENT_QUOTES ) ; } $ dataArray [ ] = $ tagArray ; } return array ( 'count' => $ childrenCount , 'offset' => $ offset , 'filter' => $ filter , 'data' => $ dataArray ) ; }
|
Returns the JSON encoded string of children tags for supplied GET params Used in YUI version of children tags list in admin interface
|
55,888
|
protected function getHighestEnergyPoint ( \ Imagick $ image ) { $ size = $ image -> getImageGeometry ( ) ; $ im = imagecreatefromstring ( $ image -> getImageBlob ( ) ) ; if ( $ im === false ) { $ msg = 'GD failed to create image from string' ; throw new \ Exception ( $ msg ) ; } $ xcenter = 0 ; $ ycenter = 0 ; $ sum = 0 ; $ sampleSize = round ( $ size [ 'height' ] * $ size [ 'width' ] ) / 50 ; for ( $ k = 0 ; $ k < $ sampleSize ; $ k ++ ) { $ i = mt_rand ( 0 , $ size [ 'width' ] - 1 ) ; $ j = mt_rand ( 0 , $ size [ 'height' ] - 1 ) ; $ rgb = imagecolorat ( $ im , $ i , $ j ) ; $ r = ( $ rgb >> 16 ) & 0xFF ; $ g = ( $ rgb >> 8 ) & 0xFF ; $ b = $ rgb & 0xFF ; $ val = $ this -> rgb2bw ( $ r , $ g , $ b ) ; $ sum += $ val ; $ xcenter += ( $ i + 1 ) * $ val ; $ ycenter += ( $ j + 1 ) * $ val ; } if ( $ sum ) { $ xcenter /= $ sum ; $ ycenter /= $ sum ; } $ point = array ( 'x' => $ xcenter , 'y' => $ ycenter , 'sum' => $ sum / round ( $ size [ 'height' ] * $ size [ 'width' ] ) ) ; return $ point ; }
|
By doing random sampling from the image find the most energetic point on the passed in image
|
55,889
|
public function setIslandoraClaims ( JwtAuthGenerateEvent $ event ) { global $ base_secure_url ; $ event -> addClaim ( 'iat' , time ( ) ) ; $ expiry_setting = \ Drupal :: config ( IslandoraSettingsForm :: CONFIG_NAME ) -> get ( IslandoraSettingsForm :: JWT_EXPIRY ) ; $ expiry = $ expiry_setting ? $ expiry_setting : '+2 hour' ; $ event -> addClaim ( 'exp' , strtotime ( $ expiry ) ) ; $ event -> addClaim ( 'webid' , $ this -> currentUser -> id ( ) ) ; $ event -> addClaim ( 'iss' , $ base_secure_url ) ; $ event -> addClaim ( 'sub' , $ this -> currentUser -> getAccountName ( ) ) ; $ event -> addClaim ( 'roles' , $ this -> currentUser -> getRoles ( FALSE ) ) ; }
|
Sets claims for a Islandora consumer on the JWT .
|
55,890
|
public function validate ( JwtAuthValidateEvent $ event ) { $ token = $ event -> getToken ( ) ; $ uid = $ token -> getClaim ( 'webid' ) ; $ name = $ token -> getClaim ( 'sub' ) ; $ roles = $ token -> getClaim ( 'roles' ) ; $ url = $ token -> getClaim ( 'iss' ) ; if ( $ uid === NULL || $ name === NULL || $ roles === NULL || $ url === NULL ) { $ event -> invalidate ( "Expected data missing from payload." ) ; return ; } $ user = $ this -> userStorage -> load ( $ uid ) ; if ( $ user === NULL ) { $ event -> invalidate ( "Specified UID does not exist." ) ; } elseif ( $ user -> getAccountName ( ) !== $ name ) { $ event -> invalidate ( "Account name does not match." ) ; } }
|
Validates that the Islandora data is present in the JWT .
|
55,891
|
public function loadUser ( JwtAuthValidEvent $ event ) { $ token = $ event -> getToken ( ) ; $ uid = $ token -> getClaim ( 'webid' ) ; $ user = $ this -> userStorage -> load ( $ uid ) ; $ event -> setUser ( $ user ) ; }
|
Load and set a Drupal user to be authentication based on the JWT s uid .
|
55,892
|
protected function evaluateFile ( FileInterface $ file ) { $ uri = $ file -> getFileUri ( ) ; $ scheme = $ this -> fileSystem -> uriScheme ( $ uri ) ; return ! empty ( $ this -> configuration [ 'filesystems' ] [ $ scheme ] ) ; }
|
The actual evaluate function .
|
55,893
|
public function index ( ) { $ currentUserId = Auth :: user ( ) -> id ; $ threads = Thread :: getAllLatest ( ) -> get ( ) ; return view ( 'chat.index' , compact ( 'threads' , 'currentUserId' ) ) ; }
|
Show all of the message threads to the user
|
55,894
|
public function show ( $ id ) { try { $ thread = Thread :: findOrFail ( $ id ) ; } catch ( ModelNotFoundException $ e ) { Session :: flash ( 'error_message' , 'The thread with ID: ' . $ id . ' was not found.' ) ; return redirect ( 'message' ) ; } $ userId = Auth :: user ( ) -> id ; $ users = User :: whereNotIn ( 'id' , $ thread -> participantsUserIds ( $ userId ) ) -> get ( ) ; $ thread -> markAsRead ( $ userId ) ; return view ( 'chat.show' , compact ( 'thread' , 'users' ) ) ; }
|
Shows a message thread
|
55,895
|
public function store ( ) { $ input = Input :: all ( ) ; $ thread = Thread :: create ( [ 'subject' => $ input [ 'subject' ] , ] ) ; Message :: create ( [ 'thread_id' => $ thread -> id , 'user_id' => Auth :: user ( ) -> id , 'body' => $ input [ 'message' ] , ] ) ; Participant :: create ( [ 'thread_id' => $ thread -> id , 'user_id' => Auth :: user ( ) -> id , 'last_read' => new Carbon ] ) ; if ( Input :: has ( 'recipients' ) ) { $ thread -> addParticipants ( $ input [ 'recipients' ] ) ; } return redirect ( 'message' ) ; }
|
Stores a new message thread
|
55,896
|
public function participantsUserIds ( $ userId = null ) { $ users = $ this -> participants ( ) -> lists ( 'user_id' ) ; if ( $ userId ) { $ users [ ] = $ userId ; } return $ users ; }
|
Returns an array of user ids that are associated with the thread
|
55,897
|
public function scopeForUserWithNewMessages ( $ query , $ userId ) { return $ query -> join ( 'participants' , 'threads.id' , '=' , 'participants.thread_id' ) -> where ( 'participants.user_id' , $ userId ) -> where ( function ( $ query ) { $ query -> where ( 'threads.updated_at' , '>' , $ this -> getConnection ( ) -> raw ( $ this -> getConnection ( ) -> getTablePrefix ( ) . 'participants.last_read' ) ) -> orWhereNull ( 'participants.last_read' ) ; } ) -> select ( 'threads.*' ) ; }
|
Returns threads with new messages that the user is associated with
|
55,898
|
public function scopeBetween ( $ query , array $ participants ) { $ query -> whereHas ( 'participants' , function ( $ query ) use ( $ participants ) { $ query -> whereIn ( 'user_id' , $ participants ) -> groupBy ( 'thread_id' ) -> havingRaw ( 'COUNT(thread_id)=' . count ( $ participants ) ) ; } ) ; }
|
Returns threads between given user ids
|
55,899
|
public function addParticipants ( array $ participants ) { if ( count ( $ participants ) ) { foreach ( $ participants as $ user_id ) { Participant :: firstOrCreate ( [ 'user_id' => $ user_id , 'thread_id' => $ this -> id , ] ) ; } } }
|
Adds users to this thread
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.