/** * Answer a resource that represents an Individual node in this model. * If a resource with the given uri exists in the model, it will be re-used. * If not, a new one is created in the updateable sub-model of the ontology model. * * @param string $uri * @return object Individual * @access public */ function createIndividual($uri = null) { $individual = new Individual($uri); $individual->setAssociatedModel($this); $individual->setVocabulary($this->vocabulary); return $individual; }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($society, $yr, $id) { if (Helpers::perm('admin', $society) or Helpers::perm('edit', $society)) { $data['soc'] = $society; $data['society'] = Society::where('society', '=', $society)->first(); $data['goal'] = Goal::with(array('individual' => function ($query) { $query->wherePivot('deleted_at', null)->orderBy('surname', 'asc'); }))->where('slug', '=', $id)->where('society_id', '=', $data['society']->id)->first(); $data['contact'] = Individual::find($data['goal']->contact); $data['pagetitle'] = $data['goal']->groupname; $daysofweek = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'); $data['meeting'] = $daysofweek[-1 + $data['goal']->meeting]; return View::make('goals.show', $data); } else { return View::make("shared.unauthorised"); } }
public function actionSearch() { $term = $_GET['term']; $nameCriteria = new CDbCriteria(); //$nameCriteria->addSearchCondition('name_first', $term . '%', false); $nameCriteria->addSearchCondition('name_last', $term . '%', false, 'OR'); $phoneCriteria = new CDbCriteria(); $phoneCriteria->addSearchCondition('phone_contact', '%' . $term, false); $nameCriteria->mergeWith($phoneCriteria, false); $individuals = Individual::model()->findAll($nameCriteria); $names = array(); foreach ($individuals as $individual) { if ($individual->family->name) { $last_name = $individual->family->name; } else { $last_name = $individual->name_last; } $names[] = array('name' => stripslashes($last_name . ', ' . $individual->name_first), 'id' => $individual->family->id); } echo json_encode(array('names' => $names)); exit; }
public function combineWith(Individual $a) { $pivot = Random\getRandStringIndex($this->data); return [new StringIndividual($this->solution, substr($this->data, 0, $pivot) . substr($a->getData(), $pivot)), new StringIndividual($this->solution, substr($a->getData(), 0, $pivot) . substr($this->data, $pivot))]; }
/** * Find the user with a specified genealogy record. * * @param Individual $individual * * @return User|null */ public static function findByGenealogyRecord(Individual $individual) { $user_id = Database::prepare("SELECT SQL_CACHE user_id" . " FROM `##user_gedcom_setting`" . " WHERE gedcom_id = :tree_id AND setting_name = 'gedcomid' AND setting_value = :xref")->execute(array('tree_id' => $individual->getTree()->getTreeId(), 'xref' => $individual->getXref()))->fetchOne(); return self::find($user_id); }
/** * Each object type may have its own special rules, and re-implement this function. * * @param int $access_level * * @return bool */ protected function canShowByType($access_level) { // Hide a family if any member is private preg_match_all('/\\n1 (?:CHIL|HUSB|WIFE) @(' . WT_REGEX_XREF . ')@/', $this->gedcom, $matches); foreach ($matches[1] as $match) { $person = Individual::getInstance($match, $this->tree); if ($person && !$person->canShow($access_level)) { return false; } } return true; }
// Filter for privacy foreach ($rows as $row) { $note = Note::getInstance($row->xref, $WT_TREE, $row->gedcom); if ($note->canShowName()) { $data[] = array('value' => $note->getXref(), 'label' => $note->getFullName()); } } echo json_encode($data); return; case 'IFS': $data = array(); // Fetch all data, regardless of privacy $rows = get_INDI_rows($WT_TREE, $term); // Filter for privacy foreach ($rows as $row) { $person = Individual::getInstance($row->xref, $WT_TREE, $row->gedcom); if ($person->canShowName()) { $data[] = array('value' => $person->getXref(), 'label' => str_replace(array('@N.N.', '@P.N.'), array(I18N::translateContext('Unknown surname', '…'), I18N::translateContext('Unknown given name', '…')), $row->n_full) . ', <i>' . $person->getLifeSpan() . '</i>'); } } // Fetch all data, regardless of privacy $rows = get_SOUR_rows($WT_TREE, $term); // Filter for privacy foreach ($rows as $row) { $source = Source::getInstance($row->xref, $WT_TREE, $row->gedcom); if ($source->canShowName()) { $data[] = array('value' => $source->getXref(), 'label' => $source->getFullName()); } } // Fetch all data, regardless of privacy $rows = get_FAM_rows($WT_TREE, $term);
public static function user() { if (Yii::app()->user->isGuest) { //$_GET['id'] must be individual id. if (isset($_GET['id'])) { return Individual::model()->findByPk($_GET['id']); } else { return null; } } else { return Individual::model()->findByPk(Yii::app()->user->id); } }
public function crossoverUniform(Population $population, $selectionMethod = 2, $tournamentSize = 10) { $newPopulation = new Population($population->size()); for ($populationIndex = 0; $populationIndex < $population->size(); $populationIndex++) { $parent1 = $population->getFittestIndividual($populationIndex); if ($this->crossoverRate > Random::generate() && $populationIndex > $this->elitismCount) { $offspring = new Individual($parent1->getChromosomeLength()); if ($selectionMethod == 1) { $parent2 = $this->selectParentRoulette($population); } else { if ($selectionMethod == 2) { if ($tournamentSize <= $population->size()) { $parent2 = $this->selectParentTournament($population, $tournamentSize); } else { throw new Exception("Tournament size larger than populations"); } } } for ($geneIndex = 0; $geneIndex < $parent1->getChromosomeLength(); $geneIndex++) { if (0.5 > Random::generate()) { $offspring->setGene($geneIndex, $parent1->getGene($geneIndex)); } else { $offspring->setGene($geneIndex, $parent2->getGene($geneIndex)); } } $newPopulation->setIndividual($populationIndex, $offspring); } else { $newPopulation->setIndividual($populationIndex, $parent1); } } return $newPopulation; }
<?php include_once 'includes/main.php'; include_once 'includes/Individual.php'; $post_data = isset($_REQUEST['post_data']) ? json_decode($_REQUEST['post_data'], true) : false; if (isset($post_data)) { $individual_id = $post_data['individual_id']; $individual = new Individual($individual_id); $_SESSION['logged_in'] = true; $_SESSION['user'] = array('name_first' => $individual->find('name_first'), 'name_last' => $individual->find('name_last'), 'individual_id' => $individual_id, 'email' => $individual->find('email')); } echo_bootstrap(get_html(), array('css' => 'profile')); function get_html() { return <<<HTML \t\t<main> \t\t\t<h2>Welcome to your profile page</h2> \t\t\t<p>Hello {$_SESSION['user']['name_first']}!</p> \t\t\t<p>Welcome to your login page.</p> \t\t</main> HTML; }
$validation_errors[] = "secret_validation"; } } $repo = new Repo(); $row = $repo->getArraySingle($repo->buildSql(array('table' => 'individual', 'index' => 'email', 'value' => $email, 'columns' => array('email')))); if (count($row)) { $message[] = 'Email address is already taken.'; $validation_errors[] = 'email'; } if (!empty($validation_errors)) { http_response_code(400); header("Content-Type: application/json"); echo json_encode(array('success' => false, 'validation_errors' => $validation_errors, 'message' => "<div class='notice bad'><p>" . implode("<br/>", $message) . "</p></div>")); exit; } $individual = new Individual(''); $success = $individual->create(array('name_first' => $name_first, 'name_last' => $name_last, 'email' => $email, 'hash' => $encrypt->encrypt($secret))); if ($success == true) { $action = 'show_success'; } } elseif ($ax == 'update_secret') { if ($secret == $secret_validation) { $store_hash_success = $encrypt->storeHash($encrypt->encrypt($secret), $individual_id); } } elseif ($ax == 'submit-login') { if ($email == '') { $validation_errors[] = 'email'; $message[] = 'Please enter your email address.'; } if ($secret == '') { $validation_errors[] = 'secret';
private function getChildren($couple) { $geneCount = $couple[0]->getGeneCount(); $child1 = new Individual($geneCount); $child2 = new Individual($geneCount); /* @var Individual[] $couple */ for ($i = 0; $i < count($geneCount); $i++) { if (rand(0, 1)) { // Swap gene $child1->setGene($i, $couple[1]->getGene($i)); $child2->setGene($i, $couple[0]->getGene($i)); } else { // No gene swap $child1->setGene($i, $couple[0]->getGene($i)); $child2->setGene($i, $couple[1]->getGene($i)); } } return [$child1, $child2]; }
public function mutateUniform(Population $population, Element $element) { $newPopulation = new Population($population->size()); for ($populationIndex = 0; $populationIndex < $population->size(); $populationIndex++) { $individual = $population->getFittestIndividual($populationIndex); $randomIndividual = new Individual($element); for ($geneIndex = 0; $geneIndex < $individual->getChromosomeLength(); $geneIndex++) { if ($populationIndex >= $this->elitismCount) { if ($this->mutationRate > Random::generate()) { $individual->setGene($geneIndex, $randomIndividual->getGene($geneIndex)); } } } $newPopulation->setIndividual($populationIndex, $individual); } return $newPopulation; }