private function checkproperties($properties) { $emptyprops = from('$property')->in($properties)->where('$property == ""')->select('$property'); if (count($emptyprops) > 0) { throw new DataException('mandatoryfields'); } }
public function testYourself() { // Replace the string "you_birthday" with your birthday's datestring $your_birthday = GigasecondTest::dateSetup("1986-03-04"); $gs = from($your_birthday); $this->assertSame("2017-11-10 01:46:40", $gs->format("Y-m-d H:i:s")); }
public function indexAction() { $names = array("Daniel", "Franco", "Jose", "Maria", "Vane", "Rogelio", "Lia"); $result = from('$name')->in($names)->where('$name => strlen($name) < 5')->select('$name'); var_dump($result); exit; }
public function testYourself() { $this->markTestSkipped("Skip"); $your_birthday = GigasecondTest::dateSetup("your_birthday"); $gs = from($your_birthday); $this->assertSame("2046-10-03 01:46:39", $gs->format("Y-m-d H:i:s")); }
function gen() { (yield 1); debug_print_backtrace(); (yield 2); yield from from(2); debug_print_backtrace(); }
function gen($i = 0) { if ($i < 1000) { yield from gen(++$i); } else { (yield $i); yield from from(++$i); } }
/** * Load entity * * @param array $entity * @param array $crit * @param array $opts * * @return array */ function flat_load(array $entity, array $crit = [], array $opts = []) : array { $stmt = db()->prepare(select($entity['attr']) . from($entity['tab']) . where($crit, $entity['attr'], $opts) . order($opts['order'] ?? [], $entity['attr']) . limit($opts['limit'] ?? 0, $opts['offset'] ?? 0)); $stmt->execute(); if (!empty($opts['one'])) { return $stmt->fetch() ?: []; } return $stmt->fetchAll(); }
function getZipContentsAsQueryable($zipFilePath) { $zip = new ZipArchive(); $zip->open($zipFilePath); $zipContents = []; for ($i = 0; $i < $zip->numFiles; $i++) { $zipContents[] = $zip->statIndex($i); } return from($zipContents); }
function get_materia($id) { $this->db->selelct('*'); $this->db > -from('curso_materia'); $this->db->where('id_curso', $id); $resultado = $this->db->get(); if ($resultado->num_rows() > 0) { return $resultado->result(); } else { return FALSE; } }
/** * Index Page action for this controller. * * Maps to the following URL * /index.php/admin/skills */ public function index() { $skillCategories = $this->Categories_model->get_categories(); $skills = $this->Portfolios_model->get_portfolios(); $skillsByCategory = Enumerable::from($skillCategories)->orderBy('$cat ==> $cat["name"]')->groupJoin(from($skills)->orderBy('$skill ==> $skill["name"]'), '$cat ==> $cat["id"]', '$skill ==> $skill["categoryId"]', '($cat, $sks) ==> array( "name" => $cat["name"], "skills" => $sks )'); $this->view_bag['skillsByCategory'] = $skillsByCategory; $this->view_bag['title'] = 'Skills'; $this->template->load(ADMIN_TEMPLATE_NAME, 'admin/skills/index', $this->view_bag); }
/** * Default method */ function show() { $this->refresh_modules_list($silent = true); if (main()->is_post()) { if (is_array($_POST['name']) && !empty($_POST['name'])) { $where = 'name IN("' . implode('","', _es(array_keys($_POST['name']))) . '")'; } if ($_POST['activate_selected']) { $active = 1; } elseif ($_POST['disable_selected']) { $active = 0; } if (isset($active) && $where) { db()->update('admin_modules', ['active' => $active], $where); cache_del('admin_modules'); } return js_redirect(url('/@object')); } if (!isset($this->_yf_plugins)) { $this->_yf_plugins = main()->_preload_plugins_list(); $this->_yf_plugins_classes = main()->_plugins_classes; } $items = []; foreach ((array) from('admin_modules')->order_by('name', 'asc')->all() as $a) { $name = $a['name']; $plugin_name = ''; if (isset($this->_yf_plugins_classes[$name])) { $plugin_name = $this->_yf_plugins_classes[$name]; } $locations = []; $dir = ADMIN_MODULES_DIR; $places = ['framework' => ['dir' => YF_PATH . $dir, 'file' => YF_PREFIX . $name . YF_CLS_EXT], 'project' => ['dir' => ADMIN_SITE_PATH . $dir, 'file' => $name . YF_CLS_EXT], 'app' => ['dir' => APP_PATH . $dir, 'file' => $name . YF_CLS_EXT]]; if ($plugin_name) { $places += ['framework_plugin' => ['dir' => YF_PATH . 'plugins/' . $plugin_name . '/' . $dir, 'file' => YF_PREFIX . $name . YF_CLS_EXT], 'project_plugin' => ['dir' => PROJECT_PATH . 'plugins/' . $plugin_name . '/' . $dir, 'file' => $name . YF_CLS_EXT], 'app_plugin' => ['dir' => APP_PATH . 'plugins/' . $plugin_name . '/' . $dir, 'file' => $name . YF_CLS_EXT]]; } foreach ($places as $pname => $p) { $path = $p['dir'] . $p['file']; if (file_exists($path)) { $locations[$pname] = url('/file_manager/edit/' . urlencode($path)); } } $items[] = ['name' => $a['name'], 'active' => $a['active'], 'locations' => $locations]; } css('.table .checkbox { min-height: 5px; }'); return table($items, ['condensed' => 1, 'pager_records_on_page' => 10000, 'filter' => true, 'filter_params' => ['name' => 'like']])->form()->check_box('name', ['field_desc' => '#', 'width' => '1%'])->text('name')->func('locations', function ($field, $params, $row) { foreach ((array) $field as $loc => $link) { $out[] = '<a href="' . $link . '" class="btn btn-mini btn-xs">' . $loc . '</a>'; } return implode(PHP_EOL, (array) $out); })->btn('conf', url('/conf_editor/admin_modules/%d'), ['id' => 'name'])->btn_active(['id' => 'name'])->footer_submit(['value' => 'activate selected'])->footer_submit(['value' => 'disable selected'])->footer_link('Refresh list', url('/@object/refresh_modules_list'), ['icon' => 'icon-refresh']); }
function gen() { try { (yield "gen" => 0); } catch (Exception $e) { print "catch in gen()\n{$e}\n"; } try { yield from from(0); } catch (Exception $e) { print "catch in gen()\n{$e}\n"; } yield from from(2); }
public function __construct($params = null) { if ($params !== null && is_array($params)) { if (array_key_exists("from", $params)) { from($params["from"]); } elseif (array_key_exists("to", $params)) { to($params["to"]); } elseif (array_key_exists("header", $params)) { header($params["header"]); } elseif (array_key_exists("text", $params)) { text($params["text"]); } elseif (array_key_exists("subject", $params)) { subject($params["subject"]); } } return $this; }
/** */ function _filter_form_balance($filter, $replace) { $order_fields = []; foreach (explode('|', 'operation_id|datetime_update|datetime_start|datetime_finish|title|amount|balance') as $f) { $order_fields[$f] = $f; } $payment_api = _class('payment_api'); $providers = $payment_api->provider(); $providers__select_box = []; foreach ($providers as $id => $item) { $providers__select_box[$id] = $item['title']; } $payment_status = $payment_api->get_status(); $payment_status__select_box = []; $payment_status__select_box[-1] = 'ВСЕ СТАТУСЫ'; foreach ($payment_status as $id => $item) { $payment_status__select_box[$id] = $item['title']; } $min_date = from('payment_account')->one('UNIX_TIMESTAMP(MIN(datetime_create))'); return form($replace, ['filter' => true, 'selected' => $filter])->hidden('user_id')->hidden('account_id')->text('operation_id', 'Номер операции')->text('title', 'Название')->select_box('status_id', $payment_status__select_box, ['show_text' => 'статус', 'desc' => 'Статус'])->select_box('provider_id', $providers__select_box, ['show_text' => 'провайдер', 'desc' => 'Провайдер'])->radio_box('direction', ['' => 'все', 'in' => 'приход', 'out' => 'расход'], ['desc' => 'Направление'])->daterange('datetime_update', ['format' => 'YYYY-MM-DD', 'min_date' => date('Y-m-d', $min_date ?: time() - 86400 * 30), 'max_date' => date('Y-m-d', time() + 86400), 'autocomplete' => 'off', 'desc' => 'Дата обновления', 'no_label' => 1])->select_box('order_by', $order_fields, ['show_text' => 1, 'desc' => 'Сортировка'])->radio_box('order_direction', ['asc' => 'прямой', 'desc' => 'обратный'], ['desc' => 'Направление сортировки'])->save_and_clear(); }
function send_mail_multipart($from, $from_address, $to, $to_address, $subject, $body_plain, $body_html, $charset) { global $emailAnnounce; $body_html = add_host_to_urls($body_html); if (count($to_address) > 1) { if (isset($emailAnnounce)) { if (empty($to)) { $to_header = $emailAnnounce; } else { $to_header = $to . " <{$emailAnnounce}>"; } } else { if (empty($to)) { $to_header = '(undisclosed recipients)'; } else { $to_header = "({$to})"; } } $bcc = 'Bcc: ' . join(', ', $to_address) . PHP_EOL; } else { if (empty($to)) { if (is_array($to_address)) { $to_header = $to_address[0]; } else { $to_header = $to_address; } } else { if (is_array($to_address)) { $to_header = qencode($to, $charset) . " <{$to_address[0]}>"; } else { $to_header = qencode($to, $charset) . " <{$to_address}>"; } } $bcc = ''; } $separator = uniqid('==eClass-Multipart_Boundary_0_', true) . '_' . md5(time()); $headers = from($from, $from_address) . $bcc . "MIME-Version: 1.0" . PHP_EOL . "Content-Type: multipart/alternative;" . PHP_EOL . " boundary=\"{$separator}\"" . reply_to($from, $from_address); $body = "This is a multi-part message in MIME format." . PHP_EOL . PHP_EOL . "--{$separator}" . PHP_EOL . "Content-Type: text/plain; charset={$charset}" . PHP_EOL . "Content-Transfer-Encoding: 8bit\n\n{$body_plain}" . PHP_EOL . PHP_EOL . "--{$separator}" . PHP_EOL . "Content-Type: text/html; charset={$charset}" . PHP_EOL . "Content-Transfer-Encoding: 8bit" . PHP_EOL . PHP_EOL . "<html><head><meta http-equiv='Content-Type' " . "content='text/html; charset=\"{$charset}\"'>" . "<title>message</title></head><body>\n" . "{$body_html}\n</body></html>" . PHP_EOL . "--{$separator}--" . PHP_EOL; return @mail($to_header, qencode($subject, $charset), $body, $headers); }
/** */ function preview($extra = []) { conf('ROBOTS_NO_INDEX', true); no_graphics(true); if (main()->USER_ID != 1) { return print _403('You should be logged as user 1'); } // Example of url: /dynamic/preview/static_pages/29/ $object = preg_replace('~[^a-z0-9_]+~ims', '', $_GET['id']); $id = preg_replace('~[^a-z0-9_]+~ims', '', $_GET['page']); if (!strlen($object)) { return print _403('Object is required'); } $ref = $_SERVER['HTTP_REFERER']; $body = ''; if (is_post() && isset($_POST['text'])) { $u_ref = parse_url($ref); $u_self = parse_url(WEB_PATH); $u_adm = parse_url(ADMIN_WEB_PATH); if ($u_ref['host'] && $u_ref['host'] == $u_self['host'] && $u_ref['host'] == $u_adm['host'] && $u_ref['path'] == $u_adm['path']) { $body = $_POST['text']; } else { return print _403('Preview security check not passed'); } } if (!$body) { $q = from($object)->whereid($id); if ($object == 'static_pages') { $body = $q->one('text'); } elseif ($object == 'tips') { $body = $q->one('text'); } elseif ($object == 'faq') { $body = $q->one('text'); } elseif ($object == 'news') { $body = $q->one('full_text'); } } $body = '<div class="container">' . $body . '</div>'; return print common()->show_empty_page($body); }
public function setAccess($object, $access) { if ($object instanceof Module) { if ($access) { $this->moduleaccess[$object->getId()] = $access; } else { if (isset($this->moduleaccess[$object->getId()])) { unset($this->moduleaccess[$object->getId()]); } } } else { if ($object instanceof Right) { if ($access) { $this->rights[$object->getId()] = $access; } else { if (isset($this->rights[$object->getId()])) { unset($this->rights[$object->getId()]); } } } else { if ($object instanceof Site) { if ($access) { $sites = from('$site')->in($this->sites)->where('$site => $site->getId() == ' . $object->getId())->select('$site'); if (count($sites) == 0) { $this->sites[] = $object; } } else { $sites = from('$site')->in($this->sites)->where('$site => $site->getId() != ' . $object->getId())->select('$site'); $this->sites = $sites; } } else { throw new DataException('wrongtype'); } } } }
protected function runForm() { if (from($_REQUEST, 'user_name') && from($_REQUEST, 'user_password')) { $this->install(); $this->saveConfigs(); $_SESSION[$this->siteUrl]["user"] = $this->user; return true; } else { unset($_SESSION[$this->siteUrl]["user"]); return false; } }
/** */ function _show_quick_filter() { $a = []; $status_names = from('payment_status')->get_2d('status_id, title'); $count_by_status = select(['status_id', 'COUNT(*) AS num'])->from('payment_operation')->where('direction', '=', 'in')->group_by('status_id')->get_2d(); $statuses_display = [1 => 'text-warning', 2 => 'text-success', 5 => 'text-warning', 3 => 'text-danger', 6 => 'text-danger', 4 => 'text-muted', 7 => 'text-info']; foreach ((array) $statuses_display as $status_id => $css_class) { if ($count_by_status[$status_id]) { $name = $status_names[$status_id]; $a[] = a('/@object/filter_save/clear/?filter=status_id:' . $status_id, $name, 'fa fa-filter', $name, $css_class, ''); } } $a[] = a('/@object/filter_save/clear/', 'Clear filter', 'fa fa-close', '', '', ''); return $a ? '<div class="pull-right">' . implode(PHP_EOL, $a) . '</div>' : ''; }
<?php return (array) from('timezones')->where('active', '1')->order_by('seconds ASC', 'name ASC')->all();
* This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category PHPLinq * @package PHPLinq * @copyright Copyright (c) 2008 - 2009 PHPLinq (http://www.codeplex.com/PHPLinq) * @license http://www.gnu.org/licenses/lgpl.txt LGPL * @version 0.4.0, 2009-01-27 */ /** Error reporting */ error_reporting(E_ALL); /** Include path **/ set_include_path(get_include_path() . PATH_SEPARATOR . '../Classes/' . PATH_SEPARATOR . './resources/'); /** PHPLinq_LinqToObjects */ require_once 'PHPLinq/LinqToObjects.php'; // Create data source $employees = null; require_once 'employees.inc.php'; $result = from('$employee')->in($employees)->where('$employee => strlen($employee->Name) == 4')->skip(1)->take(2)->select('$employee'); print_r($result);
* specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ namespace { from('Hoa')->import('File.Finder'); } namespace Hoa\File { /** * Class \Hoa\File\Watcher. * * A naive file system watcher that fires three events: new, move and modify. * * @author Ivan Enderlin <*****@*****.**> * @copyright Copyright © 2007-2014 Ivan Enderlin. * @license New BSD License */ class Watcher extends Finder implements \Hoa\Core\Event\Listenable { /** * Listeners.
<?php require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/vendor/hoa/core/Core.php'; require_once __DIR__ . '/vendor/atoum/atoum/scripts/runner.php'; from('Hoathis')->import('Atoum.Test.~');
function testFunctions() { $this->assertInstanceOf('YaLinqo\\Enumerable', from(new \EmptyIterator())); }
* version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category PHPLinq * @package PHPLinq * @copyright Copyright (c) 2008 - 2009 PHPLinq (http://www.codeplex.com/PHPLinq) * @license http://www.gnu.org/licenses/lgpl.txt LGPL * @version 0.4.0, 2009-01-27 */ /** Error reporting */ error_reporting(E_ALL); /** Include path **/ set_include_path(get_include_path() . PATH_SEPARATOR . '../Classes/' . PATH_SEPARATOR . './resources/'); /** PHPLinq_LinqToObjects */ require_once 'PHPLinq/LinqToObjects.php'; // Create data source $employees = null; require_once 'employees.inc.php'; $result = from('$employee')->in($employees)->where('$employee => substr($employee->Name, 0, 4) == "Bill"')->select('new { "EmailAddress" => $employee->Email, "Domain" => substr($employee->Email, strpos($employee->Email, "@") + 1) }'); print_r($result);
/** */ function _get_items($lang) { $items = []; foreach ((array) from(self::table)->where('locale', $lang)->order_by('order ASC')->all() as $id => $item) { $items[$id] = $item + ['have_children' => 0]; } foreach ((array) $items as $id => $item) { $parent_id = $item['parent_id']; if (!$parent_id) { continue; } $items[$parent_id]['have_children']++; } return $items; }
{ foreach (range(0, 2 << $levels) as $v) { (yield $v); } } function gen($gen, $level) { if ($level % 2) { (yield $gen->current()); } yield from $gen; } foreach (range(0, 6) as $levels) { print "{$levels} level" . ($levels == 1 ? "" : "s") . "\n\n"; $all = array(); $all[] = $gens[0][0] = from($levels); for ($level = 1; $level < $levels; $level++) { for ($i = 0; $i < 1 << $level; $i++) { $all[] = $gens[$level][$i] = gen($gens[$level - 1][$i >> 1], $level); } } while (1) { foreach ($all as $gen) { var_dump($gen->current()); $gen->next(); if (!$gen->valid()) { break 2; } } } print "\n\n";
* specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ namespace { from('Hoa')->import('Console.Exception'); } namespace Hoa\Console\Chrome { /** * Class \Hoa\Console\Chrome\Exception. * * Extending the \Hoa\Console\Exception class. * * @author Ivan Enderlin <*****@*****.**> * @copyright Copyright © 2007-2014 Ivan Enderlin. * @license New BSD License */ class Exception extends \Hoa\Console\Exception { } }
/** */ function show() { return table(from(self::table), ['id' => 'code', 'filter' => true, 'filter_params' => ['__default_order' => 'active DESC, name ASC'], 'pager_records_on_page' => 300])->text('code')->text('code3')->text('name')->text('name_eng')->text('cont')->text('tld')->text('currency')->text('languages')->text('geoname_id')->btn_active(); }
* specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ namespace { from('Hoa')->import('File.Exception.~')->import('File.Temporary.~')->import('Stream.I~.In')->import('Stream.I~.Out'); } namespace Hoa\File\Temporary { /** * Class \Hoa\File\Temporary\ReadWrite. * * Read/write a temporary file. * * @author Ivan Enderlin <*****@*****.**> * @copyright Copyright © 2007-2014 Ivan Enderlin. * @license New BSD License */ class ReadWrite extends Temporary implements \Hoa\Stream\IStream\In, \Hoa\Stream\IStream\Out { /** * Open a file.