sentence1 stringlengths 52 3.87M | sentence2 stringlengths 1 47.2k | label stringclasses 1
value |
|---|---|---|
public function cutRender()
{
$x = $this->app->template->get('document_ready');
if (is_array($x)) {
$x = implode('', $x);
}
if (!empty($x)) {
echo '<script type="text/javascript">'.$x.'</script>';
}
} | [private] When partial render is done, this function includes JS for rendered region. | entailment |
public function getJS($obj)
{
$this->hook('pre-getJS');
$r = '';
foreach ($obj->js as $key => $chains) {
$o = '';
foreach ($chains as $chain) {
$o .= $chain->_render().";\n";
}
switch ($key) {
case 'never':
... | [private] Collect JavaScript chains from specified object and add them into onReady section.
@param AbstractView $obj
@return string | entailment |
protected function buildCall($url)
{
if (!$this->callBuilt) {
$this->apiBase .= $url;
$this->callBuilt = true;
}
} | Builds the API call address.
@param $url | entailment |
protected function buildUrl(array $segments = [])
{
//Get the base URL and add a ?
$url = $this->apiBase.'?';
if (isset($this->apiEnding)) {
$segments = array_merge($segments, $this->apiEnding);
}
foreach ($segments as $key => $value) {
$url = $url."... | Builds a URL.
@param array $segments
@return string | entailment |
public function buildBody($values, $key = null)
{
if (is_array($values)) {
$this->body = array_merge($this->body, $values);
} else {
$this->body[$key] = $values;
}
} | Builds the body part of the request and adds it to the body array.
@param array|string $values
@param null $key | entailment |
protected function getAuth()
{
if (isset($this->auth['username']) && isset($this->auth['password'])) {
return [$this->auth['username'], $this->auth['password']];
}
} | Returns the auth array for requests. If not set, will return null.
@return array|null | entailment |
public function send(OutgoingMessage $message)
{
$composeMessage = $message->composeMessage();
//Convert to sms77 format.
$numbers = implode(',', $message->getTo());
$data = [
'u' => $this->auth['username'],
'p' => $this->auth['password'],
... | Sends a SMS message.
@param \SimpleSoftwareIO\SMS\OutgoingMessage $message | entailment |
protected function handleError($body)
{
$error = 'An error occurred. Status code: '.$body.' - ';
//From https://www.sms77.de/api.pdf Rückgabewerte (German doc)
switch ($body) {
case '101':
$error .= 'Versand an mindestens einen Empfänger fehlgeschlagen';
... | Log the error message which ocurred.
@param $body | entailment |
public function addTitle($title, $class = 'Menu_Advanced_Title')
{
$i = $this->add(
$class,
null,
null,
array_merge($this->defaultTemplate(), array('Title'))
);
/** @type Menu_Advanced_Title $i */
$i->set($title);
return $i;
... | Adds a title to your menu. | entailment |
public function addMenuItem($page, $label = null)
{
if (!$label) {
$label = ucwords(str_replace('_', ' ', $page));
}
return $this->addItem($label, $page);
} | compatibility | entailment |
public function getUploadedFiles()
{
if ($c = $this->model) {
$a = explode(',', $this->value);
$b = array();
foreach ($a as $val) {
if ($val) {
$b[] = $val;
}
}
$files = implode(',', filter_var_ar... | those can be done in flash thingie as well | entailment |
public function setTarget($js_func)
{
$this->on('click', 'a')->univ()->frameURL($this->js()->_selectorThis()->attr('href'));
return $this;
} | This will add a new behaviour for clicking on the menu items. For
example setTarget('frameURL') will show menu links inside a frame
instead of just linking to them. | entailment |
public function addSubMenu($label)
{
// we use MenuSeparator tag here just to put View_Popover outside of UL list.
// Otherwise it breaks correct HTML and CSS.
/** @type View_Popover $f */
$f = $this->add('View_Popover');
$this->addMenuItem($f->showJS('#'.$this->name.'_i'.cou... | @param string $label
@return Menu_jUI | entailment |
public function setModel($model, $display_field = null)
{
if ($model instanceof Model) {
return AbstractObject::setModel($model);
}
$this->model_name = is_string($model) ? $model : get_class($model);
$this->model_name = (string) $this->app->normalizeClassName($this->mode... | Set model
@param Model|string $model
@param string|bool $display_field
@return Model|$this | entailment |
public function getModel()
{
if (!$this->model) {
$this->model = $this->add($this->model_name);
}
/** @type Model $this->model */
if ($this->display_field) {
$this->model->title_field = $this->display_field;
}
if ($this->table_alias) {
... | Return model of field
@return Model | entailment |
public function ref($mode = null)
{
if ($mode == 'model') {
return $this->add($this->model_name);
}
$this->getModel()->unload();
if ($mode === false || $mode == 'ignore') {
return $this->model;
}
if ($mode == 'load') {
return $thi... | ref() will traverse reference and will attempt to load related model's entry. If the entry will fail to load
it will return model which would not be loaded. This can be changed by specifying an argument:.
'model' - simply create new model and return it without loading anything
false or 'ignore' - will not even try to ... | entailment |
public function refSQL()
{
/** @type SQL_Model $q */
$q = $this->ref('model');
$q->addCondition($q->id_field, $this);
return $q;
} | Return DSQL for field
@return SQL_Model | entailment |
public function getDereferenced()
{
if ($this->dereferenced_field) {
return $this->dereferenced_field;
}
$f = preg_replace('/_id$/', '', $this->short_name);
if ($f != $this->short_name) {
return $f;
}
$f = $this->short_name.'_text';
if... | Return name of dereferenced field
@return string | entailment |
public function destroy()
{
if ($e = $this->owner->hasElement($this->getDereferenced())) {
$e->destroy();
}
return parent::destroy();
} | Destroy this field and dereferenced field.
@return $this | entailment |
public function init()
{
parent::init();
$this->add($this->layout_class);
$this->menu = $this->layout->addMenu('Menu_Vertical');
$this->menu->swatch = 'ink';
//$m = $this->layout->addFooter('Menu_Horizontal');
//$m->addItem('foobar');
$this->add('jUI');
... | Initialization. | entailment |
public function page_sandbox($p)
{
$p->title = 'Install Developer Tools';
//$p->addCrumb('Install Developer Tools');
$v = $p->add('View', null, null, array('view/developer-tools'));
$v->add('Button')->set('Install Now')
->addClass('atk-swatch-green')
->onCli... | @todo Description
@return string | entailment |
public function getInstalledAddons()
{
if (!$this->controller_install_addon) {
$this->controller_install_addon = $this->add('sandbox\\Controller_InstallAddon');
}
if ($this->controller_install_addon && $this->controller_install_addon->getSndBoxAddonReader()) {
return... | Return all registered in sandbox_addons.json addons
sandbox/Controller_AddonsConfig_Reflection.
@return array | entailment |
public function getInitiatedAddons($addon_api_name = null)
{
if ($addon_api_name !== null) {
return $this->addons[$addon_api_name];
}
return $this->addons;
} | @todo Description
@param string $addon_api_name
@return AbstractObject|array Addon object or array of objects | entailment |
private function initAddon($addon)
{
$base_path = $this->pathfinder->base_location->getPath();
$init_class_path = $base_path.'/../'.$addon->get('addon_full_path').'/lib/Initiator.php';
if (file_exists($init_class_path)) {
include $init_class_path;
$class_name = str_re... | @todo Description
@param Controller_Addon $addon | entailment |
public function importFields($model, $fields = null)
{
$this->model = $model;
if ($fields === false) {
return;
}
if (!$fields) {
if ($model->only_fields) {
$fields = $model->only_fields;
} else {
$fields = [];
... | Import model fields in view.
Use $fields === false if you want to associate view with model, but don't fill view fields.
@param \atk4\data\Model $model
@param array|string|bool $fields
@return void|$this | entailment |
public function importField($field)
{
if (is_string($field)) {
$field = $this->model->hasElement($field);
}
/** @type \atk4\data\Field $field */
if (!$field || !$field instanceof \atk4\data\Field) {
return;
}
// prepare name
$name = $... | Import one field from model into form.
@param string|\atk4\data\Field $field
@return void | entailment |
public function sendRawRequest($model, $url, $method = 'GET', $data = null)
{
if ($model->debug) {
echo '<font color="blue">'.
htmlspecialchars("$method $url (".json_encode($data).')').
'</font>';
}
$method = strtolower($method);
$pest = $... | Sends request to specified URL with specified method and data. | entailment |
public function loadById($model, $id)
{
$data = $this->sendItemRequest($model, $id);
if (is_array($data)) {
$model->id = $id;
$model->data = $data;
}
} | Implement loadBy | entailment |
public function save($model, $id, $data)
{
if (is_null($id)) { // insert
$model->data = $this->sendCollectionRequest($model, $this->insert_mode, $data);
$model->id = $model->data ? $model->data[$model->id_field] : null;
} else { // update
$model->data = $this->sen... | Saving, updating and deleting data | entailment |
public function isActive($mode = null)
{
if ($mode !== null && isset($_GET[$this->name])) {
return $_GET[$this->name] == $mode;
}
return isset($_GET[$this->name]) ? $_GET[$this->name] : false;
} | Returns true if the URL is requesting the page to be shown.
If no parameter is passed, then return active page mode.
@param string $mode Optionally ask for specific mode
@return bool|string | entailment |
public function bindEvent($title = '', $event = 'click', $selector = null)
{
$t = $this->type;
if (is_null($event)) {
$event = 'click';
}
$this->owner->on($event, $selector)->univ()->$t($title, $this->getURL(), $this->frame_options);
return $this;
} | Bind owner's event (click by default) to a JavaScript chain
which would open a new frame (or dialog, depending on $type
property), and execute associated code inside it.
@param string $title Title of the frame
@param string $event JavaScript event
@param string $selector Not all parent will respond to click but ... | entailment |
public function set($method_or_arg, $method = null)
{
$method = is_callable($method_or_arg) ? $method_or_arg : $method;
$arg = is_callable($method_or_arg) ? null : $method_or_arg;
$self = $this;
if ($this->isActive($arg)) {
$this->app->addHook('post-init', function () u... | Associates code with the page. This code will be executed within
a brand new page when called by URL.
@param callable $method_or_arg Optional argument
@param callable $method function($page){ .. }
@return $this | entailment |
public function getPage()
{
if ($this->page) {
return $this->page;
}
// Remove original page
$this->app->page_object->destroy(false);
$this->page = $this->app->add(
$this->page_class,
$this->name,
null,
$this->page... | Simply returns a page we can put stuff on. This page would
be displayed instead of regular page, so beware.
@return Page page to be displayed | entailment |
public function addColumn($name, $title = null, $buttontext = null, $grid = null)
{
if ($grid === null) {
$grid = $this->owner;
}
/** @type Grid $this->owner */
/** @type Grid $grid */
if (!is_array($buttontext)) {
$buttontext = array('descr' => $butt... | Call this if you are adding this inside a grid.
@param string $name Field Name (must not contain spaces)
@param string $title Header for the column
@param array|string $buttontext Text to put on the button
@param Grid $grid Specify grid to use, other than $owner
@return $this | entailment |
public function addIcon($i)
{
/** @type Icon $icon */
$icon = $this->add('Icon', null, 'Icon');
return $icon->set($i)->addClass('atk-size-mega');
} | By default box uses information Icon.
You can use addIcon() to override or $this->template->del('Icon') to remove.
@param string $i
@return Icon | entailment |
public function addButton($label = 'Continue')
{
if (!is_array($label)) {
$label = array($label, 'icon-r' => 'right-big');
}
/** @type Button $button */
$button = $this->add('Button', null, 'Button');
return $button->set($label);
} | Adds Button on the right side of the box for follow-up action.
@param array|string $label
@return Button | entailment |
public function addClose()
{
if ($this->recall('closed', false)) {
$this->destroy();
}
$self = $this;
/** @type Icon $icon */
$icon = $this->add('Icon', null, 'Button');
$icon
->addComponents(array('size' => 'mega'))
->set('cancel-... | View box can be closed by clicking on the cross.
@return $this | entailment |
public function init()
{
parent::init();
if (!$this->skip_var) {
$this->skip_var = $this->name.'_skip';
}
$this->skip_var = $this->_shorten($this->skip_var);
} | Initialization. | entailment |
public function setSource($source)
{
if ($this->memorize) {
if (isset($_GET[$this->skip_var])) {
$this->skip = $this->memorize('skip', (int) $_GET[$this->skip_var]);
} else {
$this->skip = (int) $this->recall('skip');
}
} else {
... | Set a custom source. Must be an object with foundRows() method.
@param mixed $source | entailment |
public function recursiveRender()
{
// get data source
if (!$this->source) {
// force grid sorting implemented in Grid_Advanced
if ($this->owner instanceof Grid_Advanced) {
$this->owner->getIterator();
}
// set data source for Paginat... | Recursively render this view. | entailment |
public function driver($driver)
{
$this->container['sms.sender'] = $this->container->share(function ($app) use ($driver) {
return (new DriverManager($app))->driver($driver);
});
$this->driver = $this->container['sms.sender'];
} | Changes the set SMS driver.
@param $driver | entailment |
public function send($view, $data, $callback)
{
$data['message'] = $message = $this->createOutgoingMessage();
//We need to set the properties so that we can later pass this onto the Illuminate Mailer class if the e-mail gateway is used.
$message->view($view);
$message->data($data);
... | Send a SMS.
@param string $view The desired view.
@param array $data The data that needs to be passed into the view.
@param \Closure $callback The methods that you wish to fun on the message.
@return \SimpleSoftwareIO\SMS\OutgoingMessage The outgoing message that was sent. | entailment |
protected function createOutgoingMessage()
{
$message = new OutgoingMessage($this->container['view']);
//If a from address is set, pass it along to the message class.
if (isset($this->from)) {
$message->from($this->from);
}
return $message;
} | Creates a new Message instance.
@return \SimpleSoftwareIO\SMS\OutgoingMessage | entailment |
public function handle($request, Closure $next)
{
$request->merge($request->xml(true));
return $next($request);
} | Handle an incoming request.
@param \Illuminate\Http\Request $request
@param \Closure $next
@return mixed | entailment |
public function loadCurrent($model)
{
$model->_table[$this->short_name]->next();
$model->data = $model->_table[$this->short_name]->current();
$model->id = $model->data[$model->id_field];
} | Provided that rewind was called before, load next data entry | entailment |
public function count($model, $alias = null)
{
// prepare new query
$q = $this->getDsqlForSelect($model)->del('fields')->del('order')->del('limit');
// add expression field to query
return $q->field($q->count(), $alias);
} | Returns dynamic query selecting number of entries in the database.
@param string $alias Optional alias of count expression
@return DSQL | entailment |
public function reload()
{
$f = $this->findTemplate($this->template_file);
$template_source = implode('', file($f));
$this->loadTemplateFromString($template_source);
return $this;
} | Causes the template to be refreshed from it's original source | entailment |
public function exception($message = 'Undefined Exception', $type = null, $code = null)
{
$o = $this->owner ? $this->owner->__toString() : 'none';
return parent::exception($message, $type, $code)
->addMoreInfo('owner', $o)
->addMoreInfo('template', $this->template_source)
... | 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 Exception_Template | entailment |
public function getTagRef($tag, &$template)
{
if ($this->isTopTag($tag)) {
$template = &$this->template;
return $this;
}
@list($tag, $ref) = explode('#', $tag);
if (!$ref) {
$ref = 1;
}
if (!isset($this->tags[$tag])) {
... | This is a helper method which populates an array pointing
to the place in the template referenced by a said tag.
Because there might be multiple tags and getTagRef is
returning only one template, it will return the first
occurence:
{greeting}hello{/}, {greeting}world{/}
calling getTagRef('greeting',$template) will ... | entailment |
public function getTagRefList($tag, &$template)
{
if (is_array($tag)) {
// TODO: test
$res = array();
foreach ($tag as $t) {
$template = array();
$this->getTagRefList($t, $te);
foreach ($template as &$tpl) {
... | For methods which execute action on several tags, this method
will return array of templates. You can then iterate
through the array and update all the template values.
{greeting}hello{/}, {greeting}world{/}
calling getTagRefList('greeting',$template) will point
second argument towards array(&array('hello'),&array('... | entailment |
public function hasTag($tag)
{
if (is_array($tag)) {
return true;
}
@list($tag, $ref) = explode('#', $tag);
return isset($this->tags[$tag]) || $this->isTopTag($tag);
} | Checks if template has defined a specified tag. | entailment |
public function set($tag, $value = null, $encode = true)
{
if (!$tag) {
return $this;
}
if (is_array($tag)) {
if (is_null($value)) {
foreach ($tag as $s => $v) {
$this->trySet($s, $v, $encode);
}
ret... | This function will replace region refered by $tag to a new content.
If tag is found inside template several times, all occurences are
replaced.
ALTERNATIVE USE(2) of this function is to pass associative array as
a single argument. This will assign multiple tags with one call.
Sample use is:
set($_GET);
would read a... | entailment |
public function del($tag)
{
if ($this->isTopTag($tag)) {
$this->loadTemplateFromString('');
return $this;
}
$this->getTagRefList($tag, $template);
foreach ($template as &$ref) {
$ref = array();
// TODO recursively go through template,... | Empty contents of specified region. If region contains sub-hierarchy,
it will be also removed.
TODO: This does not dispose of the tags which were previously
inside the region. This causes some severe pitfalls for the users
and ideally must be checked and proper errors must be generated. | entailment |
public function append($tag, $value, $encode = true)
{
if ($value instanceof URL) {
$value = $value->__toString();
}
if ($encode) {
$value = htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8');
}
$this->getTagRefList($tag, $template);
foreach ($t... | Add more content inside a tag. | entailment |
public function findTemplate($template_name)
{
/*
* Find template location inside search directory path
*/
if (!$this->app) {
throw new Exception_InitError('You should use add() to add objects!');
}
$f = $this->app->locatePath(
$this->templat... | template loading and parsing | entailment |
public function _selector($selector = null)
{
if ($selector === false) {
$this->library = null;
} elseif ($selector instanceof self) {
$this->library = '$('.$selector.')';
} else {
$this->library = '$('.json_encode($selector).')';
}
return... | Chain binds to parent object by default. Use this to use other selector $('selector')
@param mixed $selector
@return $this | entailment |
public function _prepend($code)
{
if (is_array($code)) {
$code = implode(';', $code);
}
$this->prepend = $code.';'.$this->prepend;
return $this;
} | Execute more JavaScript code before chain. Avoid using.
@param array|string $code
@return $this | entailment |
public function execute()
{
if (isset($_POST['ajax_submit']) || $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
//if($this->app->jquery)$this->app->jquery->getJS($this->owner);
if (headers_sent($file, $line)) {
echo "<br/>Direct output (echo or print) detect... | Send chain in response to form submit, button click or ajaxec() function for AJAX control output. | entailment |
public function _safe_js_string($str)
{
$l = strlen($str);
$ret = '';
for ($i = 0; $i < $l; ++$i) {
switch ($str[$i]) {
case "\r":
$ret .= '\\r';
break;
case "\n":
$ret .= '\\n';
... | [private] used by custom json_encoding
@param string $str
@return string | entailment |
protected function _flattern_objects($arg, $return_comma_list = false)
{
/*
* This function is very similar to json_encode, however it will traverse array
* before encoding in search of objects based on AbstractObject. Those would
* be replaced with their json representation if fu... | [private] custom json_encoding. called on function arguments.
@param mixed $arg
@param bool $return_comma_list
@return string | entailment |
public function redirect($page = null, $arg = array())
{
$url = $this->app->url($page, $arg);
return $this->univ()->_fn('redirect', array($url));
} | Calls real redirect (from univ), but accepts page name.
Use url() for 1st argument manually anyway.
@param string $page Page name
@param array $arg Arguments
@return $this | entailment |
public function reload($arg = array(), $fn = null, $url = null, $interval = null)
{
if ($fn && $fn instanceof self) {
$fn->_enclose();
}
$obj = $this->owner;
if ($url === null) {
$url = $this->app->url(null, array('cut_object' => $obj->name));
}
... | Reload object.
You can bind this to custom event and trigger it if object is not
directly accessible.
If interval is given, then object will periodically reload itself.
@param array $arg
@param jQuery_Chain $fn
@param string $url
@param int $interval Interval in milisec. how often to reload obje... | entailment |
public function _enclose($fn = null, $preventDefault = false)
{
// builds structure $('obj').$fn(function(){ $('obj').XX; });
if ($fn === null) {
$fn = true;
}
$this->enclose = $fn;
$this->preventDefault = $preventDefault;
return $this;
} | Chain will not be called but will return callable function instead.
@param jQuery_Chain $fn
@param bool $preventDefault
@return $this | entailment |
public function _render()
{
$ret = $this->prepend;
if ($this->library) {
$ret .= $this->library;
} else {
if ($this->str) {
$ret .= "$('#".$this->owner->getJSID()."')";
}
}
$ret .= $this->str;
if ($this->enclose ===... | Render and return js chain as string
@return string | entailment |
public function addField($name, $alias = null)
{
$field = $this->add($this->field_class, $name);
/** @type Field_Base $field */
$field = $field->actual($alias);
/** @type Field_Base $field */
return $field;
} | Creates field definition object containing field meta-information such as caption, type
validation rules, default value etc.
@param string $name
@param string $alias
@return Field_Base | entailment |
public function addExpression($name, $expression, $field_class = UNDEFINED)
{
if ($field_class === UNDEFINED) {
$field_class = $this->defaultExpressionFieldClass;
}
$field = $this->add($field_class, $name);
/** @type Field_Callback $field */
$field->setExpression(... | Add expression: the value of those field will calculate when you use get method.
@param string $name
@param mixed $expression
@param string $field_class
@return Field_Base | entailment |
public function set($name, $value = UNDEFINED)
{
if (is_array($name)) {
foreach ($name as $key => $val) {
$this->set($key, $val);
}
return $this;
} elseif ($value === UNDEFINED) {
throw $this->exception('You must define the second argu... | Set value of fields. If only a single argument is specified
and it is a hash, will use keys as property names and set values
accordingly.
@param $name array or string
@param $value null or value
@return $this | entailment |
public function get($name = null)
{
if ($name === null) {
$data = $this->data;
foreach ($this->_expressions as $key => $field) {
$data[$key] = $field->getValue($this, $this->data);
}
foreach ($this->elements as $key => $field) {
... | Get the value of a model field. If field $name is not specified, then
returns associative hash containing all field data.
@param string $name
@return mixed | entailment |
public function getGroupField($group = 'all')
{
$toExclude = array();
$toAdd = array();
if (strpos($group, ',') !== false) {
foreach (explode(',', $group) as $g) {
if ($g[0] === '-') {
$toExclude[] = substr($g, 1);
} else {
... | Return all fields that belongs to the specified group.
You can use the subtractions group also ("all,-group1,-group2").
@param string $group
@return array | entailment |
public function setActualFields($group = UNDEFINED)
{
if (is_array($group)) {
$this->actual_fields = $group;
return $this;
}
if ($group === UNDEFINED) {
$group = 'all';
}
$this->actual_fields = $this->getGroupField($group);
return... | Set the actual fields of this model.
You can use an array to set the list of fields or a string to
use the grouping.
@param array|string $group string or array
@return $this | entailment |
public function getActualFields()
{
if ($this->actual_fields === false) {
$this->actual_fields = $this->getGroupField();
}
return $this->actual_fields;
} | Get the actual fields.
@return array the actual fields | entailment |
public function getTitleField()
{
if ($this->title_field && $this->hasElement($this->title_field)) {
return $this->title_field;
}
return $this->id_field;
} | Return the title field.
@return string the title field | entailment |
public function isDirty($name)
{
/** @type Field_Base $field */
$field = $this->getElement($name);
return $this->dirty[$name] ||
(!$this->loaded() && $field->has_default_value);
} | Return true if the field is set.
@param string $name
@return bool | entailment |
public function setControllerData($controller)
{
if (is_string($controller)) {
$controller = $this->app->normalizeClassName($controller, 'Data');
} elseif (!$controller instanceof Controller_Data) {
throw $this->exception('Inappropriate Controller. Must extend Controller_Data... | Set the controller data of this model.
@param string|Controller_Data $controller
@return Controller_Data | entailment |
public function setControllerSource($table = null)
{
if (is_null($this->controller)) {
throw $this->exception('Call setControllerData before');
}
$this->controller->setSource($this, $table);
} | Set the source to the controller data.
The $table argument depends on the controller data implementation.
@param mixed $table | entailment |
public function setSource($controller, $table = null)
{
$this->setControllerData($controller);
$this->setControllerSource($table);
return $this;
} | Associate model with a specified data source. The controller could be
either a string (postfix for Controller_Data_..) or a class. One data
controller may be used with multiple models.
If the $table argument is not specified then :php:attr:`Model::table`
will be used to find out name of the table / collection. | entailment |
public function supports($feature)
{
if (!$this->controller) {
return false;
}
$s = 'support'.$feature;
return $this->controller->$s;
} | Returns if certain feature is supported by model | entailment |
public function load($id)
{
if (!$this->controller) {
throw $this->exception('Unable to load model, setSource() must be set');
}
if ($this->loaded()) {
$this->unload();
}
$this->hook('beforeLoad', array('load', array($id)));
$this->controller... | Like tryLoad method but if the record not found, an exception is thrown.
@param $id
@return $this | entailment |
public function loadAny()
{
if ($this->loaded()) {
$this->unload();
}
$this->hook('beforeLoad', array('loadAny', array()));
$this->controller->loadByConditions($this);
$this->endLoad();
return $this;
} | Like tryLoadAny method but if the record not found, an exception is thrown.
@return $this | entailment |
public function loadBy($field, $cond, $value = UNDEFINED)
{
if ($field == $this->id_field && $value === UNDEFINED) {
return $this->load($cond);
}
if ($field == $this->id_field && cond === '=') {
return $this->load($value);
}
if ($this->loaded()) {
... | Like tryLoadBy method but if the record not found, an exception is thrown.
@param $field
@param $cond
@param $value
@return $this | entailment |
public function tryLoadBy($field, $cond = UNDEFINED, $value = UNDEFINED)
{
try {
$this->loadBy($field, $cond, $value);
} catch (Exception_NotFound $e) {
// ignore not-found exception
}
return $this;
} | Adding temporally condition to the model to retrive the first record
The condition specified is removed after the controller data call.
@param $field
@param $cond
@param $value
@return $this | entailment |
public function unload()
{
if ($this->_save_later) {
$this->_save_later = false;
$this->saveAndUnload();
}
if ($this->loaded()) {
$this->hook('beforeUnload');
}
$this->data = $this->dirty = array();
$this->id = null;
$this->... | Forget loaded data.
@return $this | entailment |
public function reset()
{
$ret = $this->unload();
$this->_table = array();
$this->conditions = array();
$this->order = array();
$this->limit = array();
return $ret;
} | Same as unload() method.
@return $this | entailment |
public function save()
{
$this->hook('beforeSave', array($this->id));
$is_update = $this->loaded();
if ($is_update) {
$source = array();
foreach ($this->dirty as $name => $junk) {
$source[$name] = $this->get($name);
}
// No sa... | Saves record with current controller. Uses $this->id as primary key.
If not set, new record is created. | entailment |
public function delete($id = null)
{
if ($this->loaded() && !is_null($id) && ($id !== $this->id)) {
throw $this->exception('Unable to determine which record to delete');
}
if (!is_null($id) && (!$this->loaded() || ($this->loaded() && $id !== $this->id))) {
$this->load... | Delete a record. If the model is loaded, delete the current id.
If not loaded, load model through the $id parameter and delete. | entailment |
public function deleteAll()
{
if ($this->loaded()) {
$this->unload();
}
$this->hook('beforeDeleteAll');
$this->controller->deleteAll($this);
$this->hook('afterDeleteAll');
return $this;
} | Deletes all records associated with this model. | entailment |
public function addCondition($field, $operator = UNDEFINED, $value = UNDEFINED)
{
if (!$this->controller) {
throw $this->exception('Controller for this model is not set', 'NotImplemented');
}
if (!@$this->controller->supportConditions) {
throw $this->exception('The co... | Adds a new condition for this model | entailment |
public function count($alias = null)
{
if ($this->controller && $this->controller->hasMethod('count')) {
return $this->controller->count($this, $alias);
}
throw $this->exception('The controller doesn\'t support count', 'NotImplemented')
->addMoreInfo('controller', $th... | Count records of model.
@param string $alias Optional alias of count result
@return int | entailment |
public function hasOne($model, $our_field = UNDEFINED, $field_class = UNDEFINED)
{
if ($field_class === UNDEFINED) {
$field_class = $this->defaultHasOneFieldClass;
}
if ($our_field === UNDEFINED) {
// guess our field
$tmp = $this->app->normalizeClassName(... | {{{ Relational methods | entailment |
public function ref($ref1)
{
list($ref, $rest) = explode('/', $ref1, 2);
if (!isset($this->_references[$ref])) {
/** @type Field_Base $e */
$e = $this->hasElement($ref);
if ($e && $e->hasMethod('ref')) {
return $e->ref();
} else {
... | Traverses reference of relation.
@param string $ref1
@return Model | entailment |
public function init()
{
/*
* During form initialization it will go through it's own template and
* search for lots of small template chunks it will be using. If those
* chunk won't be in template, it will fall back to default values.
* This way you can re-define how form... | }}} | entailment |
public function error($field, $text = null)
{
/** @type Form_Field $form_field */
$form_field = $this->getElement($field);
$form_field->displayFieldError($text);
} | Adds error message to form field.
@param string $field
@param string $text | entailment |
public function addField($type, $options = null, $caption = null, $attr = null)
{
$insert_into = $this->layout ?: $this;
if (is_object($type) && $type instanceof AbstractView && !($type instanceof Form_Field)) {
// using callback on a sub-view
$insert_into = $type;
... | Adds field in form.
@param AbstractView|array|string $type
@param AbstractView|array|string $options
@param string $caption
@param string $attr Deprecated argument
@return Form_Field | entailment |
public function importFields($model, $fields = null)
{
/** @type Controller_MVCForm $c */
$c = $this->add($this->default_controller);
$c->importFields($model, $fields);
} | Imports model fields in form by using form controller.
@param Model $model
@param array|string|bool $fields | entailment |
public function set($field_or_array, $value = UNDEFINED)
{
// We use UNDEFINED, because 2nd argument of "null" is meaningfull
if (is_array($field_or_array)) {
foreach ($field_or_array as $key => $val) {
if (isset($this->elements[$key]) && ($this->elements[$key] instanceof... | /*
temporarily disabled. TODO: will be implemented with abstract datatype
function setSource($table,$db_fields=null){
if(is_null($db_fields)){
$db_fields=array();
foreach($this->elements as $key=>$el){
if(!($el instanceof Form_Field))continue;
if($el->no_save)continue;
$db_fields[]=$key;
}
}
$this->dq = $this->app->db-... | entailment |
public function setFieldError($field, $name)
{
if (!$this->app->compat_42) {
throw $this->exception('4.3', '_Obsolete');
}
$this->errors[$field] = (isset($this->errors[$field]) ? $this->errors[$field] : '').$name;
} | /* external error management | entailment |
public function init()
{
parent::init();
$this->cache = &$this->app->smlite_cache;
$this->settings = $this->getDefaultSettings();
$this->settings['extension'] = $this->app->getConfig('smlite/extension', '.html');
} | Template creation, interface functions | entailment |
public function get($tag)
{
if ($this->isTopTag($tag)) {
return $this->template;
}
$v = $this->tags[$tag][0];
if (is_array($v) && count($v) == 1) {
$v = array_shift($v);
}
return $v;
} | Finds tag and returns contents.
THIS FUNTION IS DANGEROUS!
- if you want a rendered region, use renderRegion()
- if you want a sub-template use cloneRegion()
- if you want to copy part of template to other SMlite object,
do not forget to call rebuildTags() if you plan to refer them.
Not calling rebuildTags() will ren... | entailment |
public function append($tag, $value, $encode = true)
{
if ($value instanceof URL) {
$value = $value->__toString();
}
// Temporary here until we finish testing
if ($encode
&& $value != $this->app->encodeHtmlChars($value, ENT_NOQUOTES)
&& $this->app-... | This appends static content to region refered by a tag. This function
is useful when you are adding more rows to a list or table.
If tag is used for several regions inside template, they all will be
appended with new data. | entailment |
public function setMessage($tag, $args = array())
{
if (!is_array($args)) {
$args = array($args);
}
$fmt = $this->app->_($this->get($tag));
// Try to analyze format and see which formatter to use
if (class_exists('MessageFormatter', false) && strpos($fmt, '{') !=... | Provided that the HTML tag contains ICU-compatible message format
string, it will be localized then integrated with passed arguments. | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.