Example #1
0
 public static function injectForBe($flightVoyages, $injectSearchParams = false)
 {
     $newFlights = array();
     try {
         if (!is_iterable($flightVoyages)) {
             throw new CException('Flight Voyages are not iterable.');
         }
         foreach ($flightVoyages as $key => $flight) {
             $newFlight = $flight;
             if ($injectSearchParams) {
                 $newFlight['serviceClass'] = $injectSearchParams['serviceClass'];
                 $newFlight['freeWeight'] = $newFlight['serviceClass'] == 'E' ? $flight['economFreeWeight'] : $flight['businessFreeWeight'];
                 $newFlight['freeWeightDescription'] = $newFlight['serviceClass'] == 'E' ? $flight['economDescription'] : $flight['businessDescription'];
                 unset($newFlight['economFreeWeight']);
                 unset($newFlight['businessFreeWeight']);
                 unset($newFlight['economDescription']);
                 unset($newFlight['businessDescription']);
             }
             $newFlights[] = $newFlight;
         }
         return $newFlights;
     } catch (Exception $e) {
         $newException = new Exception("Error: " . $e->getMessage() . " Data: " . CVarDumper::dumpAsString($flightVoyages));
         Yii::app()->RSentryException->logException($newException);
         return $newFlights;
     }
 }
Example #2
0
/** Builds a templatable many to one subform, whith exit/create/delete of items.
 * @param string $subform - standard view/template specifier, like
 *  <tt>'project.forms.edititems-subform'</tt>
 * @param array $args - Associatice array of optional args
 * 'templatable_data_sets_class' => optional additional classes to add to the templatable-data-sets div.
 * 'params' => optional array of additional parameters to be passed to the subform
 * 'collection_name' => the relationship name used by it's owning class, like 'items'
 * 'item_name' => The name the subform uses for it's variable/model
 * 'collection' => the collection of existing instances, like, $project->items;
 * 'create_button_label' => How to label the "New Item" button
 * 'create_button_class' => additional classes to add to the create/new button
 */
function multiSubform($subform, $args = [])
{
    $templatable_data_sets_class = keyValOrDefault('templatable_data_sets_class', $args);
    $collection = keyValOrDefault('collection', $args, []);
    if (!is_iterable($collection)) {
        $collection = [];
    }
    $item_name = keyValOrDefault('item_name', $args, 'item');
    $collection_name = keyValOrDefault('collection_name', $args, 'items');
    $create_button_label = keyValOrDefault('create_button_label', $args, 'New Item');
    $params[$collection_name] = keyValOrDefault($collection_name, $args);
    $params = keyValOrDefault('params', $args, []);
    $out = "\n<div class='templatable-data-sets {$templatable_data_sets_class}'>\n";
    $out .= "<input type='hidden' name='{$collection_name}' value='' />\n";
    $idx = -1;
    if (count($collection)) {
        foreach ($collection as $idx => $data) {
            $params = $params;
            $params[$item_name] = $data;
            $params['idx'] = $idx;
            $out .= view($subform, $params) . "\n";
        }
    }
    $out .= "\n    <div class='js btn create-new-data-set pkmvc-button'\n      data-itemcount='" . ++$idx . "'>{$create_button_label}\n  </div>\n";
    $out .= "<fieldset class='template-container hidden' disabled >\n";
    $params['idx'] = "__CNT_TPL__";
    $params[$item_name] = new Universal();
    $out .= view($subform, $params);
    $out .= "\n</fieldset>\n";
    $out .= "</div>\n";
    return $out;
}
Example #3
0
/**
 * Return a new array with the values set to the key/value pair glued together
 *
 * @param String $glue
 * @param Iterable $pieces
 *
 * @return array
 */
function implode_assoc($glue, $pieces)
{
    if (!is_iterable($pieces)) {
        throw new UnexpectedValueException('Data must be iterable.', 2526);
    }
    // iterable expected
    $ret = array();
    foreach ($pieces as $key => $val) {
        $ret[] = $key . $glue . $val;
    }
    return $ret;
}
 /** Build a template HTML to create and delete one-to-many relations in a form
  * 
  * @param string $subform - standard view/template specifier, like
  *  <tt>'project.forms.edititems-subform'</tt>
  * @param array $args - Associatice array of optional args
  * 'templatable_data_sets_class' => optional additional classes to add to the templatable-data-sets div.
  * 'params' => optional array of additional parameters to be passed to the subform
  * 'collection_name' => the relationship name used by it's owning class, like 'items'
  * 'item_name' => The name the subform uses for it's variable/model
  * 'dataset' => the collection of existing instances, like, $project->items;
  * 'create_button_label' => How to label the "New Item" button
  * 'create_button_class' => additional classes to add to the create/new button
  */
 public function __construct($subform, $args = [])
 {
     $this->templatable_data_sets_class = keyValOrDefault('templatable_data_sets_class', $args, '');
     $this->dataset = keyValOrDefault('dataset', $args, []);
     $this->item_name = keyValOrDefault('item_name', $args, 'item');
     $this->collection_name = keyValOrDefault('collection_name', $args, 'items');
     $this->create_button_label = keyValOrDefault('create_button_label', $args, 'New Item');
     $this->params[$this->collection_name] = keyValOrDefault($this->collection_name, $args);
     if (!is_iterable($this->dataset)) {
         $this->dataset = [];
     }
     $this->subform = $subform;
     $this->params = keyValOrDefault('params', $args, []);
 }
Example #5
0
 /**
  * Advance the inner iterator until we get a non-empty outer iterator.
  */
 function nextOuter()
 {
     while ($this->inner->valid()) {
         $v = $this->inner->current();
         if (is_iterable($v)) {
             $this->outer = iterator($v);
             $this->outer->rewind();
             if ($this->outer->valid()) {
                 return;
             }
             $this->inner->next();
         } else {
             break;
         }
     }
     $this->outer = null;
 }
Example #6
0
 public function toCCCP($configIn = null)
 {
     $ret = array();
     if ($configIn === null) {
         $config = $this->_config;
     } else {
         $config = $configIn;
     }
     if (is_iterable($config)) {
         foreach ($config as $key => $value) {
             if ($key != 'db') {
                 $ret[$key] = $this->toCCCP($value);
             }
         }
     }
     if ($configIn === null) {
         $ret = Zend_Json::encode(object($ret));
     }
     return $ret;
 }
Example #7
0
/**
 * Extracts and escapes text from the given value, for outputting to the HTTP client.
 *
 * <p>Note: this returns escaped text, except if the given argument is a {@see RawText} instance, in which case it
 * returns raw text.
 *
 * @param string|RawText $s
 * @return string
 */
function _e($s)
{
    if (!is_scalar($s)) {
        if (is_null($s)) {
            return '';
        }
        if ($s instanceof RawText) {
            return $s->toString();
        }
        if ($s instanceof RenderableInterface) {
            $s = $s->getRendering();
        } elseif (is_object($s) && method_exists($s, '__toString')) {
            $s = (string) $s;
        } else {
            if (is_iterable($s)) {
                return iteratorOf($s)->current();
            }
            return sprintf('[%s]', typeOf($s));
        }
    }
    return htmlentities($s, ENT_QUOTES, 'UTF-8', false);
}
 /**
  * Checks if the given argument is a valid iterable value. If it's not, it throws a fault.
  *
  * @param NavigationLinkInterface[]|\Traversable|callable $navMap
  * @return \Iterator
  * @throws Fault {@see Faults::ARG_NOT_ITERABLE}
  */
 static function validateNavMap($navMap)
 {
     if (!is_iterable($navMap)) {
         throw new Fault(Faults::ARG_NOT_ITERABLE);
     }
 }
Example #9
0
 public function get_xml_views()
 {
     $workbook_id = $this->input->post('workbook_id');
     $server_url = $this->config->item('tableau_server_url');
     $token = $this->input->cookie('token', TRUE);
     $site_id = $this->input->cookie('site_id', TRUE);
     $response = get_views($server_url, $site_id, $token, $workbook_id);
     $xml = simplexml_load_string($response) or die("Error: Se perdiĆ³ conectividad con el servidor");
     $array_views = $xml->views;
     if (is_iterable($array_views->view)) {
         foreach ($array_views->view as $view) {
             //despues descomentar se usa una img local
             $view->img = base64_encode(get_view_img($server_url, $workbook_id, $site_id, $token, $view['id']));
         }
         echo $array_views->asXML();
     } else {
         echo '<error> bad response </error>';
     }
 }
 function with($handlers)
 {
     if (!is_iterable($handlers)) {
         $handlers = [$handlers];
     }
     $class = get_class($this);
     /** @var static $new */
     $new = new $class($this->injector, $this->matcher);
     return $new->set($handlers);
 }
Example #11
0
 public function value($new_value = null)
 {
     if (!is_null($new_value)) {
         if ($this->mode == 'read') {
             throw new Exception('Datastore is in read mode.');
         }
         // assigning a DataStoreNode, just copy members
         if ($new_value instanceof DataStoreNode) {
             $this->value = $new_value->value();
             $this->child_name = $new_value->childName();
             $this->children = $new_value->getChildren();
         } else {
             if (is_object($new_value) && method_exists($new_value, 'toDS')) {
                 $new_value = $new_value->toDS();
             }
             if (is_assoc($new_value)) {
                 foreach ($new_value as $name => $value) {
                     $this->addNode($name, $value);
                 }
             } elseif (is_iterable($new_value)) {
                 $this->value = array();
                 foreach ($new_value as $v) {
                     if (is_array($v) && !empty($v) && !is_assoc($v)) {
                         throw new Exception('Cannot have nested indexed arrays.');
                     }
                     $this->value[] = new DataStoreNode($v);
                 }
             } else {
                 $this->value = $new_value;
             }
         }
     }
     return $this->value;
 }
 protected function render()
 {
     $prop = $this->props;
     $isMultiple = $prop->multiple;
     $assets = $this->context->getAssetsService();
     $assets->addInlineScript("selenia.ext.select.props['{$prop->id}']=" . JavascriptCodeGen::makeOptions(['autoOpenLinked' => $prop->autoOpenLinked, 'dataUrl' => $prop->dataUrl, 'emptyLabel' => $prop->emptyLabel, 'emptySelection' => $prop->emptySelection, 'id' => $prop->id, 'labelField' => $prop->labelField, 'linkedSelector' => $prop->linkedSelector, 'linkedUrl' => $prop->linkedUrl, 'multiple' => $prop->multiple, 'noResultsText' => $prop->noResultsText, 'valueField' => $prop->valueField, 'value' => $prop->value]));
     // If required, add auto-add tag behavior to this Chosen.
     if ($prop->autoTag && $prop->multiple) {
         $assets->addInlineScript("\n\$(function () {\n  \$ ('#{$prop->id}+.chosen-container .chosen-choices input').on ('keyup', function (ev) { console.log(ev);\n    var v = \$ (this).val ();\n    if (ev.keyCode == 13 && v) {\n      var tags  = \$ ('#{$prop->id} option').map (function (i, e) { return \$ (e).val () });\n      var found = false, l = v.length;\n      tags.each (function (i, x) {\n        if (x.substr (0, l) == v) {\n          found = true;\n          return false\n        }\n      });\n      if (found) return;\n      \$ ('#{$prop->id}').append (\"<option>\" + v + \"</option>\");\n      \$ ('#{$prop->id}').trigger ('chosen:updated');\n      ev.preventDefault ();\n      var e     = jQuery.Event (\"keyup\");\n      e.which   = 13;\n      \$ ('#{$prop->id}+.chosen-container .chosen-choices input').val (v).trigger ('keyup').trigger (e);\n    }\n  })\n});\n");
     }
     $this->attr('name', $prop->multiple ? "{$prop->name}[]" : $prop->name);
     $this->attrIf($isMultiple, 'multiple', '');
     $this->attrIf($prop->onChange, 'onchange', $prop->onChange);
     $this->beginContent();
     if ($prop->emptySelection && !$prop->multiple) {
         $sel = exists($prop->value) ? '' : ' selected';
         echo '<option value=""' . $sel . '>' . $prop->emptyLabel . '</option>';
     }
     $viewModel = $prop->get('data');
     if (isset($viewModel)) {
         /** @var \Iterator $dataIter */
         $dataIter = iteratorOf($viewModel);
         $dataIter->rewind();
         if ($dataIter->valid()) {
             $values = $selValue = null;
             // SETUP MULTI-SELECT
             if ($isMultiple) {
                 if (isset($prop->value) && !is_iterable($prop->value)) {
                     throw new ComponentException($this, sprintf("Value of multiple selection component must be iterable or null; %s was given.", typeOf($prop->value)));
                 }
                 $it = Flow::from($prop->value);
                 $it->rewind();
                 $values = $it->valid() && is_scalar($it->current()) ? $it->all() : $it->map(pluck($prop->valueField))->all();
             } else {
                 $selValue = strval($prop->get('value'));
             }
             // NOW RENDER IT
             $template = $this->getChildren('listItemTemplate');
             $first = true;
             do {
                 $v = $dataIter->current();
                 $value = getField($v, $prop->valueField);
                 $label = getField($v, $prop->labelField);
                 if (!strlen($label)) {
                     $label = $prop->emptyLabel;
                 }
                 if ($isMultiple) {
                     $sel = array_search($value, $values) !== false ? ' selected' : '';
                 } else {
                     if ($first && !$prop->emptySelection && !$prop->multiple && !exists($selValue)) {
                         $prop->value = $selValue = $value;
                     }
                     $eq = $prop->strict ? $value === $selValue : $value == $selValue;
                     if ($eq) {
                         $this->selectedLabel = $label;
                     }
                     $sel = $eq ? ' selected' : '';
                 }
                 if ($template) {
                     // Render templated list
                     $viewModel['value'] = $value;
                     $viewModel['label'] = $label;
                     Component::renderSet($template);
                 } else {
                     // Render standard list
                     echo "<option value=\"{$value}\"{$sel}>{$label}</option>";
                 }
                 $dataIter->next();
                 $first = false;
             } while ($dataIter->valid());
         }
     }
 }
Example #13
0
/**
 * Copies values from a source object (or array) into a target object, but only those whose keys are present on the
 * given list of allowed properties.
 *
 * <p>Assignments are not recursive.
 * <p>If the target property is an object implementing ArrayAccess, the assignment is performed via `[]`, otherwise
 * it's performed via `->`.
 *
 * ><p>**Note:** empty properties are those containing null or an empty string.
 *
 * @param object|ArrayAccess            $target
 * @param object|array|Traversable|null $src  If NULL, nothing happens.
 * @param array                         $only A List of property names.
 * @throws InvalidArgumentException If any of the arguments is not of one of the expected types.
 */
function mergeOnly($target, $src, array $only)
{
    if (isset($src)) {
        if (is_iterable($src)) {
            if (is_object($target)) {
                $keys = array_flip($only);
                if ($target instanceof ArrayAccess) {
                    foreach ($src as $k => $v) {
                        if (isset($keys[$k]) && $target->offsetExists($k)) {
                            $target[$k] = $v;
                        }
                    }
                } else {
                    foreach ($src as $k => $v) {
                        if (isset($keys[$k]) && property_exists($target, $k)) {
                            $target->{$k} = $v;
                        }
                    }
                }
            } else {
                throw new InvalidArgumentException('Invalid target argument');
            }
        } else {
            throw new InvalidArgumentException('Invalid source argument');
        }
    }
}
function DUMP_HOUR()
{
    $TimeFile = "/etc/artica-postfix/pids/exec.squid.interface-size.php.DUMP_HOUR.time";
    $unix = new unix();
    $xtime = $unix->file_time_min($TimeFile);
    if ($xtime < 59) {
        events("Aborting current {$xtime}mn, require 1h minimal");
        return;
    }
    @unlink($TimeFile);
    @file_put_contents($TimeFile, time());
    $sock = new sockets();
    $q = new mysql_squid_builder();
    $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `dashboard_volume_day` (\n\t\t\t`TIME` DATETIME,\n\t\t\t`FAMILYSITE` VARCHAR(128),\n\t\t\t`USERID` VARCHAR(64),\n\t\t\t`IPADDR` VARCHAR(64),\n\t\t\t`MAC` VARCHAR(64),\n\t\t\t`CATEGORY` VARCHAR(64),\n\t\t\t`CONTENT_TYPE` VARCHAR(64),\n\t\t\t`SIZE` BIGINT UNSIGNED,\n\t\t\t`RQS` BIGINT UNSIGNED,\n\t\t\tKEY `TIME` (`TIME`),\n\t\t\tKEY `FAMILYSITE` (`FAMILYSITE`),\n\t\t\tKEY `USERID` (`USERID`),\n\t\t\tKEY `IPADDR` (`IPADDR`),\n\t\t\tKEY `MAC` (`MAC`),\n\t\t\tKEY `CONTENT_TYPE` (`CONTENT_TYPE`)\n\t\t\n\t\t\t) ENGINE=MYISAM;");
    if (!$q->ok) {
        events("FATAL: {$q->mysql_error}");
    }
    $MySQLStatisticsRetentionDays = intval($sock->GET_INFO("MySQLStatisticsRetentionDays"));
    if ($MySQLStatisticsRetentionDays == 0) {
        $MySQLStatisticsRetentionDays = 5;
    }
    $influx = new influx();
    events("MySQL Statistics Retention Days:{$MySQLStatisticsRetentionDays}");
    $c = 0;
    $TRUNCATE = false;
    $prefix = "INSERT IGNORE INTO `dashboard_volume_day` (`TIME`,`FAMILYSITE`,`USERID`,`IPADDR`,`MAC`,`CATEGORY`,`SIZE`,`RQS`) VALUES ";
    for ($i = 0; $i < $MySQLStatisticsRetentionDays + 1; $i++) {
        $timeQuery = time();
        if ($i > 0) {
            $timeQuery = strtotime("-{$i} day");
        }
        $sql = "SELECT * FROM access_log WHERE time > '" . date("Y-m-d 00:00:00", $timeQuery) . "' AND time < '" . date("Y-m-d 23:59:59", $timeQuery) . "'";
        $main = $influx->QUERY_SQL($sql);
        if (!is_iterable($main)) {
            events("dashboard_volume_day:" . date("Y-m-d 00:00:00", $timeQuery) . " no data returned");
            continue;
        }
        $d = 0;
        foreach ($main as $row) {
            $CATEGORY = null;
            $time = date("Y-m-d H:00:00", $row->ZDATE);
            $FAMILYSITE = mysql_escape_string2($row->FAMILYSITE);
            $IPADDR = mysql_escape_string2($row->IPADDR);
            $USERID = mysql_escape_string2($row->USERID);
            $MAC = mysql_escape_string2($row->MAC);
            $RQS = mysql_escape_string2($row->RQS);
            $SIZE = mysql_escape_string2($row->SIZE);
            if (property_exists($row, "CATEGORY")) {
                $CATEGORY = mysql_escape_string2($row->CATEGORY);
            }
            $RSQL[] = "('{$time}','{$FAMILYSITE}','{$USERID}','{$IPADDR}','{$MAC}','{$CATEGORY}','{$SIZE}','{$RQS}')";
            $c++;
            $d++;
            if (count($RSQL) > 500) {
                if (!$TRUNCATE) {
                    events("dashboard_volume_day:TRUNCATE TABLE");
                    $q->QUERY_SQL("TRUNCATE TABLE `dashboard_volume_day`");
                    $TRUNCATE = TRUE;
                }
                $q->QUERY_SQL($prefix . @implode(",", $RSQL));
                if (!$q->ok) {
                    events("FATAL! {$q->mysql_error}");
                    return;
                }
                $RSQL = array();
            }
        }
        if (count($RSQL) > 0) {
            if (!$TRUNCATE) {
                events("dashboard_volume_day:TRUNCATE TABLE");
                $q->QUERY_SQL("TRUNCATE TABLE `dashboard_volume_day`");
                $TRUNCATE = TRUE;
            }
            $q->QUERY_SQL($prefix . @implode(",", $RSQL));
            if (!$q->ok) {
                events("FATAL! {$q->mysql_error}");
                return;
            }
            $RSQL = array();
        }
        events("dashboard_volume_day:" . date("Y-m-d 00:00:00", $timeQuery) . " {$d} inserted rows");
    }
    if (count($RSQL) > 0) {
        if (!$TRUNCATE) {
            events("dashboard_volume_day:TRUNCATE TABLE");
            $q->QUERY_SQL("TRUNCATE TABLE `dashboard_volume_day`");
            $TRUNCATE = TRUE;
        }
        $q->QUERY_SQL($prefix . @implode(",", $RSQL));
        if (!$q->ok) {
            events("FATAL! {$q->mysql_error}");
            return;
        }
        $RSQL = array();
    }
    events("dashboard_volume_day: Total {$c} inserted rows");
    FAMILY_SITES_DAY();
    FULL_USERS_DAY();
}
Example #15
0
 /**
  * @dataProvider provideIsIterable
  */
 public function testIsIterable($expected, $var)
 {
     $this->assertSame($expected, is_iterable($var));
 }
Example #16
0
function merge_fields($group_obj)
{
    $merge_items = array();
    if (!empty($group_obj)) {
        foreach ($group_obj as $group => $items) {
            if (!is_iterable($items)) {
                continue;
            }
            foreach ($items as $name => $value) {
                $merge_items[$name] = $value;
            }
        }
    }
    return $merge_items;
}
<?php

session_start();
require_once 'dbcontroller.php';
require_once 'controladorConsultas.php';
$dbcontroller = new DBController();
// Obtengo la informaciĆ³n del usuario
$cedula = $_SESSION['username'];
// Obtengo las publicaciones que puede ver el usuario
$result = $dbcontroller->runQuery("call Ver_Publicaciones('{$cedula}')");
?>
<!-- Empiezo la lista de publicaciones -->
<ul>
<?php 
if (is_iterable($result)) {
    foreach ($result as $publicacion) {
        # code...
        ?>

<li>
	<article>
		<center>
			<header id="titulo"> <h4> <?php 
        echo $publicacion['TITULO_PUBLICACION'];
        ?>
 </h4> </header> <br>
			<section id="emisor"> <?php 
        echo $publicacion['EMISOR'];
        ?>
 </section> <br>
			<section id="destinatario"> <?php