public function saveVendorsItems($vendor_id, $shop_id, $items_data) { //echo $vendor_id."=".$shop_id; $iterator = new ArrayIterator($items_data); $cache = new CachingIterator($iterator); foreach ($cache as $value) { $key = $cache->key(); $key_part = explode('_', $key); // key = entity_id+ id ; here id value mapped with pos_vendor_item_price table $entity_id = $key_part[0]; $id = (int) $key_part[1]; $price = $cache->current(); if (!$id) { // when $id = 0; it's mean new entry $query = "INSERT INTO pos_vendor_item_price (product_id, vendor_shop_id,self_shop_id,price ) VALUES "; $query .= "(" . $entity_id . ",{$vendor_id},{$shop_id}," . $price . ")"; $result = mysql_query($query); //if any error stop operation and exist with error message. if (!$result) { break; return false; } } else { $query = " INSERT INTO pos_vendor_item_price (id,product_id, vendor_shop_id,self_shop_id,price ) VALUES "; $query .= "(" . $id . ",{$entity_id},{$vendor_id},{$shop_id}," . $price . ")"; $query .= " ON DUPLICATE KEY UPDATE price = VALUES(price) "; $result = mysql_query($query); if (!$result) { break; return false; } } } return true; }
private function getDefaultTopicData() { $topic = parent::current(); $topics = $topic['topics']; list($key, $val) = each($topics); $defaultTopic = new treeTopic($key, $val); return $defaultTopic->getData(); }
/** * Override the current() method to modify the return value * for the given index. * * @access public * @return string */ public function current() { // get the name and url of the nav item $name = parent::key(); $url = parent::current(); // determine if we're on the last element if ($this->hasNext()) { return '<li><a href="' . $url . '">' . $name . '</a></li>'; } else { return '<li class="last"><a href="' . $url . '">' . $name . '</a></li>'; } }
/** @test */ public function testMainFunctionality() { $count = 0; $it = new CachingIterator(new MapIterator(new ArrayIterator(range(0, 10)), function ($i) use(&$count) { $count += 1; return $i; })); $it->rewind(); $this->assertEquals(0, $count); $it->valid(); $this->assertEquals(0, $it->current()); $it->valid(); $it->next(); $this->assertEquals(1, $it->current()); $this->assertEquals(1, $it->current()); $this->assertEquals(1, $it->current()); $it->valid(); $it->next(); $this->assertEquals(2, $it->current()); $this->assertEquals(3, $count); }
<?php /** * CachingIterator - "Um olho no peixe e outro no gato", está sempre uma posição a frente em relação ao iterator. */ $arr = ['eu' => 'tenho', 'sou' => 'keys', 'um' => 'para', 'array' => 'comparar', 'assoc' => 'galera']; $iterator = new CachingIterator(new ArrayIterator($arr)); var_dump($iterator->current()); // null var_dump($iterator->getInnerIterator()->current()); // string(5) "tenho" foreach ($iterator as $key => $value) { echo "Atual: {$value} - "; $proximoValue = $iterator->getInnerIterator()->current(); echo "Proximo: {$proximoValue} \n"; }
<?php $unit = ambildata($_SESSION['iddetail'], 'user_detail', 'UNIT_ID'); $q = mysql_query("select * from selected_topic where UNIT_ID='{$unit}'"); $e = mysql_fetch_array($q); $c = mysql_num_rows($q); if (isset($_POST['topik'])) { if ($c >= 1) { mysql_query("delete from selected_topic where UNIT_ID='{$unit}'"); } $user = $_SESSION['username']; $array = $_POST['topik']; $sql = "insert into selected_topic (GUID,UNIT_ID,MASTER_TOPIC_ID,DTMCRT,USRCRT) values "; $it = new ArrayIterator($array); $cit = new CachingIterator($it); foreach ($cit as $value) { $sql .= "(uuid(),'{$unit}','" . $cit->current() . "',now(),'{$user}')"; if ($cit->hasNext()) { $sql .= ","; } } $a = mysql_query($sql); if ($a) { eksyen('Sukses', '?p=topics'); } else { eksyen('Gagal', 'inside.php#mastersetting'); } } ?> <form action="" method="post"> <div class="row"> <div class="col-md-12">
public function test_London_getTransitions() { $test = $this->europeLondon(); $trans = $test->getTransitions(); $first = $trans[0]; $this->assertEquals($first->getDateTimeBefore(), LocalDateTime::of(1847, 12, 1, 0, 0)); $this->assertEquals($first->getOffsetBefore(), ZoneOffset::ofHoursMinutesSeconds(0, -1, -15)); $this->assertEquals($first->getOffsetAfter(), self::$OFFSET_ZERO); $spring1916 = $trans[1]; $this->assertEquals($spring1916->getDateTimeBefore(), LocalDateTime::of(1916, 5, 21, 2, 0)); $this->assertEquals($spring1916->getOffsetBefore(), self::$OFFSET_ZERO); $this->assertEquals($spring1916->getOffsetAfter(), self::$OFFSET_PONE); $autumn1916 = $trans[2]; $this->assertEquals($autumn1916->getDateTimeBefore(), LocalDateTime::of(1916, 10, 1, 3, 0)); $this->assertEquals($autumn1916->getOffsetBefore(), self::$OFFSET_PONE); $this->assertEquals($autumn1916->getOffsetAfter(), self::$OFFSET_ZERO); $zot = null; $it = new \CachingIterator(new \ArrayIterator($trans)); while ($it->hasNext()) { $it->next(); $zot = $it->current(); if ($zot->getDateTimeBefore()->getYear() === 1990) { break; } } $this->assertEquals($zot->getDateTimeBefore(), LocalDateTime::of(1990, 3, 25, 1, 0)); $this->assertEquals($zot->getOffsetBefore(), self::$OFFSET_ZERO); $it->next(); $zot = $it->current(); $this->assertEquals($zot->getDateTimeBefore(), LocalDateTime::of(1990, 10, 28, 2, 0)); $this->assertEquals($zot->getOffsetBefore(), self::$OFFSET_PONE); $it->next(); $zot = $it->current(); $this->assertEquals($zot->getDateTimeBefore(), LocalDateTime::of(1991, 3, 31, 1, 0)); $this->assertEquals($zot->getOffsetBefore(), self::$OFFSET_ZERO); $it->next(); $zot = $it->current(); $this->assertEquals($zot->getDateTimeBefore(), LocalDateTime::of(1991, 10, 27, 2, 0)); $this->assertEquals($zot->getOffsetBefore(), self::$OFFSET_PONE); $it->next(); $zot = $it->current(); $this->assertEquals($zot->getDateTimeBefore(), LocalDateTime::of(1992, 3, 29, 1, 0)); $this->assertEquals($zot->getOffsetBefore(), self::$OFFSET_ZERO); $it->next(); $zot = $it->current(); $this->assertEquals($zot->getDateTimeBefore(), LocalDateTime::of(1992, 10, 25, 2, 0)); $this->assertEquals($zot->getOffsetBefore(), self::$OFFSET_PONE); $it->next(); $zot = $it->current(); $this->assertEquals($zot->getDateTimeBefore(), LocalDateTime::of(1993, 3, 28, 1, 0)); $this->assertEquals($zot->getOffsetBefore(), self::$OFFSET_ZERO); $it->next(); $zot = $it->current(); $this->assertEquals($zot->getDateTimeBefore(), LocalDateTime::of(1993, 10, 24, 2, 0)); $this->assertEquals($zot->getOffsetBefore(), self::$OFFSET_PONE); $it->next(); $zot = $it->current(); $this->assertEquals($zot->getDateTimeBefore(), LocalDateTime::of(1994, 3, 27, 1, 0)); $this->assertEquals($zot->getOffsetBefore(), self::$OFFSET_ZERO); $it->next(); $zot = $it->current(); $this->assertEquals($zot->getDateTimeBefore(), LocalDateTime::of(1994, 10, 23, 2, 0)); $this->assertEquals($zot->getOffsetBefore(), self::$OFFSET_PONE); $it->next(); $zot = $it->current(); $this->assertEquals($zot->getDateTimeBefore(), LocalDateTime::of(1995, 3, 26, 1, 0)); $this->assertEquals($zot->getOffsetBefore(), self::$OFFSET_ZERO); $it->next(); $zot = $it->current(); $this->assertEquals($zot->getDateTimeBefore(), LocalDateTime::of(1995, 10, 22, 2, 0)); $this->assertEquals($zot->getOffsetBefore(), self::$OFFSET_PONE); $it->next(); $zot = $it->current(); $this->assertEquals($zot->getDateTimeBefore(), LocalDateTime::of(1996, 3, 31, 1, 0)); $this->assertEquals($zot->getOffsetBefore(), self::$OFFSET_ZERO); $it->next(); $zot = $it->current(); $this->assertEquals($zot->getDateTimeBefore(), LocalDateTime::of(1996, 10, 27, 2, 0)); $this->assertEquals($zot->getOffsetBefore(), self::$OFFSET_PONE); $it->next(); $zot = $it->current(); $this->assertEquals($zot->getDateTimeBefore(), LocalDateTime::of(1997, 3, 30, 1, 0)); $this->assertEquals($zot->getOffsetBefore(), self::$OFFSET_ZERO); $it->next(); $zot = $it->current(); $this->assertEquals($zot->getDateTimeBefore(), LocalDateTime::of(1997, 10, 26, 2, 0)); $this->assertEquals($zot->getOffsetBefore(), self::$OFFSET_PONE); $this->assertEquals($it->hasNext(), false); }
<?php /** * Előre tekintés */ $data = new ArrayObject(range(0, 9)); $iterator = new CachingIterator($data->getIterator(), CachingIterator::FULL_CACHE); foreach ($iterator as $key => $value) { printf("Key %s => Value %s, Current %s, HasNext %b, Next %s\n", $key, $value, $iterator->current(), $iterator->hasNext(), $iterator->getInnerIterator()->current()); var_dump($iterator->getCache()); }
private function parseMonth(\CachingIterator $s) { $s->next(); $month = $s->current(); if ($m = preg_match(self::$MONTH, $month, $mr)) { for ($moy = 1; $moy < 13 && $moy < count($mr); $moy++) { if ($mr[$moy] !== '') { return Month::of($moy); } } } throw new IllegalArgumentException("Unknown month: " . $month); }
$selected_children = 'kinderen'; } } // Retrieving the selected children's names $selected_children_names = array(); foreach ($_POST['advert-select-children'] as $childId) { $statement = $conn->prepare("SELECT child_first_name FROM tbl_child WHERE child_id = '{$childId}'"); $statement->execute(); $child_name = $statement->fetch(PDO::FETCH_COLUMN, 0); $selected_children_names[] = $child_name; } $iterator = new ArrayIterator($selected_children_names); $cachingiterator = new CachingIterator($iterator); $selected_child_name = ''; foreach ($cachingiterator as $name) { $selected_child_name .= $cachingiterator->current(); if ($cachingiterator->hasNext()) { $selected_child_name .= ", "; } } $selected_child_name = preg_replace('/(.*),/', '$1 en', $selected_child_name); // Processing the chosen date into a readable string $chosen_date_day = ltrim(date('d', strtotime($_POST['advert-book-date'])), '0'); $chosen_date_day_string = strftime("%A", strtotime($_POST['advert-book-date'])); $chosen_date_month_string = strftime("%B", strtotime($_POST['advert-book-date'])); // Sending a booking-request e-mail to the creator of the advert $mail = new PHPMailer(); $mail->isSMTP(); $mail->SMTPDebug = 0; $mail->Debugoutput = 'html'; $mail->Host = 'smtp.transip.email';
public function Save() { $conn = Db::getInstance(); // Creating a new advert and updating the contact-information of the creator $advert_query = "INSERT INTO tbl_advert(fk_user_id, advert_description, advert_price, advert_spots, advert_school, advert_transport) VALUES ('{$this->UserId}', '{$this->Description}', '{$this->Price}', '{$this->NumberChildren}', '{$this->School}', '{$this->Transportation}');"; $advert_query .= "UPDATE tbl_user SET user_mobile_number = '{$this->MobileNumber}', user_home_number = '{$this->HomeNumber}', user_adress = '{$this->HomeAdress}', user_city = '{$this->HomeCity}' WHERE user_id = '{$this->UserId}';"; $statement = $conn->prepare($advert_query); $statement->execute(); // Gathering the last created advert id and saving all chosen services corresponding to the newly created advert $last_created_id = $conn->lastInsertId(); $services_dates_query = ""; $services_dates_query .= "INSERT INTO tbl_service(fk_advert_id, service_name) VALUES "; $iterator = new ArrayIterator($this->Services); $cachingiterator = new CachingIterator($iterator); foreach ($cachingiterator as $value) { $services_dates_query .= "('{$last_created_id}', '" . $cachingiterator->current() . "')"; if ($cachingiterator->hasNext()) { $services_dates_query .= ", "; } } $services_dates_query .= "; "; // Saving all chosen dates and timestamps corresponding to the newly created advert $services_dates_query .= "INSERT INTO tbl_availability(fk_advert_id, availability_date, availability_time_start, availability_time_end, availability_spots) VALUES "; foreach ($this->AvailableDates as $key => $d) { $services_dates_query .= "('{$last_created_id}', '" . $d . "', '" . $this->AvailableStartTimes[$key] . "', '" . $this->AvailableEndTimes[$key] . "', '" . $this->NumberChildren . "'), "; } $services_dates_query = rtrim($services_dates_query, ', ') . ";"; $statement = $conn->prepare($services_dates_query); $statement->execute(); // Saving all newly added children corresponding to the creator of the advert $children_information_query = "INSERT INTO tbl_child(child_first_name, child_last_name, child_school, child_class) VALUES "; $number_children_created = 0; foreach ($this->ChildFirstName as $key => $c) { $children_information_query .= "('" . $c . "', '" . $this->ChildLastName[$key] . "', '" . $this->School . "', '" . $this->ChildClass[$key] . "'), "; $number_children_created++; } $children_information_query = rtrim($children_information_query, ', ') . ";"; $statement = $conn->prepare($children_information_query); $statement->execute(); // Gathering all newly created children and linking them to the creator of the advert $child_last_created_id = $conn->lastInsertId(); $number_children_created_array = array(); for ($i = 0; $i < $number_children_created; ++$i) { $created_child_id = $child_last_created_id + $i; array_push($number_children_created_array, $created_child_id); } $children_link_query = "INSERT INTO tbl_user_child(fk_child_id, fk_user_id) VALUES "; foreach ($this->ChildFirstName as $key => $c) { $children_link_query .= "('" . $number_children_created_array[$key] . "', '" . $this->UserId . "'), "; } $children_link_query = rtrim($children_link_query, ', ') . ";"; $statement = $conn->prepare($children_link_query); $statement->execute(); }
public function Save() { $conn = Db::getInstance(); // Creating a new booking with all of the chosen data $statement = $conn->prepare("INSERT INTO tbl_booking(fk_advert_id, fk_booker_user_id, fk_renter_user_id, booking_number_spots, booking_price, booking_extra_information, booking_status) VALUES (:AdvertId, :BookerUserId, :RenterUserId, :NumberSpots, :Price, :ExtraInformation, 'pending')"); $statement->bindValue(':AdvertId', $this->AdvertId); $statement->bindValue(':BookerUserId', $this->BookerUserId); $statement->bindValue(':RenterUserId', $this->RenterUserId); $statement->bindValue(':NumberSpots', $this->NumberSpots); $statement->bindValue(':Price', $this->Price); $statement->bindValue(':ExtraInformation', $this->ExtraInformation); $statement->execute(); // Retrieving the last created booking_id and saving the booked date related to the newly created booking $last_created_booking_id = $conn->lastInsertId(); $statement = $conn->prepare("INSERT INTO tbl_booking_date(fk_booking_id, booking_date_format) VALUES (:BookingId, :BookingDate)"); $statement->bindValue(':BookingId', $last_created_booking_id); $statement->bindValue(':BookingDate', $this->Date); $statement->execute(); // Saving all of chosen children related to the newly created booking $selected_children_query = "INSERT INTO tbl_booking_child(fk_booking_id, fk_child_id) VALUES "; $selected_children_iterator = new ArrayIterator($this->ChildId); $selected_children_cachingiterator = new CachingIterator($selected_children_iterator); foreach ($selected_children_cachingiterator as $value) { $selected_children_query .= "({$last_created_booking_id}, " . $selected_children_cachingiterator->current() . ")"; if ($selected_children_cachingiterator->hasNext()) { $selected_children_query .= ", "; } } $statement = $conn->prepare($selected_children_query); $statement->execute(); // Saving all of the chosen services related to the newly created booking $selected_services_query = "INSERT INTO tbl_booking_service(fk_booking_id, fk_service_id) VALUES "; $selected_services_iterator = new ArrayIterator($this->ServiceId); $selected_services_cachingiterator = new CachingIterator($selected_services_iterator); foreach ($selected_services_cachingiterator as $value) { $selected_services_query .= "({$last_created_booking_id}, " . $selected_services_cachingiterator->current() . ")"; if ($selected_services_cachingiterator->hasNext()) { $selected_services_query .= ", "; } } $statement = $conn->prepare($selected_services_query); $statement->execute(); }
$page_position = ($page_number - 1) * $item_per_page; // Gathering all of the adverts that match the search criteria $search_results = $mysqli->prepare("SELECT advert_id, fk_user_id, advert_description, advert_price, advert_spots, advert_school, user_image_path, user_firstname, user_lastname, user_city, availability_spots FROM tbl_advert LEFT JOIN tbl_user ON tbl_advert.fk_user_id=tbl_user.user_id LEFT JOIN tbl_availability ON tbl_advert.advert_id=tbl_availability.fk_advert_id WHERE advert_status='approved' AND advert_school LIKE '%" . $school . "%' AND availability_spots >= '" . $spots . "' AND " . $date . " GROUP BY advert_id ORDER BY advert_id ASC LIMIT {$page_position}, {$item_per_page}"); } else { if (isset($_POST['chosenFilter'])) { // Collecting all given search variables with filter $filter_school = htmlspecialchars($_POST['filterSchool']); $filter_date = htmlspecialchars($_POST['filterDate']); $filter_spots = htmlspecialchars($_POST['filterSpots']); // Transforming the variable that holds the selected dates into a readable part for query useage $date_array = explode(', ', $filter_date); $iterator = new ArrayIterator($date_array); $cachingiterator = new CachingIterator($iterator); $filter_date = "("; foreach ($cachingiterator as $value) { $filter_date .= "availability_date = '" . $cachingiterator->current() . "'"; if ($cachingiterator->hasNext()) { $filter_date .= " OR "; } } $filter_date .= ")"; // Calculating the number of pages and the current page position $search_results = $mysqli->query("SELECT COUNT(DISTINCT(advert_id)) FROM tbl_advert LEFT JOIN tbl_availability ON tbl_advert.advert_id=tbl_availability.fk_advert_id WHERE advert_status='approved' AND advert_school LIKE '%" . $filter_school . "%' AND advert_spots >= '" . $filter_spots . "' AND " . $filter_date . ""); $get_total_rows = $search_results->fetch_row(); $total_pages = ceil($get_total_rows[0] / $item_per_page); $page_position = ($page_number - 1) * $item_per_page; switch ($_POST['chosenFilter']) { // Display the most recently created adverts that match the search criteria case 'recent': $search_results = $mysqli->prepare("SELECT advert_id, fk_user_id, advert_description, advert_price, advert_spots, advert_school, user_image_path, user_firstname, user_lastname, user_city, availability_spots FROM tbl_advert LEFT JOIN tbl_user ON tbl_advert.fk_user_id=tbl_user.user_id LEFT JOIN tbl_availability ON tbl_advert.advert_id=tbl_availability.fk_advert_id WHERE advert_status='approved' AND advert_school LIKE '%" . $filter_school . "%' AND availability_spots >= '" . $filter_spots . "' AND " . $filter_date . " GROUP BY advert_id ORDER BY advert_id DESC LIMIT {$page_position}, {$item_per_page}"); break;