sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
public function renderRows() { $this->odd_even = null; $this->total_rows = 0; $this->template->del($this->container_tag); // render data rows $iter = $this->getIterator(); foreach ($iter as $this->current_id => $this->current_row) { if ($this->current_row instanceof Model || $this->current_row instanceof \atk4\data\Model) { $this->current_row = (array) $this->current_row->get(); } elseif (!is_array($this->current_row) && !($this->current_row instanceof ArrayAccess)) { // Looks like we won't be abel to access current_row as array, so we will // copy it's value inside $this->current instead and produce an empty array // to be filled out by a custom iterators $this->current = $this->current_row; $this->current_row = get_object_vars($this->current); } $this->current_row_html = array(); if (!empty($this->sep_html) && $this->total_rows) { $this->renderSeparator(); } // calculate rows so far ++$this->total_rows; // if onRender totals enabled, then update totals if ($this->totals_type == 'onRender') { $this->updateTotals(); } // render data row $this->renderDataRow(); } // calculate grand totals if needed if ($this->totals_type == 'onRequest') { $this->updateGrandTotals(); } // set total row count $this->totals['row_count'] = $this->total_rows; // render totals row $this->renderTotalsRow(); }
Render lister rows.
entailment
public function renderDataRow() { $this->formatRow(); $this->template->appendHTML( $this->container_tag, $this->rowRender($this->row_t) ); }
Render data row.
entailment
public function renderTotalsRow() { $this->current_row = $this->current_row_html = array(); if ($this->totals !== false && is_array($this->totals) && $this->totals_t) { $this->current_row = $this->totals; $this->formatTotalsRow(); $this->template->appendHTML( $this->container_tag, $this->rowRender($this->totals_t) ); } else { $this->template->tryDel('totals'); } }
Render Totals row.
entailment
public function formatRow() { parent::formatRow(); if (is_array($this->current_row) || $this->current_row instanceof ArrayAccess) { $this->odd_even = $this->odd_even == $this->odd_css_class ? $this->even_css_class : $this->odd_css_class; $this->current_row['odd_even'] = $this->odd_even; } }
Format lister row.
entailment
public function formatTotalsRow() { $this->formatRow(); $this->hook('formatTotalsRow'); // deal with plural - not localizable! if ($this->current_row['row_count'] == 0) { $this->current_row['row_count'] = 'no'; $this->current_row['plural_s'] = 's'; } else { $this->current_row['plural_s'] = $this->current_row['row_count'] > 1 ? 's' : ''; } }
Additional formatting for Totals row. @todo This plural_s method suits only English locale !!!
entailment
public function updateTotals() { if (is_array($this->totals)) { foreach ($this->totals as $key => $val) { if (is_object($this->current_row[$key])) { continue; } $this->totals[$key] = $val + $this->current_row[$key]; } } }
Add current rendered row values to totals. Called before each formatRow() call.
entailment
public function updateGrandTotals() { // get model $m = $this->getIterator(); // create DSQL query for sum and count request $fields = array_keys($this->totals); // select as sub-query $sub_q = $m->dsql()->del('limit')->del('order'); $q = $this->app->db->dsql();//->debug(); $q->table($sub_q, 'grandTotals'); // alias is mandatory if you pass table as DSQL foreach ($fields as $field) { $q->field($q->sum($field), $field); } $q->field($q->count(), 'total_cnt'); // execute DSQL $data = $q->getHash(); // parse results $this->total_rows = $data['total_cnt']; unset($data['total_cnt']); $this->totals = $data; }
Calculate grand totals of all rows. Called one time on rendering phase - before renderRows() call.
entailment
public function formatRow() { parent::formatRow(); $page = $this->model['page']; if (!$page && $this->max_depth) { // by default resort to parent pages $tmp = array(); for ($i = 0; $i < $this->max_depth; ++$i) { $tmp[] = '..'; } --$this->max_depth; $page = $this->app->url(implode('/', $tmp)); } if ($page) { $this->current_row_html['crumb'] = '<a href="'.$this->app->url($page).'">'. htmlspecialchars($this->model['name']). '</a>'; } else { $this->current_row_html['crumb'] = htmlspecialchars($this->model['name']); } }
Format row (overwrite)
entailment
public function render() { $this->max_depth = count($this->setModel($this->model)) - 1; return parent::render(); }
Render object
entailment
public function send(OutgoingMessage $message) { $composeMessage = $message->composeMessage(); foreach ($message->getTo() as $to) { $data = [ 'to' => $to, 'messagebody' => $composeMessage, ]; $this->buildBody($data); $this->postRequest(); } }
Sends a SMS message. @param \SimpleSoftwareIO\SMS\OutgoingMessage $message
entailment
public function send(OutgoingMessage $message) { $from = $message->getFrom(); $composeMessage = $message->composeMessage(); foreach ($message->getTo() as $to) { $response = $this->plivo->send_message([ 'dst' => $to, 'src' => $from, 'text' => $composeMessage, ]); if ($response['status'] != 202) { $this->SMSNotSentException($response['response']['error']); } } }
Sends a SMS message. @param \SimpleSoftwareIO\SMS\OutgoingMessage $message
entailment
protected function processReceive($raw) { $incomingMessage = $this->createIncomingMessage(); $incomingMessage->setRaw($raw); $incomingMessage->setMessage($raw->resource_uri); $incomingMessage->setFrom($raw->message_uuid); $incomingMessage->setId($raw->message_uuid); $incomingMessage->setTo($raw->to_number); }
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->plivo->get_messages([ 'offset' => $start, 'limit' => $end, ]); $incomingMessages = []; foreach ($rawMessages['objects'] as $rawMessage) { $incomingMessage = $this->createIncomingMessage(); $this->processReceive($incomingMessage, $rawMessage); $incomingMessages[] = $incomingMessage; } return $incomingMessages; }
Checks the server for messages and returns their results. @param array $options @return array
entailment
public function getMessage($messageId) { $rawMessage = $this->plivo->get_message(['record_id' => $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
public function receive($raw) { if ($this->verify) { $this->validateRequest(); } $incomingMessage = $this->createIncomingMessage(); $incomingMessage->setRaw($raw->get()); $incomingMessage->setMessage($raw->get('resource_uri')); $incomingMessage->setFrom($raw->get('from_number')); $incomingMessage->setId($raw->get('message_uuid')); $incomingMessage->setTo($raw->get('to_number')); return $incomingMessage; }
Receives an incoming message via REST call. @param mixed $raw @return \SimpleSoftwareIO\SMS\IncomingMessage
entailment
protected function validateRequest() { $data = $_POST; $url = $this->url; $signature = $_SERVER['X-Plivo-Signature']; $authToken = $this->authToken; if (!$this->plivo->validate_signature($url, $data, $signature, $authToken)) { throw new \InvalidArgumentException('This request was not able to verify it came from Plivo.'); } return true; }
Checks if a message is authentic from Plivo. @throws \InvalidArgumentException
entailment
public function useOldTemplateTags() { $this->app->setConfig(array('template' => array( 'ldelim' => '<\?', 'rdelim' => '\?>', ))); if ($this->app->template) { // reload it $this->app->template->settings = array_merge( $this->app->template->getDefaultSettings(), $this->app->getConfig('template', array()) ); $this->app->template->reload(); } return $this; }
Forces Agile Toolkit to use <?tag?> templates instead of {tag}
entailment
public function useNoPublic() { $this->app->pathfinder->base_location->defineContents(array( 'public' => 'atk4/public/atk4', 'js' => 'atk4/public/atk4/js', )); $this->app->pathfinder->base_location->setBaseURL($this->app->pm->base_url); return $this; }
Agile Toolkit 43 expects public/atk4 to point to atk4/public/atk4. If you can't do that, oh well
entailment
public function init() { parent::init(); $this->app->requires('atk', $this->atk_version); if (!$this->addon_name) { throw $this->exception('Addon name must be specified in it\'s Controller'); } $this->namespace = substr(get_class($this), 0, strrpos(get_class($this), '\\')); $this->addon_base_path = $this->app->locatePath('addons', $this->namespace); if (count($this->addon_private_locations) || count($this->addon_public_locations)) { $this->addAddonLocations($this->base_path); } }
???
entailment
public function routePages($page_prefix) { if ($this->app instanceof App_Frontend) { /** @type App_Frontend $this->app */ $this->app->routePages($page_prefix, $this->namespace); } }
This routes certain prefixes to an add-on. Call this method explicitly from init() if necessary.
entailment
public function addLocation($contents, $public_contents = null) { $this->location = $this->app->pathfinder->addLocation($contents); $this->location->setBasePath($this->addon_base_path); // If class has assets, those have probably been installed // into the public location // TODO: test if ($this->has_assets) { if (is_null($public_contents)) { $public_contents = array( 'public' => '.', 'js' => 'js', 'css' => 'css', ); } $this->location = $this->app->pathfinder->public_location ->addRelativeLocation($this->addon_base_path, $contents); } return $this->location; }
This defines the location data for the add-on. Call this method explicitly from init() if necessary.
entailment
public function send(OutgoingMessage $message) { foreach ($message->getTo() as $number) { $this->logger->notice("Sending SMS message to: $number"); } }
Sends a SMS message. @param \SimpleSoftwareIO\SMS\OutgoingMessage $message
entailment
protected function processReceive($rawMessage) { $incomingMessage = $this->createIncomingMessage(); $incomingMessage->setRaw($rawMessage); $incomingMessage->setFrom((string) $rawMessage->FromNumber); $incomingMessage->setMessage((string) $rawMessage->TextRecord->Message); $incomingMessage->setId((string) $rawMessage['id']); $incomingMessage->setTo((string) $rawMessage->ToNumber); return $incomingMessage; }
Creates many IncomingMessage objects and sets all of the properties. @param $rawMessage @return mixed
entailment
public function composeMessage() { // Attempts to make a view. // If a view can not be created; it is assumed that simple message is passed through. try { return $this->views->make($this->view, $this->data)->render(); } catch (\InvalidArgumentException $e) { return $this->view; } }
Composes a message. @return \Illuminate\View\Factory
entailment
public function attachImage($image) { $this->mms = true; if (is_array($image)) { $this->attachImages = array_merge($this->attachImages, $image); } else { $this->attachImages[] = $image; } }
Attaches an image to a message. @param string $image Path to image.
entailment
public function init() { parent::init(); if (@$_GET[$this->owner->name.'_cut_field'] == $this->name) { $this->app->addHook('pre-render', array($this, '_cutField')); } /* TODO: finish refactoring // find the form $obj=$this->owner; while(!$obj instanceof Form){ if($obj === $this->app)throw $this->exception('You must add fields only inside Form'); $obj = $obj->owner; } $this->setForm($obj); */ }
/ }}}
entailment
public function addButton($label, $options = array()) { $position = 'after'; if (is_string($options)) { $position = $options; } else { if (isset($options['position'])) { $position = $options['position']; } } if ($position == 'after') { /** @type Button $button */ $button = $this->afterField()->add('Button', $options); $button->set($label); } else { /** @type Button $button */ $button = $this->beforeField()->add('Button', $options); $button->set($label); } $this->js('change', $button->js()->data('val', $this->js()->val())); return $button; }
Position can be either 'before' or 'after'
entailment
public function addIcon($icon, $link = null) { if (!$this->_icon) { $this->_icon = $this->add('Icon', null, 'icon'); } $this->_icon->set($icon); if ($link) { $this->_icon->setElement('a') ->setAttr('href', $link); } $this->template->trySetHTML('before_input', '<span class="atk-input-icon atk-jackscrew">'); $this->template->trySetHTML('after_input', '</span>'); return $this->_icon; }
Wraps input field into a <span> to align icon correctly
entailment
public function validate($rule = null) { if (is_null($rule)) { throw $this->exception('Incorrect usage of field validation'); } if (is_string($rule)) { // If string is passed, prefix with the field name $rule = $this->short_name.'|'.$rule; } elseif (is_array($rule)) { // if array is passed, prepend with the rule array_unshift($rule, $this->short_name); $rule = array($rule); } elseif (is_callable($rule)) { // callable or something else is passed. Wrap into array. $rule = array(array($this->short_name, $rule)); } $this->form->validate($rule); return $this; }
This method has been refactored to integrate with Controller_Validator.
entailment
public function validateField($condition, $msg = null) { if (is_callable($condition)) { $this->form->addHook('validate', array($this, '_validateField'), array($condition, $msg)); } else { $this->form->addHook('validate', 'if(!('.$condition.'))$this->displayFieldError("'. ($msg ?: 'Error in '.$this->caption).'");'); } return $this; }
Executes a callback. If callback returns string, shows it as error message. If callback returns "false" shows either $msg or a standard error message. about field being incorrect
entailment
public function validateNotNULL($msg = null) { $this->setMandatory(); if ($msg && $msg !== true) { $msg = $this->app->_($msg); } else { $msg = sprintf($this->app->_('%s is a mandatory field'), $this->caption); } $this->validateField(array($this, '_validateNotNull'), $msg); return $this; }
Adds "X is a mandatory field" message
entailment
public function init() { parent::init(); $this->page = null; $this->saved_base_path = $this->pm->base_path; $this->pm->base_path .= basename($_SERVER['SCRIPT_NAME']); $this->add('jUI'); $this->template->trySet('version', 'Web Software Installer'); $this->stickyGET('step'); $this->s_first = $this->s_last = $this->s_current = $this->s_prev = $this->s_next = null; $this->s_cnt = 0; $this->initInstaller(); }
Initialization.
entailment
public function makePage($step, $template = 'step/default') { return $this->layout->add($this->page_class, null, null, array($template)); }
@todo Description @param string $step Unused parameter !!! @param string $template @return View
entailment
public function initStep($step) { $step_method = 'step_'.$step; /** @type H1 $h */ $h = $this->add('H1'); if (!$this->hasMethod($step_method)) { return $h->set('No such step'); } $h->set('Step '.$this->s_cnt.': '.$this->s_title); $page = $this->makePage($step); return $this->$step_method($page); }
@todo Description @param string $step @return mixed
entailment
public function showIntro($v) { /** @type H1 $h */ $h = $v->add('H1'); $h->set('Welcome to Web Software'); /** @type P $p */ $p = $v->add('P'); $p->set('Thank you for downloading this software. '. 'This wizard will guide you through the installation procedure.'); /** @type View_Warning $w */ $w = $v->add('View_Warning'); if (!is_writable('.')) { $w->setHTML('This installation does not have permissions to create your '. '<b>config.php</b> file for you. You will need to manually create this file'); } elseif (file_exists('config.php')) { $w->setHTML('It appears that you already have <b>config.php</b> file in your '. 'application folder. This installation will read defaults from config.php, but it will ultimatelly '. '<b>overwrite</b> it with the new settings.'); } /** @type Button $b */ $b = $v->add('Button'); $b->set('Start')->js('click')->univ()->location($this->stepURL('first')); }
@todo Description @param View $v
entailment
public function stepURL($position) { $s = 's_'.$position; $s = $this->$s; return $this->url(null, array('step' => $s)); }
@todo Description. @param string $position @return URL
entailment
public function postInit() { foreach ($this->elements as $x => $field) { if ($field instanceof Form_Field) { $field->set($this->recall($x)); if ($field->no_save || !$field->get()) { continue; } // also apply the condition if ($this->view->model && $this->view->model->hasElement($x)) { // take advantage of field normalization $this->view->model->addCondition($x, $field->get()); } } } // call applyFilter hook if such exist, pass model of associated view as parameter $this->hook('applyFilter', array($this->view->model)); }
Remembers values and uses them as condition.
entailment
public function memorizeAll() { // memorize() method doesn't memorize anything if value is null foreach ($this->get() as $field => $value) { if ((isset($this->reset) && $this->isClicked($this->reset)) || is_null($value)) { $this->forget($field); } else { $this->memorize($field, $value); } } }
Memorize filtering parameters.
entailment
public function addButtons() { $this->save = $this->addSubmit('Save'); $this->reset = $this->addSubmit('Reset'); return $this; }
Add Save and Reset buttons. @return $this
entailment
public function submitted() { if (parent::submitted()) { if (isset($this->reset) && $this->isClicked($this->reset)) { $this->forget(); $this->js(null, $this->view->js()->reload())->reload()->execute(); } else { $this->memorizeAll(); } $this->view->js()->reload()->execute(); } }
On form submit memorize or forget filtering parameters.
entailment
public function send(OutgoingMessage $message) { $composedMessage = $message->composeMessage(); $data = [ 'PhoneNumbers' => $message->getTo(), 'Message' => $composedMessage, ]; $this->buildCall('/sending/messages'); $this->buildBody($data); $this->postRequest(); }
Sends a SMS message. @param \SimpleSoftwareIO\SMS\OutgoingMessage $message
entailment
public function checkMessages(array $options = []) { $this->buildCall('/incoming-messages'); $this->buildBody($options); $rawMessages = $this->getRequest()->json(); return $this->makeMessages($rawMessages['Response']['Entries']); }
Checks the server for messages and returns their results. @param array $options @return array
entailment
public function getMessage($messageId) { $this->buildCall('/incoming-messages'); $this->buildCall('/'.$messageId); $rawMessage = $this->getRequest()->json(); return $this->makeMessage($rawMessage['Response']['Entry']); }
Gets a single message by it's ID. @param string|int $messageId @return \SimpleSoftwareIO\SMS\IncomingMessage
entailment
protected function processReceive($rawMessage) { $incomingMessage = $this->createIncomingMessage(); $incomingMessage->setRaw($rawMessage); $incomingMessage->setFrom($rawMessage['PhoneNumber']); $incomingMessage->setMessage($rawMessage['Message']); $incomingMessage->setId($rawMessage['ID']); $incomingMessage->setTo('313131'); return $incomingMessage; }
Returns an IncomingMessage object with it's properties filled out. @param $rawMessage @return mixed|\SimpleSoftwareIO\SMS\IncomingMessage
entailment
public function receive($raw) { //Due to the way EZTexting handles Keyword Submits vs Replys //We must check both values. $from = $raw->get('PhoneNumber') ? $raw->get('PhoneNumber') : $raw->get('from'); $message = $raw->get('Message') ? $raw->get('Message') : $raw->get('message'); $incomingMessage = $this->createIncomingMessage(); $incomingMessage->setRaw($raw->get()); $incomingMessage->setFrom($from); $incomingMessage->setMessage($message); $incomingMessage->setTo('313131'); return $incomingMessage; }
Receives an incoming message via REST call. @param mixed $raw @return \SimpleSoftwareIO\SMS\IncomingMessage
entailment
public function addSeparator($template = null) { $this->items[] = $this->add( 'MenuSeparator', $this->short_name.'_separator'.count($this->items), 'Item', $template ); return $this; }
/*function insertMenuItem($index,$label,$href=null){ $tail=array_slice($this->data,$index); $this->data=array_slice($this->data,0,$index); $this->addMenuItem($label,$href); $this->data=array_merge($this->data,$tail); return $this; }
entailment
public function init() { parent::init(); if ($this->include_id_column) { $this->addColumn('text', 'id'); } $this->addColumn('text', 'name'); $this->addColumn('text', 'value'); }
Initialization
entailment
public function setNoText($icon = null) { $this->options['text'] = false; if ($icon !== null) { $this->setIcon($icon); } return $this; }
Set button without text and optionally with icon. @param string $icon Icon CSS class @return $this
entailment
public function setIcon($icon) { if ($icon[0] != '<') { $icon = '<i class="icon-'.$icon.'"></i>'; } $this->template->trySetHTML('icon', $icon); return $this; }
Sets icon for button. @param string $icon Icon CSS class @return $this @todo Implement this trough Icon view
entailment
public function setLabel($label) { if (is_array($label) && $label['icon']) { $this->setIcon($label['icon']); } elseif (is_string($label)) { return $this->setText($label); } return $this; }
Sets label of button. @param string|array $label @return $this
entailment
public function render() { $this->addClass('atk-button'); $c = $this->template->get('Content'); if (is_array($c)) { $c = $c[0]; } if ($this->template->get('icon') && $c) { $this->template->setHTML('nbsp', '&nbsp;'); } parent::render(); }
Render button.
entailment
public function link($page, $args = array()) { $this->setElement('a'); $this->setAttr('href', $this->app->url($page, $args)); return $this; }
Set button as HTML link object <a href="">. @param string $page @param array $args @return $this
entailment
public function addPopover($js_options = array(), $class_options = null) { $this->options['icons']['secondary'] = $this->js_triangle_class; /** @type View_Popover $popover */ $popover = $this->owner->add($this->popover_class, $class_options, $this->spot); $this->js('click', $popover->showJS($js_options)); return $popover; }
When button is clicked, opens a frame containing generic view. Because this is based on a dialog (popover), this is a modal action even though it does not add dimming / transparency. @param array $js_options Options to pass to popover JS widget @param array $class_options Options to pass to popover PHP class @return View_Popover
entailment
public function addSplitButton($options = null) { $options = array_merge( array( 'text' => false, 'icons' => array( 'primary' => $this->js_triangle_class, ), ), $options ?: array() ); /** @type Button $but */ $but = $this->owner->add('Button', array('options' => $options), $this->spot); /** @type Order $order */ $order = $this->owner->add('Order'); $order->move($but, 'after', $this)->now(); // Not very pretty, but works well $but ->js(true) ->removeClass('ui-corner-all') ->addClass('ui-corner-right') ->css('margin-left', '-2px'); $this ->js(true) ->removeClass('ui-corner-all') ->addClass('ui-corner-left') ->css('margin-right', '-2px'); return $but; }
Adds another button after this one with an arrow and returns it. @param array $options Options to pass to new Button class @return Button New button object (button with triangle)
entailment
public function addMenu($options = array(), $vertical = false) { $this->options['icons']['secondary'] = $this->js_triangle_class; // add menu $this->menu = $this->owner->add($this->menu_class, $options, $this->spot); /** @type Menu_jUI $this->menu */ $this->menu->addStyle('display', 'none'); // show/hide menu on button click $this->js('click', array( $this->js() ->toggleClass($this->js_active_class), $this->menu->js() ->toggle() ->position($this->getPosition($vertical)), )); // hide menu on clicking outside of menu $this->js(true)->_selectorDocument()->bind( 'click', $this->js(null, array( $this->js()->removeClass($this->js_active_class), $this->menu->js()->hide(), ))->_enclose() ); return $this->menu; }
Show menu when clicked. For example, dropdown menu. @param array $options Options to pass to Menu class @param bool $vertical Direction of menu (false=horizontal, true=vertical) @return Menu
entailment
public function isClicked($message = null) { $cl = $this->js('click')->univ(); if ($message !== null) { $cl->confirm($message); } $cl->ajaxec($this->app->url(null, array($this->name => 'clicked')), true); return isset($_GET[$this->name]); }
Add click handler on button and returns true if button was clicked. @param string $message Confirmation question to ask @return bool
entailment
public function onClick($callback, $confirm_msg = null) { if ($this->isClicked($confirm_msg)) { // TODO: add try catch here $ret = call_user_func($callback, $this, $_POST); // if callback response is JS, then execute it if ($ret instanceof jQuery_Chain) { $ret->execute(); } // blank chain otherwise $this->js()->univ()->successMessage(is_string($ret) ? $ret : 'Success')->execute(); } return $this; }
Add click handler on button and executes $callback if button was clicked. @param callback $callback Callback function to execute @param string $confirm_msg Confirmation question to ask @return $this
entailment
public function onClickConsole($callback, $title = null) { if (is_null($title)) { $title = $this->template->get('Content'); } $this->virtual_page = $this->add('VirtualPage', ['type' => 'frameURL']); /** @type VirtualPage $this->virtual_page */ $this->virtual_page ->bindEvent($title) ->set(function ($p) use ($callback) { /** @type View_Console $console */ $console = $p->add('View_Console'); $console->set($callback); }); }
Add click handler on button, that will execute callback. Similar to onClick, however output from callback execution will appear in a dialog window with a console. @param callable $callback @param string $title
entailment
public function convertDate($date, $from = null, $to = 'Y-m-d') { if (!$date) { return null; } if ($from === null) { $from = $this->app->getConfig('locale/date', null); } if ($from === null) { // no format configured, so use our best guess. Will work with Y-m-d $date = new DateTime($date); } else { $date = date_create_from_format($from, (string) $date); } if ($to === null) { $to = $this->app->getConfig('locale/date', 'Y-m-d'); } if ($date === false) { throw $this->exception('Date format is not correct'); } return date_format($date, $to); }
Convert date from one format to another. @param string $date Date in string format @param string $from Optional source format, or null to use locale/date from configuration @param string $to Optional target format, or null to use locale/date from configuration @return string|null
entailment
public function getIdsFromConditions($rows, $conditions, $limit = null) { $withLimit = !is_null($limit) && (is_array($limit) && !is_null($limit[0])); if ($withLimit) { $max = is_null($limit[1]) ? $limit[0] : ($limit[0] + $limit[1]); } $ids = array(); foreach ($rows as $id => $row) { if ($id === '__ids__') { continue; } $valid = true; foreach ($conditions as $c) { if (!$this->isValid($row, $c)) { $valid = false; break; } } if ($valid === true) { $ids[] = $id; if ($withLimit && isset($max) && count($ids) > $max) { break; } } } if ($withLimit) { if ($limit[1] === null) { $ids = array_slice($ids, 0, $limit[0]); } else { $ids = array_slice($ids, $limit[0], $limit[1]); } } return $ids; }
resolve all conditions
entailment
public function init() { parent::init(); try { // Extra 24-hour protection parent::init(); $this->getLogger(); $this->pm = $this->add($this->pagemanager_class, $this->pagemanager_options); /** @type Controller_PageManager $this->pm */ $this->pm->parseRequestedURL(); // It's recommended that you use versioning inside your API, // for example http://api.example.com/v1/user // // This way version is accessible anywhere from $this->app->version list($this->version,) = explode('_', $this->page, 2); // Add-ons may define additional endpoints for your API, but // you must activate them explicitly. $this->pathfinder->base_location->defineContents(array('endpoint' => 'endpoint')); } catch (Exception $e) { $this->caughtException($e); } }
Initialization.
entailment
public function encodeOutput($data) { // TODO - use HTTP_ACCEPT here ? //var_dump($_SERVER['HTTP_ACCEPT']); if ($_GET['format'] == 'xml') { throw $this->exception('only JSON format is supported', null, 406); } if ($_GET['format'] == 'json_pretty') { header('Content-type: application/json'); echo json_encode($data, JSON_PRETTY_PRINT); return; } if ($_GET['format'] == 'html') { echo '<pre>'; echo json_encode($data, JSON_PRETTY_PRINT); return; } header('Content-type: application/json'); if ($data === null) { $data = array(); } echo json_encode($data); }
Output will be properly fromatted. @param mixed $data
entailment
public function execute() { try { try { $file = $this->app->locatePath('endpoint', str_replace('_', '/', $this->page).'.php'); include_once $file; $this->pm->base_path = '/'; } catch (Exception $e) { http_response_code(500); if ($e instanceof Exception_Pathfinder) { $error = array( 'error' => 'No such endpoint', 'type' => 'API_Error', ); } else { $error = array( 'error' => 'Problem with endpoint', 'type' => 'API_Error', ); } $this->caughtException($e); $this->encodeOutput($error); return; } try { $class = 'endpoint_'.$this->page; $this->endpoint = $this->add($class); $this->endpoint->app = $this; $this->endpoint->api = $this->endpoint->app; // compatibility with ATK 4.2 and lower $method = strtolower($_SERVER['REQUEST_METHOD']); $raw_post = file_get_contents('php://input'); if ($raw_post && $raw_post[0] == '{') { $args = json_decode($raw_post, true); } elseif ($method == 'put') { parse_str($raw_post, $args); } else { $args = $_POST; } if ($_GET['method']) { $method .= '_'.$_GET['method']; } if (!$this->endpoint->hasMethod($method)) { throw $this->exception('Method does not exist for this endpoint', null, 404) ->addMoreInfo('method', $method) ->addMoreInfo('endpoint', $this->endpoint) ; } $this->logRequest($method, $args); // Perform the desired action $this->encodeOutput($this->endpoint->$method($args)); $this->logSuccess(); } catch (Exception $e) { $this->caughtException($e); http_response_code($e->getCode() ?: 500); $error = array( 'error' => $e->getMessage(), 'type' => get_class($e), 'more_info' => $e instanceof BaseException ? $e->more_info : null, ); array_walk_recursive($error, function (&$item) { if (is_object($item)) { $item = (string) $item; } }); $this->encodeOutput($error); } } catch (Exception $e) { $this->caughtException($e); } }
Execute.
entailment
public function setAttr($attribute, $value = null) { if (is_array($attribute) && is_null($value)) { foreach ($attribute as $k => $v) { $this->setAttr($k, $v); } return $this; } $this->template->appendHTML('attributes', ' '.$attribute.'="'.$value.'"'); return $this; }
Add attribute to element. Previously added attributes are not affected. @param string|array $attribute Name of the attribute, or hash @param string $value New value of the attribute @return $this
entailment
public function addClass($class) { if (is_array($class)) { foreach ($class as $c) { $this->addClass($class); } return $this; } $this->template->append('class', ' '.$class); return $this; }
Add CSS class to element. Previously added classes are not affected. Multiple CSS classes can also be added if passed as space separated string or array of class names. @param string|array $class CSS class name or array of class names @return $this
entailment
public function addComponents(array $class, $append_to_tag = 'class') { foreach ($class as $key => $value) { if (is_array($value)) { continue; } if ($value === true) { $this->template->append($append_to_tag, ' atk-'.$key); continue; } $this->template->append($append_to_tag, ' atk-'.$key.'-'.$value); } return $this; }
Agile Toolkit CSS now supports concept of Components. Using this method you can define various components for this element:. addComponents( [ 'size'=>'mega', 'swatch'=>'green' ] );
entailment
public function removeClass($class) { $cl = ' '.$this->template->get('class').' '; $cl = str_replace(' '.trim($class).' ', ' ', $cl); $this->template->set('class', trim($cl)); return $this; }
Remove CSS class from element, if it was added with setClass or addClass. @param string $class Single CSS class name to remove @return $this
entailment
public function setStyle($property, $style = null) { $this->template->del('style'); $this->addStyle($property, $style); return $this; }
Set inline CSS style of element. Old styles will be removed. Multiple CSS styles can also be set if passed as array. @param string|array $property CSS Property or hash @param string $style CSS Style definition @return $this
entailment
public function addStyle($property, $style = null) { if (is_array($property) && is_null($style)) { foreach ($property as $k => $v) { $this->addStyle($k, $v); } return $this; } $this->template->append('style', ';'.$property.':'.$style); return $this; }
Add inline CSS style to element. Multiple CSS styles can also be set if passed as array. @param string|array $property CSS Property or hash @param string $style CSS Style definition @return $this
entailment
public function removeStyle($property) { // get string or array of style tags added $st = $this->template->get('style'); // if no style, do nothing if (!$st) { return $this; } // if only one style, then put it in array if (!is_array($st)) { $st = array($st); } // remove all styles and set back the ones which don't match property $this->template->del('style'); foreach ($st as $k => $rule) { if (strpos($rule, ';'.$property.':') === false) { $this->template->append('style', $rule); } } return $this; }
Remove inline CSS style from element, if it was added with setStyle or addStyle. @param string $property CSS Property to remove @return $this
entailment
public function set($text) { if (!is_array($text)) { return $this->setText($text); } if (!is_null($text[0])) { $this->setText($text[0]); } // If icon is defined, it will either insert it into // a designated spot or will combine it with text if ($text['icon']) { if ($this->template->hasTag('icon')) { /** @type Icon $_icon */ $_icon = $this->add('Icon', null, 'icon'); $_icon->set($text['icon']); } else { /** @type Icon $_icon */ $_icon = $this->add('Icon'); $_icon->set($text['icon']); if ($text[0]) { /** @type Html $_html */ $_html = $this->add('Html'); $_html->set('&nbsp;'); /** @type Text $_text */ $_text = $this->add('Text'); $_text->set($text[0]); } } unset($text['icon']); } if ($text['icon-r']) { if ($this->template->hasTag('icon-r')) { /** @type Icon $_icon */ $_icon = $this->add('Icon', null, 'icon'); $_icon->set($text['icon']); } else { if ($text[0]) { /** @type Text $_text */ $_text = $this->add('Text'); $_text->set($text[0]); /** @type Html $_html */ $_html = $this->add('Html'); $_html->set('&nbsp;'); } /** @type Icon $_icon */ $_icon = $this->add('Icon'); $_icon->set($text['icon-r']); } unset($text['icon']); } if ($text[0]) { unset($text[0]); } // for remaining items - apply them as components if (!empty($text)) { $this->addComponents($text); } return $this; }
Sets text to appear inside element. Automatically escapes HTML characters. See also setHTML(). 4.3: You can now pass array to this, which will cleverly affect components of this widget and possibly assign icon @param string|array $text Text @return $this
entailment
public function setText($text) { $this->template->trySet('Content', $this->app->_($text)); return $this; }
Sets text to appear inside element. Automatically escapes HTML characters. See also setHTML(). @param string $text Text @return $this @TODO: Imants: I believe we should use set() here not trySet()
entailment
public function render() { $c = $this->template->get('current'); $this->template->del('current'); $parts = explode('_', $this->app->page); $matched = false; while (!empty($parts)) { $tag = implode('_', $parts); if ($this->template->is_set('current_'.$tag)) { $this->template->trySet('current_'.$tag, $c); $matched = true; } array_pop($parts); } if (!$matched) { $this->template->set('current', $c); } parent::render(); }
}}}
entailment
public function importFields($model, $fields = null) { $this->model = $model; $this->form = $this->owner; if ($fields === false) { return; } if (!$fields) { $fields = 'editable'; } if (!is_array($fields)) { // note: $fields parameter is only useful if model is SQL_Model $fields = $model->getActualFields($fields); } // import fields one by one foreach ($fields as $field) { $this->importField($field); } // set update hook if (!$this->_hook_set) { $this->owner->addHook('update', array($this, 'update')); $model->addHook('afterLoad', array($this, 'setFields')); $this->_hook_set = true; } return $this; }
Import model fields in form. Use $fields === false if you want to associate form with model, but don't create form fields. @param Model $model @param array|string|bool $fields @return void|$this
entailment
public function importField($field, $field_name = null) { $field = $this->model->hasElement($field); if (!$field) { return; } /** @type Field $field */ if (!$field->editable()) { return; } if ($field_name === null) { $field_name = $this->_unique($this->owner->elements, $field->short_name); } $field_type = $this->getFieldType($field); $field_caption = $field->caption(); $this->field_associations[$field_name] = $field; if ($field->listData() || $field instanceof Field_Reference) { if ($field_type == 'Line') { $field_type = 'DropDown'; } } $form_field = $this->owner->addField($field_type, $field_name, $field_caption); $form_field->set($field->get()); $field_placeholder = $field->placeholder() ?: $field->emptyText() ?: null; if ($field_placeholder) { $form_field->setAttr('placeholder', $field_placeholder); } if ($field->hint()) { $form_field->setFieldHint($field->hint()); } if ($field->listData()) { /** @type Form_Field_ValueList $form_field */ $a = $field->listData(); $form_field->setValueList($a); } if ($msg = $field->mandatory()) { $form_field->validateNotNULL($msg); } if ($field instanceof Field_Reference || $field_type == 'reference') { $form_field->setModel($field->getModel()); } if ($field->theModel) { $form_field->setModel($field->theModel); } if ($form_field instanceof Form_Field_ValueList && !$field->mandatory()) { /** @type string $text */ $text = $field->emptyText(); $form_field->setEmptyText($text); } if ($field->onField()) { call_user_func($field->onField(), $form_field); } return $form_field; }
Import one field from model into form. @param string $field @param string $field_name @return void|Form_Field
entailment
public function getFields() { $models = array(); /** * @var Form_Field $form_field * @var Field $model_field */ foreach ($this->field_associations as $form_field => $model_field) { $v = $this->form->get($form_field); $model_field->set($v); if (!isset($models[$model_field->owner->name])) { $models[$model_field->owner->name] = $model_field->owner; } } return $models; }
Returns array of models model_name => Model used in this form. @return array
entailment
public function getFieldType($field) { // default form field type $type = 'Line'; // try to find associated form field type if (isset($this->type_associations[$field->type()])) { $type = $this->type_associations[$field->type()]; } if ($field instanceof Field_Reference) { $type = 'DropDown'; } // if form field type explicitly set in model if ($field->display()) { $tmp = $field->display(); if (is_array($tmp)) { $tmp = $tmp['form']; } if ($tmp) { $type = $tmp; } } return $type; }
Returns form field type associated with model field. Redefine this method to add special handling of your own fields. @param Field $field @return string
entailment
public function rule_if($a) { $b = $this->pullRule(); if (!$this->get($b)) { $this->stop(); } return $a; }
Advanced logic.
entailment
public function send(OutgoingMessage $message) { $composeMessage = $message->composeMessage(); //Convert to callfire format. $numbers = implode(',', $message->getTo()); $data = [ 'To' => $numbers, 'Message' => $composeMessage, ]; $this->buildCall('/text'); $this->buildBody($data); $this->postRequest(); }
Sends a SMS message. @param \SimpleSoftwareIO\SMS\OutgoingMessage $message
entailment
public function checkMessages(array $options = []) { $this->buildCall('/text'); $rawMessages = $this->getRequest()->xml(); return $this->makeMessages($rawMessages->Text); }
Checks the server for messages and returns their results. @param array $options @return array
entailment
public function getMessage($messageId) { $this->buildCall('/text/'.$messageId); return $this->makeMessage($this->getRequest()->xml()->Text); }
Gets a single message by it's ID. @param string|int $messageId @return \SimpleSoftwareIO\SMS\IncomingMessage
entailment
public function set($fx) { /** @type VirtualPage $p */ $p = $this->add('VirtualPage'); $p->set($fx); $this->setURL($p->getURL()); return $this; }
If callable is passed, it will be executed when the dialog is popped through the use of VirtualPage. @param callable $fx @return $this
entailment
public function showJS($options = null, $options_compat = array()) { if (!empty($options_compat)) { $options = $options_compat; } $loader_js = $this->url ? $this->js()->atk4_load(array($this->url)) : $options['open_js'] ?: null; $this->js(true)->dialog(array_extend(array( 'modal' => true, 'dialogClass' => ($options['class'] ?: 'atk-popover').$this->pop_class. ' atk-popover-'.($options['tip'] ?: 'top-center'), 'dragable' => false, 'resizable' => false, 'minHeight' => 'auto', 'autoOpen' => false, 'width' => 250, 'open' => $this->js(null, array( $this->js()->_selector('.ui-dialog-titlebar:last')->hide(), $loader_js, ))->click( $this->js()->dialog('close')->_enclose() )->_selector('.ui-widget-overlay:last')->_enclose()->css('opacity', '0'), ), $options))->parent()->append('<div class="atk-popover-arrow"></div>') ; return $this->js()->dialog('open')->dialog('option', array( 'position' => $p = array( 'my' => $options['my'] ?: 'center top', 'at' => $options['at'] ?: 'center bottom+8', 'of' => $this->js()->_selectorThis(), //'using'=>$this->js( // null, // 'function(position,data){ $( this ).css( position ); console.log("Position: ",data); '. // 'var rev={vertical:"horizontal",horizontal:"vertical"}; '. // '$(this).find(".arrow").addClass(rev[data.important]+" "+data.vertical+" "+data.horizontal);}' //) ), )); }
Returns JS which will position this element and show it. @param array $options @param array $options_compat Deprecated options @return jQuery_Chain
entailment
public function send(OutgoingMessage $message) { $from = $message->getFrom(); $composeMessage = $message->composeMessage(); foreach ($message->getTo() as $number) { $data = [ 'from' => $from, 'to' => $number, 'body' => $composeMessage, ]; $this->buildBody($data); $this->postRequest(); } }
Sends a SMS message. @param \SimpleSoftwareIO\SMS\OutgoingMessage $message @return void
entailment
public function checkMessages(array $options = []) { $this->buildBody($options); $rawMessages = json_decode($this->getRequest()->getBody()->getContents()); return $this->makeMessages($rawMessages->data); }
Checks the server for messages and returns their results. See https://developer.flowroute.com/docs/lookup-a-set-of-messages. @param array $options @return array
entailment
protected function processReceive($rawMessage) { $incomingMessage = $this->createIncomingMessage(); $incomingMessage->setRaw($rawMessage); $incomingMessage->setFrom((string) $rawMessage->attributes->from); $incomingMessage->setMessage((string) $rawMessage->attributes->body); $incomingMessage->setId((string) $rawMessage->id); $incomingMessage->setTo((string) $rawMessage->attributes->to); return $incomingMessage; }
Creates many IncomingMessage objects and sets all of the properties. @param $rawMessage @return mixed
entailment
public function getMessage() { if (!is_a($this->container, 'PhpBotFramework\Entities\Message')) { $this->container['message'] = new Message($this->container['message']); } return $this->container['message']; }
\brief Get message attached to this callback. @return Message $message Message object attached to this callback.
entailment
public function buildView(FormView $view, FormInterface $form, array $options) { $resolver = $this->getResolver($options); $itemProperty = $options['item_property']; $accessor = PropertyAccess::createPropertyAccessor(); $data = $form->getData(); if($data) { $item = $resolver->resolveItem($accessor->getValue($data, $itemProperty)); $view->vars['label'] = $item->getLabel(); $view->vars['translation_domain'] = $item->getTranslationDomain(); } if(isset($options['item_full_name'])) { $view->vars['full_name'] = sprintf('%s', ($options['item_full_name'])); } $view->vars['item_template'] = $resolver->resolveFormTemplate($accessor->getValue($data, $itemProperty));; }
{@inheritdoc}
entailment
public static function paginateItems( $items, int $index, Keyboard &$keyboard, callable $format_item, int $item_per_page = 3, string $prefix = 'list', string $delimiter = DELIMITER ) : string { // Assign the position of first item to show $item_position = ($index - 1) * $item_per_page + 1; $items_number = $items->rowCount(); $counter = 1; $items_displayed = 0; $total_pages = intval($items_number / $item_per_page); // If there an incomplete page if (($items_number % $item_per_page) != 0) { $total_pages++; } // Initialize keyboard with the list $keyboard->addListKeyboard($index, $total_pages, $prefix); $message = ''; // Iterate over all results while ($item = $items->fetch()) { // If we have to display the first item of the page and we // found the item to show (using the position calculated before) if ($items_displayed === 0 && $counter === $item_position) { $message .= $format_item($item, $keyboard); $items_displayed++; // If there is space for other items } elseif ($items_displayed > 0 && $items_displayed < $item_per_page) { $message .= $delimiter; $message .= $format_item($item, $keyboard); $items_displayed++; } elseif ($items_displayed === $item_per_page) { break; } else { $counter++; } } return $message; }
\brief Paginate a number of items got as a result by a query. \details Take items to show in the page $index, delimiting in by $delimiter, and call the closure $format_item on each item paginated. Taking a select query result, take items that have to be shown on page of index $index (calculated with $item_per_page). @param mixed $items Result of a select query using pdo object. @param int $index Index of the page to show. @param PhpBotFramework\Entities\InlineKeyboard $keyboard Inline keyboard object to call PhpBotFramework\\Entities\\InlineKeyboard::addListKeyboard() on it for browsing results. @param closure $format_item A closure that take the item to paginate and the keyboard. You can use it to format the item and add some inline keyboard button for each item. @param string $prefix Prefix to pass to InlineKeyboard::addListKeyboard. @param string $delimiter A string that will be used to concatenate each item. @return string The string message with the items of page $index, with $delimiter between each of them. @see PhpBotFramework\\Entities\\InlineKeyboard
entailment
public function getUpdates(int $offset = 0, int $limit = 100, int $timeout = 60) { $parameters = [ 'offset' => $offset, 'limit' => $limit, 'timeout' => $timeout, ]; return $this->execRequest('getUpdates?' . http_build_query($parameters)); }
\brief Request bot updates. \details Request updates received by the bot using method getUpdates of Telegram API. [API reference](https://core.telegram.org/bots/api#getupdates) @param int $offset <i>Optional</i>. Identifier of the first update to be returned. Must be greater by one than the highest among the identifiers of previously received updates. By default, updates starting with the earliest unconfirmed update are returned. An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id. The negative offset can be specified to retrieve updates starting from -offset update from the end of the updates queue. All previous updates will forgotten. @param int $limit <i>Optional</i>. Limits the number of updates to be retrieved. Values between 1—100 are accepted. @param int $timeout <i>Optional</i>. Timeout in seconds for long polling. @return Array|false Array of updates (can be empty).
entailment
public function createView($options = []): View { $view = View::create(null, 200); $templateVars = []; $templateVars['stylesheets'] = $options['stylesheets']; $templateVars['javascripts'] = $options['javascripts']; if($options['translations']) { $templateVars['translations'] = $this->getTranslations(); } if($options['routes']) { $templateVars['routes'] = $this->getRoutes(); } $templateVars['data'] = [ 'view' => ['view_id' => null] ]; $view->setTemplateData($templateVars); $view->setTemplate($options['template']); return $view; }
{@inheritdoc}
entailment
public function getResources(SyliusRequestConfiguration $requestConfiguration, RepositoryInterface $repository) { if($requestConfiguration instanceof RequestConfiguration && $repository instanceof EntityRepositoryInterface) { if($requestConfiguration->hasFilters()) { $query = $this->filterQueryBuilder->buildQueryFromRequestConfiguration($requestConfiguration); if (null !== $repositoryMethod = $requestConfiguration->getRepositoryMethod()) { $callable = [$repository, $repositoryMethod]; $resources = call_user_func_array($callable, array_merge([$query], $requestConfiguration->getRepositoryArguments())); return $resources; } return $repository->filter($query); } } if (null !== $repositoryMethod = $requestConfiguration->getRepositoryMethod()) { $callable = [$repository, $repositoryMethod]; $resources = call_user_func_array($callable, $requestConfiguration->getRepositoryArguments()); return $resources; } if (!$requestConfiguration->isPaginated() && !$requestConfiguration->isLimited()) { return $repository->findBy($requestConfiguration->getCriteria(), $requestConfiguration->getSorting()); } if (!$requestConfiguration->isPaginated()) { return $repository->findBy($requestConfiguration->getCriteria(), $requestConfiguration->getSorting(), $requestConfiguration->getLimit()); } return $repository->createPaginator($requestConfiguration->getCriteria(), $requestConfiguration->getSorting()); }
{@inheritdoc}
entailment
public function connect(array $params) : bool { $params = $this->addDefaultValue($params); $config = $this->getDns($params); try { $this->pdo = new \PDO($config, $params['username'], $params['password'], $params['options']); $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); return true; } catch (\PDOException $e) { echo 'Unable to connect to database, an error occured:' . $e->getMessage(); } return false; }
\brief Open a database connection using PDO. \details Provides a simple way to initialize a database connection and create a PDO instance. @param array $params Parameters for initialize connection. Index required: - <code>username</code> - <code>password</code> (can be an empty string) Optional index: - <code>dbname</code> - <code>adapter</code> <b>Default</b>: <code>mysql</code> - <code>host</code> <b>Default</b>: <code>localhost</code> - <code>options</code> (<i>Array of options passed when creating PDO object</i>) @return bool True when the connection is succefully created.
entailment
public function getPreviewResponse($resource, $options = array()) { $map = $this->container->getParameter('cmf_routing.controllers_by_class'); $controllerDefinition = null; foreach ($map as $class => $value) { if ($resource instanceof $class) { $controllerDefinition = $value; break; } } if($controllerDefinition === null) { throw new PreviewException( sprintf( 'No controller found for resource, did you add "%s" to cmf_routing.dynamic.controller_by_class in your configuration?', get_class($resource) ) ); } try { $request = new Request(array(), array(), array('_controller' => $controllerDefinition)); $controller = $this->container->get('debug.controller_resolver')->getController($request); $response = call_user_func_array($controller, array($resource)); } catch(\Exception $e) { throw new PreviewException( sprintf( 'Something went wrong while trying to invoke the controller "%s", this "%s" was thrown before with message: %s', $controllerDefinition, get_class($e), $e->getMessage() ) ); } return $response; }
{@inheritdoc}
entailment
public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('enhavo_newsletter'); $rootNode ->children() // Driver used by the resource bundle ->scalarNode('driver')->defaultValue('doctrine/orm')->end() // Object manager used by the resource bundle, if not specified "default" will used ->scalarNode('object_manager')->defaultValue('default')->end() ->end() ->children() ->arrayNode('resources') ->addDefaultsIfNotSet() ->children() ->arrayNode('newsletter') ->addDefaultsIfNotSet() ->children() ->variableNode('options')->end() ->arrayNode('classes') ->addDefaultsIfNotSet() ->children() ->scalarNode('model')->defaultValue('Enhavo\Bundle\NewsletterBundle\Entity\Newsletter')->end() ->scalarNode('controller')->defaultValue('Enhavo\Bundle\NewsletterBundle\Controller\NewsletterController')->end() ->scalarNode('repository')->defaultValue('Enhavo\Bundle\NewsletterBundle\Repository\NewsletterRepository')->end() ->scalarNode('factory')->defaultValue('Sylius\Component\Resource\Factory\Factory')->end() ->scalarNode('form')->defaultValue('Enhavo\Bundle\NewsletterBundle\Form\Type\NewsletterType')->cannotBeEmpty()->end() ->end() ->end() ->end() ->end() ->arrayNode('subscriber') ->addDefaultsIfNotSet() ->children() ->variableNode('options')->end() ->arrayNode('classes') ->addDefaultsIfNotSet() ->children() ->scalarNode('model')->defaultValue('Enhavo\Bundle\NewsletterBundle\Entity\Subscriber')->end() ->scalarNode('controller')->defaultValue('Enhavo\Bundle\NewsletterBundle\Controller\SubscriberController')->end() ->scalarNode('repository')->defaultValue('Enhavo\Bundle\NewsletterBundle\Repository\SubscriberRepository')->end() ->scalarNode('factory')->defaultValue('Sylius\Component\Resource\Factory\Factory')->end() ->scalarNode('form')->defaultValue('Enhavo\Bundle\NewsletterBundle\Form\Type\SubscriberType')->cannotBeEmpty()->end() ->end() ->end() ->end() ->end() ->end() ->end() ->end() ; $rootNode ->children() ->arrayNode('groups')->addDefaultsIfNotSet()->end() ->arrayNode('storage') ->addDefaultsIfNotSet() ->children() ->scalarNode('default')->defaultValue('local')->end() ->arrayNode('groups') ->addDefaultsIfNotSet() ->children() ->variableNode('defaults')->defaultValue([])->end() ->end() ->end() ->variableNode('settings')->defaultValue([])->end() ->end() ->end() ->arrayNode('strategy') ->addDefaultsIfNotSet() ->children() ->scalarNode('default')->defaultValue('notify')->end() ->variableNode('settings')->defaultValue([])->end() ->end() ->end() ->arrayNode('newsletter') ->addDefaultsIfNotSet() ->children() ->arrayNode('mail') ->addDefaultsIfNotSet() ->children() ->scalarNode('from')->end() ->end() ->end() ->arrayNode('template') ->addDefaultsIfNotSet() ->children() ->scalarNode('base')->defaultValue('EnhavoNewsletterBundle:Theme:base.html.twig')->end() ->scalarNode('show')->defaultValue('EnhavoNewsletterBundle:Theme:showNewsletter.html.twig')->end() ->end() ->end() ->end() ->end() ->variableNode('forms') ->end() ->end() ; return $treeBuilder; }
{@inheritdoc}
entailment
public function getFcm() { if (!isset($this->_fcm)) { $this->_fcm = $this->createFcm(); } return $this->_fcm; }
Returns FCM client @return \paragraph1\phpFCM\Client
entailment
protected function createFcm() { $client = new \paragraph1\phpFCM\Client(); $client->setApiKey($this->apiKey); $client->setProxyApiUrl($this->proxyApiUrl); $client->injectHttpClient($this->getHttpClient()); return $client; }
Creates FCM client @return \paragraph1\phpFCM\Client
entailment
public function getHttpClient() { if (!isset($this->_httpClient)) { $this->_httpClient = Yii::createObject($this->guzzleClass, [$this->guzzleConfig]); } return $this->_httpClient; }
Returns Guzzle client @return \GuzzleHttp\ClientInterface
entailment
public function createMessage($deviceTokens = []) { $message = new Message(); if (is_string($deviceTokens)) { $deviceTokens = [$deviceTokens]; } if (!is_array($deviceTokens)) { throw new InvalidParamException("\$deviceTokens must be string or array"); } foreach ($deviceTokens as $token) { $message->addRecipient($this->createDevice($token)); } return $message; }
Creates Message object @param string[]|string $deviceTokens tokens of recipient devices @return Message
entailment
public function getLanguageDatabase() : string { $pdo = $this->bot->getPDO(); // Get the language from the bot $sth = $pdo->prepare('SELECT language FROM ' . $this->user_table . ' WHERE ' . $this->id_column . ' = :chat_id'); $chat_id = $this->bot->chat_id; $sth->bindParam(':chat_id', $chat_id); try { $sth->execute(); } catch (\PDOException $e) { throw new BotException($e->getMessage() . "/n" . $e->getLine()); } $row = $sth->fetch(); if (isset($row['language'])) { $this->language = $row['language']; return $row['language']; } $this->language = 'en'; return 'en'; }
\brief Get current user's language from the database, and set it in $language. @return string Language set for the current user, throw error if there is language is not set for the user.
entailment