public static function getEliteFour($where = null, $limit = null, $order = ' e.`order`, e.`id` ') { if (!is_null($where)) { $where = 'WHERE ' . $where; } $getEliteFour = TPP::db()->query("SELECT\n\t\t\te.`id`,\n\t\t\te.`name`,\n\t\t\te.`type`,\n\t\t\te.`attempts`,\n\t\t\te.`wins`,\n\t\t\te.`losses`,\n\t\t\te.`time`,\n\t\t\te.`is_rematch`,\n\t\t\te.`order`,\n\t\t\tGROUP_CONCAT(\n\t\t\t\tDISTINCT CONCAT_WS('" . self::SEPARATOR_2 . "',\n\t\t\t\t\tefp.`id`,\n\t\t\t\t\tefp.`pokemon`,\n\t\t\t\t\tefp.`level`\n\t\t\t\t) SEPARATOR '" . self::SEPARATOR_1 . "'\n\t\t\t) as `pokemon`,\n\t\t\tGROUP_CONCAT(\n\t\t\t\tDISTINCT CONCAT_WS('" . self::SEPARATOR_2 . "',\n\t\t\t\t\tefpm.elite_four_pokemon_id,\n\t\t\t\t\tefpm.name\n\t\t\t\t) SEPARATOR '" . self::SEPARATOR_1 . "'\n\t\t\t) as `moves`\n\t\t\tFROM `elite_four` e\n\t\t\tJOIN `elite_four_pokemon` efp\n\t\t\t\tON efp.`elite_four_id` = e.`id`\n\t\t \tLEFT JOIN `elite_four_pokemon_move` efpm\n\t\t \t\tON efpm.`elite_four_pokemon_id` = efp.`id`\n\t\t\t" . $where . "\n\t\t\tGROUP BY e.`id`\n\t\t\tORDER BY " . $order . $limit); if (!$getEliteFour) { return []; } $return = []; $beaten = $count_e4 = 0; while ($eliteFour = $getEliteFour->fetch()) { $count_e4++; if (isset($eliteFour['time']) && $eliteFour['time'] != '') { $beaten++; } $newE4 = new self(); $newE4->setAttributes(['id' => (int) $eliteFour['id'], 'name' => $eliteFour['name'], 'type' => $eliteFour['type'], 'attempts' => (int) $eliteFour['attempts'], 'wins' => (int) $eliteFour['wins'], 'losses' => (int) $eliteFour['losses'], 'time' => $eliteFour['time'], 'order' => (int) $eliteFour['order'], 'is_rematch' => (bool) $eliteFour['is_rematch'], 'pokemon' => parent::getPokemonForTrainer($eliteFour['pokemon'], ['id', 'pokemon', 'level'])]); $moves = []; foreach (explode(self::SEPARATOR_1, $eliteFour['moves']) as $move) { $ex = explode(self::SEPARATOR_2, $move); $moves[$ex[0]][] = $ex[1]; } foreach ($newE4->pokemon as $p) { if (isset($moves[$p->id])) { $p->moves = $p->setMoves($moves[$p->id]); } } $return[] = $newE4; } return ['beaten' => $beaten === $count_e4, 'elitefour' => $return]; }
/** * * @param unknown_type $template * @param unknown_type $data * @return string */ protected function includeTemplate($template, $data = null) { $view = new self(); $view->setTemplate($template); $view->copyAll($data); return $view->render(); }
/** * @param array $symptoms * @param array $exclusions * @return string */ public static function generateRelatedSymptom(array $symptoms, array $exclusions = array()) { $instance = new self(); $symptoms = $instance->applyExclusions($symptoms, $exclusions); $symptoms = $instance->invertSymptoms($symptoms); return $instance->extractCause($symptoms); }
public static function constructFailure($status, $nwk_addr_of_interest) { $frame = new self(); $frame->setStatus($status); $frame->setNwkAddrOfInterest($nwk_addr_of_interest); return $frame; }
public static function get_template($args = '') { global $l10n; $defaults = array('locale' => null, 'title' => ''); $args = wp_parse_args($args, $defaults); $locale = $args['locale']; $title = $args['title']; if ($locale) { $mo_orig = $l10n['contact-form-7']; wpcf7_load_textdomain($locale); } self::$current = $contact_form = new self(); $contact_form->title = $title ? $title : __('Untitled', 'contact-form-7'); $contact_form->locale = $locale ? $locale : get_locale(); $properties = $contact_form->get_properties(); foreach ($properties as $key => $value) { $properties[$key] = WPCF7_ContactFormTemplate::get_default($key); } $contact_form->properties = $properties; $contact_form = apply_filters('wpcf7_contact_form_default_pack', $contact_form, $args); if (isset($mo_orig)) { $l10n['contact-form-7'] = $mo_orig; } return $contact_form; }
public static function createCivil($input) { $answer = []; $rules = ['number_civil' => 'required', 'date' => 'required', 'demandant' => 'required', 'defendant' => 'required', 'matery' => 'required', 'secretary' => 'required', 'file' => 'required']; $validation = Validator::make($input, $rules); if ($validation->fails()) { $answer['message'] = $validation; $answer['error'] = true; } else { $civil = new self(); $civil->number_civil = $input['number_civil']; $civil->date = $input['date']; $civil->demandant = $input['demandant']; $civil->defendant = $input['defendant']; $civil->matery = $input['matery']; $civil->secretary = $input['secretary']; $civil->file = $input['file']; $civil->references = $input['references']; $civil->description = $input['description']; $civil->status = 1; if ($civil->save()) { $answer['message'] = 'Creado con exito!'; $answer['error'] = false; } else { $answer['message'] = 'CIVIL CREATE error, team noob!'; $answer['error'] = false; } } return $answer; }
/** * Creates a stylesheet link with LESS support * * @param string $style file name * @param array $attributes default attributes * @param bool $index include the index page * @param array $imports compare file date for these too, CSS and LESS in style @import * @return string */ public static function style($file, array $attributes = null, $index = false, $imports = null) { $imports = (array) $imports; // Compile only .less files if (substr_compare($file, '.less', -5, 5, false) === 0) { $css = substr_replace($file, 'css', -4); $compiled = is_file($css) ? filemtime($css) : 0; try { // Check if imported files have changed $compile = filemtime($file) > $compiled; if (!$compile && !empty($imports)) { foreach ($imports as $import) { if (filemtime($import) > $compiled) { $compile = true; break; } } } // Compile LESS if ($compile) { $compiler = new self($file); file_put_contents($css, $compiler->parse()); } $file = $css; } catch (Exception $e) { Kohana::$log->add(Kohana::ERROR, __METHOD__ . ': Error compiling LESS file ' . $file . ', ' . $e->getMessage()); } } return HTML::style($file . '?' . filemtime($file), $attributes, $index); }
/** * Set option * * @param $name * @param $value * @param null $context * @param null $type * @return bool */ public static function setEntry($name, $value, $context = null, $type = null) { $item = self::where('name', $name)->first(); if (!$item) { $item = new self(); } $item->name = $name; if (!$type) { if (is_string($value)) { $type = 'string'; } else { $type = 'serializable'; } } if ($type == 'serializable') { $value = serialize($value); } elseif ($type == 'json') { $value = json_encode($value); } elseif ($type == 'hashed') { $value = Hash::make($value); } elseif ($type == 'crypted') { $value = Crypt::encrypt($value); } $item->value = $value; $item->type = $type; $item->context = $context; return $item->save(); }
/** * Load an image * * @param $filename * @return Image * @throws Exception */ public static function load($filename) { $instance = new self(); // Require GD library if (!extension_loaded('gd')) { throw new Exception('Required extension GD is not loaded.'); } $instance->filename = $filename; $info = getimagesize($instance->filename); switch ($info['mime']) { case 'image/gif': $instance->image = imagecreatefromgif($instance->filename); break; case 'image/jpeg': $instance->image = imagecreatefromjpeg($instance->filename); break; case 'image/png': $instance->image = imagecreatefrompng($instance->filename); imagesavealpha($instance->image, true); imagealphablending($instance->image, true); break; default: throw new Exception('Invalid image: ' . $instance->filename); break; } $instance->original_info = array('width' => $info[0], 'height' => $info[1], 'orientation' => $instance->get_orientation(), 'exif' => function_exists('exif_read_data') ? $instance->exif = @exif_read_data($instance->filename) : null, 'format' => preg_replace('/^image\\//', '', $info['mime']), 'mime' => $info['mime']); $instance->width = $info[0]; $instance->height = $info[1]; imagesavealpha($instance->image, true); imagealphablending($instance->image, true); return $instance; }
/** * Transforms a string or an array to a query object. * * If query is empty, * * @param mixed $query * * @throws \Elastica\Exception\NotImplementedException * * @return self */ public static function create($query) { switch (true) { case $query instanceof self: return $query; case $query instanceof AbstractQuery: return new self($query); case $query instanceof AbstractFilter: $newQuery = new self(); $newQuery->setPostFilter($query); return $newQuery; case empty($query): return new self(new MatchAll()); case is_array($query): return new self($query); case is_string($query): return new self(new QueryString($query)); case $query instanceof AbstractSuggest: return new self(new Suggest($query)); case $query instanceof Suggest: return new self($query); } // TODO: Implement queries without throw new NotImplementedException(); }
public static function addChat($IDParent, $Type, $Tag, $Text, $IDUser = null) { $IDChat = parent::addChat($IDParent, $Text, $IDUser); $TheChat = new self(); $Data = array('Tag' => $Tag, 'Type' => $Type); return $TheChat->update($Data, "IDChat = '{$IDChat}'"); }
public static function init($run = true) { static $console; if (!$console) { // 实例化console $console = new self('Think Console', '0.1'); // 读取指令集 if (is_file(CONF_PATH . 'command' . EXT)) { $commands = (include CONF_PATH . 'command' . EXT); if (is_array($commands)) { foreach ($commands as $command) { if (class_exists($command) && is_subclass_of($command, "\\think\\console\\command\\Command")) { // 注册指令 $console->add(new $command()); } } } } } if ($run) { // 运行 $console->run(); } else { return $console; } }
public static function launch() {/*{{{*/ $fix = new self(); $fix->mailbox = BeanFinder::get('configs')->aladdinMailbox; $content = ''; try { //$fix->checkDiseaseHospitalInfo4Baidu(); //$fix->checkDiseaseInfo4Daidu(); //$fix->checkDoctorForBaidu(); //$fix->checkHospitalFacultyDoctorInfo(); //$fix->checkOfficeDoctor4Baidu(); //$fix->writeContent2File(); $fix->synFile(); $fix->sendEmail(); } catch(Exception $ex) { $content .= $ex->getMessage(); } if(false == empty($content)) { EmailClient::getInstance()->sendSync($fix->mailbox, "阿拉丁监控脚本异常", $content, $type='text/html'); } }/*}}}*/
/** * Method for object initialization by the string * @param string $string response string * @return Error error object */ public static function initializeByString($string) { $object = json_decode($string); $Response = new self(); $Response->setError($object->error); return $Response; }
/** * Set a fake page layout. Used when we test URL generation. * @param int $id assumed attempt id. * @param string $layout layout to set. Like quiz attempt.layout. E.g. '1,2,0,3,4,0,'. * @param array $infos slot numbers which contain 'descriptions', or other non-questions. * @return quiz_attempt attempt object for use in unit tests. */ public static function setup_fake_attempt_layout($id, $layout, $infos = array()) { $attempt = new stdClass(); $attempt->id = $id; $attempt->layout = $layout; $course = new stdClass(); $quiz = new stdClass(); $cm = new stdClass(); $cm->id = 0; $attemptobj = new self($attempt, $quiz, $cm, $course, false); $attemptobj->slots = array(); foreach (explode(',', $layout) as $slot) { if ($slot == 0) { continue; } $attemptobj->slots[$slot] = new stdClass(); $attemptobj->slots[$slot]->slot = $slot; $attemptobj->slots[$slot]->requireprevious = 0; $attemptobj->slots[$slot]->questionid = 0; } $attemptobj->sections = array(); $attemptobj->sections[0] = new stdClass(); $attemptobj->sections[0]->heading = ''; $attemptobj->sections[0]->firstslot = 1; $attemptobj->sections[0]->shufflequestions = 0; $attemptobj->infos = $infos; $attemptobj->link_sections_and_slots(); $attemptobj->determine_layout(); $attemptobj->number_questions(); return $attemptobj; }
public static function add($params) { $game = new self(); $game->member_id = $params->member_id; $game->subgame_id = $params->game_id; $game->save(); }
/** * @param string $name * @param string $abbreviation * @return CM_Model_Location_Country */ public static function create($name, $abbreviation) { $country = new self(); $country->_set(array('name' => $name, 'abbreviation' => $abbreviation)); $country->commit(); return $country; }
public static function factory($attributes) { $defaultAttributes = array('nonce' => ''); $instance = new self(); $instance->_initialize(array_merge($defaultAttributes, $attributes)); return $instance; }
static function &create_new($repo_path, $gitdir = null, $source = null, $remote_source = false, $reference = null) { if ($gitdir && is_dir($gitdir) || is_dir($repo_path) && is_dir($repo_path . "/.git")) { throw new \Exception('"' . $repo_path . '" is already a git repository'); } else { $repo = new self($repo_path, $gitdir, true, false); if (is_string($source)) { if ($remote_source) { if (!is_dir($reference) || !is_dir($reference . '/.git')) { throw new \Exception('"' . $reference . '" is not a git repository. Cannot use as reference.', 1); } else { if (strlen($reference)) { $reference = realpath($reference); $reference = "--reference {$reference}"; } } $repo->clone_remote($source, $reference); } else { $repo->clone_from($source); } } else { $repo->run('init'); } return $repo; } }
static function showForGroup(Group $group) { global $DB; $ID = $group->getField('id'); if (!$group->can($ID, READ)) { return false; } $canedit = $group->can($ID, UPDATE); if ($canedit) { // Get data $item = new self(); if (!$item->getFromDB($ID)) { $item->getEmpty(); } $rand = mt_rand(); echo "<form name='group_level_form{$rand}' id='group_level_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<input type='hidden' name='" . self::$items_id . "' value='{$ID}' />"; echo "<div class='spaced'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th>" . __('Level attribution', 'itilcategorygroups') . "</th></tr>"; echo "<tr class='tab_bg_2'><td class='center'>"; Dropdown::showFromArray('lvl', array(NULL => "---", 1 => __('Level 1', 'itilcategorygroups'), 2 => __('Level 2', 'itilcategorygroups'), 3 => __('Level 3', 'itilcategorygroups'), 4 => __('Level 4', 'itilcategorygroups')), array('value' => $item->fields['lvl'])); echo "</td></tr>"; echo "</td><td class='center'>"; if ($item->fields["id"]) { echo "<input type='hidden' name='id' value='" . $item->fields["id"] . "'>"; echo "<input type='submit' name='update' value=\"" . __('Save') . "\"\n class='submit'>"; } else { echo "<input type='submit' name='add' value=\"" . __('Save') . "\" class='submit'>"; } echo "</td></tr>"; echo "</table></div>"; Html::closeForm(); } }
public function getAwardNumberListByDate($date) { if ($date < $this->getStartCountDate()) { return array(); } $awardNumberList = array(); $opendate = strtotime($date); $now = time(); foreach ($this->getAwardTimeInfo() as $item) { $start = strtotime($date . ' ' . $item['start']); $end = strtotime($date . ' ' . $item['end']); for ($i = $start; $i <= $end; $i += $item['interval']) { $fetch = new self($i); $latestAwardExpectInfo = $fetch->getLatestAwardExpectInfo(); if (!empty($latestAwardExpectInfo)) { $awardNumber = $fetch->fetchAwardNumberInfo($latestAwardExpectInfo['expect']); if ($awardNumber) { if ($latestAwardExpectInfo['opentime'] <= $now) { $awardNumber['opendate'] = $opendate; $awardNumber['opentime'] = $latestAwardExpectInfo['opentime']; $awardNumberList[] = $awardNumber; } } } } } return $awardNumberList; }
/** * Function to get instance of this model * @param <Array> $rowData * @return <Settings_SysVars_Field_Model> field model */ public static function getInstanceByRow($rowData) { $fieldModel = new self(); foreach ($rowData as $key => $value) { $fieldModel->set($key, $value); } return $fieldModel; }
public static function getCoverProducts() { $coverProducts = new self(); $coverProducts->where(array('is_cover' => true, 'status' => 'publish')); $coverProducts->order('created_on', 'desc'); return $coverProducts; }
public static function fromRow(array $row) { // 'constructor' using db query row $instance = new self(); $instance->fill($row); return $instance; }
/** * * * @return PHPUnit_Framework_TestSuite the instance of PHPUnit_Framework_TestSuite */ public static function suite() { $suite = new self(); $files = $suite->getTestFiles(); $suite->addTestFiles($files); return $suite; }
public static function construct($attribute_id, $datatype_id) { $element = new self(); $element->setAttributeId($attribute_id); $element->setDatatypeId($datatype_id); return $element; }
/** * Manage instance usage of this class */ public static function &getInstance($type = 'base') { if (key_exists($type, self::$dbCache)) { $db = self::$dbCache[$type]; vglobal('adb', $db); return $db; } else { if (key_exists('base', self::$dbCache)) { $db = self::$dbCache['base']; vglobal('adb', $db); return $db; } } $config = self::getDBConfig($type); $db = new self($config['db_type'], $config['db_server'], $config['db_name'], $config['db_username'], $config['db_password'], $config['db_port']); if ($db->database == NULL) { $db->log('Database getInstance: Error connecting to the database', 'error'); $db->checkError('Error connecting to the database'); return false; } else { self::$dbCache[$type] = $db; vglobal('adb', $db); } return $db; }
/** * setState (convert from array to object). * * @return string */ public static function __set_state($array) { $businessPropery = new self(); $businessPropery->setType($array['type']); $businessPropery->setEntityProperty($array['entityProperty']); return $businessPropery; }
/** * @param $context TestSwarmContext * @param $userAgent string * @return BrowserInfo */ public static function newFromContext(TestSwarmContext $context, $userAgent) { $bi = new self(); $bi->context = $context; $bi->parseUserAgent($userAgent); return $bi; }
public static function send() { $me = new self("global"); $sent = array(); $pastlink = new FutureLink_PastUI(); $feed = $pastlink->feed(); $items = array(); //we send something only if we have something to send if (empty($feed->feed->entry) == false) { foreach ($feed->feed->entry as &$item) { if (empty($item->futurelink->href) || isset($sent[$item->futurelink->hash])) { continue; } $sent[$item->futurelink->hash] = true; $client = new Zend\Http\Client($item->futurelink->href, array('timeout' => 60)); if (!empty($feed->feed->entry)) { $client->setParameterPost(array('protocol' => 'futurelink', 'metadata' => json_encode($feed))); try { $client->setMethod(Zend\Http\Request::METHOD_POST); $response = $client->send(); $request = $client->getLastResponse(); $result = $response->getBody(); $resultJson = json_decode($response->getBody()); //Here we add the date last updated so that we don't have to send it if not needed, saving load time. if (!empty($resultJson->feed) && $resultJson->feed == "success") { $me->addItem(array('dateLastUpdated' => $item->pastlink->dateLastUpdated, 'pastlinklinkHash' => $item->pastlink->hash, 'futurelinkHash' => $item->futurelink->hash)); } $items[$item->pastlink->text] = $result; } catch (Exception $e) { } } } return $items; } }