/** * Assign necessary Smarty variables and return a template name to * load in order to display a summary of the item suitable for use in * search results. * * @access public * @return string Name of Smarty template file to display. */ public function getSearchResult() { global $configArray; global $interface; $id = $this->getUniqueID(); $interface->assign('summId', $id); $shortId = substr($id, 6); $interface->assign('summShortId', $shortId); //Trim the list prefix for the short id $person = new Person(); $person->personId = $shortId; $person->find(); if ($person->N > 0) { $person->fetch(); $person = Person::staticGet('personId', $shortId); $interface->assign('summPicture', $person->picture); } $name = $this->getName(); $interface->assign('summTitle', trim($name)); $interface->assign('birthDate', $person->formatPartialDate($person->birthDateDay, $person->birthDateMonth, $person->birthDateYear)); $interface->assign('deathDate', $person->formatPartialDate($person->deathDateDay, $person->deathDateMonth, $person->deathDateYear)); $interface->assign('lastUpdate', $person->lastModified); $interface->assign('dateAdded', $person->dateAdded); $interface->assign('numObits', count($person->obituaries)); return 'RecordDrivers/Person/result.tpl'; }
/** * Add person to training session */ public function addPersonToTraining($person_id, $training_id) { $select = $this->select()->from($this->_name, array('doesExist' => 'COUNT(*)'))->setIntegrityCheck(false)->where("person_id = {$person_id} AND training_id = {$training_id}"); $row = $this->fetchRow($select); if ($row->doesExist) { return -1; } else { //make sure person isn't deleted $person = new Person(); $prows = $person->find($person_id); if ($prows) { $prow = $prows->current(); } if (!$prows || !$prow || $prow->is_deleted) { return 0; } $data['person_id'] = $person_id; $data['training_id'] = $training_id; try { return $this->insert($data); } catch (Zend_Exception $e) { error_log($e); } } }
function launch() { global $configArray; global $interface; //Check to see if we are doing the reindex. If so, we need to do it in batches //Because PHP will time out doing the full reindex, break up into chunks of 25 records at a time. //Process is as follows: //1. Display form for the user to start the reindex process //2. System loads the total nummber of records in the database //5. Total number of records in the database are stored in the session with the filename and current status //6. Information sent back to browser with number of records, etc. //7. Browser does AJAX callbacks to run each batch and update progress bar when each finishes. (in JSON.php) //8. Separate action available to cancel the batch if (isset($_REQUEST["submit"])) { $person = new Person(); $person->find(); $numRecords = $person->N; $_SESSION['genealogyDateFix']['currentRecord'] = 0; $_SESSION['genealogyDateFix']['numRecords'] = $numRecords; $interface->assign('startDateFix', true); $interface->assign('numRecords', $numRecords); $interface->assign('percentComplete', 0); } $interface->setTemplate('genealogyFixDates.tpl'); $interface->setPageTitle('Fix Dates in Genalogy Information'); $interface->display('layout.tpl'); }
public static function destroy() { $params = $_POST; $user_id = $params['user_id']; $user_to_destroy = Person::find($user_id); $user_to_destroy->destroy(); Redirect::to('/usermanagement', array('message' => 'User removed')); View::make('notimplemented.html'); }
function getAllObjects() { $object = new Person(); $object->orderBy('lastName, firstName'); $object->find(); $objectList = array(); while ($object->fetch()) { $objectList[$object->personId] = clone $object; } return $objectList; }
public static function get_user_logged_in() { //katsotaan onko session-globaaliin tallennettu 'user'-avainta if (isset($_SESSION['user'])) { //jos on niin niin poimitaan sen arvo $user_id = $_SESSION['user']; //ja luodaan olio user-luokan find-metodilla $user_object = Person::find($user_id); return $user_object; } //ei löytynyt eli käyttäjä ei ole kirjautunut return null; }
/** * Calculates the sum of all shifts in a given period for a given person id. * * @return int $subjectTotal */ public function countStatisticsById($id, $from, $till) { // get all events for the month, currently jan15 for testing $events = ClubEvent::where('evnt_date_start', '>', $from)->where('evnt_date_start', '<', $till)->get(); $subject = Person::find($id); $subjectTotal = 0; foreach ($events as $event) { // for each event - get its schedule $schedule = Schedule::findOrFail($event->getSchedule->id); // for each schedule - get its entries that have this person's id $entries = ScheduleEntry::where('schdl_id', '=', $schedule->id)->where('prsn_id', '=', $subject->id)->get(); // for each entry - get its job type weight foreach ($entries as $entry) { $weight = $entry->getJobType->jbtyp_statistical_weight; //and add it to subject's total $subjectTotal += $weight; } } return $subjectTotal; }
function launch() { global $interface; global $configArray; global $user; global $timer; $timer->logTime("Starting to reindex person"); $recordId = $_REQUEST['id']; $quick = isset($_REQUEST['quick']) ? true : false; $person = new Person(); $person->personId = $recordId; if ($person->find(true)) { $ret = $person->saveToSolr($quick); if ($ret) { echo json_encode(array("success" => true)); } else { echo json_encode(array("success" => false, "error" => "Could not update solr")); } } else { echo json_encode(array("success" => false, "error" => "Could not find a record with that id")); } }
$row = Event::find($id); $row->delete(); } else { // Set error. $error = "CantDeleteEvent"; $message = "The event could not be deleted since some assistance lists are linked to him"; $statusCode = 422; } } // Person. if ($type == "person") { // Verify if the person is used by assistances. $count = Assistance::count(array('conditions' => 'person_id = ' . $id)); if ($count <= 0) { // Delete person. $row = Person::find($id); $row->delete(); } else { // Set error. $error = "CantDeletePerson"; $message = "The person could not be deleted since some assistance lists are linked to him"; $statusCode = 422; } } // User. if ($type == "user") { // Verify if the user is used by assistances. $count = Assistance::count(array('conditions' => 'user_id = ' . $id)); if ($count <= 0) { // Delete officer. $row = User::find($id);
/** * Show the form for editing the specified person. * * @param int $id * @return Response */ public function edit($id) { $person = Person::find($id); return View::make('people.edit', compact('person')); }
<?php require_once '../../include.php'; $type = $_GET['type']; $_person = new Person(); $persons = $_person->find($type, 15, 0); ?> <div class="loading"> <img src="<?php echo HOSTURL; ?> static/images/loading.gif"/> </div> <?php if (count($persons) < 1) { echo "尚无数据。"; } ?> <ul class="person-list"> <?php foreach ($persons as $i) { ?> <li pid="<?php echo $i['id']; ?> "> <a class="item" href="javascript:void(0);"><?php echo $i['name']; ?> </a> <div class="person_click_loading hide">
/** * List trainings and allow person to be assigned */ public function assignTrainingAction() { $id = $this->getSanParam('id'); $this->view->assign('id', $id); $maxAge = $this->getSanParam('maxage'); $this->view->assign('maxage', $maxAge); $person = new Person(); $rows = $person->find($id); $row = $rows->current(); $this->view->assign('person_row', $row); require_once 'models/table/Training.php'; $tableObj = new Training(); $age = "training_start_date < NOW() AND training_start_date > DATE_SUB(NOW(), INTERVAL 30 DAY)"; switch ($maxAge) { case '60days': $age = "training_start_date < NOW() AND training_start_date > DATE_SUB(NOW(), INTERVAL 60 DAY)"; break; case '1quarter': $age = "training_start_date < NOW() AND training_start_date > DATE_SUB(NOW(), INTERVAL 96 DAY)"; break; case '6months': $age = "training_start_date < NOW() AND training_start_date > DATE_SUB(NOW(), INTERVAL 185 DAY)"; break; case 'all': $age = '1'; break; } $trainings = $tableObj->getTrainingsAssign($id, $age); foreach ($trainings as $k => $r) { $trainings[$k]['input_checkbox'] = '<input type="checkbox" name="training_ids[]" value="' . $r['training_id'] . '">'; } $this->view->assign('trainings', $trainings); $request = $this->getRequest(); // save if ($request->isPost()) { $status = ValidationContainer::instance(); $training_ids = $this->getSanParam('training_ids'); if ($training_ids) { require_once 'models/table/PersonToTraining.php'; foreach ($training_ids as $training_id) { $tableObj = new PersonToTraining(); $result = $tableObj->addPersonToTraining($id, $training_id); } $status->setStatusMessage(t('The') . ' ' . t('Training') . t('(s) have been assigned.')); $status->setRedirect('/person/edit/id/' . $id); } else { $status->setStatusMessage(t('No') . ' ' . t('Trainings') . ' ' . t('selected') . '.'); } $this->sendData($status); } }
function jsonContacts($_index = null, $_cache = null) { $_JSON = array(); $_QUERY = array(); $contacts = array(); $_JSON['error'] = ''; $_JSON['code'] = ''; $config = Config::get('API'); if (Auth::check()) { $credits = Auth::user()->credits; $subscriptions = Auth::user()->subscription()->first(); if ($subscriptions != null) { $transactions = $subscriptions->transaction()->get(); if (count($transactions) > 0) { foreach ($transactions as $transaction) { $credits = $credits + $transaction->credits; } } } $_JSON['error'] = ''; if ($credits == 0) { $_JSON['error'] = 'You don't have sufficient funds to purchase contacts'; } else { $index = Input::get('index', 0); $user = User::find(Auth::user()->id); if ($_cache == null) { $CONTACTS = unserialize($user->cache); } else { $CONTACTS = $_cache; } if (count($CONTACTS) > 0) { $FIELD = $CONTACTS[$index]; $www = explode(" ", trim($FIELD['www'])); for ($i = 0; $i < count($www); $i++) { $www[$i] = explode('www.', $www[$i]); if (!empty($www[$i][1])) { $www[$i] = $www[$i][1]; } else { $www[$i] = $www[$i][0]; } } $www = array_unique($www); /*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ $first_last = "&firstname=" . urlencode($FIELD['name']) . "&lastname=" . urlencode($FIELD['lastname']); $last_first = "&firstname=" . urlencode($FIELD['lastname']) . "&lastname=" . urlencode($FIELD['name']); $_QUERY[0] = $first_last . "&name=" . urlencode($FIELD['company_name']); $_QUERY[1] = $first_last . "&name="; /*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ $url = $config['api_jigsaw']['url'] . "/rest/searchContact.json?token=" . $config['api_jigsaw']['token']; $i = 0; /*----------------------------------------------------------------------------*/ $www_crawled = $this->searchCompany($FIELD['company_name']); if (!empty($www_crawled)) { foreach ($www_crawled as $key => $w) { $www[] = $key; } } $_www = array(); for ($w = 0; $w < count($www); $w++) { if (!empty($www[$w])) { if (!empty($www_crawled[$www[$w]])) { $_www[] = $www[$w]; } } } $www = $_www; try { if (count($contacts) == 0) { if ($config['api_jigsaw']['status'] == true) { $param = "&offset=0&pageSize=400" . $_QUERY[$i]; $json = file_get_contents($url . $param); $decode = json_decode($json); $contacts = $decode->contacts; $this->saveContacts($contacts, $www[0], $www_crawled[$www[0]], serialize($www_crawled)); } $CONTACTS[$index]['www'] = $www[0]; $CONTACTS[$index]['company_linkedin_www'] = $www_crawled[$www[0]]; $CONTACTS[$index]['www_variants'] = serialize($www_crawled); } } catch (Exception $e) { Log::notice($e->getMessage()); } $WWW = ""; $ino = 0; $www = array_unique($www); for ($w = 0; $w < count($www); $w++) { if (!empty($www[$w])) { $temp = explode('/', $www[$w]); if (!empty($temp[1])) { $www[$w] = $temp[0]; } } } //Log::notice($www); $CONTACTS[$index]['variants'] = implode(' ', $www); /*----------------------------------------------------------------------------*/ $i = 1; $_www = array(); for ($w = 0; $w < count($www); $w++) { if (!empty($www[$w])) { if (!empty($www_crawled[$www[$w]])) { $_www[] = $www[$w]; } } } $www = $_www; try { for ($w = 0; $w < count($www); $w++) { if (!empty($www[$w])) { if ($www[$w] != "") { $www[$w] = explode('www.', $www[$w]); if (!empty($www[$w][1])) { $www[$w] = $www[$w][1]; } else { $www[$w] = $www[$w][0]; } if (!empty($www_crawled[$www[$w]])) { if ($config['api_jigsaw']['status'] == true) { $param = "&offset=0&pageSize=400" . $_QUERY[$i] . urlencode($www[$w]); $WWW = $www[$w]; $json = file_get_contents($url . $param); $decode = json_decode($json); $contacts = $decode->contacts; $this->saveContacts($contacts, $www[$w], $www_crawled[$www[$w]], serialize($www_crawled)); } $CONTACTS[$index]['www'] = $www[$w]; $CONTACTS[$index]['company_linkedin_www'] = $www_crawled[$www[$w]]; $CONTACTS[$index]['www_variants'] = serialize($www_crawled); } } } } } catch (Exception $e) { Log::notice($e->getMessage()); } $contacts = array(); $person_id = 1; $contacts = Person::where('firstname', '=', trim($FIELD['name']))->where('lastname', '=', trim($FIELD['lastname']))->get(); /*----------------------------------------------------------------------------*/ $person_id = 1; $percent_temp = 0; $api_contact_id = 0; foreach ($contacts as $contact) { similar_text($contact->title, $FIELD['title'], $percent1); similar_text($contact->company_name, $FIELD['company_name'], $percent2); if ($percent1 > 40 && $percent2 > 40) { $percent = ($percent1 + $percent2) / 2; if ($percent > $percent_temp) { $percent_temp = $percent; $person_id = $contact->id; $api_contact_id = $contact->api_contact_id; } } } if ($percent_temp == 0) { foreach ($contacts as $contact) { for ($w = 0; $w < count($www); $w++) { if (!empty($www[$w])) { similar_text($contact->title, $FIELD['title'], $percent); if ($percent > 40) { $pattern = '/' . trim($www[$w]) . '/i'; $status = preg_match($pattern, $contact->www); if ($status == 1) { if ($percent > $percent_temp) { $percent_temp = $percent; $person_id = $contact->id; $api_contact_id = $contact->api_contact_id; } } } } } } } /*----------------------------------------------------------------------------*/ $CONTACTS[$index]['email'] = ''; $CONTACTS[$index]['phone'] = ''; $CONTACTS[$index]['name'] = str_replace('-', '', $CONTACTS[$index]['name']); $CONTACTS[$index]['lastname'] = str_replace('-', '', $CONTACTS[$index]['lastname']); $CONTACTS[$index]['name'] = str_replace('_', '', $CONTACTS[$index]['name']); $CONTACTS[$index]['lastname'] = str_replace('_', '', $CONTACTS[$index]['lastname']); $CONTACTS[$index]['name'] = str_replace('.', '', $CONTACTS[$index]['name']); $CONTACTS[$index]['lastname'] = str_replace('.', '', $CONTACTS[$index]['lastname']); $CONTACTS[$index]['name'] = str_replace(',', '', $CONTACTS[$index]['name']); $CONTACTS[$index]['lastname'] = str_replace(',', '', $CONTACTS[$index]['lastname']); $CONTACTS[$index]['name'] = str_replace('>', '', $CONTACTS[$index]['name']); $CONTACTS[$index]['lastname'] = str_replace('>', '', $CONTACTS[$index]['lastname']); $CONTACTS[$index]['name'] = str_replace('<', '', $CONTACTS[$index]['name']); $CONTACTS[$index]['lastname'] = str_replace('<', '', $CONTACTS[$index]['lastname']); try { $item_id = null; if ($person_id != 1) { $cnt = Person::find($person_id); if ($cnt->email == "") { if ($config['api_jigsaw']['status'] == true) { $contact_details = $config['api_jigsaw']['url'] . '/rest/contacts/' . $api_contact_id . '.json?token=' . $config['api_jigsaw']['token'] . '&username='******'api_jigsaw']['username'] . '&password='******'api_jigsaw']['password'] . '&purchaseFlag=true'; $json = file_get_contents($contact_details); $decode = json_decode($json); $details = $decode->contacts[0]; $cnt->email = $details->email; $cnt->phone = $details->phone; } } if ($cnt->email != '') { $new_domen = explode('@', $cnt->email); if (!empty($new_domen[1])) { $CONTACTS[$index]['www'] = $new_domen[1]; } $cnt->www = $new_domen[1]; $cnt->save(); } $CONTACTS[$index]['email'] = $cnt->email; $CONTACTS[$index]['phone'] = $cnt->phone; $_JSON['firstname'] = $CONTACTS[$index]['name']; $_JSON['lastname'] = $CONTACTS[$index]['lastname']; $_JSON['title'] = $CONTACTS[$index]['title']; $_JSON['companyName'] = $CONTACTS[$index]['company_name']; $_JSON['location'] = $CONTACTS[$index]['location']; $_JSON['member_id'] = $CONTACTS[$index]['member_id']; $_JSON['email'] = $CONTACTS[$index]['email']; $_JSON['phone'] = $CONTACTS[$index]['phone']; if ($CONTACTS[$index]['email'] != '') { $_array = array(); $_array['email'] = $CONTACTS[$index]['email']; $_array['result'] = true; $_array['exactity'] = 'exact'; $CONTACTS[$index]['email'] = array($_array); } $item_id = $this->saveToList(Auth::user()->id, serialize($CONTACTS[$index]), $person_id); } else { $item_id = $this->saveToList(Auth::user()->id, serialize($CONTACTS[$index]), $person_id); } if (!empty($item_id)) { } } catch (Exception $e) { Log::notice($e->getMessage()); $_JSON['error'] = 'The server is busy now, try again later!'; $_JSON['code'] = '0003'; } } } } else { $_JSON['error'] = ''; $_JSON['code'] = '0001'; } return Response::json($_JSON); }
/** * Turn our results into an Excel document * * @access public * @public array $result Existing result set (null to do new search) * @return string Excel document */ public function buildExcel($result = null) { // First, get the search results if none were provided // (we'll go for 50 at a time) if (is_null($result)) { $this->limit = 2000; $result = $this->processSearch(false, false); } // Prepare the spreadsheet ini_set('include_path', ini_get('include_path' . ';/PHPExcel/Classes')); include 'PHPExcel.php'; include 'PHPExcel/Writer/Excel2007.php'; $objPHPExcel = new PHPExcel(); $objPHPExcel->getProperties()->setTitle("Search Results"); $objPHPExcel->setActiveSheetIndex(0); $objPHPExcel->getActiveSheet()->setTitle('Results'); //Add headers to the table $sheet = $objPHPExcel->getActiveSheet(); $curRow = 1; $curCol = 0; $sheet->setCellValueByColumnAndRow($curCol++, $curRow, 'First Name'); $sheet->setCellValueByColumnAndRow($curCol++, $curRow, 'Last Name'); $sheet->setCellValueByColumnAndRow($curCol++, $curRow, 'Birth Date'); $sheet->setCellValueByColumnAndRow($curCol++, $curRow, 'Death Date'); $sheet->setCellValueByColumnAndRow($curCol++, $curRow, 'Veteran Of'); $sheet->setCellValueByColumnAndRow($curCol++, $curRow, 'Cemetery'); $sheet->setCellValueByColumnAndRow($curCol++, $curRow, 'Addition'); $sheet->setCellValueByColumnAndRow($curCol++, $curRow, 'Block'); $sheet->setCellValueByColumnAndRow($curCol++, $curRow, 'Lot'); $sheet->setCellValueByColumnAndRow($curCol++, $curRow, 'Grave'); $maxColumn = $curCol - 1; for ($i = 0; $i < count($result['response']['docs']); $i++) { $curDoc = $result['response']['docs'][$i]; $curRow++; $curCol = 0; //Get supplemental information from the database require_once ROOT_DIR . '/sys/Genealogy/Person.php'; $person = new Person(); $id = str_replace('person', '', $curDoc['id']); $person->personId = $id; if ($person->find(true)) { //Output the row to excel $sheet->setCellValueByColumnAndRow($curCol++, $curRow, isset($curDoc['firstName']) ? $curDoc['firstName'] : ''); $sheet->setCellValueByColumnAndRow($curCol++, $curRow, isset($curDoc['lastName']) ? $curDoc['lastName'] : ''); $sheet->setCellValueByColumnAndRow($curCol++, $curRow, $person->formatPartialDate($person->birthDateDay, $person->birthDateMonth, $person->birthDateYear)); $sheet->setCellValueByColumnAndRow($curCol++, $curRow, $person->formatPartialDate($person->deathDateDay, $person->deathDateMonth, $person->deathDateYear)); $sheet->setCellValueByColumnAndRow($curCol++, $curRow, isset($curDoc['veteranOf']) ? implode(', ', $curDoc['veteranOf']) : ''); $sheet->setCellValueByColumnAndRow($curCol++, $curRow, isset($curDoc['cemeteryName']) ? $curDoc['cemeteryName'] : ''); $sheet->setCellValueByColumnAndRow($curCol++, $curRow, $person->addition); $sheet->setCellValueByColumnAndRow($curCol++, $curRow, $person->block); $sheet->setCellValueByColumnAndRow($curCol++, $curRow, $person->lot); $sheet->setCellValueByColumnAndRow($curCol++, $curRow, $person->grave); } } for ($i = 0; $i < $maxColumn; $i++) { $sheet->getColumnDimensionByColumn($i)->setAutoSize(true); } //Output to the browser header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="Results.xlsx"'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('php://output'); //THIS DOES NOT WORK WHY? $objPHPExcel->disconnectWorksheets(); unset($objPHPExcel); }
public function pageList($p, $z) { $this->assign('people', Person::find()); }
function testsperengine() { global $tests; SmartTest::instance()->progress(); SmartTest::instance()->testPack = "perform generic bean manipulation"; $ok = 1; $bean = RedBean_OODB::dispense("note"); $bean->message = "hai"; $bean->color = 3; $bean->date = time(); $bean->special = 'n'; $bean->state = 90; RedBean_OODB::set($bean); $bean2 = RedBean_OODB::getById("note", 1); if ($bean2->state != 90 || $bean2->special != 'n' || $bean2->message != 'hai') { $ok = 0; SmartTest::failedTest(); } SmartTest::instance()->progress(); $bean->message = "lorem ipsum"; RedBean_OODB::set($bean); $bean->message = 1; $bean->color = "green"; $bean->date = str_repeat("BLABLA", 100); RedBean_OODB::set($bean); $note = $bean; SmartTest::instance()->progress(); $person = RedBean_OODB::dispense("person"); $person->age = 50; $person->name = "Bob"; $person->gender = "m"; RedBean_OODB::set($person); RedBean_OODB::associate($person, $note); $memo = RedBean_OODB::getById("note", 1); $authors = RedBean_OODB::getAssoc($memo, "person"); if (count($authors) !== 1) { SmartTest::failedTest(); } RedBean_OODB::trash($authors[1]); $authors = RedBean_OODB::getAssoc($memo, "person"); if (count($authors) > 0) { $ok = 0; } if (!$ok) { SmartTest::failedTest(); } //unit tests //drop the note table SmartTest::instance()->progress(); SmartTest::instance()->testPack = "dispense an RedBean_OODB Bean"; $oBean = RedBean_OODB::dispense(); if (!$oBean instanceof OODBBean) { SmartTest::failedTest(); } SmartTest::instance()->progress(); SmartTest::instance()->testPack = "put a bean in the database"; $person = RedBean_OODB::dispense("person"); $person->name = "John"; $person->age = 35; $person->gender = "m"; $person->hasJob = true; $id = RedBean_OODB::set($person); $johnid = $id; $person2 = RedBean_OODB::getById("person", $id); if ($person2->age != $person->age) { SmartTest::failedTest(); } $person2->anotherprop = 2; RedBean_OODB::set($person2); $person = RedBean_OODB::dispense("person"); $person->name = "Bob"; $person->age = 50; $person->gender = "m"; $person->hasJob = false; $bobid = RedBean_OODB::set($person); SmartTest::instance()->progress(); SmartTest::instance()->testPack = "find records on basis of similarity"; $ids = RedBean_OODB::getBySQL("`gender`={gender} order by `name` asc", array("gender" => "m"), "person"); if (count($ids) != 2) { SmartTest::failedTest(); } SmartTest::instance()->progress(); $ids = RedBean_OODB::getBySQL("`gender`={gender} OR `color`={clr} ", array("gender" => "m", "clr" => "red"), "person"); if (count($ids) != 0) { SmartTest::failedTest(); } SmartTest::instance()->progress(); $ids = RedBean_OODB::getBySQL("`gender`={gender} AND `color`={clr} ", array("gender" => "m", "clr" => "red"), "person"); if (count($ids) != 0) { SmartTest::failedTest(); } SmartTest::instance()->progress(); R::gen("Person"); $dummy = new Person(); $dummy->age = 40; SmartTest::instance()->test(count(Person::find($dummy, array("age" => ">"))), 1); $dummy->age = 20; SmartTest::instance()->test(count(Person::find($dummy, array("age" => ">"))), 2); $dummy->age = 100; SmartTest::instance()->test(count(Person::find($dummy, array("age" => ">"))), 0); $dummy->age = 100; SmartTest::instance()->test(count(Person::find($dummy, array("age" => "<="))), 2); $dummy->name = "ob"; SmartTest::instance()->test(count(Person::find($dummy, array("name" => "LIKE"))), 1); $dummy->name = "o"; SmartTest::instance()->test(count(Person::find($dummy, array("name" => "LIKE"))), 2); $dummy->gender = "m"; SmartTest::instance()->test(count(Person::find($dummy, array("gender" => "="))), 2); $dummy->gender = "f"; SmartTest::instance()->test(count(Person::find($dummy, array("gender" => "="))), 0); SmartTest::instance()->test(count(Person::listAll()), 2); SmartTest::instance()->test(count(Person::listAll(0, 1)), 1); SmartTest::instance()->test(count(Person::listAll(1)), 1); $can = Person::where("`gender`={gender} order by `name` asc", array("gender" => "m"), "person"); //test array access foreach ($can as $item) { if ($item->getName() == "Bob" || $item->getName() == "John") { SmartTest::instance()->progress(); } else { SmartTest::failedTest(); } } //test array access $bean = $can[0]; if ($bean->name == "Bob") { SmartTest::instance()->progress(); } else { SmartTest::failedTest(); } if ($can->count() != 2) { SmartTest::failedTest(); } SmartTest::instance()->progress(); $can->rewind(); SmartTest::instance()->test($can->key(), 0); SmartTest::instance()->test($can->valid(), true); SmartTest::instance()->test($can->current()->getName(), "Bob"); $can->next(); SmartTest::instance()->test($can->key(), 1); SmartTest::instance()->test($can->valid(), false); SmartTest::instance()->test($can->current()->getName(), "John"); $can->seek(0); SmartTest::instance()->test($can->key(), 0); $beans = $can->getBeans(); if (count($beans) != 2) { SmartTest::failedTest(); } SmartTest::instance()->progress(); //test slicing $can->slice(0, 1); $can->rewind(); SmartTest::instance()->test($can->current()->getName(), "Bob"); SmartTest::instance()->test($can->count(), 1); $b1 = array_shift($beans); if ($b1->name != "Bob") { SmartTest::failedTest(); } SmartTest::instance()->progress(); //basic functionality where() $beans = Person::where("`gender`={gender} order by `name` asc", array("gender" => "m"), "person")->getBeans(); if (count($beans) != 2) { SmartTest::failedTest(); } SmartTest::instance()->progress(); //without backticks should still work $beans = Person::where("gender={person} order by `name` asc", array("person" => "m"), "person")->getBeans(); if (count($beans) != 2) { SmartTest::failedTest(); } SmartTest::instance()->progress(); //like comparing should still work $beans = Person::where("gender={gender} and `name` LIKE {name} order by `name` asc", array("gender" => "m", "name" => "B%"), "person")->getBeans(); if (count($beans) != 1) { SmartTest::failedTest(); } SmartTest::instance()->progress(); $searchBean = RedBean_OODB::dispense("person"); $searchBean->gender = "m"; SmartTest::instance()->progress(); SmartTest::instance()->testPack = "associate beans with eachother?"; $app = RedBean_OODB::dispense("appointment"); $app->kind = "dentist"; RedBean_OODB::set($app); RedBean_OODB::associate($person2, $app); $appforbob = array_shift(RedBean_OODB::getAssoc($person2, "appointment")); if (!$appforbob || $appforbob->kind != "dentist") { SmartTest::failedTest(); } SmartTest::instance()->progress(); SmartTest::instance()->testPack = "delete a bean?"; $person = RedBean_OODB::getById("person", $bobid); RedBean_OODB::trash($person); try { $person = RedBean_OODB::getById("person", $bobid); $ok = 0; } catch (ExceptionFailedAccessBean $e) { $ok = true; } if (!$ok) { SmartTest::failedTest(); } SmartTest::instance()->progress(); SmartTest::instance()->testPack = "unassociate two beans?"; $john = RedBean_OODB::getById("person", $johnid); //hmmmmmm gaat mis bij innodb $app = RedBean_OODB::getById("appointment", 1); RedBean_OODB::unassociate($john, $app); $john2 = RedBean_OODB::getById("person", $johnid); $appsforjohn = RedBean_OODB::getAssoc($john2, "appointment"); if (count($appsforjohn) > 0) { SmartTest::failedTest(); } SmartTest::instance()->progress(); SmartTest::instance()->testPack = "unassociate by deleting a bean?"; $anotherdrink = RedBean_OODB::dispense("whisky"); $anotherdrink->name = "bowmore"; $anotherdrink->age = 18; $anotherdrink->singlemalt = 'y'; RedBean_OODB::set($anotherdrink); RedBean_OODB::associate($anotherdrink, $john); $hisdrinks = RedBean_OODB::getAssoc($john, "whisky"); if (count($hisdrinks) !== 1) { SmartTest::failedTest(); } RedBean_OODB::trash($anotherdrink); $hisdrinks = RedBean_OODB::getAssoc($john, "whisky"); if (count($hisdrinks) !== 0) { SmartTest::failedTest(); } SmartTest::instance()->progress(); SmartTest::instance()->testPack = "create parent child relationships?"; $pete = RedBean_OODB::dispense("person"); $pete->age = 48; $pete->gender = "m"; $pete->name = "Pete"; $peteid = RedBean_OODB::set($pete); $rob = RedBean_OODB::dispense("person"); $rob->age = 19; $rob->name = "Rob"; $rob->gender = "m"; $saskia = RedBean_OODB::dispense("person"); $saskia->age = 20; $saskia->name = "Saskia"; $saskia->gender = "f"; RedBean_OODB::set($saskia); RedBean_OODB::set($rob); RedBean_OODB::addChild($pete, $rob); RedBean_OODB::addChild($pete, $saskia); $children = RedBean_OODB::getChildren($pete); $names = 0; if (is_array($children) && count($children) === 2) { foreach ($children as $child) { if ($child->name === "Rob") { $names++; } if ($child->name === "Saskia") { $names++; } } } if (!$names) { SmartTest::failedTest(); } $daddies = RedBean_OODB::getParent($saskia); $daddy = array_pop($daddies); if ($daddy->name === "Pete") { $ok = 1; } else { $ok = 0; } if (!$ok) { SmartTest::failedTest(); } SmartTest::instance()->progress(); SmartTest::instance()->testPack = "remove a child from a parent-child tree?"; RedBean_OODB::removeChild($daddy, $saskia); $children = RedBean_OODB::getChildren($pete); $ok = 0; if (count($children) === 1) { $only = array_pop($children); if ($only->name === "Rob") { $ok = 1; } } SmartTest::instance()->progress(); SmartTest::instance()->testPack = "save on the fly while associating?"; $food = RedBean_OODB::dispense("dish"); $food->name = "pizza"; RedBean_OODB::associate($food, $pete); $petesfood = RedBean_OODB::getAssoc($pete, "food"); if (is_array($petesfood) && count($petesfood) === 1) { $ok = 1; } if (!$ok) { SmartTest::failedTest(); } //some extra tests... quick without further notice. $food = RedBean_OODB::dispense("dish"); $food->name = "spaghetti"; RedBean_OODB::trash($food); //test aggregation functions //insert stat table $s = RedBean_OODB::dispense("stattest"); $s->amount = 1; RedBean_OODB::set($s); $s = RedBean_OODB::dispense("stattest"); $s->amount = 2; RedBean_OODB::set($s); $s = RedBean_OODB::dispense("stattest"); $s->amount = 3; RedBean_OODB::set($s); SmartTest::instance()->testPack = "can we use aggr functions using Redbean?"; if (RedBean_OODB::numberof("stattest") != 3) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } if (RedBean_OODB::maxof("stattest", "amount") != 3) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } if (RedBean_OODB::minof("stattest", "amount") != 1) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } if (RedBean_OODB::avgof("stattest", "amount") != 2) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } if (RedBean_OODB::sumof("stattest", "amount") != 6) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } if (count(RedBean_OODB::distinct("stattest", "amount")) != 3) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } RedBean_OODB::setLocking(true); $i = 3; SmartTest::instance()->testPack = "generate only valid classes?"; try { $i += RedBean_OODB::gen(""); SmartTest::instance()->progress(); } catch (Exception $e) { SmartTest::failedTest(); } //nothing try { $i += RedBean_OODB::gen("."); SmartTest::instance()->progress(); } catch (Exception $e) { SmartTest::failedTest(); } //illegal chars try { $i += RedBean_OODB::gen(","); SmartTest::instance()->progress(); } catch (Exception $e) { SmartTest::failedTest(); } //illegal chars try { $i += RedBean_OODB::gen("null"); SmartTest::instance()->progress(); } catch (Exception $e) { SmartTest::failedTest(); } //keywords try { $i += RedBean_OODB::gen("Exception"); SmartTest::instance()->progress(); } catch (Exception $e) { SmartTest::failedTest(); } //reserved SmartTest::instance()->progress(); SmartTest::instance()->testPack = "generate classes using Redbean?"; if (!class_exists("Bug")) { $i += RedBean_OODB::gen("Bug"); if ($i !== 4) { SmartTest::failedTest(); } } else { if ($i !== 3) { SmartTest::failedTest(); } } if (!class_exists("Bug")) { SmartTest::failedTest(); } SmartTest::instance()->progress(); SmartTest::instance()->testPack = "use getters and setters"; $bug = new Bug(); $bug->setSomething(sha1("abc")); if ($bug->getSomething() != sha1("abc")) { SmartTest::failedTest(); } //can we use non existing props? --triggers fatal.. $bug->getHappy(); SmartTest::instance()->progress(); SmartTest::instance()->testPack = "Use boolean values and retrieve them with is()?"; if ($bug->isHappy()) { SmartTest::failedTest(); } SmartTest::instance()->progress(); $bug->setHappy(true); $bug->save(); $bug = new Bug(1); if (!$bug->isHappy()) { SmartTest::failedTest(); } SmartTest::instance()->progress(); $bug->setHappy(false); if ($bug->isHappy()) { SmartTest::failedTest(); } SmartTest::instance()->progress(); SmartTest::instance()->testPack = "avoid race-conditions by locking?"; RedBean_OODB::gen("Cheese,Wine"); $cheese = new Cheese(); $cheese->setName('Brie'); $cheese->save(); $cheese = new Cheese(1); //try to mess with the locking system... $oldkey = RedBean_OODB::$pkey; RedBean_OODB::$pkey = 1234; $cheese = new Cheese(1); $cheese->setName("Camembert"); $ok = 0; try { $cheese->save(); } catch (ExceptionFailedAccessBean $e) { $ok = 1; } if (!$ok) { SmartTest::failedTest(); } SmartTest::instance()->progress(); $bordeaux = new Wine(); $bordeaux->setRegion("Bordeaux"); try { $bordeaux->add($cheese); } catch (ExceptionFailedAccessBean $e) { $ok = 1; } if (!$ok) { SmartTest::failedTest(); } SmartTest::instance()->progress(); try { $bordeaux->attach($cheese); } catch (ExceptionFailedAccessBean $e) { $ok = 1; } if (!$ok) { SmartTest::failedTest(); } SmartTest::instance()->progress(); try { $bordeaux->add(new Wine()); $ok = 1; } catch (ExceptionFailedAccessBean $e) { $ok = 0; } if (!$ok) { SmartTest::failedTest(); } SmartTest::instance()->progress(); RedBean_OODB::$pkey = $oldkey; $cheese = new Cheese(1); $cheese->setName("Camembert"); $ok = 0; try { $cheese->save(); $ok = 1; } catch (ExceptionFailedAccessBean $e) { $ok = 0; } if (!$ok) { SmartTest::failedTest(); } SmartTest::instance()->progress(); try { RedBean_OODB::$pkey = 999; RedBean_OODB::setLockingTime(0); $cheese = new Cheese(1); $cheese->setName("Cheddar"); $cheese->save(); RedBean_OODB::setLockingTime(10); SmartTest::instance()->progress(); } catch (Exception $e) { SmartTest::failedTest(); } try { RedBean_OODB::$pkey = 123; RedBean_OODB::setLockingTime(100); $cheese = new Cheese(1); $cheese->setName("Cheddar2"); $cheese->save(); RedBean_OODB::setLockingTime(10); SmartTest::failedTest(); } catch (Exception $e) { SmartTest::instance()->progress(); } try { RedBean_OODB::$pkey = 42; RedBean_OODB::setLockingTime(0); $cheese = new Cheese(1); $cheese->setName("Cheddar3"); $cheese->save(); RedBean_OODB::setLockingTime(10); SmartTest::instance()->progress(); } catch (Exception $e) { SmartTest::failedTest(); } //test value ranges SmartTest::instance()->progress(); SmartTest::instance()->testPack = "protect inner state of RedBean"; try { RedBean_OODB::setLockingTime(-1); SmartTest::failedTest(); } catch (ExceptionInvalidArgument $e) { } SmartTest::instance()->progress(); SmartTest::instance()->testPack = "protect inner state of RedBean"; try { RedBean_OODB::setLockingTime(1.5); SmartTest::failedTest(); } catch (ExceptionInvalidArgument $e) { } SmartTest::instance()->progress(); SmartTest::instance()->testPack = "protect inner state of RedBean"; try { RedBean_OODB::setLockingTime("aaa"); SmartTest::failedTest(); } catch (ExceptionInvalidArgument $e) { } SmartTest::instance()->progress(); SmartTest::instance()->testPack = "protect inner state of RedBean"; try { RedBean_OODB::setLockingTime(null); SmartTest::failedTest(); } catch (ExceptionInvalidArgument $e) { } SmartTest::instance()->progress(); //test convenient tree functions SmartTest::instance()->testPack = "convient tree functions"; if (!class_exists("Person")) { RedBean_OODB::gen("person"); } $donald = new Person(); $donald->setName("Donald"); $donald->save(); $kwik = new Person(); $kwik->setName("Kwik"); $kwik->save(); $kwek = new Person(); $kwek->setName("Kwek"); $kwek->save(); $kwak = new Person(); $kwak->setName("Kwak"); $kwak->save(); $donald->attach($kwik); $donald->attach($kwek); $donald->attach($kwak); if (count($donald->children()) != 3) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } if (count($kwik->siblings()) != 2) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } //todo if ($kwik->hasParent($donald) != true) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } if ($donald->hasParent($kwak) != false) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } if ($donald->hasChild($kwak) != true) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } if ($donald->hasChild($donald) != false) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } if ($kwak->hasChild($kwik) != false) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } if ($kwak->hasSibling($kwek) != true) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } if ($kwak->hasSibling($kwak) != false) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } if ($kwak->hasSibling($donald) != false) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } //copy SmartTest::instance()->testPack = "copy functions"; $kwak2 = $kwak->copy(); $id = $kwak2->save(); $kwak2 = new Person($id); if ($kwak->getName() != $kwak2->getName()) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } SmartTest::instance()->testPack = "countRelated"; R::gen("Blog,Comment"); $blog = new Blog(); $blog2 = new Blog(); $blog->setTitle("blog1"); $blog2->setTitle("blog2"); for ($i = 0; $i < 5; $i++) { $comment = new Comment(); $comment->setText("comment no. {$i} "); $blog->add($comment); } for ($i = 0; $i < 3; $i++) { $comment = new Comment(); $comment->setText("comment no. {$i} "); $blog2->add($comment); } if ($blog->numofComment() !== 5) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } if ($blog2->numofComment() !== 3) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } SmartTest::instance()->testPack = "associate tables of the same name"; $blog = new Blog(); $blogb = new Blog(); $blog->title = 'blog a'; $blogb->title = 'blog b'; $blog->add($blogb); $b = $blog->getRelatedBlog(); if (count($b) !== 1) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } $b = array_pop($b); if ($b->title != 'blog b') { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } SmartTest::instance()->testPack = "inferTypeII patch"; $blog->rating = 4294967295.0; $blog->save(); $id = $blog->getID(); $blog2->rating = -1; $blog2->save(); $blog = new Blog($id); if ($blog->getRating() != 4294967295.0) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } SmartTest::instance()->testPack = "Longtext column type"; $blog->message = str_repeat("x", 65535); $blog->save(); $blog = new Blog($id); if (strlen($blog->message) != 65535) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } $rows = RedBean_OODB::$db->get("describe blog"); if ($rows[3]["Type"] != "text") { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } $blog->message = str_repeat("x", 65536); $blog->save(); $blog = new Blog($id); if (strlen($blog->message) != 65536) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } $rows = RedBean_OODB::$db->get("describe blog"); if ($rows[3]["Type"] != "longtext") { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } Redbean_OODB::clean(); SmartTest::instance()->testPack = "Export"; RedBean_OODB::gen("justabean"); $oBean = new JustABean(); $oBean->setA("a"); $oOtherBean = new OODBBean(); $oOtherBean->a = "b"; $oBean2 = new OODBBean(); $oBean->exportTo($oBean2); if ($oBean2->a !== "a") { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } $oBean2 = $oBean->exportTo($oBean2); if ($oBean2->a !== "a") { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } $oBean->exportTo($oBean2, $oOtherBean); if ($oBean2->a !== "b") { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } $arr = array(); $oBean->exportTo($arr); if ($arr["a"] !== "a") { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } $arr = array(); $arr = $oBean->exportTo($arr); if ($arr["a"] !== "a") { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } $arr = $oBean->exportTo($arr, $oOtherBean); if ($arr["a"] !== "b") { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } SmartTest::instance()->testPack = "Export Array"; $oBean->a = "a"; $oInnerBean = new JustABean(); $oInnerBean->setID(123); $oBean->innerbean = $oInnerBean; $arr = $oBean->exportAsArr(); if (!is_array($arr)) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } if ($arr["innerbean"] !== 123) { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } if ($arr["a"] !== "a") { SmartTest::failedTest(); } else { SmartTest::instance()->progress(); } //test 1-to-n SmartTest::instance()->testPack = "1-to-n relations"; R::gen("Track,Disc"); $cd1 = new Disc(); $cd1->name = 'first'; $cd1->save(); $cd2 = new Disc(); $cd2->name = 'second'; $cd2->save(); $track = new Track(); $track->title = "song 1"; $track->belongsTo($cd1); $discs = $track->getRelatedDisc(); SmartTest::instance()->test(count($discs), 1); $track->belongsTo($cd2); $discs = $track->getRelatedDisc(); SmartTest::instance()->test(count($discs), 1); $track2 = new Track(); $track2->title = "song 2"; $cd1->exclusiveAdd($track2); SmartTest::instance()->test(count($track->getRelatedDisc()), 1); $cd2->exclusiveAdd($track2); SmartTest::instance()->test(count($track->getRelatedDisc()), 1); }
public function testUnset() { // Cleanup Person::deleteAll(); $person = new Person(); $person->post_title = 'Jane'; $person->age = 10; $person->save(); $this->assertEquals(10, $person->age); unset($person->age); $this->assertEmpty($person->age); $person->save(); $person_id = $person->ID; $person = Person::find($person_id); $this->assertEmpty($person->age); }
public function borrar_persona() { $id = Input::get('idedit'); $persona = Person::find($id); if ($persona->delete()) { Session::flash('message', 'Eliminado correctamente'); Session::flash('class', 'success'); } else { Session::flash('message', 'Ha ocurrido un error, intentelo nuevamente'); Session::flash('class', 'danger'); } return Redirect::to('persona'); }
function fixGenealogyDates() { //Make a connection to the database $recordsPerBatch = 10; $startRecord = isset($_SESSION['genealogyDateFix']['currentRecord']) ? $_SESSION['genealogyDateFix']['currentRecord'] : 0; $currentRecord = $startRecord; $numRecords = $_SESSION['genealogyDateFix']['numRecords']; //Get the next set of people to reindex $person = new Person(); $person->limit($startRecord, $recordsPerBatch); $person->find(); if ($person->N) { while ($person->fetch() == true) { //Check the dates to see if they need to be fixed $dateUpdated = false; if (isset($person->birthDate) && strlen($person->birthDate) > 0 && $person->birthDate != '0000-00-00') { $dateParts = date_parse($person->birthDate); $person->birthDateDay = $dateParts['day']; $person->birthDateMonth = $dateParts['month']; $person->birthDateYear = $dateParts['year']; $person->birthDate = ''; $dateUpdated = true; } if (isset($person->deathDate) && strlen($person->deathDate) > 0 && $person->deathDate != '0000-00-00') { $dateParts = date_parse($person->deathDate); $person->deathDateDay = $dateParts['day']; $person->deathDateMonth = $dateParts['month']; $person->deathDateYear = $dateParts['year']; $person->deathDate = ''; $dateUpdated = true; } //Update marriages $marriages = $person->marriages; $marriagesUpdated = false; foreach ($marriages as $key => $marriage) { $marriageUpdated = false; if (isset($marriage->marriageDate) && strlen($marriage->marriageDate) > 0 && $marriage->marriageDate != '0000-00-00') { $dateParts = date_parse($person->marriageDate); $marriage->marriageDateDay = $dateParts['day']; $marriage->marriageDateMonth = $dateParts['month']; $marriage->marriageDateYear = $dateParts['year']; $marriage->marriageDate = ''; $marriageUpdated = true; } if ($marriageUpdated) { $marriages[$key] = $marriage; $marriagesUpdated = true; } } if ($marriagesUpdated) { $person->marriages = $marriages; $dateUpdated = true; } //Update obituaries $obituaries = $person->obituaries; $obituariesUpdated = false; foreach ($obituaries as $key => $obit) { $obitUpdated = false; if (isset($obit->date) && strlen($obit->date) > 0 && $obit->date != '0000-00-00') { $dateParts = date_parse($obit->date); $obit->dateDay = $dateParts['day']; $obit->dateMonth = $dateParts['month']; $obit->dateYear = $dateParts['year']; $obit->date = ''; $obitUpdated = true; } if ($obitUpdated) { $obituaries[$key] = $obit; $obituariesUpdated = true; } } if ($obituariesUpdated) { $person->obituaries = $obituaries; $dateUpdated = true; } if ($dateUpdated) { $person->update(); } $currentRecord += 1; } } $_SESSION['genealogyDateFix']['currentRecord'] = $currentRecord; $moreData = $currentRecord < $numRecords; if (!$moreData) { //Optimize the solr core $person->optimize(); } return array('percentComplete' => floor($currentRecord / $numRecords * 100), 'moreData' => $moreData, 'currentRecord' => $currentRecord); }
{ Event::on('query.started', array($this, 'started')); Event::on('query.completed', array($this, 'completed')); } /** Called when a query has started. */ public function started($query, $arguments) { $this->active = array('query' => $query, 'arguments' => $arguments, 'start' => microtime(true)); } /** Called when a query has completed. */ public function completed($query) { $active = $this->active; $active['end'] = microtime(true); $active['duration'] = $active['end'] - $active['start']; $this->stats[] = $active; $this->active = null; } /** Returns the collected statistics. */ public function getStats() { return $this->stats; } } $stats = new Stats(); $stats->register(); // Execute some queries Person::find(10); Person::objects()->fetch(); // Print collected statistics print_r($stats->getStats());
* 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"; print_r($post);
private function checkLogin($postedData, &$rtnarray, $ismbllogin){ try{ $logindata = \Login::find('all', array('conditions' => array('login=?', $postedData->login))); if(count($logindata) != 1 || !$logindata[0]){ $rtnarray['RetCode'] = Menu::app_InvalidUserPassword; $rtnarray['message'] = "Login not found";//$this->response()->getMessageForCode(Menu::Forbidden); //"Given :" . count($logindata) . ":" + $postedData->login . "::::" . $postedData->pass . ":::";// }else{ $logindata = $logindata[0]; $ispassok = false; if(!isset($postedData->isPassencoded)) $postedData->isPassencoded = 1; if($postedData->isPassencoded === 1){ $salt = "d30bd965c0e92fae88258a8defa365ea415ed907"; $ispassok = $logindata->pass === $postedData->pass.'$'.$salt; }else{ list($stored_pw, $stored_salt) = explode('$', $logindata->pass); $ispassok = ($stored_pw === sha1($postedData->login.$postedData->pass.$stored_salt)); } if($ispassok) { $userdata = \Person::find($logindata->person_id); $rec = array(); $rec['user']['id'] = $logindata->person_id; $rec['user']['hash_id'] = $logindata->hash_id; $rec['user']['login'] = $logindata->login; $rec['user']['role'] = $userdata->type; $rec['user']['geo_update_frq'] = $userdata->geo_update_frq; if(!$ismbllogin){ $this->getConfigs($rec); } $rtnarray['data'] = $rec; $rtnarray['RetCode'] = Menu::app_OK; $rtnarray['message'] = "Login Success"; $this->setStatusMap(1);//1 is for orders $this->checkAndSendMSAlertMail(); }else{ $rtnarray['RetCode'] = Menu::app_InvalidUserPassword; $rtnarray['message'] = "Wrong password"; } } } catch (\ActiveRecord\DatabaseException $ex) { $rtnarray['RetCode'] = Menu::app_UnableToProcess; $rtnarray['message'] = "Unable able to process your request."; $this->log->debug($ex->getMessage()); } catch (\Slim\Exception $ex) { $message = "Internal server error."; $rtnarray['RetCode'] = Menu::InternalServerError; $rtnarray['message'] = $message; } catch (\Exception $ex) { $message = "Internal server error."; $rtnarray['RetCode'] = Menu::InternalServerError; $rtnarray['message'] = $message; } }
/** * testFindThreaded method * * @return void */ public function testFindThreaded() { $Model = new Person(); $Model->recursive = -1; $Model->Behaviors->attach('Tree', array('parent' => 'mother_id')); $result = $Model->find('threaded'); $expected = array(array('Person' => array('id' => '4', 'name' => 'mother - grand mother', 'mother_id' => '0', 'father_id' => '0'), 'children' => array(array('Person' => array('id' => '2', 'name' => 'mother', 'mother_id' => '4', 'father_id' => '5'), 'children' => array(array('Person' => array('id' => '1', 'name' => 'person', 'mother_id' => '2', 'father_id' => '3'), 'children' => array()))))), array('Person' => array('id' => '5', 'name' => 'mother - grand father', 'mother_id' => '0', 'father_id' => '0'), 'children' => array()), array('Person' => array('id' => '6', 'name' => 'father - grand mother', 'mother_id' => '0', 'father_id' => '0'), 'children' => array(array('Person' => array('id' => '3', 'name' => 'father', 'mother_id' => '6', 'father_id' => '7'), 'children' => array()))), array('Person' => array('id' => '7', 'name' => 'father - grand father', 'mother_id' => '0', 'father_id' => '0'), 'children' => array())); $this->assertEquals($expected, $result); }
function testUpdateOnCollection() { $person = new Person(); $person->age = 23; $person->lessThan('age', 23)->update(); $people = $person->find(); $this->assertEquals(count($people), 4); $person = new Person(); $person->age = 100; $person->all()->update(); $people = $person->find(); $this->assertEquals(count($people), 6); }
/** * testFindThreaded method * * @return void */ public function testFindThreaded() { $this->loadFixtures('Person'); $Model = new Person(); $Model->recursive = -1; $result = $Model->find('threaded'); $result = Hash::extract($result, '{n}.children'); $expected = array(array(), array(), array(), array(), array(), array(), array()); $this->assertEquals($expected, $result); $result = $Model->find('threaded', array('parent' => 'mother_id')); $expected = array(array('Person' => array('id' => '4', 'name' => 'mother - grand mother', 'mother_id' => '0', 'father_id' => '0'), 'children' => array(array('Person' => array('id' => '2', 'name' => 'mother', 'mother_id' => '4', 'father_id' => '5'), 'children' => array(array('Person' => array('id' => '1', 'name' => 'person', 'mother_id' => '2', 'father_id' => '3'), 'children' => array()))))), array('Person' => array('id' => '5', 'name' => 'mother - grand father', 'mother_id' => '0', 'father_id' => '0'), 'children' => array()), array('Person' => array('id' => '6', 'name' => 'father - grand mother', 'mother_id' => '0', 'father_id' => '0'), 'children' => array(array('Person' => array('id' => '3', 'name' => 'father', 'mother_id' => '6', 'father_id' => '7'), 'children' => array()))), array('Person' => array('id' => '7', 'name' => 'father - grand father', 'mother_id' => '0', 'father_id' => '0'), 'children' => array())); $this->assertEquals($expected, $result); }
} else { // Return error message. ApiUtils::returnError($app, 'UserNotLogged'); } } catch (Exception $e) { // An exception ocurred. Return an error message. ApiUtils::handleException($app, $e); } }); // Service for get all persons from a group. $app->get('/findByGroup/:id', function ($id) use($app) { try { // Verify that the user is logged. if (isset($_SESSION['user'])) { // Get list of persons in the group. $rows = ApiUtils::rowsToMaps(Person::find('all', array('group_id' => $id))); // Return result. echo json_encode(array("row" => $rows, "error" => null)); } else { // Return error message. ApiUtils::returnError($app, 'UserNotLogged'); } } catch (Exception $e) { // An exception ocurred. Return an error message. ApiUtils::handleException($app, $e); } }); // Service for get the rows of a table. $app->get('/searchByDate/:date1/:date2', function ($date1, $date2) use($app) { try { // Verify that the user is logged.