/** * Inicializa los datos iniciales. * * Los acos se deben generar antes, ejecutando: * `./Console/cake AclExtras.AclExtras aco_sync` * * @return bool */ private function initBasicData() { $group = new Group(); $user = new User(); $person = new Person(); $genre = new Genre(); if ($genre->countItems() == 0) { self::initGenres($genre); } if ($person->countItems() == 0 || !$person->exists(1)) { self::initPeople($person); } if ($group->countItems() == 0) { self::initGroups($group); } if ($user->countItems() == 0) { self::initUsers($user); } $hr = $user->query('SELECT COUNT(*) AS count FROM `aros_acos`'); // debug($hr[0][0]['count']); if ((int) $hr[0][0]['count'] == 0) { $this->initGroupsPermissions(); } return true; }
/** * 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 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))); }
* 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); /** * To check if a model exists by primary key, without fetching it, use * Model::exists(). This returns a boolean. */ $ex1 = Person::exists($personID); $ex2 = Person::exists(999); $ex3 = Post::exists($postDate, $postNo); $ex4 = Post::exists($postDate, 999); echo SEPARATOR; echo "Person #{$personID} exists: "; var_dump($ex1); echo "Person #999 exists: "; var_dump($ex2); echo "Post {$postDate} {$postNo} exists: "; var_dump($ex3); echo "Post {$postDate} 999 exists: "; var_dump($ex4);
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; } }
public function upload_photo($person_id = NULL) { if (is_null($person_id)) { add_error_flash_message('Osoba sa nenašla.'); redirect(site_url('persons')); } $person = new Person(); $person->get_by_id((int) $person_id); if (!$person->exists()) { add_error_flash_message('Osoba sa nenašla.'); redirect(site_url('persons')); } $upload_config = array('upload_path' => 'user/photos/data/' . (int) $person->id . '/', 'allowed_types' => 'jpg|png', 'max_size' => '1024', 'max_width' => '1024', 'max_height' => '1024', 'file_name' => 'temp_photo.png', 'overwrite' => TRUE); $this->load->library('upload', $upload_config); @mkdir($upload_config['upload_path'], DIR_WRITE_MODE, TRUE); if ($this->upload->do_upload('photo')) { $resize_config = array('image_library' => 'gd2', 'source_image' => $upload_config['upload_path'] . $upload_config['file_name'], 'create_thumb' => FALSE, 'maintain_ratio' => TRUE, 'width' => 256, 'height' => 256, 'quality' => '90%', 'new_image' => $upload_config['upload_path'] . 'photo.png'); $this->load->library('image_lib', $resize_config); if ($this->image_lib->resize()) { $resize_config['width'] = 64; $resize_config['height'] = 64; $resize_config['new_image'] = $upload_config['upload_path'] . 'photo_min.png'; @unlink($upload_config['new_image']); $this->image_lib->initialize($resize_config); $this->image_lib->resize(); @unlink($resize_config['source_image']); add_success_flash_message('Súbor úspešne nahraný.'); redirect(site_url('persons/edit_photo/' . (int) $person->id)); } else { @unlink($resize_config['source_image']); add_error_flash_message('Súbor sa nepodarilo preškálovať:' . $this->image_lib->display_errors('<br /><br />', '')); redirect(site_url('persons/edit_photo/' . (int) $person->id)); } } else { add_error_flash_message('Súbor sa nepodarilo nahrať, vznikla nasledujúca chyba:' . $this->upload->display_errors('<br /><br />', '')); redirect(site_url('persons/edit_photo/' . (int) $person->id)); } }
public function get_batch_ledcoin_addition_form() { $workplaces = new Workplace(); $workplaces->order_by('title', 'asc'); $workplaces->get_iterated(); $workplace_values = array('' => ''); foreach ($workplaces as $workplace) { $workplace_values[$workplace->id] = $workplace->title; } $form = array('fields' => array('comment' => array('name' => 'batch_amount[comment]', 'id' => 'batch_amount-comment', 'label' => 'Komentár', 'type' => 'text_input', 'data' => array('stay-visible' => 'true'), 'placeholder' => 'Sem pridajte komentár, alebo nechajte prázdne.', 'hint' => 'Pozor, globálne nastavenie pre všetkých účastníkov.'), 'workplace' => array('name' => 'batch_amount[workplace_id]', 'id' => 'batch_amount-workplace_id', 'label' => 'Zamestnanie', 'type' => 'select', 'data' => array('stay-visible' => 'true'), 'values' => $workplace_values, 'hint' => 'Pozor, globálne nastavenie pre všetkých účastníkov.'), 'addition_type' => array('name' => 'batch_amount[addition_type]', 'type' => 'select', 'id' => 'batch_amount-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')), 'arangement' => array('workplace', 'comment', 'addition_type')); $persons = new Person(); $persons->include_related('group', 'title'); $persons->where('admin', '0'); $persons->order_by_related('group', 'title', 'asc')->order_by('surname', 'asc')->order_by('name', 'asc'); $persons->get_iterated(); if ($persons->exists()) { $form['fields']['persons_divider'] = array('type' => 'divider', 'data' => array('stay-visible' => 'true')); $form['arangement'][] = 'persons_divider'; } $current_group = NULL; foreach ($persons as $person) { if ($person->group_id !== $current_group) { $form['fields']['divider_group_' . $person->group_id] = array('type' => 'divider', 'data' => array('stay-visible' => 'true')); if (trim($person->group_title) !== '') { $form['fields']['divider_group_' . $person->group_id]['text'] = 'Skupina: "' . $person->group_title . '"'; } $form['arangement'][] = 'divider_group_' . $person->group_id; $current_group = $person->group_id; $form['fields']['group_' . $current_group . '_slider'] = array('name' => 'group[' . $current_group . ']', 'id' => 'group-' . $current_group, 'class' => 'group_common_slider', 'data' => array('group_id' => $current_group), 'label' => 'Spoločné nastavenie času', 'min' => 0, 'max' => 25, 'step' => 0.1, 'default' => 0, 'type' => 'slider'); $form['arangement'][] = 'group_' . $current_group . '_slider'; } $form['fields']['person_' . $person->id] = array('name' => 'person_amount[' . $person->id . ']', 'id' => 'person_amount-' . $person->id, 'class' => 'group_' . $current_group, 'label' => '<span class="person_name_label"><img src="' . get_person_image_min($person->id) . '" alt="" /><span class="person_name">' . $person->name . ' ' . $person->surname . '</span></span>', 'type' => 'slider', 'min' => 0, 'max' => 25, 'step' => 0.1, 'data' => array('person-name' => $person->name . ' ' . $person->surname, 'person-login' => $person->login), 'default' => 0, 'validation' => array(array('if-field-not-equals' => array('field' => 'person_amount[' . $person->id . ']', 'value' => 0), 'rules' => 'required|floatpoint|convert_floatpoint|greater_than[0]'))); $form['arangement'][] = 'person_' . $person->id; } return $form; }
/** * @test */ public function shouldBeAbleToHaveJoins() { // given $person = new Person(); if (!$person->exists()) { $person->createTable(); } $person->deleteTableData(); $person->setFirstname('John'); $person->setZip('4330'); $person->commit(); $id = $person->getId(); $city = new City(); if (!$city->exists()) { $city->createTable(); } $city->deleteTableData(); $city->setZip(4330); $city->setCity('Algard'); $city->commit(); // when $person = new Person($id); // then $this->assertEquals($id, $person->getId()); $this->assertEquals('4330', $person->getZip()); $this->assertEquals('Algard', $person->getCity()); }