sentence1 stringlengths 52 3.87M | sentence2 stringlengths 1 47.2k | label stringclasses 1
value |
|---|---|---|
public function render()
{
$this->params = $this->extra_params;
$r = $this->_render();
$this->debug((string) $this->getDebugQuery($r));
return $r;
} | Converts query into string format. This will contain parametric
references.
@return string Resulting query | entailment |
public function _render()
{
/**/$this->app->pr->start('dsql/render');
if (is_null($this->template)) {
$this->SQLTemplate('select');
}
$self = $this;
$res = preg_replace_callback(
'/\[([a-z0-9_]*)\]/',
function ($matches) use ($self) {
... | Helper for render(), which does the actual work.
@private
@return string Resulting query | entailment |
public function register()
{
$this->app->singleton('sms', function ($app) {
$this->registerSender();
$sms = new SMS($app['sms.sender']);
$this->setSMSDependencies($sms, $app);
//Set the from setting
if ($app['config']->has('sms.from')) {
... | Register the service provider. | entailment |
public function destroy($recursive = true)
{
if ($recursive) {
foreach ($this->elements as $el) {
if ($el instanceof self) {
$el->destroy();
}
}
}
/*
if (@$this->model && $this->model instanceof AbstractObjec... | Removes object from parent and prevents it from rendering
\code
$view = $this->add('View');
$view -> destroy();
\endcode. | entailment |
public function removeElement($short_name)
{
if (is_object($this->elements[$short_name])) {
$this->elements[$short_name]->destroy();
} else {
unset($this->elements[$short_name]);
}
return $this;
} | Remove child element if it exists.
@param string $short_name short name of the element
@return $this | entailment |
public function _removeElement($short_name)
{
unset($this->elements[$short_name]);
if ($this->_element_name_counts[$short_name] === 1) {
unset($this->_element_name_counts[$short_name]);
}
return $this;
} | Actually removes the element.
@param string $short_name short name
@return $this
@access private | entailment |
public function add(
$class,
$options = null,
$template_spot = null,
$template_branch = null
) {
if (is_array($class)) {
if (!$class[0]) {
throw $this->exception('When passing class as array, use ["Class", "option"=>123] format')
... | Creates new object and adds it as a child of current object.
Returns new object.
@param array|string|object $class Name of the new class. Can also be array with 0=>name and
rest of array will be considered as $options or object.
@param array|string $options Short name or array of properties.
0=>name will be... | entailment |
public function getElement($short_name)
{
if (!isset($this->elements[$short_name])) {
throw $this->exception('Child element not found')
->addMoreInfo('element', $short_name);
}
return $this->elements[$short_name];
} | Find child element by its short name. Use in chaining.
Exception if not found.
@param string $short_name Short name of the child element
@return AbstractObject | entailment |
public function rename($short_name)
{
unset($this->owner->elements[$this->short_name]);
$this->name = $this->name.'_'.$short_name;
$this->short_name = $short_name;
if (!$this->auto_track_element) {
$this->owner->elements[$short_name] = true;
} else {
... | Names object accordingly. May not work on some objects.
@param string $short_name Short name of the child element
@return $this | entailment |
public function setController($controller, $name = null)
{
$controller = $this->app->normalizeClassName($controller, 'Controller');
return $this->add($controller, $name);
} | Associate controller with the object.
@param string|object $controller Class or instance of controller
@param string|array $name Name or property for new controller
@return AbstractController Newly added controller | entailment |
public function setModel($model)
{
// in case of Agile Data model - don't add it to object.
// Agile Data Model owner is Agile Data Persistance and so be it.
if ($model instanceof \atk4\data\Model) {
return $this->model = $model;
}
$model = $this->app->normalizeC... | Associate model with object.
@param string|object $model Class or instance of model
@return AbstractModel Newly added Model | entailment |
public function exception($message = 'Undefined Exception', $type = null, $code = null)
{
if ($type === null) {
$type = $this->default_exception;
} elseif ($type[0] == '_') {
if ($this->default_exception == 'BaseException') {
$type = 'Exception_'.substr($type,... | Returns relevant exception class. Use this method with "throw".
@param string $message Static text of exception.
@param string $type Exception class or class postfix
@param string $code Optional error code
@return BaseException | entailment |
public function debug($msg = true, $file = null, $line = null)
{
if (is_bool($msg)) {
$this->debug = $msg;
return $this;
}
if (is_object($msg)) {
throw $this->exception('Do not debug objects');
}
// The rest of this method is obsolete
... | Turns on debug mode for this object.
Using first argument as string is obsolete.
@param bool|string $msg "true" to start debugging
@param string $file obsolete
@param string $line obsolete | entailment |
public function upCall($type, $args = array())
{
/*
* Try to handle something on our own and in case we are not able,
* pass to parent. Such as messages, notifications and request for
* additional info or descriptions are passed this way.
*/
if (method_exists($thi... | Call specified method for this class and all parents up to app.
@param string $type information
@param array $args relative offset in backtrace
@obsolete | entailment |
public function addHook($hook_spot, $callable, $arguments = array(), $priority = 5)
{
if (!is_array($arguments)) {
throw $this->exception('Incorrect arguments');
}
if (is_string($hook_spot) && strpos($hook_spot, ',') !== false) {
$hook_spot = explode(',', $hook_spot);... | If priority is negative, then hooks will be executed in reverse order.
@param string $hook_spot Hook identifier to bind on
@param AbstractObject|callable $callable Will be called on hook()
@param array $arguments Arguments are passed to $callable
@param int $prio... | entailment |
public function hook($hook_spot, $arg = array())
{
if (!is_array($arg)) {
throw $this->exception(
'Incorrect arguments, or hook does not exist'
);
}
$return = array();
if ($arg === UNDEFINED) {
$arg = array();
}
if ... | Execute all callables assigned to $hook_spot.
@param string $hook_spot Hook identifier
@param array $arg Additional arguments to callables
@return mixed Array of responses or value specified to breakHook | entailment |
public function tryCall($method, $arguments)
{
if ($ret = $this->hook('method-'.$method, $arguments)) {
return $ret;
}
array_unshift($arguments, $this);
if (($ret = $this->app->hook('global-method-'.$method, $arguments))) {
return $ret;
}
} | Attempts to call dynamic method. Returns array containing result or false.
@param string $method Name of the method
@param array $arguments Arguments
@return mixed | entailment |
public function addMethod($name, $callable)
{
if (is_string($name) && strpos($name, ',') !== false) {
$name = explode(',', $name);
}
if (is_array($name)) {
foreach ($name as $h) {
$this->addMethod($h, $callable);
}
return $this... | Add new method for this object.
@param string|array $name Name of new method of $this object
@param callable $callable Callback
@return $this | entailment |
public function hasMethod($name)
{
return method_exists($this, $name)
|| isset($this->hooks['method-'.$name])
|| isset($this->app->hooks['global-method-'.$name]);
} | Return if this object has specified method (either native or dynamic).
@param string $name Name of the method
@return bool | entailment |
public function logError($error, $msg = '')
{
if (is_object($error)) {
// we got exception object obviously
$error = $error->getMessage();
}
$this->app->getLogger()->logLine($msg.' '.$error."\n", null, 'error');
} | Output string into error file.
@param string $error error
@param string $msg msg
@obsolete | entailment |
public function each($callable)
{
if ($this instanceof Iterator) {
if (is_string($callable)) {
foreach ($this as $obj) {
if ($obj->$callable() === false) {
break;
}
}
return $this;
... | A handy shortcut for foreach(){ .. } code. Make your callable return
"false" if you would like to break the loop.
@param string|callable $callable will be executed for each member
@return $this | entailment |
public function _unique(&$array, $desired = null)
{
if (!is_array($array)) {
throw $this->exception('not array');
}
$postfix = count($array);
$attempted_key = $desired;
while (array_key_exists($attempted_key, $array)) {
// already used, move on
... | This funcion given the associative $array and desired new key will return
the best matching key which is not yet in the array.
For example, if you have array('foo'=>x,'bar'=>x) and $desired is 'foo'
function will return 'foo_2'. If 'foo_2' key also exists in that array,
then 'foo_3' is returned and so on.
@param array... | entailment |
public function pack($from, $to)
{
if (($gzip = gzopen($to, 'wb')) === false) {
throw new Exception('Unable create compressed file.');
}
if (($source = fopen($from, 'rb')) === false) {
throw new Exception('Unable open the compression source file.');
}
... | Compresses a file.
@param string $from The source
@param string $to The target
@throws Exception | entailment |
public function unpack($from, $to)
{
if (($gzip = gzopen($from, 'rb')) === false) {
throw new Exception('Unable to read compressed file.');
}
if (($target = fopen($to, 'w')) === false) {
throw new Exception('Unable to open the target.');
}
while ($st... | Uncompresses a file.
@param string $from The source
@param string $to The target
@throws Exception | entailment |
public function setModel($m)
{
if (is_string($m)) {
$m = 'Model_'.$m;
}
$this->model = $this->add($m);
return $this->model;
} | @param string $m
@return Model | entailment |
public function setEmptyText($text = null)
{
$this->empty_text = $text === null ? $this->default_empty_text : $text;
return $this;
} | Sets default text which is displayed on a null-value option.
Set to "Select.." or "Pick one.."
@param string $text Pass null to use default text, empty string - disable
@return $this | entailment |
public function validateValidItem()
{
if (!$this->value) {
return;
}
// load allowed values in values_list
// @todo Imants: Actually we don't need to load all values from Model in
// array, just to check couple of posted values.
// Probably we... | Validate POSTed field value.
@return bool | entailment |
public function getValueList()
{
// add model data rows in value list
try {
if ($this->model) {
$id = $this->model->id_field;
$title = $this->model->getElement($this->model->title_field);
$this->value_list = array();
foreac... | Return value list.
@return array | entailment |
public function normalize()
{
$data = $this->get();
if (is_array($data)) {
$data = implode($this->separator, $data);
}
$data = trim($data, $this->separator);
if (!$data) {
$data = null;
}
if (get_magic_quotes_gpc()) {
$this... | Normalize POSTed data. | entailment |
public function send(OutgoingMessage $message)
{
try {
$message = $this->mailer->send(['text' => $message->getView()], $message->getData(), function ($email) use ($message) {
$this->generateMessage($email, $message);
});
} catch (InvalidArgumentException $e) {... | Sends a SMS message via the mailer.
@param SimpleSoftwareIO\SMS\OutgoingMessage $message
@return Illuminate\Mail\Message | entailment |
protected function generateMessage($email, $message)
{
foreach ($message->getToWithCarriers() as $number) {
$email->to($this->buildEmail($number, $message));
}
if ($message->getAttachImages()) {
foreach ($message->getAttachImages() as $image) {
$email... | Generates the Laravel Message Object.
@param Illuminate\Mail\Message $email
@param SimpleSoftwareIO\SMS\OutgoingMessage $message
@return Illuminate\Mail\Message | entailment |
protected function sendRaw(OutgoingMessage $message)
{
$message = $this->mailer->raw($message->getView(), function ($email) use ($message) {
$this->generateMessage($email, $message);
});
return $message;
} | Sends a SMS message via the mailer using the raw method.
@param SimpleSoftwareIO\SMS\OutgoingMessage $message
@return Illuminate\Mail\Message | entailment |
protected function buildEmail($number, OutgoingMessage $message)
{
if (!$number['carrier']) {
throw new \InvalidArgumentException('A carrier must be specified if using the E-Mail Driver.');
}
return $number['number'].'@'.$this->lookupGateway($number['carrier'], $message->isMMS()... | Builds the email address of a number.
@param array $number
@param SimpleSoftwareIO\SMS\OutgoingMessage $message
@return string | entailment |
protected function lookupGateway($carrier, $mms)
{
if ($mms) {
switch ($carrier) {
case 'att':
return 'mms.att.net';
case 'airfiremobile':
throw new \InvalidArgumentException('Air Fire Mobile does not support Email Gateway ... | Finds the gateway based on the carrier and MMS.
@param string $carrier
@param bool $mms
@return string | entailment |
public function send(OutgoingMessage $message)
{
$from = $message->getFrom();
$composeMessage = $message->composeMessage();
foreach ($message->getTo() as $to) {
$this->twilio->account->messages->create([
'To' => $to,
'From' => $from,
... | Sends a SMS message.
@param \SimpleSoftwareIO\SMS\OutgoingMessage $message | entailment |
protected function processReceive($raw)
{
$incomingMessage = $this->createIncomingMessage();
$incomingMessage->setRaw($raw);
$incomingMessage->setMessage($raw->body);
$incomingMessage->setFrom($raw->from);
$incomingMessage->setId($raw->sid);
$incomingMessage->setTo($r... | Processing the raw information from a request and inputs it into the IncomingMessage object.
@param $raw | entailment |
public function checkMessages(array $options = [])
{
$start = array_key_exists('start', $options) ? $options['start'] : 0;
$end = array_key_exists('end', $options) ? $options['end'] : 25;
$rawMessages = $this->twilio->account->messages->getIterator($start, $end, $options);
$incoming... | Checks the server for messages and returns their results.
@param array $options
@return array | entailment |
public function getMessage($messageId)
{
$rawMessage = $this->twilio->account->messages->get($messageId);
$incomingMessage = $this->createIncomingMessage();
$this->processReceive($incomingMessage, $rawMessage);
return $incomingMessage;
} | Gets a single message by it's ID.
@param string|int $messageId
@return \SimpleSoftwareIO\SMS\IncomingMessage | entailment |
protected function validateRequest()
{
//Twilio requires that all POST data be sorted alpha to validate.
$data = $_POST;
ksort($data);
// append the data array to the url string, with no delimiters
$url = $this->url;
foreach ($data as $key => $value) {
$u... | Checks if a message is authentic from Twilio.
@throws \InvalidArgumentException | entailment |
public function sseMessageLine($text, $id = null)
{
if (!is_null($id)) {
echo "id: $id\n";
}
$text = explode("\n", $text);
$text = 'data: '.implode("\ndata: ", $text)."\n\n";
echo $text;
flush();
} | Sends text through SSE channel. Text may contain newlines
which will be transmitted proprely. Optionally you can
specify ID also. | entailment |
public function sseMessageJSON($text, $id = null)
{
if (!is_null($id)) {
echo "id: $id\n";
}
$text = 'data: '.json_encode($text)."\n\n";
$this->_out_encoding = false;
echo $text;
flush();
$this->_out_encoding = true;
} | Sends text or structured data through SSE channel encoded
in JSON format. You may supply id argument. | entailment |
public function jsEval($str)
{
if (is_object($str)) {
$str = $str->_render();
}
$data = ['js' => $str];
$this->sseMessageJSON($data);
} | Add ability to send javascript. | entailment |
public function out($str, $opt = array())
{
$data = array_merge($opt, ['text' => rtrim($str, "\n")]);
//if($color)$data['style']='color: '.$color;
$this->sseMessageJSON($data);
} | Displays output in the console. | entailment |
public function rule_regex($a)
{
$opt = array();
$rule = $this->pullRule();
if ($rule[0] != '/') {
$rule = '/^'.$rule.'*$/';
}
$opt['regexp'] = $rule;
if (!filter_var($a, FILTER_VALIDATE_REGEXP, ['options' => $opt])) {
return $this->fail('does... | Requires a regex pattern as the
next rule in the chain.
Please give your rule a custom error message. | entailment |
public function rule_in($a)
{
$vals = $this->prep_in_vals($a);
if (!in_array($a, $vals)) {
return $this->fail('has an invalid value');
}
} | Checks that value is in the list provided.
Syntax: |in|foo,bar,foobar. | entailment |
public function rule_not_in($a)
{
$vals = $this->prep_in_vals($a);
if (in_array($a, $vals)) {
return $this->fail('has an invalid value');
}
} | Checks that value is not in the list provided.
Syntax: |not_in|foo,bar,foobar. | entailment |
public function rule_between($a)
{
$min = $this->pullRule(true);
$max = $this->pullRule(true);
if (is_numeric($a)) {
if ($a < $min || $a > $max) {
return $this->fail('must be between {{arg1}} and {{arg2}}', $min, $max);
}
} else {
... | Inclusive range check.
Overloaded: checks value for numbers,
string-length for other values.
Next 2 rules must specify the min and max | entailment |
public function rule_decimal_places($a)
{
$places = $this->pullRule();
$pattern = sprintf('/^[0-9]+\.[0-9]{%s}$/', $places);
if (!preg_match($pattern, $a)) {
return $this->fail('Must have {{arg1}} decimal places', $places);
}
} | Checks for a specific number of
decimal places.
Arg: int- number of places | entailment |
public function rule_bool($a)
{
// We don't use PHP inbuilt test - a bit restrictive
// Changes PHP true/false to 1, 0
$a = strtolower($a);
$vals = array('true', 'false', 't', 'f', 1, 0, 'yes', 'no', 'y', 'n');
if (!in_array($a, $vals)) {
return $this->fail('Mu... | Validate for true|false|t|f|1|0|yes|no|y|n.
Normalizes to lower case | entailment |
public function rule_true($a)
{
// Changes PHP true to 1
$a = strtolower($a);
$vals = array('true', 't', 1, 'yes', 'y');
if (!in_array($a, $vals)) {
return $this->fail('Must be true');
}
} | Validate for true|t|1|yes|y.
Normalizes to lower case
Useful for 'if' rules | entailment |
public function rule_false($a)
{
// Changes PHP false to 0
$a = strtolower($a);
$vals = array('false', 'f', 0, 'no', 'n');
if (!in_array($a, $vals)) {
return $this->fail('Must be false');
}
} | Validate for false|f|0|no|n.
Normalizes to lower case
Useful for 'if' rules | entailment |
public function validate_iso_date($a)
{
$date = explode('-', $a);
$msg = 'Must be date in format: YYYY-MMM-DD';
if (count($date) != 3) {
return $this->fail($msg);
}
if (strlen($date[0]) !== 4 || strlen($date[1]) !== 2 || strlen($date[2]) !== 2) {
re... | Validate for ISO date in format YYYY-MM-DD.
Also checks for valid month and day values | entailment |
public function rule_iso_time($a)
{
$pattern = "/^([0-9]{2}):([0-9]{2})(?::([0-9]{2})(?:(?:\.[0-9]{1,}))?)?$/";
$msg = 'Must be a valid ISO time';
if (preg_match($pattern, $a, $matches)) {
if ($matches[1] > 24) {
return $this->fail($msg);
}
... | Validate for ISO time.
Requires a complete hour:minute:second time with
the optional ':' separators.
Checks for hh:mm[[:ss][.**..] where * = microseconds
Also checks for valid # of hours, mins, secs | entailment |
public function rule_iso_datetime($a)
{
$parts = explode(' ', $a);
$msg = 'Must be a valid ISO datetime';
if (count($parts) != 2) {
return $this->fail($msg);
}
try {
$this->rule_iso_date($parts[0]);
} catch (Exception $e) {
return... | Validate ISO datetime in the format:.
YYYY-MM-DD hh:mm:ss with optional microseconds | entailment |
public function rule_before($a)
{
$time = $this->pullRule();
if (strtotime($a) >= strtotime($time)) {
return $this->fail('Must be before {{arg1}}', $time);
}
} | Checks any PHP datetime format:
http://www.php.net/manual/en/datetime.formats.date.php. | entailment |
public function rule_after($a)
{
$time = $this->pullRule();
if (strtotime($a) <= strtotime($time)) {
return $this->fail('Must be after {{arg1}}', $time);
}
} | Checks any PHP datetime format:
http://www.php.net/manual/en/datetime.formats.date.php. | entailment |
public function rule_credit_card($a)
{
// Card formats keep changing and there is too high a risk
// of false negatives if we get clever. So we just check it
// with the Luhn Mod 10 formula
// Calculate the Luhn check number
$msg = 'Not a valid card number';
$sum =... | Validate for credit card number.
Uses the Luhn Mod 10 check | entailment |
public function rule_to_truncate_custom($a)
{
$len = $this->pullRule();
$append = $this->pullRule();
return $this->mb_truncate($a, $len, $append);
} | Requires parameters: length,
custom string to end of string. | entailment |
public function rule_to_name($name, $is_capitalise_prefix = false)
{
/*
A name can have up to 5 components, space delimited:
Worst case:
salutation | forenames | prefix(es) | main name | suffix
Ms | Jo-Sue Ellen | de la | Mer-Savarin | III
... | Useful for cleaning up input where you don't want to present
an error to the user - eg a checkout where ease of use is
more important than accuracy. Can save a lot of re-keying.
Some libraries don't clean up names if already in mixed case.
Experience shows this isn't very useful, as many users
will type mAry, JOSepH e... | entailment |
protected function card_date_parser($a, $type)
{
// Strip out any slash
$date = str_replace('/', '', $a);
// Check that we have 4 digits
if (!preg_match('|^[0-9]{4}$|', $date)) {
return false;
}
$month = substr($date, 0, 2);
$year = substr($dat... | Helper for validating card to and from dates. | entailment |
protected function prep_in_vals($a)
{
$vals = $this->pullRule();
if (is_array($vals)) {
return $vals;
}
$vals = explode(',', $vals);
array_walk($vals, function ($val) {
return trim($val);
});
// create_function('&$val', '$val = trim($val... | Explode and trim a comma-delmited list
for the in and not_in rules. | entailment |
public function setActualFields($fields)
{
if ($this->owner->model->hasMethod('getActualFields')) {
$this->importFields($this->owner->model, $fields);
}
} | Import model fields in grid.
@param array|string|bool $fields | entailment |
public function importFields($model, $fields = null)
{
$this->model = $model;
$this->grid = $this->owner;
if ($fields === false) {
return;
}
if (!$fields) {
$fields = 'visible';
}
if (!is_array($fields)) {
// note: $fields... | Import model fields in form.
@param Model $model
@param array|string|bool $fields
@return void|$this | entailment |
public function importField($field)
{
$field = $this->model->hasElement($field);
if (!$field) {
return;
}
/** @type Field $field */
$field_name = $field->short_name;
if ($field instanceof Field_Reference) {
$field_name = $field->getDereferenc... | Import one field from model into grid.
@param string $field
@return void|Grid|Controller_Grid_Format | entailment |
public function _beforeInit()
{
$this->pm = $this->add($this->pagemanager_class, $this->pagemanager_options);
/** @type Controller_PageManager $this->pm */
$this->pm->parseRequestedURL();
parent::_beforeInit();
} | Executed before init, this method will initialize PageManager and
pathfinder. | entailment |
public function init()
{
$this->getLogger();
// Verify Licensing
//$this->licenseCheck('atk4');
// send headers, no caching
$this->sendHeaders();
$this->cleanMagicQuotes();
parent::init();
// in addition to default initialization, set up logger an... | Redefine this function instead of default constructor. | entailment |
public function cleanMagicQuotes()
{
if (!function_exists('stripslashes_array')) {
function stripslashes_array(&$array, $iterations = 0)
{
if ($iterations < 3) {
foreach ($array as $key => $value) {
if (is_array($value)) {
... | Magic Quotes were a design error. Let's strip them if they are enabled. | entailment |
public function destroySession()
{
if ($this->_is_session_initialized) {
$_SESSION = array();
if (isset($_COOKIE[$this->name])) {
setcookie($this->name/*session_name()*/, '', time() - 42000, '/');
}
session_destroy();
$this->_is_ses... | Completely destroy existing session. | entailment |
public function addStylesheet($file, $ext = '.css', $locate = 'css')
{
//$file = $this->app->locateURL('css', $file . $ext);
if (@$this->included[$locate.'-'.$file.$ext]++) {
return;
}
if (strpos($file, 'http') !== 0 && $file[0] != '/') {
$url = $this->locate... | @todo Description
@param string $file
@param string $ext
@param string $locate
@return $this | entailment |
public function main()
{
try {
// Initialize page and all elements from here
$this->initLayout();
} catch (Exception $e) {
if (!($e instanceof Exception_Stop)) {
return $this->caughtException($e);
}
//$this->caughtException(... | Call this method from your index file. It is the main method of Agile Toolkit. | entailment |
public function execute()
{
$this->rendered['sub-elements'] = array();
try {
$this->hook('pre-render');
$this->hook('beforeRender');
$this->recursiveRender();
if (isset($_GET['cut_object'])) {
throw new BaseException("Unable to cut obje... | Main execution loop. | entailment |
public function render()
{
$this->hook('pre-js-collection');
if (isset($this->app->jquery) && $this->app->jquery) {
$this->app->jquery->getJS($this);
}
if (!($this->template)) {
throw new BaseException('You should specify template for APP object');
}
... | Renders all objects inside applications and echo all output to the browser. | entailment |
public function redirect($page = null, $args = array())
{
/*
* Redirect to specified page. $args are $_GET arguments.
* Use this function instead of issuing header("Location") stuff
*/
$url = $this->url($page, $args);
if ($this->app->isAjaxOutput()) {
i... | Perform instant redirect to another page.
@param string $page
@param array $args | entailment |
public function setTags($t)
{
// Determine Location to atk_public
if ($this->app->pathfinder && $this->app->pathfinder->atk_public) {
$q = $this->app->pathfinder->atk_public->getURL();
} else {
$q = 'http://www.agiletoolkit.org/';
}
$t->trySet('atk_pa... | Called on all templates in the system, populates some system-wide tags.
@param Template $t | entailment |
public function addLayout($name)
{
if (!$this->template) {
return;
}
// TODO: change to functionExists()
if (method_exists($this, $lfunc = 'layout_'.$name)) {
if ($this->template->is_set($name)) {
$this->$lfunc();
}
}
... | Register new layout, which, if has method and tag in the template, will be rendered.
@param string $name
@return $this | entailment |
public function layout_Content()
{
$page = str_replace('/', '_', $this->page);
if (method_exists($this, $pagefunc = 'page_'.$page)) {
$p = $this->add('Page', $this->page, 'Content');
$this->$pagefunc($p);
} else {
$this->app->locate('page', str_replace('_... | Default handling of Content page. To be replaced by App_Frontend
This function initializes content. Content is page-dependant. | entailment |
public function send(OutgoingMessage $message)
{
$composeMessage = $message->composeMessage();
$from = $message->getFrom();
foreach ($message->getTo() as $to) {
$data = [
'from' => $from,
'bulkVariant' => $this->getVariantForSender($from),
... | Sends a SMS message.
@param \SimpleSoftwareIO\SMS\OutgoingMessage $message | entailment |
protected function sendRequest($data)
{
$curl = curl_init();
$options = [
CURLOPT_URL => "https://justsend.pl/api/rest/message/send/{$this->apiKey}/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 1... | @param $data
@return mixed | entailment |
protected function handleError($response)
{
$message = $response['responseCode'].' ('.$response['errorId'].'): '.$response['message'];
$this->throwNotSentException($message, $response['errorId']);
} | Log the error message which ocurred.
@param $response | entailment |
public function getValue($model, $data)
{
/** @type Model $model */
$model = $this->add($this->getModel());
$id = $data[$this->foreignName];
try {
$this->hook('beforeForeignLoad', array($model, $id));
$model->load($id);
$titleField = $model->get... | @todo Useless method parameter $model
@param Model $model
@param array $data
@return mixed | entailment |
public function init()
{
$this->connect();
$this->tmpFile();
if (!is_file($this->config->file) || !is_readable($this->config->file)) {
throw new Exception('Unable to access the source file.');
}
if ($this->compress) {
$gzip = new Compress();
... | {@inheritdoc} | entailment |
protected function import()
{
$query = '';
while (!feof($this->file)) {
$line = fgets($this->file);
$trim = trim($line);
if ($trim === '' || strpos($trim, '--') === 0 || strpos($trim, '/*') === 0) {
continue;
}
if (strpos... | Processes the SQL file.
Reads a SQL file by line by line. Expects that
individual queries are separated by semicolons,
and that quoted values are properly escaped,
including newlines.
Queries themselves can not contain any comments.
All comments are stripped from the file. | entailment |
public function init()
{
parent::init();
$this->days = array();
for ($i = 1; $i <= 31; ++$i) {
$this->days[$i] = str_pad($i, 2, '0', STR_PAD_LEFT);
}
$cur_year = date('Y');
$this->setYearRange($cur_year - 3, $cur_year + 3);
$this->c_year = $cur_y... | / }}} | entailment |
public function init()
{
parent::init();
if (!$this->db) {
$this->db = $this->app->db;
}
if ($this->owner instanceof Field_Reference && !empty($this->owner->owner->relations)) {
$this->relations = &$this->owner->owner->relations;
}
} | {@inheritdoc} | entailment |
public function addField($name, $actual_field = null)
{
if ($this->hasElement($name)) {
if ($name == $this->id_field) {
return $this->getElement($name);
}
throw $this->exception('Field with this name is already defined')
->addMoreInfo('field', ... | Adds field to model
@param string $name
@param string $actual_field
@return Field | entailment |
public function initQuery()
{
if (!$this->table) {
throw $this->exception('$table property must be defined');
}
$this->dsql = $this->db->dsql();
$this->dsql->debug($this->debug);
$this->dsql->table($this->table, $this->table_alias);
$this->dsql->default_fi... | Initializes base query for this model.
@link http://agiletoolkit.org/doc/modeltable/dsql | entailment |
public function debug($enabled = true)
{
if ($enabled === true) {
$this->debug = $enabled;
if ($this->dsql) {
$this->dsql->debug($enabled);
}
} else {
parent::debug($enabled);
}
return $this;
} | Turns debugging mode on|off for this model. All database operations will be outputed.
@param bool $enabled
@return $this | entailment |
public function selectQuery($fields = null)
{
/**/$this->app->pr->start('selectQuery/getActualF');
$actual_fields = $fields ?: $this->getActualFields();
if ($this->fast && $this->_selectQuery) {
return $this->_selectQuery();
}
$this->_selectQuery = $select = $t... | Completes initialization of dsql() by adding fields and expressions.
@param array $fields
@return DB_dsql | entailment |
public function fieldQuery($field)
{
$query = $this->dsql()->del('fields');
if (is_string($field)) {
$field = $this->getElement($field);
}
$field->updateSelectQuery($query);
return $query;
} | Return query for a specific field. All other fields are ommitted. | entailment |
public function titleQuery()
{
$query = $this->dsql()->del('fields');
/** @type Field $el */
$el = $this->hasElement($this->title_field);
if ($this->title_field && $el) {
$el->updateSelectQuery($query);
return $query;
}
return $query->field($... | Returns query which selects title field | entailment |
public function addExpression($name, $expression = null)
{
/** @type Field_Expression $f */
$f = $this->add('Field_Expression', $name);
return $f->set($expression);
} | Adds and returns SQL-calculated expression as a read-only field.
See Field_Expression class.
@param string $name
@param mixed $expression
@return DB_dsql | entailment |
public function join(
$foreign_table,
$master_field = null,
$join_kind = null,
$_foreign_alias = null,
$relation = null
) {
if (!$_foreign_alias) {
$_foreign_alias = '_'.$foreign_table[0];
}
$_foreign_alias = $this->_unique($this->relations... | Constructs model from multiple tables.
Queries will join tables, inserts, updates and deletes will be applied on both tables | entailment |
public function leftJoin(
$foreign_table,
$master_field = null,
$join_kind = null,
$_foreign_alias = null,
$relation = null
) {
if (!$join_kind) {
$join_kind = 'left';
}
$res = $this->join($foreign_table, $master_field, $join_kind, $_foreig... | Creates weak join between tables.
The foreign table may be absent and will not be automatically deleted. | entailment |
public function hasOne($model, $our_field = null, $display_field = null, $as_field = null)
{
// register reference, but don't create any fields there
// parent::hasOne($model,null);
// model, our_field
$this->_references[null] = $model;
if (!$our_field) {
if (!i... | Defines one to many association | entailment |
public function hasMany($model, $their_field = null, $our_field = null, $as_field = null)
{
if (!$our_field) {
$our_field = $this->id_field;
}
if (!$their_field) {
$their_field = ($this->table).'_id';
}
/** @type SQL_Many $rel */
$rel = $this->... | Defines many to one association | entailment |
public function containsOne($field, $model)
{
if (is_array($field) && $field[0]) {
$field['name'] = $field[0];
unset($field[0]);
}
if ($e = $this->hasElement(is_string($field) ? $field : $field['name'])) {
$e->destroy();
}
$this->add('Relat... | Defines contained model for field | entailment |
public function ref($name, $load = null)
{
if (!$name) {
return $this;
}
/** @type Field $field */
$field = $this->getElement($name);
return $field->ref($load);
} | Traverses references. Use field name for hasOne() relations. Use model name for hasMany() | entailment |
public function refSQL($name, $load = null)
{
/** @type Field_Reference $ref */
$ref = $this->getElement($name);
return $ref->refSQL($load);
} | Returns Model with SQL join usable for subqueries. | entailment |
public function addCondition($field, $cond = UNDEFINED, $value = UNDEFINED, $dsql = null)
{
// by default add condition to models DSQL
if (!$dsql) {
$dsql = $this->_dsql();
}
// if array passed, then create multiple conditions joined with OR
if (is_array($field))... | Adds "WHERE" condition / conditions in underlying DSQL.
It tries to be smart about where and how the field is defined.
$field can be passed as:
- string (field name in this model)
- Field object
- DSQL expression
- array (see note below)
$cond can be passed as:
- string ('=', '>', '<=', etc.)
- value can be passed h... | entailment |
public function setLimit($count, $offset = null)
{
$this->_dsql()->limit($count, $offset);
return $this;
} | Sets limit on query | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.