function getGovernment($prime_minister, $current_person_id) { $sql = "\n SELECT g.idperson, g.title, g.mintime, g.maxtime, p.display_name\n FROM govro_people AS g\n LEFT JOIN people AS p ON p.id = g.idperson\n WHERE g.idperson != {$current_person_id} AND\n title != 'Prim-ministru' AND\n title NOT LIKE 'viceprim%' AND\n mintime >= {$prime_minister[time_from]} AND\n ((maxtime = 0 AND {$prime_minister[time_to]} = 0) OR\n (maxtime != 0 AND maxtime >= {$prime_minister[time_to]}))\n ORDER BY maxtime, title"; $government = array(); $s = mysql_query($sql); while ($r = mysql_fetch_array($s)) { $gov_person = new Person(); $gov_person->setId($r['idperson']); $member = array('display_name' => $r['display_name'], 'title' => removeUselessPrefix($r['title']), 'idperson' => $r['idperson'], 'time_from' => $r['mintime'], 'time_to' => $r['maxtime'], 'history_snippet' => $gov_person->getHistorySnippet(), 'tiny_img_url' => getTinyImgUrl($r['idperson'])); array_push($government, $member); } return $government; }
<?php class Person { private $name; private $age; private $id; public function __construct($name, $age) { $this->name = $name; $this->age = $age; } public function setId($id) { $this->id = $id; } public function __clone() { $this->id = 0; } } $person = new Person("bob", 44); $person->setId(343); $person2 = clone $person; var_dump($person2);
function getPeopleList($startWith, $count) { $s = mysql_query("\n SELECT id, name, display_name\n FROM people\n LIMIT {$startWith}, {$count}\n "); $ret = array(); while ($r = mysql_fetch_array($s)) { $r['tiny_image'] = getTinyImgUrl($r['id']); $ret[] = $r; } return $ret; } /** * This is hacked up utility used for finding links about people. It will * open a few iframes with a google search for their blog, and their website, * and it will allow me to add links that i get from those google searches. */ $id = (int) $_GET['id']; // A person is selected. Fetch their name. $person = new Person(); $person->setId($id); $person->loadFromDb(); $COUNT = $_GET['count'] ? $_GET['count'] : 15; $start = $_GET['start'] ? $_GET['start'] : 0; $people = getPeopleList($start, $COUNT); $t = new Smarty(); $t->assign('name', $person->displayName); $t->assign('id', $person->id); $t->assign('people', $people); $t->assign('start', $start); $t->assign('prev', $start - $COUNT); $t->assign('next', $start + $COUNT); $t->display('links_searches.tpl');
$p4->setEyesColor(new EyesColor(EyesColor::MARK_BLUE)); $p4->setHairColor(new HairColor(HairColor::MARK_BLONDE)); $p4->setSkinColor(new SkinColor(0.2)); $p4->setId($generationLevel . '_' . $personId); $personId++; $p5 = new Person(); $p5->setEyesColor(new EyesColor(EyesColor::MARK_BROWN)); $p5->setHairColor(new HairColor(HairColor::MARK_BROWN)); $p5->setSkinColor(new SkinColor(0.5)); $p5->setId($generationLevel . '_' . $personId); $personId++; $p6 = new Person(); $p6->setEyesColor(new EyesColor(EyesColor::MARK_BLUE)); $p6->setHairColor(new HairColor(HairColor::MARK_BLONDE)); $p6->setSkinColor(new SkinColor(0.5)); $p6->setId($generationLevel . '_' . $personId); $personId++; /*$p7 = new Person(); $p7->setEyesColor(new EyesColor(EyesColor::MARK_GREEN)); $p7->setHairColor(new HairColor(HairColor::MARK_BLACK)); $p7->setSkinColor(new SkinColor(0.2)); $p7->setId($generationLevel.'_'.$personId); $personId++;*/ $population = new Population(); $population->setPersons([$p1, $p2, $p3, $p4, $p5, $p6]); $generationLevel++; $solution = $population->getFittest($target); ?> <section> <h1>Initial Population</h1>
public static function getPersons() { $dados = Database::ReadAll("person", "*"); if (!$dados) { return ''; } foreach ($dados as $dado) { $person = new Person(); $person->setId($dado['ID_PERSON']); $person->setName($dado['NAME_PERSON']); $person->setEmail($dado['EMAIL']); $person->setAge($dado['AGE']); $person->setSex($dado['SEX']); $person->setPhone($dado['PHONE']); $person->setOperator($dado['OPERATOR']); $person->setMaritalStatus($dado['MARITAL_STATUS']); $person->setChildren($dado['CHILDREN']); $religion = Religion::getReligion("WHERE id_religion = " . $dado['ID_RELIGION']); $person->setReligion($religion); $address = Address::getAddress("AND id_address = " . $dado['ID_ADDRESS']); $person->setAddress($address); $login = Login::getLogin($dado['ID_PERSON']); $person->setLogin($login); $persons[] = $person; } return $persons; }
function __construct($balance) { $this->balance = $balance; } } class Person { private $name; private $age; private $id; public $account; function __construct($name, $age, Account $account) { $this->name = $name; $this->age = $age; $this->account = $account; } function setId($id) { $this->id = $id; } function __clone() { $this->id = 0; } } $person = new Person('Василий', 50, new Account(50)); $person->setId(545); $person2 = clone $person; $person->account->balance += 50; print_r($person2->account->balance);
} } //Data Process for the mother $mother = new Person(); if ($_POST["idMother"] !== '0' && $_POST["idMother"] !== '') { $mother = PersonManager::getSinglePerson('id', $_POST["idMother"]); $mother->setId($_POST["idMother"]); $mother->setNames($_POST["nameMother"]); $mother->setLastname1($_POST["lastname1Mother"]); $mother->setLastname2($_POST["lastname2Mother"]); $mother->setGender('F'); PersonManager::updatePerson($mother); } else { if ($_POST["nameMother"] !== '') { $mother = new Person(); $mother->setId(0); $mother->setNames($_POST["nameMother"]); $mother->setLastname1($_POST["lastname1Mother"]); $mother->setLastname2($_POST["lastname2Mother"]); $mother->setGender('F'); PersonManager::addPerson($mother, 'true'); $mother = PersonManager::getSinglePerson('id', PersonManager::getLastID()); } } //Process The Child $child->setIdFather($father->getId()); $child->setIdMother($mother->getId()); if ($child->getId() === '0') { PersonManager::addPerson($child, 'true'); $child = PersonManager::getSinglePerson('id', PersonManager::getLastID()); } else {
<?php class Person { public $id; public $name; public $age; function __construct($name, $age) { $this->name = $name; $this->age = $age; } function setId($id) { $this->id = $id; } function __destruct() { // вызывается при удалении обьекта if (!empty($this->id)) { // если у обьекта есть id, то сохраняет его в БД print "Сохранение обьекта Person"; } } } $person = new Person("John", 33); // создаём обьект $person->setId(12); // назначаем id unset($person); // удаляем из памяти (в этот момент вызывается деструктор)
$course->setDescription('PHP Programming'); $course->save(); $s->addCourses($course); $p = new Person(); $p->setCity($c); $p->setEmail('*****@*****.**'); $p->setName('Other Person'); $p->save(); $b = new Book(); $b->setAuthor($p); $b->setTitle('PHP Book'); $b->save(); Hypersistence::commit(); //LOAD $p = new Person(); $p->setId(1); $p->load(); echo $p->getName() . "\n"; $books = $p->getBooks()->execute(); foreach ($books as $b) { echo $b->getTitle() . "\n"; } $s = new Student(); $s->setId(1); $s->load(); echo $s->getName() . "\n"; $courses = $s->getCourses(); foreach ($courses as $c) { echo $c->getDescription() . "\n"; $course = $c; }
/** * Tests Person->setId() */ public function testSetId() { $this->Person->setId('id'); $this->assertEquals('id', $this->Person->id); }
public function assignPageContent(\phpQueryObject $_) { $this->setSynopsis(trim($_['p[itemprop=description]']->text())); if ($duration = $_['[itemprop=duration]']->attr('datetime')) { $this->setLength(new \DateInterval($duration)); } $this->setRating((double) $_['[itemprop=ratingValue]']->text()); $this->setTitle(trim($_['h1 [itemprop=name]']->text())); $this->setVotes((int) preg_replace('/[^\\d]+/', '', $_['[itemprop=ratingCount]']->text())); $this->setPosterUri($_['img[itemprop=image]']->attr('src')); $this->setDatePublished(\DateTime::createFromFormat('Y-m-d', $_['.infobar [itemprop="datePublished"]']->attr('content'))); $g = []; foreach ($_['.infobar [itemprop=genre]'] as $genre) { $g[] = pq($genre)->text(); } $this->setGenres($g); foreach ($_['#title-overview-widget [itemtype="http://schema.org/Person"][itemprop!=actors]'] as $x) { $x = pq($x); foreach ($x['a[itemprop=url]'] as $p) { $p = pq($p); $person = new Person(); $person->setId(preg_replace('@^.*(nm\\d+).*@', '$1', $p->attr('href'))); $person->setName($p->text()); if (!isset($this->_people[$x->attr('itemprop')])) { $this->_people[$x->attr('itemprop')] = []; } $this->_people[$x->attr('itemprop')][$person->getId()] = $person; } } // Casting if (!isset($this->_people['actors'])) { $this->_people['actors'] = []; } foreach ($_['table.cast_list tr:has([itemprop=name])'] as $p) { $p = pq($p); $actor = new Actor(); $actor->setId(preg_replace('@^.*(nm\\d+).*@', '$1', $p['[itemprop=url]']->attr('href'))); $actor->setName($p['[itemprop=name]']->text()); $actor->setCharacter($p['a[href^=/character]']->text()); $this->_people['actors'][$actor->getId()] = $actor; } }
$this->_color->setVal($val); return $this; } } try { $p = new Person(); $db->drop($p); $db->create($p); // Let's insert an object first. $p->setName('Mike'); $p->setColor('blue'); $db->insert($p); $id = $p->getId(); echo "## Loading\n"; $p = new Person(); $p->setId($id); $db->load($p); $p->prettyPrint(); echo "## Updating\n"; $p->setColor('red'); $db->update($p); $p->prettyPrint(); echo "## Loading Multiple\n"; $p2 = new Person(); $p2->setName('Bob'); $p2->setColor('red'); $db->insert($p2); $p3 = new Person(); $p3->setName('John'); $p3->setColor('purple'); $db->insert($p3);
/** * Loads the people that are currently in the people table in our database. * * @return {HashMap.<String, Person>} The hash table with the people, where * the key is the name of each person (lower case, no diacritics, all * names sorted alphabetically). */ function loadPeopleFromDb() { $results = array(); $s = mysql_query("SELECT * FROM people"); while ($r = mysql_fetch_array($s)) { $person = new Person(); $person->setName($r['name']); $person->setDisplayName($r['display_name']); $person->setId($r['id']); $results[$person->name] = $person; } return $results; }
} else { $grandFatherM = new Person(); $grandFatherM->setId('NULL'); } if ($_POST["nameMotherM"] !== '') { $grandMotherM = new Person(); $grandMotherM->setId(0); $grandMotherM->setNames($_POST["nameMotherM"]); $grandMotherM->setLastname1($_POST["lastname1MotherM"]); $grandMotherM->setLastname2($_POST["lastname2MotherM"]); $grandMotherM->setGender('F'); PersonManager::addPerson($grandMotherM, 'true'); $grandMotherM = PersonManager::getSinglePerson('id', PersonManager::getLastID()); } else { $grandMotherM = new Person(); $grandMotherM->setId('NULL'); } $mother->getIdMother($grandMotherM->getId()); $mother->getIdFather($grandFatherM->getId()); PersonManager::addPerson($mother, 'true'); $mother = PersonManager::getSinglePerson('id', PersonManager::getLastID()); } } //Process The Child $child->setIdFather($father->getId()); $child->setIdMother($mother->getId()); if ($child->getId() === '0') { PersonManager::addPerson($child, 'true'); $child = PersonManager::getSinglePerson('id', PersonManager::getLastID()); } else { PersonManager::updatePerson($child);
<?php require_once '../secret/db_user.php'; require_once '../_top.php'; // Load wp-config so that we can use the fact that the user is logged in. require_once '../wp-config.php'; include_once '../hp-includes/people_lib.php'; include_once '../hp-includes/user_utils.php'; // current_user is a variable set by Wordpress. $uid = is_user_logged_in() ? $current_user->ID : 0; if ($uid == 0) { die("({error:'Trebuie să te autentifici pentru a urmări un politician.'})"); } // Sanitize the inputs a little bit. $person_id = mysql_real_escape_string($_GET['person_id']); $action = mysql_real_escape_string($_GET['action']); $person = new Person(); $person->setId($person_id); // Also record this in the moderation queue so we can see who added what. $ip = $_SERVER['REMOTE_ADDR']; $userLogin = getUserLogin($uid); mysql_query("INSERT INTO moderation_queue(type, idperson, value, ip, time)\n VALUES('follow', {$person_id}, 'follow by {$userLogin}', '{$ip}', " . time() . ")"); if ($action == 'follow') { $person->addFollowByUser($uid); echo "({new_action:'unfollow'})"; } else { $person->removeFollowByUser($uid); echo "({new_action:'follow'})"; } require_once '../_bottom.php';
public static function fromJson($json) { $person = new Person(); return $person->setId($json->Id)->setFirstName($json->Firstname)->setLastName($json->Lastname); }