/** * @covers QueueController::Add * @todo Implement testAdd(). */ public function testAdd() { $person = Person::factory('adult'); $person->name = 'Poehavshiy'; $person->add(); $store = Store::factory('Grocery'); $store->name = 'Prison'; $store->add(); $product = new Product(); $product->name = 'Sladkiy hleb'; $product->add(); $request = Application::getInstance()->request; $request->setParams(array('storeId' => $store->id, 'personId' => $person->id, 'product_' . $product->id => 'on')); $personId = $request->p('personId'); $storeId = $request->p('storeId'); $store = Store::get($storeId); $person = Person::get($personId); $store->queue->add($person); $person->basket->drop(); $name = 'product_' . $product->id; $value = $product; if (preg_match_all('/^product_(\\d+)$/', $name, $matches)) { $person->basket->add(Product::get($matches[1][0])); } }
public function testOneToOneRelation() { $person = Person::get(1); $partner = $person->partner; $this->assertTrue($partner instanceof Person, 'must be a Person instance'); $this->assertEquals(2, $partner->id, 'partner id'); }
public function hasmany() { $author = Person::get()->first(); $posts = $author->Posts(); $posts->toArray(); $content .= '$author = Person::get()->first(); <br>'; $content .= '$posts = $author->Posts(); <br>'; $content .= '$posts->toArray(); <br>'; return $this->customise(new ArrayData(array('Title' => "Performance: {$this->dbType} has many", 'Content' => $content)))->renderWith(array('PerformanceController', 'AppController')); }
public function Remove() { $this->_response()->asJSON(); try { $person = Person::get($this->_request()->g('id')); $person->remove(); return array('success' => 1); } catch (Exception $e) { return array('error' => $e->getMessage()); } }
public function editar_persona_area() { $fk_persona = Person::get()->lists('full_name', 'id'); $fk_area = Area_Interes::get()->lists('area_interes_nombre', 'id'); $inputs = Input::get('idedit'); $persona_area = Persona_Area_Interes::find($inputs); if ($persona_area) { return View::make('persona_area_interes.createPersonaArea', array('fk_persona' => $fk_persona, 'fk_area' => $fk_area, 'persona_area' => $persona_area)); } else { return Redirect::to('persona_area'); } }
/** * Сохраняет информацию об корзине покупателя * * Принимает: personId, product_id1, product_id2, ... * * @return type */ public function Save() { $this->_response()->asJSON(); try { $person = Person::get($this->_request()->p('personId')); $person->basket; $map = array(); foreach ($_POST as $name => $value) { if (preg_match_all('/^product_(\\d+)$/', $name, $matches)) { $map[$matches[1][0]] = $value; } } $person->basket->map($map); return array('success' => true); } catch (Exception $e) { return array('error' => $e->getMessage()); } }
/** * oa登录 * @param $ticket */ public function action_oa($ticket) { if (TXApp::$base->person->exist()) { TXApp::$base->request->redirect('/'); } if ($ticket) { $client = new \SoapClient($this->oa_wsdl_url); $res = $client->DecryptTicket(['encryptedTicket' => $ticket]); $rtx = $res->DecryptTicketResult->LoginName; if ($user = $this->userDAO->filter(['name' => $rtx])->find()) { Person::get($user['id'])->login(); } else { $id = $this->userDAO->add(['name' => $rtx, 'registerTime' => time()]); Person::get($id)->login(); } TXApp::$base->request->redirect('/'); } else { $url = TXApp::$base->request->getBaseUrl(true) . '/login/oa'; TXApp::$base->request->redirect("http://login.oa.com/modules/passport/signin.ashx?url={$url}"); } }
/** * Tests if login and password match one and only one person record. * @param string $login user login. * @param type $password user password (plain). * @return boolean returns TRUE on successful or existing authentification, FALSE otherwise. */ function auth_authentificate($login, $password) { if (auth_is_authentificated()) { return TRUE; } $CI =& get_instance(); $CI->load->library('session'); $person = new Person(); $person->where('enabled', 1); $person->where('login', $login); $person->where('password', sha1($password)); $person->get(); if ($person->exists() && $person->result_count() == 1) { $GLOBALS['ledcoin-user-data'] = $person->to_array(); unset($GLOBALS['ledcoin-user-data']['password']); unset($GLOBALS['ledcoin-user-data']['created']); unset($GLOBALS['ledcoin-user-data']['updated']); $GLOBALS['ledcoin-user-auth'] = TRUE; $CI->session->set_userdata('user-id', $person->id); return TRUE; } return FALSE; }
/** * Create some sample data. */ $person = Person::fromArray(["name" => "Freddy Mercury"]); $person->save(); $personID = $person->id; $postDate = date('Y-m-d'); $postNo = 1; $post = Post::fromArray(['date' => $postDate, 'no' => $postNo, 'title' => "My only post"]); $post->save(); /** * To fetch a single record by it's primary key use: * - Model::get() - throws an exception if record does not exist * - Model::find() - returns NULL if record does not exist */ $person = Person::get($personID); $person = Person::find($personID); /** * Also works for composite primary keys. */ $post = Post::get($postDate, $postNo); $post = Post::find($postDate, $postNo); /** * You can pass the composite primary key as an array. */ $postID = array($postDate, $postNo); $post = Post::get($postID); $post = Post::find($postID); echo SEPARATOR . "This is person #10:\n"; print_r($person); echo SEPARATOR . "This is Post {$postDate} #{$postNo}:\n";
function people_get() { if (!$this->get('search')) { $this->response(NULL, 400); } //echo $this->get('search'); $people = new Person(); $people->select('id, name, pfsnumber, public, country'); $people->or_like('name', $this->get('search')); $people->or_like('pfsnumber', $this->get('search')); $people->order_by('name', 'asc'); $people->limit(5); $people->get(); if ($people->exists()) { $people_array = $people->all_to_array(); $this->response($people_array, 200); // 200 being the HTTP response code } else { $this->response(array('error' => 'People could not be found'), 404); } }
public function generate($type = 0) { $scenario_options = array('played_most', 'played_least', 'season', 'evergreen'); $person_options = array('player_complete_pfs', 'player_complete_core', 'gm_complete_pfs', 'gm_complete_core'); if (in_array($type, $scenario_options)) { // This is a scenario based statistic $scenarios = new Scenario(); $scenarios->where('archived IS NULL', NULL); if ($type == 'evergreen') { $scenarios->where('evergreen', '1'); } $scenarios->get(); $options = array(); foreach ($scenarios as $scenario) { $options[$scenario->id] = $scenario->players->count(); } // Sort if ($type == 'played_least') { asort($options); } else { arsort($options); } // Select only top 5 $options = array_slice($options, 0, 10, true); // Delete old data $this->where('type', $type)->get()->delete_all(); $number = 1; foreach ($options as $key => $option) { $this->clear(); $this->type = $type; $this->number = $number; $this->scenario_id = $key; $this->comment = $option; $this->created_on = date("Y-m-d H:i:s"); $this->save(); $number++; } } else { // This is a person based statistic $people = new Person(); $people->get(); $number = 1; $options = array(); foreach ($people as $person) { if ($type == 'player_complete_pfs') { $scenarios = $person->scenarios->where_join_field('players', 'pfs IS NOT NULL', NULL, FALSE)->where('archived IS NULL', NULL)->get(); $options[$person->id] = $scenarios->result_count(); } elseif ($type == 'gm_complete_pfs') { $scenarios = $person->scenarios->where_join_field('players', 'pfs_gm IS NOT NULL', NULL, FALSE)->where('archived IS NULL', NULL)->get(); $options[$person->id] = $scenarios->result_count(); } elseif ($type == 'player_complete_core') { $scenarios = $person->scenarios->where_join_field('players', 'core IS NOT NULL', NULL, FALSE)->where('archived IS NULL', NULL)->get(); $options[$person->id] = $scenarios->result_count(); } elseif ($type == 'gm_complete_core') { $scenarios = $person->scenarios->where_join_field('players', 'core_gm IS NOT NULL', NULL, FALSE)->where('archived IS NULL', NULL)->get(); $options[$person->id] = $scenarios->result_count(); } } // Sort arsort($options); // Select only top 5 $options = array_slice($options, 0, 10, true); // Delete old data $this->where('type', $type)->get()->delete_all(); // Get total amount of scenarios $scenarios = new Scenario(); $total = $scenarios->where('archived IS NULL', NULL)->count(); foreach ($options as $key => $option) { $this->clear(); $this->type = $type; $this->number = $number; $this->person_id = $key; $this->comment = $option . '/' . $total; $this->save(); $number++; } } return TRUE; }
// Include Phormium and models require __DIR__ . "/../vendor/autoload.php"; require __DIR__ . "/models/Contact.php"; require __DIR__ . "/models/Person.php"; require __DIR__ . "/models/Post.php"; require __DIR__ . "/models/Tag.php"; $date = date('Y-m-d'); // Configure Phormium \Phormium\DB::configure('config.json'); // Create a person and three contacts Person::fromArray(["id" => 1, "name" => "Ivan"])->save(); Contact::fromArray(["id" => 1, "person_id" => 1, "value" => "foo"])->save(); Contact::fromArray(["id" => 2, "person_id" => 1, "value" => "bar"])->save(); Contact::fromArray(["id" => 3, "person_id" => 1, "value" => "baz"])->save(); // Fetch the person, then get her contacts $person = Person::get(1); $contacts = $person->contacts()->fetch(); print_r($contacts); // Fetch the contact, then get the person it belongs to $contact = Contact::get(1); $person = $contact->person()->single(); print_r($person); // Create a post and three tags Post::fromArray(["date" => $date, "no" => 1, "title" => "Post #1"])->save(); Tag::fromArray(["id" => 1, "post_date" => $date, "post_no" => 1, "value" => "Tag #1"])->save(); Tag::fromArray(["id" => 2, "post_date" => $date, "post_no" => 1, "value" => "Tag #2"])->save(); Tag::fromArray(["id" => 3, "post_date" => $date, "post_no" => 1, "value" => "Tag #3"])->save(); // Fetch a post, then fetch it's tags $post = Post::get($date, 1); $tags = $post->tags()->fetch(); print_r($tags);
/** * 获取单例全局量 * @param $name * @return mixed * @throws TXException */ public function __get($name) { switch ($name) { case 'person': return Person::get(); case 'request': return TXRequest::getInstance(); case 'redis': return TXRedis::instance(); case 'memcache': return TXMemcache::instance(); case 'session': return TXSession::instance(); case 'router': case 'cache': $module = 'TX' . ucfirst($name); return TXFactory::create($module); default: throw new TXException(1006, $name); } }
/** * Test the \DenBeke\ORM\ORM::setOptions() method for 'limit' and 'orderBy' options * * @depends testInit */ public function testLimitAndOrderBy() { $person = new Person(['name' => 'C', 'city' => 'CC']); $id = $person->add(); $person = new Person(['name' => 'D', 'city' => 'DD']); $id = $person->add(); $options = ['orderBy' => ['name', 'ASC'], 'limit' => 2]; $persons = Person::get($options); $this->assertEquals('Alice', $persons[0]->name); $this->assertEquals('Bob', $persons[1]->name); $this->assertEquals(2, sizeof($persons)); }