public function testInsert() { $this->prepareDB(false); $oDriver = DBDriver::get_instance('sqlite', array('filename' => dirname(__FILE__) . '/unittest.db')); $oPerson = new Person(); $oPerson->firstName = 'Jerome'; $oPerson->lastName = 'Poichet'; $mRes = $oPerson->insert($oDriver); $mRes = Person::select('Person')->where('firstName', 'Jerome')->exec($oDriver); $this->assertEquals(1, $mRes->numRows()); $oOther = $mRes->fetch(); $this->assertEquals('Person', get_class($oOther)); $this->assertNotNull($oOther->id); $this->assertEquals($oPerson->id, $oOther->id); }
public function run() { $name = !empty($_POST['name']) ? $_POST['name'] : ""; $email = !empty($_POST['email']) ? $_POST['email'] : ""; $postalCode = !empty($_POST['cp']) ? $_POST['cp'] : ""; $pwd = !empty($_POST['pwd']) ? $_POST['pwd'] : ""; $city = !empty($_POST['city']) ? $_POST['city'] : ""; //Get the person data $newPerson = array('name' => $name, 'email' => $email, 'postalCode' => $postalCode, 'pwd' => $pwd, 'city' => $city); try { $res = Person::insert($newPerson, false); Person::saveUserSessionData($res["id"], $email, array("name" => $name)); } catch (CTKException $e) { $res = array("result" => false, "msg" => $e->getMessage()); } Rest::json($res); exit; }
public function actionInsertNewPerson() { $res = Person::insert(array('name' => "Test", 'email' => "*****@*****.**", 'postalCode' => "97426", 'pwd' => "vlanlepass")); var_dump($res); }
public function testDeleteMultiple() { $oDriver = DBDriver::get_instance('mongo'); // Clean up database Person::delete('Person')->where('firstName', 'Jerome')->exec($oDriver); $iCount = 10; for ($i = 0; $i < $iCount; $i++) { $oPerson = new Person(); $oPerson->firstName = 'Jerome'; $oPerson->lastName = 'Poichet'; $mRes = $oPerson->insert()->exec($oDriver); } $oRes = Person::select('Person')->where('firstName', 'Jerome')->exec($oDriver); $this->assertEquals($iCount, $oRes->numRows()); Person::delete('Person')->where('firstName', 'Jerome')->exec($oDriver); $oRes = Person::select('Person')->where('firstName', 'Jerome')->exec($oDriver); $this->assertEquals(0, $oRes->numRows()); }
*/ $person = new Person(); $person->name = "Frank Zappa"; $person->birthday = "1940-12-20"; $person->salary = 1000; $person->insert(); echo SEPARATOR . "New person inserted:\n"; print_r($person); /** * To create a Model from data contained in an array, use the merge() method to * overwrite any data in the model with the data from the array. */ $data = array('name' => 'Captain Beefheart', 'birthday' => '1941-01-15', 'salary' => 1200); $person = new Person(); $person->merge($data); $person->insert(); echo SEPARATOR . "New person inserted:\n"; print_r($person); /** * To change an existing record, fetch it from the database, perform the * required changes and call update(). */ $personID = $person->id; echo SEPARATOR . "Person #{$personID} before changes:\n"; print_r(Person::get($personID)); // Get, change, update $person = Person::get($personID); $person->salary += 500; $person->update(); echo SEPARATOR . "Person #{$personID} after changes:\n"; print_r(Person::get($personID));
function testInsert() { $people = Make::a('Person')->all(); $people_count = count($people); $person = new Person(); $person->firstName = 'Joe'; $person->lastName = 'Biden'; $person->age = 65; $person->insert(); $people = Make::a('Person')->all(); $this->assertEquals($people_count + 1, count($people)); }
/** * When an initation to join an organization network is sent : * this method will : * 1. Create a new person and organization. * 2. Make the new person a member and admin of the organization * 3. Join the network of the organization inviting * @param type $person the minimal data to create a person * @param type $organization the minimal data to create an organization * @param type $parentOrganizationId the organization Id to join the network of * @return newPersonId ans newOrganizationId */ public static function createPersonOrganizationAndAddMember($person, $organization, $parentOrganizationId) { //The data check is normaly done before inserting but the both data (organization and person) //must be ok before inserting //Check person datas Person::getAndcheckPersonData($person, false); //Check organization datas Organization::getAndCheckOrganization($organization); //Create a new person $newPerson = Person::insert($person); //Create a new organization $newOrganization = Organization::insert($organization, $newPerson["id"]); //Link the person as an admin Link::addMember($newOrganization["id"], Organization::COLLECTION, $newPerson["id"], PHType::TYPE_CITOYEN, $newPerson["id"], true); //Link the organization as a member of the invitor //TODO SBAR - On GRANDDIR case, the parent organization can manage (data, event, project...) their organization members. //Should be a parameter of the application. $isParentOrganizationAdmin = true; Link::addMember($parentOrganizationId, Organization::COLLECTION, $newOrganization["id"], Organization::COLLECTION, $newPerson["id"], $isParentOrganizationAdmin); return array("result" => true, "msg" => Yii::t("organisation", "The invitation process completed with success"), "id" => $newOrganization["id"]); }
public function actionInsertNewPerson() { $params = array('name' => "Test", 'email' => "*****@*****.**", 'postalCode' => "97426", "city" => "97401", 'pwd' => "vlanlepass"); $res = Person::insert($params); var_dump($params); }