public function Take($count) { $result = new Collection(); $currentCount = 0; foreach ($this->m_items as $item) { $result->Add($item); $currentCount++; if ($currentCount == $count) { break; } } return $result; }
/** * RETORNA UMA COLEÇÂO COM OS PRODUTOS DO CARRINHO * @param $nomeIndiceArraySessao (É importante que esse parâmetro tenha a mesma ordem do da string) * @return Collection(); */ public function getCarrinho($nomeIndiceArraySessao) { $colecao = new Collection(); $arraySession = explode('#', substr($_SESSION[$this->nomeSessao], 0, -1)); $arrayItem = array(); if (count($arraySession) > 0) { foreach ($arraySession as $key => $value) { if ($value != '') { $arrayItem = explode('|', $value); foreach ($nomeIndiceArraySessao as $keySecundario => $value) { $item[$value] = $arrayItem[$keySecundario]; } $item['key'] = $key; $colecao->Add($item); } } } return $colecao; }
public function All($modelCollection) { $result = new Collection(); $tableName = $modelCollection->ModelCache['MetaData']['TableName']; $columns = array_keys($modelCollection->ModelCache['Columns']); $sqlStatement = "SELECT * FROM {$tableName}"; if (!($preparedStatement = $this->Database->prepare($sqlStatement))) { echo "Failed to prepare PDO statement"; var_dump($this->Database->errorInfo()); } $preparedStatement->execute(); $fields = array(); foreach ($columns as $column) { $name = $column; ${$name} = null; $fields[$name] =& ${$name}; } foreach ($preparedStatement as $row) { $item = new $modelCollection->ModelName($modelCollection); $item->FlagAsSaved(); foreach ($fields as $key => $value) { $item->{$key} = $row[$key]; } $result->Add($item); } return $result; }
public function All($modelCollection) { $result = new Collection(); $tableName = $modelCollection->ModelCache['MetaData']['TableName']; $columns = array_keys($modelCollection->ModelCache['Columns']); $sqlStatement = "SELECT * FROM {$tableName}"; if (!($preparedStatement = $this->Database->prepare($sqlStatement))) { echo $this->Database->error; } $preparedStatement->execute(); if (!($meta = $preparedStatement->result_metadata())) { return null; } $fields = array(); foreach ($columns as $column) { $name = $column; ${$name} = null; $fields[$name] =& ${$name}; } call_user_func_array(array($preparedStatement, 'bind_result'), $fields); while ($preparedStatement->fetch()) { $item = new $modelCollection->ModelName($modelCollection); $item->FlagAsSaved(); foreach ($fields as $key => $value) { $item->{$key} = $value; } $result->Add($item); } $preparedStatement->close(); return $result; }
/** * * Execulta uma consulta sql e retorna uma coleção * @param String $sql * @param Array $optionsField * @param Boolean $debug * @return Collection() */ public static function getCollection($sql, $optionsField = '', $debug = false) { try { self::$rs = self::getExecute($sql)->fetchAll(PDO::FETCH_ASSOC); $colecao = new Collection(); foreach (self::$rs as $row) { $obj = array(); foreach ($row as $key => $value) { /** * VERIFICA SE EXISTE OPÇÕES PARA O CAMPO */ if (!empty($optionsField) && !empty($value)) { if (array_key_exists($key, $optionsField) && !empty($value)) { $fieldValue = self::getFormatField($key, $optionsField, $value); } else { $fieldValue = $value; } $obj[$key] = $fieldValue; } else { $obj[$key] = $value; } } if (!empty($debug)) { self::getDebugArray($obj, $debug); } $colecao->Add($obj); } unset($optionsField); unset($key); unset($value); unset($sql); unset($obj); return $colecao; } catch (Exception $e) { self::getMsgErro($sql); } }
/** * @return void * @param Season $o_season * @param bool $b_is_working * @desc Adds a season to the end of the competition */ public function AddSeason(Season $o_season, $b_is_working = false) { $o_season->SetCompetition($this); $i_index = parent::Add($o_season); if ($b_is_working or $this->i_working_index == -1) { $this->SetWorkingIndex($i_index); } }
$Url['Onglet'] = 'FilmsParAnnee'; } else { $Url['Onglet'] = $_REQUEST['Onglet']; } // ===================================================================================================================================================== // Préparation des données à fournir à la vue : Le tableau $Vue // ===================================================================================================================================================== $nbFilm = Bd::GetNbfilms(); $nbGenre = Bd::GetNbGenres(); $nbFilmAnnee = Bd::GetNbFilmsParAnnee(); $nbFilmGenre = Bd::GetNbFilmsParGenre(); $lesStatsAnnee = new Collection(); $lesStatsGenre = new Collection(); foreach ($nbFilmAnnee as $tuple) { $Stat = new Statistique($tuple['Annee'], $tuple['NbFilm']); $lesStatsAnnee->Add($Stat); } foreach ($nbFilmGenre as $tuple) { $Stat = new Statistique($tuple['LibelleGenre'], $tuple['NbFilm']); $lesStatsGenre->Add($Stat); } $Vue['NbFilms'] = $nbFilm; $Vue['NbGenre'] = $nbGenre; $Vue['Onglet'] = $Url['Onglet']; $Vue['StatsAnnee'] = $lesStatsAnnee; $Vue['StatsGenre'] = $lesStatsGenre; $Infos['Page']['ContenuAvecEncarts'] = VueFilm::GetXhtmlStatistiques($Vue); // ===================================================================================================================================================== // Création d'une page en lui passant en paramètre le tableau $Infos. Si ce n'est pas fait, une page "standard" sera créée par défaut dans le contrôleur principal // ===================================================================================================================================================== $Page = new PageAvecEncartsGaucheDroite($Infos);