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();
 }
 public function rewind()
 {
     parent::rewind();
     if ($this->valid()) {
         $this->currentResult = $this->handleItem($this->current());
     }
     if ($this->hasNext()) {
         $this->nextResult = $this->handleItem($this->getInnerIterator()->current());
     }
 }
Example #4
0
function test($ar, $flags)
{
    echo "==={$flags}===\n";
    $it = new CachingIterator($ar, 0);
    try {
        $it->setFlags($flags);
    } catch (Exception $e) {
        echo 'Exception: ' . $e->getMessage() . "\n";
        var_dump($it->getFlags());
        return;
    }
    var_dump($it->getFlags());
    try {
        foreach ($it as $v) {
            var_dump((string) $it);
        }
    } catch (Exception $e) {
        echo 'Exception: ' . $e->getMessage() . "\n";
    }
}
Example #5
0
File: Room.php Project: cwcw/cms
 /**
  * Array representation of this object (to be used in conjunction with the PLAY signal)
  *
  * @return array
  */
 public function toArray()
 {
     $filename = self::FT_ROOM;
     if (!empty($this->_roomOptions)) {
         $filename .= '/';
         $it = new CachingIterator(new ArrayIterator($this->_roomOptions));
         foreach ($it as $name => $value) {
             $filename .= $name . '=' . $value;
             if ($it->hasNext()) {
                 $filename .= ',';
             }
         }
     }
     $filename .= ':' . $this->_name;
     $ret = array(self::ARR_FILENAME => $filename, self::ARR_TYPE => $this->_channel);
     if (null !== $this->_transition) {
         $ret[self::ARR_TRANS] = $this->_transition;
     }
     return $ret;
 }
Example #6
0
 /**
  * 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>';
     }
 }
 function _fetch($check)
 {
     $valid = parent::_fetch($check);
     if (!$check || $valid) {
         $iterator = $this->getInnerIterator();
         if ($this->hasChildren = $iterator->hasChildren()) {
             $this->getChildren = new RecursiveCachingIterator($iterator->getChildren(), $this->getFlags());
         } else {
             $this->getChildren = NULL;
         }
     }
     return $valid;
 }
Example #8
0
 /**
  * Transform plain array to multidimensional
  * @param	array		$data
  * @param	string	$separator
  * @return	array
  */
 public static function plainToMulti($data, $separator = '.')
 {
     $result = new Core_ArrayObject();
     foreach ($data as $key => $value) {
         $pieces = new CachingIterator(new ArrayIterator(explode($separator, $key)));
         $current =& $result;
         foreach ($pieces as $piece) {
             if ($pieces->hasNext()) {
                 if (!isset($current->{$piece})) {
                     $current->{$piece} = new Core_ArrayObject();
                 }
                 $current =& $current->{$piece};
             } else {
                 $current->{$piece} = $value;
             }
         }
     }
     return $result->toArray();
 }
 function next()
 {
     if ($this->hasChildren = $this->it->hasChildren()) {
         try {
             $child = $this->it->getChildren();
             if (!$this->ref) {
                 //TODO:
                 //  $this->ref = new ReflectionClass($this);
             }
             //$this->getChildren = $ref->newInstance($child, $this->flags);
         } catch (Exception $e) {
             if (!$this->flags & self::CATCH_GET_CHILD) {
                 throw $e;
             }
             $this->hasChildren = false;
             $this->getChildren = NULL;
         }
     } else {
         $this->getChildren = NULL;
     }
     parent::next();
 }
Example #10
0
 require_once 'connect.php';
 $from_stamp = strtotime($from);
 $to_stamp = strtotime($to);
 echo $from_stamp, $to_stamp;
 $conn = dbConnect();
 if ($affected_nodes != NULL) {
     $nodes = preg_split('/\\s/', $affected_nodes);
     $sql = 'INSERT INTO disturbances (system_id, from_stamp, to_stamp, notes) VALUES (?, ?, ?, ?)';
     $stmt = $conn->stmt_init();
     if ($stmt = $conn->prepare($sql)) {
         $stmt->bind_param('ssss', $system_id, date('Y-m-d H:i:s', $from_stamp), date('Y-m-d H:i:s', $to_stamp), $notes);
         $stmt->execute();
         $dist_id = $stmt->insert_id;
         $sqlquery = 'INSERT INTO disturbance_nodes (disturbance_id, node) VALUES ';
         $ait = new ArrayIterator($nodes);
         $cit = new CachingIterator($ait);
         foreach ($cit as $node) {
             if ($node != NULL) {
                 $sqlquery .= '("' . $dist_id . '", "' . $node . '")';
                 if ($cit->hasNext()) {
                     $sqlquery .= ",";
                 }
             }
         }
         mysqli_query($conn, $sqlquery);
     } else {
         $result = mysqli_error($conn);
     }
     mysqli_close($conn);
     echo "Disturbance added with id " . $dist_id;
 }
Example #11
0
 /**
  * Add wildcards to the given URI.
  *
  * @param  string  $uri
  * @return string
  */
 public function addUriWildcards($uri, $reflection, $method)
 {
     $refAction = $reflection->getReflectionClass()->getMethod($method);
     $app = Application::instance();
     $parameter = '';
     $patterns = $app->router->getPattern();
     $arguments = new \CachingIterator(new \ArrayIterator($refAction->getParameters()));
     foreach ($arguments as $key => $param) {
         if (!$param->isOptional()) {
             if (array_key_exists('{:' . $param->getName() . '}', $patterns)) {
                 $slash = $arguments->hasNext() ? '/' : '';
                 $parameter .= '{:' . $param->getName() . '}' . $slash;
             }
         }
     }
     return $uri . '/' . $parameter;
 }
Example #12
0
<?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());
}
 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);
 }
Example #14
0
 public function get($table, $fields, array $where = null, $order = null, $limit = null, $cache = null, array $options = null)
 {
     if (!is_array($table)) {
         $table = [$table];
     }
     if (!isset($options['prefix_tables']) || $options['prefix_tables'] === true) {
         array_walk($table, function (&$v, &$k) {
             if (strlen($v) < 7 || substr($v, 0, 7) != ':table_') {
                 $v = ':table_' . $v;
             }
         });
     }
     if (!is_array($fields)) {
         $fields = [$fields];
     }
     if (isset($order) && !is_array($order)) {
         $order = [$order];
     }
     if (isset($limit)) {
         if (is_array($limit) && count($limit) === 2 && is_numeric($limit[0]) && is_numeric($limit[1])) {
             $limit = implode(', ', $limit);
         } elseif (!is_numeric($limit)) {
             $limit = null;
         }
     }
     $statement = 'select ' . implode(', ', $fields) . ' from ' . implode(', ', $table);
     if (!isset($where) && !isset($cache)) {
         if (isset($order)) {
             $statement .= ' order by ' . implode(', ', $order);
         }
         return $this->query($statement);
     }
     if (isset($where)) {
         $statement .= ' where ';
         $counter = 0;
         $it_where = new \CachingIterator(new \ArrayIterator($where), \CachingIterator::TOSTRING_USE_CURRENT);
         foreach ($it_where as $key => $value) {
             if (is_array($value)) {
                 if (isset($value['val'])) {
                     $statement .= $key . ' ' . (isset($value['op']) ? $value['op'] : '=') . ' :cond_' . $counter;
                 }
                 if (isset($value['rel'])) {
                     if (isset($value['val'])) {
                         $statement .= ' and ';
                     }
                     if (is_array($value['rel'])) {
                         $it_rel = new \CachingIterator(new \ArrayIterator($value['rel']), \CachingIterator::TOSTRING_USE_CURRENT);
                         foreach ($it_rel as $rel) {
                             $statement .= $key . ' = ' . $rel;
                             if ($it_rel->hasNext()) {
                                 $statement .= ' and ';
                             }
                         }
                     } else {
                         $statement .= $key . ' = ' . $value['rel'];
                     }
                 }
             } else {
                 $statement .= $key . ' = :cond_' . $counter;
             }
             if ($it_where->hasNext()) {
                 $statement .= ' and ';
             }
             $counter++;
         }
     }
     if (isset($order)) {
         $statement .= ' order by ' . implode(', ', $order);
     }
     if (isset($limit)) {
         $statement .= ' limit ' . $limit;
     }
     $Q = $this->prepare($statement);
     if (isset($where)) {
         $counter = 0;
         foreach ($it_where as $value) {
             if (is_array($value)) {
                 if (isset($value['val'])) {
                     $Q->bindValue(':cond_' . $counter, $value['val']);
                 }
             } else {
                 $Q->bindValue(':cond_' . $counter, $value);
             }
             $counter++;
         }
     }
     if (isset($cache)) {
         if (!is_array($cache)) {
             $cache = [$cache];
         }
         call_user_func_array([$Q, 'setCache'], $cache);
     }
     $Q->execute();
     return $Q;
 }
 /**
  * Update statement.
  * Sample: Record::getInstance()->updates('MyTable', array('foo' => 'bar', 'foo2' => 'bar4', 'foo9' => 'bar4'))->find('fooID', 22)->execute();
  *
  * @param string $sTable
  * @param array $aValues
  * @return object this
  */
 public function updates($sTable, array $aValues)
 {
     $aValues = is_null($aValues) ? $this->_aValues : $aValues;
     $this->_sSql = 'UPDATE' . Db::prefix($sTable) . 'SET ';
     $oCachingIterator = new \CachingIterator(new \ArrayIterator($aValues));
     foreach ($oCachingIterator as $sField => $sValue) {
         $this->_sSql .= $sField . ' = ' . $this->escape($sValue);
         $this->_sSql .= $oCachingIterator->hasNext() ? ',' : '';
     }
     return $this;
 }
Example #16
0
 public function pages($config = array())
 {
     $config = new Library\ObjectConfig($config);
     $config->append(array('pages' => array(), 'active' => null, 'attribs' => array('class' => array('nav'))));
     $result = '';
     $first = true;
     $last_level = 0;
     $pages = clone $config->pages;
     // We use a CachingIterator to peek ahead to the next item so that we can properly close elements
     $collection = new \CachingIterator($pages->getIterator(), \CachingIterator::TOSTRING_USE_KEY);
     foreach ($collection as $page) {
         $next_page = null;
         if ($collection->hasNext()) {
             $next_page = $collection->getInnerIterator()->current();
         }
         $next_level = is_object($next_page) ? count(explode('/', $next_page->path)) : false;
         $level = count(explode('/', $page->path));
         // Start a new level
         if ($level > $last_level) {
             $attributes = $first ? ' ' . $this->buildAttributes($config->attribs) : '';
             $result .= "<ul{$attributes}>";
             // Used to put the title in the menu
             if ($first && $config->title) {
                 $result .= '<li class="nav-header">' . $config->title . "</li>";
             }
             $first = false;
         }
         $classes = array();
         if ($config->active) {
             if (in_array($page->id, array_merge($config->active->getParentIds(), (array) $config->active->id))) {
                 $classes[] = 'active';
             }
             if ($page->id == $config->active->id) {
                 $classes[] = 'current';
             }
             foreach ($config->pages as $value) {
                 if (strpos($value->path, $page->path . '/') === 0) {
                     $classes[] = 'parent';
                     break;
                 }
             }
         }
         if ($page->type == 'separator') {
             $classes[] = 'nav-header';
         }
         $result .= '<li' . ($classes ? ' class="' . implode(' ', $classes) . '"' : '') . ">";
         switch ($page->type) {
             case 'component':
                 $link = $this->getTemplate()->getView()->getRoute($page->getLink()->getQuery());
                 $result .= '<a href="' . (string) $link . '">';
                 $result .= $page->title;
                 $result .= '</a>';
                 break;
             case 'menulink':
                 $page_linked = $this->getObject('application.pages')->getPage($page->getLink()->query['Itemid']);
                 $result .= '<a href="' . $page_linked->getLink() . '">';
                 $result .= $page->title;
                 $result .= '</a>';
                 break;
             case 'separator':
                 $result .= '<span class="separator ' . ($config->disabled ? 'nolink' : '') . '">' . $page->title . '</span>';
                 break;
             case 'url':
                 $result .= '<a href="' . $page->getLink() . '">';
                 $result .= $page->title;
                 $result .= '</a>';
                 break;
             case 'redirect':
                 $result .= '<a href="' . $page->route . '">';
                 $result .= $page->title;
                 $result .= '</a>';
         }
         //$result .= $level;
         if ($level < $next_level) {
             // don't close <li>
         } elseif ($level === $next_level) {
             $result .= "</li>";
         } elseif ($next_level === false || $level > $next_level) {
             // Last one of the level
             $result .= "</li>";
             for ($i = 0; $i < $level - $next_level; ++$i) {
                 if ($next_level === false) {
                     $result .= "</ul>";
                 } else {
                     $result .= "</ul></li>";
                 }
             }
         }
         $last_level = $level;
     }
     return $result;
 }
Example #17
0
<?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";
}
Example #18
0
 /**
  * @return mixed
  */
 public function getSql()
 {
     $query = 'SELECT ';
     if (!$this->select || !$this->from) {
         throw new \RuntimeException();
     }
     $ait = new \ArrayIterator($this->select);
     $cit = new \CachingIterator($ait);
     foreach ($cit as $select) {
         $query .= " " . $select;
         if ($cit->hasNext()) {
             $query .= ", ";
         }
     }
     $query .= " FROM " . $this->from . " ";
     if (!$this->ignoreJoins) {
         foreach ($this->joins as $join) {
             $query .= " " . $join;
         }
     }
     if ($this->wheres && !$this->ignoreWheres) {
         $query .= " WHERE ";
         $ait = new \ArrayIterator($this->wheres);
         $cit = new \CachingIterator($ait);
         foreach ($cit as $where) {
             $query .= " " . $where;
             if ($cit->hasNext()) {
                 $query .= " AND ";
             }
         }
     }
     if ($this->groupBy && !$this->ignoreGroupBy) {
         $query .= " GROUP BY ";
         $query .= implode(',', $this->groupBy);
     }
     if ($this->having && !$this->ignoreHaving) {
         $query .= " HAVING ";
         $query .= implode(',', $this->having);
     }
     if ($this->orders && !$this->ignoreOrderBy) {
         $query .= " ORDER BY ";
         $count = count($this->orders);
         $i = 1;
         foreach ($this->orders as $key => $order) {
             $query .= " " . $order['order'] . " " . $order['sort'];
             if ($count > $i) {
                 $query .= ", ";
             }
             $i++;
         }
     }
     if ($this->getLimit() && !$this->getIgnoreLimit()) {
         $query .= " LIMIT " . $this->getLimit();
         if ($this->getOffset() && !$this->getIgnoreOffset()) {
             $query .= " OFFSET " . $this->getOffset();
         }
     }
     return $query;
 }
Example #19
0
<?php

require "connection.php";
require "dbAccess.php";
// this is internal data, no need to check for XSS
$jsonids = $_POST["ids"];
$ids = json_decode($jsonids, true);
// create db connection
$access = new dbAccess();
$access->openConnection();
// begin sql statement
$sql = "insert into notify (event_id, user_id, inviter_id) values ";
// iterate through $ids array for a single batch sql query
$iter = new ArrayIterator($ids);
// a new caching iterator gives us access to hasNext()
$citer = new CachingIterator($iter);
// loop over the array
foreach ($citer as $value) {
    // add to the query
    $sql .= "('" . $ids[$citer->key()]["event_id"] . "','" . $ids[$citer->key()]["user_id"] . "','" . $ids[$citer->key()]["inviter_id"] . "')";
    // if there is another array member, add a comma
    if ($citer->hasNext()) {
        $sql .= ",";
    }
}
// run query
$result = $access->conn->query($sql);
// report success if query succeeded
if (!empty($result)) {
    $returnValue["status"] = "Success";
    $returnValue["message"] = "Users invited";
Example #20
0
 /**
  * Finds the line where the requested PHP Token appears
  *
  * @param   string  $type   PHP Token constant or a custom one (@see tokenChar())
  * @param   string  $name   Name of the token (ie variable name)
  * @param   int     $skip   How many line should I skip from the beginning?
  *
  * @return  int|null    Returns the corrispongin line or null if not found
  */
 protected function findToken($type, $name, $skip = 0)
 {
     $tokens = token_get_all($this->code);
     $iterator = new ArrayIterator($tokens);
     $collection = new CachingIterator($iterator, CachingIterator::TOSTRING_USE_CURRENT);
     $ignoreSkip = false;
     // Ok let's start looking for the requested token
     foreach ($collection as $token) {
         $line = 0;
         if (is_string($token)) {
             $info['token'] = $this->tokenChar($token);
             $info['value'] = $token;
         } else {
             $info['token'] = token_name($token[0]);
             $info['value'] = $token[1];
             $line = $token[2];
         }
         // If I have the skip argument I have to skip the first lines (literal chars are always skipped since they
         // don't report the line they're in)
         if ($skip && $line < $skip && !$ignoreSkip) {
             continue;
         }
         // Ok, now I can stop checking for the skip (again, literal chars have no line info, otherwise I'll
         // keep skipping them all the time
         $ignoreSkip = true;
         // Ok token found, let's get the line
         if ($info['token'] == $type && $info['value'] == $name) {
             // If it's an array, that's easy
             if (is_array($token)) {
                 return $token[2];
             } else {
                 // It's a string, I have to fetch the next token so I'll have the proper line number
                 // To be sure, I have to iterate until I finally get an array for the token
                 $next = null;
                 while (!is_array($next)) {
                     $next = $collection->getInnerIterator()->current();
                     // The next token is not an array (ie it's a char like ;.=?)? Move the iterator forward and fetch
                     // the next token
                     if (!is_array($next)) {
                         $collection->getInnerIterator()->next();
                         continue;
                     }
                     return $next[2];
                 }
             }
         }
     }
     return null;
 }
Example #21
0
 $count = -1;
 while ($query_name = current($queries)) {
     if ($query_name == $table) {
         $query[] = sprintf(key($queries));
     }
     next($queries);
 }
 if (count($query) == 0) {
     $query[] = sprintf('SELECT * FROM "%s"', $table);
     if (isset($id) === true) {
         $query[] = sprintf('WHERE "%s" = ? LIMIT 1', 'id');
     } else {
         if (isset($_GET['where'])) {
             $query[] = 'WHERE';
             $wheres = $_GET['where'];
             foreach ($iter = new CachingIterator(new ArrayIterator($wheres), CachingIterator::TOSTRING_USE_KEY) as $where) {
                 if (count(array_diff(['col', 'op', 'val'], array_keys($where))) !== 0) {
                     error_log('Invalid where filters. All filters must define the following keys: `col`, `op`, `val`');
                     exit(ArrestDB::Reply(ArrestDB::$HTTP[400]));
                 }
                 $column = $where['col'];
                 $operator = $where['op'];
                 $data[] = $where['val'];
                 $query[] = sprintf('"%s" %s ? %s', $column, $operator, $iter->hasNext() ? 'AND' : '');
             }
         }
         $countQuery = str_replace('SELECT *', 'SELECT COUNT(*)', sprintf('%s;', implode(' ', $query)));
         $count = intval(array_shift(array_values(array_shift(ArrestDB::Query($countQuery, $data)))));
         if (isset($_GET['by']) === true) {
             if (isset($_GET['order']) !== true) {
                 $_GET['order'] = 'ASC';
Example #22
0
{
    public function seek($index)
    {
        if ($index < count($this->a)) {
            $this->i = $index;
        }
        echo __METHOD__ . '(' . $index . ")\n";
    }
}
$a = array(1, 2, 3, 4, 5);
$it = new LimitIterator(new NumericArrayIterator($a), 1, 3);
foreach ($it as $v) {
    print $v . ' is ' . ($it->greaterThan(2) ? 'greater than 2' : 'less than or equal 2') . "\n";
}
echo "===SEEKABLE===\n";
$a = array(1, 2, 3, 4, 5);
$it = new LimitIterator(new SeekableNumericArrayIterator($a), 1, 3);
foreach ($it as $v) {
    print $v . ' is ' . ($it->greaterThan(2) ? 'greater than 2' : 'less than or equal 2') . "\n";
}
echo "===STACKED===\n";
echo "Shows '2 is greater than 2' because the test is actually done with the current value which is 3.\n";
$a = array(1, 2, 3, 4, 5);
$it = new CachingIterator(new LimitIterator(new SeekableNumericArrayIterator($a), 1, 3));
foreach ($it as $v) {
    print $v . ' is ' . ($it->greaterThan(2) ? 'greater than 2' : 'less than or equal 2') . "\n";
}
?>
===DONE===
<?php 
exit(0);
 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);
 }
Example #24
0
 function rewind()
 {
     parent::rewind();
     $this->counter = parent::valid() ? 1 : 0;
 }
Example #25
0
<br><h1>Select Topic</h1>
<?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">
<?php

$i = new ArrayIterator(array(1, 1, 1, 1, 1));
$i = new CachingIterator($i, CachingIterator::FULL_CACHE);
foreach ($i as $value) {
    echo $i->count() . "\n";
}
?>
===DONE===
Example #27
0
File: rest.php Project: wushian/MDD
 /**
  * Detect format
  *
  * Detect which format should be used to output the data
  *
  * @return  string
  */
 protected function _detect_format()
 {
     // A format has been passed as an argument in the URL and it is supported
     if (\Input::param('format') and $this->_supported_formats[\Input::param('format')]) {
         return \Input::param('format');
     }
     // Otherwise, check the HTTP_ACCEPT (if it exists and we are allowed)
     if ($acceptable = \Input::server('HTTP_ACCEPT') and \Config::get('rest.ignore_http_accept') !== true) {
         // If anything is accepted, and we have a default, return that
         if ($acceptable == '*/*' and !empty($this->rest_format)) {
             return $this->rest_format;
         }
         // Split the Accept header and build an array of quality scores for each format
         $fragments = new \CachingIterator(new \ArrayIterator(preg_split('/[,;]/', \Input::server('HTTP_ACCEPT'))));
         $acceptable = array();
         $next_is_quality = false;
         foreach ($fragments as $fragment) {
             $quality = 1;
             // Skip the fragment if it is a quality score
             if ($next_is_quality) {
                 $next_is_quality = false;
                 continue;
             } elseif ($fragments->hasNext()) {
                 $next = $fragments->getInnerIterator()->current();
                 if (strpos($next, 'q=') === 0) {
                     list($key, $quality) = explode('=', $next);
                     $next_is_quality = true;
                 }
             }
             $acceptable[$fragment] = $quality;
         }
         // Sort the formats by score in descending order
         uasort($acceptable, function ($a, $b) {
             $a = (double) $a;
             $b = (double) $b;
             return $a > $b ? -1 : 1;
         });
         // Check each of the acceptable formats against the supported formats
         foreach ($acceptable as $pattern => $quality) {
             // The Accept header can contain wildcards in the format
             $find = array('*', '/');
             $replace = array('.*', '\\/');
             $pattern = '/^' . str_replace($find, $replace, $pattern) . '$/';
             foreach ($this->_supported_formats as $format => $mime) {
                 if (preg_match($pattern, $mime)) {
                     return $format;
                 }
             }
         }
     }
     // End HTTP_ACCEPT checking
     // Well, none of that has worked! Let's see if the controller has a default
     if (!empty($this->rest_format)) {
         return $this->rest_format;
     }
     // Just use the default format
     return \Config::get('rest.default_format');
 }
<?php

$data = array('Mela', 'Pera', 'Kiwi', 'Banana', 'Pompelmo');
$it = new ArrayIterator($data);
$iterator = new CachingIterator($it);
for ($iterator->rewind(); $iterator->valid(); $iterator->next()) {
    echo $iterator, PHP_EOL;
}
<?php

$ar = array(1, 2, array(31, 32, array(331)), 4);
$it = new RecursiveArrayIterator($ar);
$it = new RecursiveIteratorIterator($it);
$it = new CachingIterator($it, CachingIterator::FULL_CACHE);
foreach ($it as $k => $v) {
    echo "{$k}=>{$v}\n";
}
echo "===CHECK===\n";
for ($i = 0; $i < 4; $i++) {
    if (isset($it[$i])) {
        var_dump($i, $it[$i]);
    }
}
$it[2] = 'foo';
$it[3] = 'bar';
$it['baz'] = '25';
var_dump($it[2]);
var_dump($it[3]);
var_dump($it['baz']);
unset($it[0]);
unset($it[2]);
unset($it['baz']);
var_dump(isset($it[0]));
// unset
var_dump(isset($it[1]));
// still present
var_dump(isset($it[2]));
// unset
var_dump(isset($it[3]));
 function __construct(Iterator $it, $flags = 0)
 {
     parent::__construct($it, $flags);
 }