Constants

SNIPPET_TITLE_LENGTH

SNIPPET_TITLE_LENGTH

MAX_SNIPPET_TITLE_LENGTH

MAX_SNIPPET_TITLE_LENGTH

SNIPPET_LENGTH_LEFT

SNIPPET_LENGTH_LEFT

SNIPPET_LENGTH_RIGHT

SNIPPET_LENGTH_RIGHT

MIN_SNIPPET_LENGTH

MIN_SNIPPET_LENGTH

DEFAULT_DESCRIPTION_LENGTH

DEFAULT_DESCRIPTION_LENGTH

Default maximum character length of a search summary

Properties

$db

$db : object

Reference to a DatasourceManager

Type

object

$db_name

$db_name : string

Name of the search engine database

Type

string

$private_db

$private_db : object

Reference to a private DatasourceManager

Type

object

$private_db_name

$private_db_name : string

Name of the private search engine database

Type

string

$edited_page_summaries

$edited_page_summaries : array

Associative array of page summaries which might be used to override default page summaries if set.

Type

array

$any_fields

$any_fields : array

These fields if present in $search_array (used by @see getRows() ), but with value "-1", will be skipped as part of the where clause but will be used for order by clause

Type

array

$search_table_column_map

$search_table_column_map : array

Used to map between search role form variables and database columns

Type

array

$web_site

$web_site : object

Reference to a WebSite object in use to serve pages (if any)

Type

object

$cache

$cache : object

Cache object to be used if we are doing caching

Type

object

Methods

__construct()

__construct(string  $db_name = \seekquarry\yioop\configs\DB_NAME, boolean  $connect = true,   $web_site = null) 

Sets up the database manager that will be used and name of the search engine database

Parameters

string $db_name

the name of the database for the search engine

boolean $connect

whether to connect to the database by default after making the datasource class

$web_site

fileGetContents()

fileGetContents(string  $filename, boolean  $force_read = false) : string

Either a wrapper for file_get_contents, or if a WebSite object is being used to serve pages, it reads it in using blocking I/O file_get_contents() and caches it before return its string contents.

Note this function assumes that only the web server is performing I/O with this file. filemtime() can be used to see if a file on disk has been changed and then you can use $force_read = true below to force re- reading the file into the cache

Parameters

string $filename

name of file to get contents of

boolean $force_read

whether to force the file to be read from presistent storage rather than the cache

Returns

string —

contents of the file given by $filename

filePutContents()

filePutContents(string  $filename, string  $data) 

Either a wrapper for file_put_contents, or if a WebSite object is being used to serve pages, writes $data to the persistent file with name $filename. Saves a copy in the RAM cache if there is a copy already there.

Parameters

string $filename

name of file to write to persistent storages

string $data

string of data to store in file

createIfNecessaryDirectory()

createIfNecessaryDirectory(string  $directory) : integer

Creates a directory and sets it to world permission if it doesn't aleady exist

Parameters

string $directory

name of directory to create

Returns

integer —

-1 on failure, 0 if already existed, 1 if created

formatSinglePageResult()

formatSinglePageResult(array  $page, array  $words = null, integer  $description_length = self::DEFAULT_DESCRIPTION_LENGTH) : array

Given a page summary, extracts snippets which are related to a set of search words. For each snippet, bold faces the search terms, and then creates a new summary array.

Parameters

array $page

a single search result summary

array $words

keywords (typically what was searched on)

integer $description_length

length of the description

Returns

array —

$page which has been snippified and bold faced

getSnippets()

getSnippets(string  $text, array  $words, string  $description_length) : string

Given a string, extracts a snippets of text related to a given set of key words. For a given word a snippet is a window of characters to its left and right that is less than a maximum total number of characters.

There is also a rule that a snippet should avoid ending in the middle of a word

Parameters

string $text

haystack to extract snippet from

array $words

keywords used to make look in haystack

string $description_length

length of the description desired

Returns

string —

a concatenation of the extracted snippets of each word

boldKeywords()

boldKeywords(string  $text, array  $words) : string

Given a string, wraps in bold html tags a set of key words it contains.

Parameters

string $text

haystack string to look for the key words

array $words

an array of words to bold face

Returns

string —

the resulting string after boldfacing has been applied

getDbmsList()

getDbmsList() : array

Gets a list of all DBMS that work with the search engine

Returns

array —

Names of available data sources

loginDbms()

loginDbms(string  $dbms) : boolean

Returns whether the provided dbms needs a login and password or not (sqlite or sqlite3)

Parameters

string $dbms

the name of a database management system

Returns

boolean —

true if needs a login and password; false otherwise

isSingleLocalhost()

isSingleLocalhost(array  $machine_urls, string  $index_timestamp = -1) : boolean

Used to determine if an action involves just one yioop instance on the current local machine or not

Parameters

array $machine_urls

urls of yioop instances to which the action applies

string $index_timestamp

if timestamp exists checks if the index has declared itself to be a no network index.

Returns

boolean —

whether it involves a single local yioop instance (true) or not (false)

translateDb()

translateDb(string  $string_id, string  $locale_tag) : mixed

Used to get the translation of a string_id stored in the database to the given locale.

Parameters

string $string_id

id to translate

string $locale_tag

to translate to

Returns

mixed —

translation if found, $string_id, otherwise

getUserId()

getUserId(string  $username) : string

Get the user_id associated with a given username (In base class as used as an internal method in both signin and user models)

Parameters

string $username

the username to look up

Returns

string —

the corresponding userid

searchArrayToWhereOrderClauses()

searchArrayToWhereOrderClauses(array  $search_array, array  $any_fields = array('status')) : array

Creates the WHERE and ORDER BY clauses for a query of a Yioop table such as USERS, ROLE, GROUP, which have associated search web forms. Searches are case insensitive

Parameters

array $search_array

each element of this is a quadruple name of a field, what comparison to perform, a value to check, and an order (ascending/descending) to sort by

array $any_fields

these fields if present in search array but with value "-1" will be skipped as part of the where clause but will be used for order by clause

Returns

array —

string for where clause, string for order by clause

getRows()

getRows(integer  $limit, integer  $num, \seekquarry\yioop\models\int&  $total, array  $search_array = array(), array  $args = null) : array

Gets a range of rows which match the provided search criteria from $th provided table

Parameters

integer $limit

starting row from the potential results to return

integer $num

number of rows after start row to return

\seekquarry\yioop\models\int& $total

gets set with the total number of rows that can be returned by the given database query

array $search_array

each element of this is a quadruple name of a field, what comparison to perform, a value to check, and an order (ascending/descending) to sort by

array $args

additional values which may be used to get rows (what these are will typically depend on the subclass implementation)

Returns

array

selectCallback()

selectCallback(mixed  $args = null) : string

Controls which columns and the names of those columns from the tables underlying the given model should be return from a getRows call.

This defaults to *, but in general will be overriden in subclasses of Model

Parameters

mixed $args

any additional arguments which should be used to determine the columns (ignored in this case)

Returns

string —

a comma separated list of columns suitable for a SQL query ("NAME" in this case)

fromCallback()

fromCallback(mixed  $args = null) : string

Controls which tables and the names of tables underlie the given model and should be used in a getRows call This defaults to the single table whose name is whatever is before Model in the name of the model. For example, by default on FooModel this method would return "FOO". If a different behavior, this can be overriden in subclasses of Model

Parameters

mixed $args

any additional arguments which should be used to determine these tables

Returns

string —

a comma separated list of tables suitable for a SQL query

whereCallback()

whereCallback(mixed  $args = null) : string

Controls the WHERE clause of the SQL query that underlies the given model and should be used in a getRows call.

This defaults to an empty WHERE clause.

Parameters

mixed $args

additional arguments that might be used to construct the WHERE clause.

Returns

string —

a SQL WHERE clause

rowCallback()

rowCallback(array  $row, mixed  $args) : array

Called after as row is retrieved by getRows from the database to perform some manipulation that would be useful for this model.

For example, in CrawlModel, after a row representing a crawl mix has been gotten, this is used to perform an additional query to marshal its components. By default this method just returns this row unchanged.

Parameters

array $row

row as retrieved from database query

mixed $args

additional arguments that might be used by this callback

Returns

array —

$row after callback manipulation

postQueryCallback()

postQueryCallback(array  $rows) : array

Called after getRows has retrieved all the rows that it would retrieve but before they are returned to give one last place where they could be further manipulated. For example, in MachineModel this callback is used to make parallel network calls to get the status of each machine returned by getRows. The default for this method is to leave the rows that would be returned unchanged

Parameters

array $rows

that have been calculated so far by getRows

Returns

array —

$rows after this final manipulation

getRoleActivities()

getRoleActivities(string  $role_id) 

Get the activities (name, method, id) that a given role can perform

Parameters

string $role_id

the rolid_id to get activities for

getUserRoles()

getUserRoles(string  $user_id, string  $filter, array  $sorts = array(), integer  $limit, integer  $num = \seekquarry\yioop\configs\NUM_RESULTS_PER_PAGE) : array

Gets all the roles associated with a user id

Parameters

string $user_id

the user_id to get roles of

string $filter

to SQL LIKE filter roles

array $sorts

directions on how to sort the columns of the results format is column_name => direction

integer $limit

starting index of first role to return

integer $num

number of roles to return

Returns

array —

of role_ids and their names

countUserRoles()

countUserRoles(integer  $user_id, string  $filter = "") : integer

Get a count of the number of groups that a user_id has.

Parameters

integer $user_id

to get roles for

string $filter

to SQL LIKE filter roles

Returns

integer —

number of roles of the filtered type for the user

checkUserRole()

checkUserRole(integer  $user_id, integer  $role_id) : boolean

Check is a user given by $user_id has the role $role_id

Parameters

integer $user_id

user to look up

integer $role_id

role to check if member of

Returns

boolean —

whether or not has role

addUserRole()

addUserRole(string  $user_id, string  $role_id) 

Adds a role to a given user

Parameters

string $user_id

the id of the user to add the role to

string $role_id

the id of the role to add

deleteUserRole()

deleteUserRole(string  $user_id, string  $role_id) 

Deletes a role from a given user

Parameters

string $user_id

the id of the user to delete the role from

string $role_id

the id of the role to delete

getRole()

getRole(string  $rolename) : array

Return the role_id and role_name row corresponding to a given rolename

Parameters

string $rolename

Returns

array —

row in role table corresponding to $rolenames

addRole()

addRole(string  $role_name) 

Add a rolename to the database using provided string

Parameters

string $role_name

the rolename to be added

addActivityRole()

addActivityRole(string  $role_id, string  $activity_id, string  $allowed_arguments = "all") 

Add an allowed activity to an existing role

Parameters

string $role_id

the role id of the role to add the activity to

string $activity_id

the id of the acitivity to add

string $allowed_arguments

$_REQUEST['arg'] values this role is allowed to use. 'all' means any allowed argumment. Otherwise whould be commma separated list of allowed arguments: For example: edit, search, ... Can also use all, -arg_name1, -arg_name2 ... to say all arguments except arg_name1, arg_name2...

updateActivityRoleArguments()

updateActivityRoleArguments(string  $role_id, string  $activity_id, string  $allowed_arguments) 

Updates the allowed arguments of an Activity within a Role

Parameters

string $role_id

the role id of the role to add the activity to

string $activity_id

the id of the acitivity to add

string $allowed_arguments

$_REQUEST['arg'] values this role is allowed to use. 'all' means any allowed argumment. Otherwise whould be commma separated list of allowed arguments: For example: edit, search, ... Can also use all, -arg_name1, -arg_name2 ... to say all arguments except arg_name1, arg_name2...

deleteRole()

deleteRole(string  $role_id) 

Delete a role by its roleid

Parameters

string $role_id
  • the roleid of the role to delete

deleteActivityRole()

deleteActivityRole(string  $role_id, string  $activity_id) 

Remove an allowed activity from a role

Parameters

string $role_id

the roleid of the role to be modified

string $activity_id

the activityid of the activity to remove

getRoleId()

getRoleId(string  $role_name) : string

Get role id associated with role_name (so role_names better be unique)

Parameters

string $role_name

to use to look up a role_id

Returns

string —

role_id corresponding to the rolename.

getRoleIdWithDb()

getRoleIdWithDb(string  $role_name, object  $db) : string

Get role id associated with role_name (so role_names better be unique) using a datasource

Parameters

string $role_name

to use to look up a role_id

object $db

a $database source used to run the role table queries on

Returns

string —

role_id corresponding to the rolename.