Ejemplo n.º 1
0
 function get_logged_user()
 {
     if (!$this->is_signed_in()) {
         return NULL;
     } else {
         $p = new Person();
         $p->where('id', $this->CI->session->userdata('person_id'))->get();
         return $p;
     }
 }
Ejemplo n.º 2
0
 public function editar_empresa_persona()
 {
     $fk_empresa = Empresa::get()->lists('full_name', 'id');
     $fk_persona = Person::where('persona_es_autorizado', '=', FALSE)->orderBy('persona_cid', 'ASC')->get()->lists('full_name', 'id');
     $inputs = Input::get('idedit');
     $empresa_persona = Empresa_Persona::find($inputs);
     if ($empresa_persona) {
         return View::make('empresa_persona.createEmpresaPersona', array('fk_empresa' => $fk_empresa, 'fk_persona' => $fk_persona, 'empresa_persona' => $empresa_persona));
     } else {
         return Redirect::to('empresa_persona');
     }
 }
Ejemplo n.º 3
0
/**
 * 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;
}
 public function editar_solicitud_afi()
 {
     $fk_empresa_persona = Empresa_Persona::get()->lists('full_name', 'id');
     $fk_persona = Person::where('persona_es_autorizado', '=', FALSE)->orderBy('persona_cid', 'ASC')->get()->lists('full_name', 'id');
     $today = Carbon::today()->toDateString();
     $inputs = Input::get('idedit');
     $solicitud_afiliacion = Solicitud_Afiliacion::find($inputs);
     //$fk_empresa_persona_seleccionada = Person::where('persona_cid','!=',$persona->persona_cid)->where('persona_es_autorizado','=',false)->lists('persona_cid', 'id');
     if ($solicitud_afiliacion) {
         return View::make('solicitud_afiliacion.createSolicitudAfi', array('fk_empresa_persona' => $fk_empresa_persona, 'fk_persona' => $fk_persona, 'solicitud_afiliacion' => $solicitud_afiliacion));
     } else {
         return Redirect::to('solicitud_afiliacion');
     }
 }
Ejemplo n.º 5
0
 public function editar_persona()
 {
     $fk_lugar = Place::lists('lugar_nombre', 'id');
     $fk_profesion = Profesion::lists('profesion_nombre', 'id');
     $fk_cargo = Cargo::lists('cargo_nombre', 'id');
     $inputs = Input::get('idedit');
     $persona = Person::find($inputs);
     $fk_persona_a_quien_autorizo = Person::where('persona_cid', '!=', $persona->persona_cid)->where('persona_es_autorizado', '=', false)->lists('persona_cid', 'id');
     if ($persona) {
         return View::make('persona.createPersona', array('persona' => $persona, 'fk_lugar' => $fk_lugar, 'fk_profesion' => $fk_profesion, 'fk_cargo' => $fk_cargo, 'fk_persona_a_quien_autorizo' => $fk_persona_a_quien_autorizo));
     } else {
         return Redirect::to('persona');
     }
 }
 function edit($id)
 {
     // Validation Rules
     $this->form_validation->set_rules('name', 'person name', 'required|min_length[10]');
     // hold error messages in div
     $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
     // check for validation
     if ($this->form_validation->run() == FALSE) {
         $data['data'] = Person::where(['id' => $id])->first();
         $this->load->view('register', $data);
     } else {
         $this->session->set_flashdata('item', 'form submitted successfully');
         Person::updateOrCreate(['id' => $this->input->post('id')], ['name' => $this->input->post('name')]);
         redirect(current_url());
     }
 }
Ejemplo n.º 7
0
 public function my_ledcoin()
 {
     auth_redirect_if_not_authentificated('errormessage/no_auth');
     $this->load->helper('filter');
     $post = $this->input->post();
     if ($post !== FALSE) {
         $post_filter = $this->input->post('filter');
         if ($post_filter !== FALSE) {
             filter_store_filter(self::FILTER_MY_LEDCOIN_TABLE, $post_filter);
         }
         redirect('ledcoin/my_ledcoin');
     }
     $filter = filter_get_filter(self::FILTER_MY_LEDCOIN_TABLE, array('page' => 1));
     $operations_addition = new Operation();
     $operations_addition->where('type', Operation::TYPE_ADDITION);
     $operations_addition->select_sum('amount', 'amount_sum');
     $operations_addition->where_related_person('id', '${parent}.id');
     $operations_mining = new Operation();
     $operations_mining->where('type', Operation::TYPE_ADDITION);
     $operations_mining->where('addition_type', Operation::ADDITION_TYPE_MINING);
     $operations_mining->select_sum('amount', 'amount_sum');
     $operations_mining->where_related_person('id', '${parent}.id');
     $operations_subtraction_direct = new Operation();
     $operations_subtraction_direct->where('type', Operation::TYPE_SUBTRACTION);
     $operations_subtraction_direct->where('subtraction_type', Operation::SUBTRACTION_TYPE_DIRECT);
     $operations_subtraction_direct->select_sum('amount', 'amount_sum');
     $operations_subtraction_direct->where_related_person('id', '${parent}.id');
     $operations_subtraction_products = new Operation();
     $operations_subtraction_products->where('type', Operation::TYPE_SUBTRACTION);
     $operations_subtraction_products->where('subtraction_type', Operation::SUBTRACTION_TYPE_PRODUCTS);
     $operations_subtraction_products->where_related('product_quantity', 'price >', 0);
     $operations_subtraction_products->group_start(' NOT', 'AND');
     $operations_subtraction_products->where_related('product_quantity', 'product_id', NULL);
     $operations_subtraction_products->group_end();
     unset($operations_subtraction_products->db->ar_select[0]);
     $operations_subtraction_products->select_func('SUM', array('@product_quantities.quantity', '*', '@product_quantities.price', '*', '@product_quantities.multiplier'), 'amount_sum');
     $operations_subtraction_products->where_related_person('id', '${parent}.id');
     $operations_subtraction_services = new Operation();
     $operations_subtraction_services->where('type', Operation::TYPE_SUBTRACTION);
     $operations_subtraction_services->where('subtraction_type', Operation::SUBTRACTION_TYPE_SERVICES);
     $operations_subtraction_services->where_related('service_usage', 'price >', 0);
     $operations_subtraction_services->group_start(' NOT', 'AND');
     $operations_subtraction_services->where_related('service_usage', 'service_id', NULL);
     $operations_subtraction_services->group_end();
     unset($operations_subtraction_services->db->ar_select[0]);
     $operations_subtraction_services->select_func('SUM', array('@service_usages.quantity', '*', '@service_usages.price', '*', '@service_usages.multiplier'), 'amount_sum');
     $operations_subtraction_services->where_related_person('id', '${parent}.id');
     $person = new Person();
     $person->where('admin', 0);
     $person->select('*');
     $person->select_subquery($operations_addition, 'plus_amount');
     $person->select_subquery($operations_mining, 'plus_mined');
     $person->select_subquery($operations_subtraction_direct, 'minus_amount_direct');
     $person->select_subquery($operations_subtraction_products, 'minus_amount_products');
     $person->select_subquery($operations_subtraction_services, 'minus_amount_services');
     $person->include_related('group', 'title');
     $person->get_by_id(auth_get_id());
     if (!$person->exists()) {
         add_error_flash_message('Nenašla sa informácia o prihlásenom používateľovi. Nemôžete si pozrieť svoj LEDCOIN.');
         redirect(site_url('ledcoin'));
     }
     $operations = new Operation();
     $operations->select('id, created, amount, type, subtraction_type, addition_type, comment');
     $operations->include_related('admin', array('name', 'surname'));
     $operations->include_related('workplace', 'title');
     $operations->where_related_person($person);
     $operations->order_by('created', 'asc');
     $operations->get_paged_iterated($filter['page'], self::MY_LEDCOIN_TABLE_ROWS_PER_PAGE);
     $this->parser->parse('web/controllers/ledcoin/my_ledcoin.tpl', array('title' => 'Môj LEDCOIN', 'operations' => $operations, 'person' => $person, 'form' => $this->get_my_ledcoin_filter_form($filter, $operations->paged)));
 }
Ejemplo n.º 8
0
 private function _check_key($key)
 {
     if ($key != '' && $key != 'nokey') {
         $person = new Person();
         $person->where('key_expire >', time());
         $person->get_by_key($key);
         if ($person->exists()) {
             header('Authorized: Valid');
             $this->user = $person;
         } else {
             header('Authorized: Invalid api-key');
             $this->user = FALSE;
         }
     } else {
         header('Authorized: nokey');
         $this->user = FALSE;
     }
 }
 /**
  * Adds new person to the schedule entry.
  *
  * @param $entry
  * @return void
  */
 private function onAdd($entry)
 {
     if (Input::get('ldapId' . $entry->id) == '') {
         // If no LDAP id provided - create new GUEST person
         $person = new Person();
         // LDAP ID
         $person->prsn_ldap_id = null;
         // NAME
         $person->prsn_name = Input::get('userName' . $entry->id);
         // PERSON STATUS = empty for guests
     } else {
         // Find existing MEMBER person in DB
         $person = Person::where('prsn_ldap_id', '=', Input::get('ldapId' . $entry->id))->first();
         // If not found - create new person with data provided
         if (is_null($person)) {
             // LDAP ID - already in the DB for existing person, adding a new one for a new person
             $person = Person::create(array('prsn_ldap_id' => Input::get('ldapId' . $entry->id)));
             // NAME - already in the DB for existing person, adding a new one for a new person
             $person->prsn_name = Input::get('userName' . $entry->id);
             // PERSON STATUS
             $person->prsn_status = Session::get('userStatus');
         }
         // If a person adds him/herself - update status from session to catch if it was changed in LDAP
         if ($person->prsn_ldap_id == Session::get('userId')) {
             $person->prsn_status = Session::get('userStatus');
             $person->prsn_name = Session::get('userName');
         }
     }
     // CLUB
     // If club input is empty setting clubId to '-' (clubId 1).
     // Else - look for a match in the Clubs DB and set person->clubId = matched club's id.
     // No match found - creating a new club with title from input.
     if (Input::get('club' . $entry->id) == '' or Input::get('club' . $entry->id) == '-') {
         $person->clb_id = '1';
     } else {
         $match = Club::firstOrCreate(array('clb_title' => Input::get('club' . $entry->id)));
         $person->clb_id = $match->id;
     }
     // COMMENT
     // Change current comment to new comment
     $entry->entry_user_comment = Input::get('comment' . $entry->id);
     // Save changes to person and schedule entry
     $person->updated_at = Carbon\Carbon::now();
     $person->save();
     $entry->prsn_id = $person->id;
     $entry->save();
 }
Ejemplo n.º 10
0
 public function get_form($type = '', $subtraction_type = '')
 {
     $this->load->helper('operations');
     $operations_addition = new Operation();
     $operations_addition->where('type', Operation::TYPE_ADDITION);
     $operations_addition->select_sum('amount', 'amount_sum');
     $operations_addition->where_related_person('id', '${parent}.id');
     $operations_subtraction_direct = new Operation();
     $operations_subtraction_direct->where('type', Operation::TYPE_SUBTRACTION);
     $operations_subtraction_direct->where('subtraction_type', Operation::SUBTRACTION_TYPE_DIRECT);
     $operations_subtraction_direct->select_sum('amount', 'amount_sum');
     $operations_subtraction_direct->where_related_person('id', '${parent}.id');
     $operations_subtraction_products = new Operation();
     $operations_subtraction_products->where('type', Operation::TYPE_SUBTRACTION);
     $operations_subtraction_products->where('subtraction_type', Operation::SUBTRACTION_TYPE_PRODUCTS);
     $operations_subtraction_products->where_related('product_quantity', 'price >', 0);
     $operations_subtraction_products->group_start(' NOT', 'AND');
     $operations_subtraction_products->where_related('product_quantity', 'product_id', NULL);
     $operations_subtraction_products->group_end();
     unset($operations_subtraction_products->db->ar_select[0]);
     $operations_subtraction_products->select_func('SUM', array('@product_quantities.quantity', '*', '@product_quantities.price', '*', '@product_quantities.multiplier'), 'amount_sum');
     $operations_subtraction_products->where_related_person('id', '${parent}.id');
     $operations_subtraction_services = new Operation();
     $operations_subtraction_services->where('type', Operation::TYPE_SUBTRACTION);
     $operations_subtraction_services->where('subtraction_type', Operation::SUBTRACTION_TYPE_SERVICES);
     $operations_subtraction_services->where_related('service_usage', 'price >', 0);
     $operations_subtraction_services->group_start(' NOT', 'AND');
     $operations_subtraction_services->where_related('service_usage', 'service_id', NULL);
     $operations_subtraction_services->group_end();
     unset($operations_subtraction_services->db->ar_select[0]);
     $operations_subtraction_services->select_func('SUM', array('@service_usages.quantity', '*', '@service_usages.price', '*', '@service_usages.multiplier'), 'amount_sum');
     $operations_subtraction_services->where_related_person('id', '${parent}.id');
     $persons = new Person();
     $persons->order_by('surname', 'asc')->order_by('name', 'asc');
     $persons->where('admin', 0);
     $persons->select('*');
     $persons->select_subquery($operations_addition, 'plus_amount');
     $persons->select_subquery($operations_subtraction_direct, 'minus_amount_direct');
     $persons->select_subquery($operations_subtraction_products, 'minus_amount_products');
     $persons->select_subquery($operations_subtraction_services, 'minus_amount_services');
     $persons->include_related('group', 'title');
     $persons->get_iterated();
     $persons_select = array('' => '');
     foreach ($persons as $person) {
         $amount = doubleval($person->plus_amount) - intval($person->minus_amount_direct) - intval($person->minus_amount_products) - intval($person->minus_amount_services);
         $persons_select[$person->id] = $person->name . ' ' . $person->surname . ' (' . $person->group_title . ' | LEDCOIN: ' . $amount . ' ' . get_inflection_ledcoin($amount) . ')';
     }
     $workplaces = new Workplace();
     $workplaces->order_by('title', 'asc');
     $workplaces->get_iterated();
     $workplaces_select = array('' => '');
     foreach ($workplaces as $workplace) {
         $workplaces_select[$workplace->id] = $workplace->title;
     }
     $form = array('fields' => array('type' => array('name' => 'operation[type]', 'type' => 'select', 'id' => 'operation-type', 'label' => 'Typ operácie', 'data' => array('stay-visible' => 'true'), 'values' => array('' => '', Operation::TYPE_ADDITION => 'Pridanie LEDCOIN-u', Operation::TYPE_SUBTRACTION => 'Odobratie LEDCOIN-u'), 'validation' => 'required'), 'subtraction_type' => array('name' => 'operation[subtraction_type]', 'type' => 'select', 'id' => 'operation-subtraction_type', 'label' => 'Spôsob odobratia LEDCOIN-u', 'data' => array('stay-visible' => 'true'), 'values' => array('' => '', Operation::SUBTRACTION_TYPE_DIRECT => 'Priame odobratie LEDCOIN-u', Operation::SUBTRACTION_TYPE_PRODUCTS => 'Nákup v bufete', Operation::SUBTRACTION_TYPE_SERVICES => 'Využitie služieb'), 'validation' => 'required'), 'addition_type' => array('name' => 'operation[addition_type]', 'type' => 'select', 'id' => 'operation-addition_type', 'data' => array('stay-visivle' => 'true'), 'label' => 'Spôsob pridania LEDCOIN-u', 'values' => array('' => '', Operation::ADDITION_TYPE_TRANSFER => 'Prevod z účtu vedúcich', Operation::ADDITION_TYPE_MINING => 'Vydolovanie LEDCOIN-u'), 'validation' => 'required'), 'person' => array('name' => 'operation[person_id]', 'type' => 'select', 'id' => 'operation-person_id', 'label' => 'Účastník', 'data' => array('stay-visible' => 'true'), 'values' => $persons_select, 'validation' => 'required'), 'workplace' => array('name' => 'operation[workplace_id]', 'type' => 'select', 'id' => 'operation-workplace_id', 'data' => array('stay-visible' => 'true'), 'label' => 'Zamestnanie', 'values' => $workplaces_select), 'comment' => array('name' => 'operation[comment]', 'type' => 'text_input', 'id' => 'comment-id', 'label' => 'Komentár', 'data' => array('stay-visible' => 'true'), 'validation' => 'max_length[255]'), 'amount' => array('name' => 'operation[amount]', 'type' => 'slider', 'id' => 'comment-amount', 'label' => 'LEDCOIN', 'data' => array('stay-visible' => 'true'), 'min' => 0, 'max' => 25, 'step' => 0.1, 'default' => 0, 'validation' => array(array('if-field-not-equals' => array('field' => 'operation[amount]', 'value' => 0), 'rules' => 'required|floatpoint|convert_floatpoint|greater_than[0]'))), 'multiplier-fake' => array('name' => 'operation[multiplier-fake]', 'type' => 'text_input', 'disabled' => true, 'id' => 'operation-multiplier-fake', 'default' => operations_ledcoin_multiplier(), 'label' => 'Multiplikátor LEDCOIN-u'), 'multiplier' => array('name' => 'operation[multiplier]', 'type' => 'hidden', 'default' => operations_ledcoin_multiplier())), 'arangement' => array('type', 'person', 'workplace', 'comment'));
     if ($type == Operation::TYPE_SUBTRACTION) {
         if ($subtraction_type == Operation::SUBTRACTION_TYPE_DIRECT) {
             $form['arangement'] = array('type', 'subtraction_type', 'person', 'workplace', 'comment', 'amount');
         } elseif ($subtraction_type == Operation::SUBTRACTION_TYPE_SERVICES) {
             $form['arangement'] = array('type', 'subtraction_type', 'person', 'comment', 'multiplier', 'multiplier-fake');
             $services = new Service();
             $services->order_by('title', 'asc');
             $services->get_iterated();
             foreach ($services as $service) {
                 $form['fields']['service_' . $service->id . '_quantity'] = array('name' => 'operation_service[' . $service->id . '][quantity]', 'class' => 'controlls-services', 'id' => 'operation_service-' . $service->id . '-quantity', 'type' => 'slider', 'min' => 0, 'max' => 240, 'label' => $service->title . ' (LEDCOIN)', 'data' => array('service-title' => $service->title), 'default' => 0, 'validation' => array(array('if-field-not-equals' => array('field' => 'operation_service[' . $service->id . '][quantity]', 'value' => 0), 'rules' => 'required|integer|greater_than[0]')));
                 $form['fields']['service_' . $service->id . '_price'] = array('name' => 'operation_service[' . $service->id . '][price]', 'class' => 'controlls-services', 'id' => 'operation_service-' . $service->id . '-price', 'type' => 'text_input', 'label' => $service->title . ' (cena za minútu)', 'data' => array('service-title' => $service->title), 'default' => $service->price, 'validation' => array(array('if-field-not-equals' => array('field' => 'operation_service[' . $service->id . '][quantity]', 'value' => 0), 'rules' => 'required|floatpoint|convert_floatpoint|greater_than[0]')));
                 $form['arangement'][] = 'service_' . $service->id . '_quantity';
                 $form['arangement'][] = 'service_' . $service->id . '_price';
             }
         } elseif ($subtraction_type == Operation::SUBTRACTION_TYPE_PRODUCTS) {
             $form['arangement'] = array('type', 'subtraction_type', 'person', 'comment', 'multiplier', 'multiplier-fake');
             $quantity_addition = new Product_quantity();
             $quantity_addition->select_sum('quantity', 'quantity_sum');
             $quantity_addition->where('type', Product_quantity::TYPE_ADDITION);
             $quantity_addition->where_related('product', 'id', '${parent}.id');
             $quantity_subtraction = new Product_quantity();
             $quantity_subtraction->select_sum('quantity', 'quantity_sum');
             $quantity_subtraction->where('type', Product_quantity::TYPE_SUBTRACTION);
             $quantity_subtraction->where_related('product', 'id', '${parent}.id');
             $products = new Product();
             $products->order_by('title', 'asc');
             $products->select('*');
             $products->select_subquery($quantity_addition, 'plus_quantity');
             $products->select_subquery($quantity_subtraction, 'minus_quantity');
             $products->get_iterated();
             $p = 1;
             foreach ($products as $product) {
                 $form['fields']['product_' . $product->id . '_quantity'] = array('name' => 'operation_product[' . $product->id . '][quantity]', 'class' => 'controlls-products', 'id' => 'operation_product-' . $product->id . '-quantity', 'type' => 'slider', 'min' => 0, 'max' => intval($product->plus_quantity) - intval($product->minus_quantity), 'label' => '<span class="product_title_label"><img src="' . get_product_image_min($product->id) . '" alt="" /><span class="product_title">' . $product->title . ' (počet kusov)</span></span>', 'default' => 0, 'disabled' => intval($product->plus_quantity) - intval($product->minus_quantity) <= 0 ? true : false, 'data' => array('product-title' => $product->title), 'validation' => array(array('if-field-not-equals' => array('field' => 'operation_product[' . $product->id . '][quantity]', 'value' => 0), 'rules' => 'required|integer|greater_than[0]|less_than_equals[' . (intval($product->plus_quantity) - intval($product->minus_quantity)) . ']')));
                 $form['fields']['product_' . $product->id . '_price'] = array('name' => 'operation_product[' . $product->id . '][price]', 'class' => 'controlls-products', 'id' => 'operation_product-' . $product->id . '-price', 'type' => 'text_input', 'label' => $product->title . ' (cena za kus)', 'default' => $product->price, 'disabled' => intval($product->plus_quantity) - intval($product->minus_quantity) <= 0 ? true : false, 'data' => array('product-title' => $product->title), 'validation' => array(array('if-field-not-equals' => array('field' => 'operation_product[' . $product->id . '][quantity]', 'value' => 0), 'rules' => 'required|floatpoint|convert_floatpoint|greater_than[0]')));
                 $form['arangement'][] = 'product_' . $product->id . '_quantity';
                 $form['arangement'][] = 'product_' . $product->id . '_price';
                 if ($p < $products->result_count()) {
                     $form['fields']['product_' . $product->id . '_divider'] = array('type' => 'divider', 'data' => array('product-title' => $product->title));
                     $form['arangement'][] = 'product_' . $product->id . '_divider';
                 }
                 $p++;
             }
         } else {
             $form['arangement'] = array('type', 'subtraction_type', 'person');
         }
     } else {
         $form['arangement'][] = 'addition_type';
         $form['arangement'][] = 'amount';
     }
     if ($type == Operation::TYPE_ADDITION) {
         $form['fields']['amount']['validation'] = 'required|floatpoint|convert_floatpoint|greater_than[0]';
     } elseif ($type == Operation::TYPE_SUBTRACTION) {
     } else {
         $form['arangement'] = array('type');
     }
     return $form;
 }
Ejemplo n.º 11
0
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);
}
 function saveContacts($contacts, $www, $company_linkedin_www, $www_variants)
 {
     if (Auth::check()) {
         foreach ($contacts as $contact) {
             $person = Person::where('api_contact_id', '=', $contact->contactId)->first();
             if ($person == null) {
                 $person = new Person();
             }
             $person->api_source = 'jigsaw.com';
             $person->check_sum_md5 = '';
             $person->api_company_id = $contact->companyId;
             $person->api_contact_id = $contact->contactId;
             $person->title = $contact->title;
             $person->company_name = $contact->companyName;
             $person->www = $www;
             $person->company_linkedin_www = $company_linkedin_www;
             $person->www_variants = $www_variants;
             $person->updated_date = $contact->updatedDate;
             $person->graveyard_status = $contact->graveyardStatus;
             $person->firstname = $contact->firstname;
             $person->lastname = $contact->lastname;
             $person->city = $contact->city;
             $person->state = $contact->state;
             $person->country = $contact->country;
             $person->zip = $contact->zip;
             $person->contact_url = $contact->contactURL;
             $person->seo_contact_url = $contact->seoContactURL;
             $person->area_code = $contact->areaCode;
             $person->address = $contact->address;
             $person->owned = $contact->owned;
             if ($person == null) {
                 $person->api_contact_sales = $contact->contactSales;
                 $person->owned_type = $contact->ownedType;
                 $person->phone = $contact->phone;
                 $person->email = $contact->email;
             }
             $person->save();
         }
     }
 }