Example #1
0
 /**
  * Returns the topics table as a presentation model (array of arrays containing
  * information about each topic, suitable for use by a view) by mirroring
  * the domain model into a presentation model.  The presentation model can be modified
  * to support the needs of a view, without mangling the raw, real underlying table data.
  * STAGE 4: Apply business logic to create a presentation model for the view.
  * @return array of ArrayObjects (containing topic info) indexed by topic id
  */
 public static function getPresentationModel()
 {
     if (self::$_presentationModel === null) {
         foreach (self::getDomainModel() as $row) {
             $row = new ArrayObject($row->toArray(), ArrayObject::ARRAY_AS_PROPS);
             $row->user = ZFDemoModel_Users::getById($row->user_id);
             self::$_presentationModel[$row->topic_id] = $row;
             /////////////////////////////
             // ==> SECTION: l10n <==
             // create a Locale object for the owner of this post (not the user of this request)
             $postLocale = new Zend_Locale($row->user->locale);
             $row->country = ZFModule_Forum::getCountry($postLocale->getRegion());
             $userLocale = ZFModule_Forum::getUserLocale();
             // locale of the user of this request
             $userLocale = Zend_Registry::get('userLocale');
             $offset = ZFModule_Forum::getTimeOffset();
             if ($row->modification_time != $row->creation_time) {
                 $row->modification_time = new Zend_Date($row->modification_time, $userLocale);
                 $row->modification_time->addTimestamp($offset);
                 // express date/time in user's local timezone
             } else {
                 $row->modification_time = '';
             }
             $row->creation_time = new Zend_Date($row->creation_time, $userLocale);
             $row->creation_time->addTimestamp($offset);
             // express date/time in user's local timezone
         }
     }
     return self::$_presentationModel;
 }
Example #2
0
 public function getIterator()
 {
     if ($this->cacheIsFilled !== TRUE) {
         $this->fillCache();
     }
     return $this->instanceCache->getIterator();
 }
 /**
  * Parse stream and return array object of parsed payments
  *
  * @param string $stream Stream of data to parse to payments
  * @return \ArrayObject
  * @throws \Exception when format is unrecognized
  */
 public function parseData($stream)
 {
     $amountPadding = 6;
     $paymentNoPadding = 2;
     $descriptionPadding = 9;
     $payerNamePadding = 7;
     $result = new \ArrayObject();
     $rows = explode(PHP_EOL, $stream);
     $trimmedRows = $rows;
     for ($i = 0; $i < count($trimmedRows); $i++) {
         if ($trimmedRows[$i] == '#7') {
             $amount = (int) substr($trimmedRows[$i + $amountPadding], 0, 11) . ',' . substr($trimmedRows[$i + $amountPadding], 11, 2);
             $paymentNo = trim($trimmedRows[$i + $paymentNoPadding]);
             $description = trim($trimmedRows[$i + $descriptionPadding]);
             $payerName = trim($trimmedRows[$i + $payerNamePadding]);
             $referenceNo = "";
             //TODO: in what location is reference no?
             //multiple invoices paid
             if ($matches = $this->_getMatches($description)) {
                 foreach ($matches as $match) {
                     $result->append(new Payment($amount, $paymentNo, $match, $payerName, $referenceNo));
                 }
             }
             //skip the entry
             $i = $i + $trimmedRows[$i + 1];
         }
     }
     return $result;
 }
Example #4
0
 /**
  * シーケンス内の指定されたインデックス位置にある要素を返します。
  *
  * @param \ArrayObject $source 返される要素が含まれるシーケンス
  * @param int $index 取得する要素の 0 から始まるインデックス
  *
  * @return mixed シーケンス内の指定された位置にある要素
  */
 public function elementAtOf(\ArrayObject $source, int $index)
 {
     if ($index < 0 || $index >= $source->count()) {
         throw new \OutOfRangeException();
     }
     return $source->offsetGet($index);
 }
Example #5
0
 /**
  * Tests getting key of a needle from a list
  * @covers \Copycat\Structure\ArrayObject::search()
  */
 public function testSearch()
 {
     $arrayObject = new ArrayObject(array(1, 'foo', 'bar' => 'baz'));
     $this->assertEquals(1, $arrayObject->search('foo'));
     $this->assertEquals('bar', $arrayObject->search('baz'));
     $this->assertFalse($arrayObject->search('bar'));
 }
 /**
  * @param \ArrayObject $collection
  */
 function it_records_array_access($collection)
 {
     $collection->offsetGet(1)->willReturn('one')->shouldBeCalled();
     $this[1]->shouldBePlayedAs($collection, 'one');
     // It's still immutable.
     $this->shouldBeEmpty();
 }
Example #7
0
 private function sentenceWrapper(SentenceUtil $sentence)
 {
     $it = $sentence->getBuildCommand()->getIterator();
     $attr = null;
     $main = new \ArrayObject();
     $append = new \ArrayObject();
     while ($it->valid()) {
         if (Util::contains($it->current()->getClause(), "commandPrint") || Util::contains($it->current()->getClause(), "commandReguler")) {
             if ($attr == null) {
                 $main->append($it->current());
             }
         } else {
             //if contains neither then add to append commands
             $append->append($it->current());
         }
         $it->next();
     }
     foreach ($append->getIterator() as $a) {
         $main->append($a);
     }
     /*
     
             $it->rewind();
     
             while ($it->valid()) {
                 if (!Util::contains($it->current()->getClause(), "commandPrint") &&
                     !Util::contains($it->current()->getClause(), "commandReguler")) {
                 }
                 $it->next();
             }
     */
     return $main;
 }
Example #8
0
 /**
  * Get parsed payments
  *
  * @return \ArrayObject Payments array
  */
 public function getPayments()
 {
     if ($this->_payments->count() == 0) {
         $this->_logger->info("No payments found, did you invoke Parser::parse() before this call?");
     }
     return $this->_payments;
 }
Example #9
0
 public function tokenize(string $string)
 {
     $beforeEncoding = mb_internal_encoding();
     mb_internal_encoding($string->getCharset());
     $tokens = new \ArrayObject();
     $currentSystem = null;
     $currentToken = '';
     $length = $string->length();
     for ($i = 0; $i <= $length; $i++) {
         $character = $string->substract($i, 1);
         if (in_array($character, $this->hiragana)) {
             $system = self::HIRAGANA;
         } elseif (in_array($character, $this->katakana)) {
             $system = self::KATAKANA;
         } else {
             $system = self::KANJI;
         }
         // First string did not have a starting system
         if ($currentSystem == null) {
             $currentSystem = $system;
         }
         // if the system still is the same, no boundary has been reached
         if ($currentSystem == $system) {
             $currentToken .= $character;
         } else {
             // Write ended token to tokens and start a new one
             $tokens->append($currentToken);
             $currentToken = $character;
             $currentSystem = $system;
         }
     }
     mb_internal_encoding($beforeEncoding);
     return $tokens;
 }
 /**
  * Using specified comparison logic, compare invoices with payments and return the payments that match the invoices
  *
  * @param \ArrayObject $invoices Invoices to compare against
  * @param \ArrayObject $payments Payments to compare with
  *
  * @return \ArrayObject Mapped payments that represented an Invoice
  * @throws \Exception When comparison fails due to incompatible data types etc.
  */
 public function compare(\ArrayObject $invoices, \ArrayObject $payments)
 {
     $results = new \ArrayObject();
     foreach ($payments as $payment) {
         if ($payment instanceof Payment) {
             foreach ($invoices as $invoice) {
                 if ($invoice instanceof Invoice) {
                     $invoiceNoMatch = false;
                     if ($invoice->getInvoiceNo() != '') {
                         $invoiceNoMatch = strpos(strtoupper($payment->getDescription()), strtoupper($invoice->getInvoiceNo())) !== false;
                     }
                     $orderNoMatch = false;
                     if ($invoice->getOrderNo() != '') {
                         $orderNoMatch = strpos(strtoupper($payment->getDescription()), strtoupper($invoice->getOrderNo())) !== false;
                     }
                     if (strtoupper($payment->getReferenceNo()) == strtoupper($invoice->getReferenceNo()) && $payment->getReferenceNo() != '' || ($orderNoMatch || $invoiceNoMatch)) {
                         $payment->setRelatedInvoice($invoice);
                         $results->append($payment);
                     }
                 } else {
                     throw new \Exception("Invoice not implementing correct interface!");
                 }
             }
         } else {
             throw new \Exception("Payment data type is incorrect!");
         }
     }
     return $results;
 }
 /**
  * @return array
  */
 public function getArray()
 {
     if ($this->isArrayObject()) {
         return $this->data->getArray();
     }
     return $this->data;
 }
Example #12
0
 public function render()
 {
     $retObj = new \ArrayObject($this->definition);
     $ret = $retObj->getArrayCopy();
     $ret['data'] = $this->formatData();
     return $ret;
 }
Example #13
0
 public function searchRegistrationByTeamId($teamId)
 {
     // the SQL query to be executed on the database
     $query = "SELECT REGISTRATION_ID, CONVERT(VARCHAR(10),REGISTRATION_ACTIVITY_DATE, 101) AS REGISTRATION_ACTIVITY_DATE,\r\n                            TOURNAMENT_ID, TOURNAMENT_NAME, CONVERT(VARCHAR(10), TOURNAMENT_DATE, 101) AS TOURNAMENT_DATE, \r\n                             Right(IsNull(Convert(Varchar,TOURNAMENT_BEGIN_TIME,100),''),7) AS TOURNAMENT_BEGIN_TIME, \r\n                             Right(IsNull(Convert(Varchar,TOURNAMENT_END_TIME,100),''),7) AS TOURNAMENT_END_TIME, \r\n                             TOURNAMENT_STREET, \r\n                             TOURNAMENT_CITY, \r\n                             TOURNAMENT_STATE_CODE,  \r\n                             TOURNAMENT_ZIP,\r\n                             TEAM_ID, TEAM_NAME,\r\n                             SPORT_TYPE_ID, SPORT_TYPE_NAME\r\n                        FROM dbo.REGISTRATION reg JOIN dbo.TEAM t on (reg.REGISTRATION_TEAM_ID = t.TEAM_ID) \r\n                        JOIN dbo.TOURNAMENT tour on(reg.REGISTRATION_TEAM_TOURNAMENT_ID = tour.TOURNAMENT_ID)\r\n                        join dbo.SPORT_TYPE sp ON (sp.SPORT_TYPE_ID = tour.TOURNAMENT_SPORT_TYPE_ID) WHERE t.TEAM_ID =" . $teamId;
     $results = executeQuery($query);
     $regList = new ArrayObject();
     foreach ($results as $result) {
         $regVO = new RegistrationVO();
         $regVO->set_registrationId($result['REGISTRATION_ID']);
         $regVO->set_activityDate($result['REGISTRATION_ACTIVITY_DATE']);
         $tournament = new Tournament();
         $tournament->set_tournamentName($result['TOURNAMENT_NAME']);
         $tournament->set_tournamentDate($result['TOURNAMENT_DATE']);
         $tournament->set_tournamentBeginTime($result['TOURNAMENT_BEGIN_TIME']);
         $tournament->set_tournamentEndTime($result['TOURNAMENT_END_TIME']);
         $tournament->set_sportTypeId($result['SPORT_TYPE_ID']);
         $tournament->set_sportTypeName($result['SPORT_TYPE_NAME']);
         $tournament->set_tournamentStreet($result['TOURNAMENT_STREET']);
         $tournament->set_tourcenameCity($result['TOURNAMENT_CITY']);
         $tournament->set_tournamentState($result['TOURNAMENT_STATE_CODE']);
         $tournament->set_tournamentZip($result['TOURNAMENT_ZIP']);
         $team = new TeamVO();
         $team->set_teamId($result['TEAM_ID']);
         $team->set_teamName($result['TEAM_NAME']);
         $regVO->set_tournament($tournament);
         $regVO->set_team($team);
         $regList->append($regVO);
     }
     return $regList;
 }
Example #14
0
 /**
  * array object değeri add edilir
  * 
  * @param \ArrayObject $ArrayObject
  * @param string $key
  * @param string $name
  * @return void
  */
 public function add(\ArrayObject $ArrayObject, $key = null, $name = null)
 {
     $iterator = $ArrayObject->getIterator();
     $this->num_rows = $iterator->count();
     if ($key == null && $name == null) {
         while ($iterator->valid()) {
             $arr = $iterator->current();
             $this->dataArr[] = ['id' => $arr, 'name' => $arr];
             $iterator->next();
             $this->error = false;
         }
     } else {
         $sonaEklenecek = array();
         while ($iterator->valid()) {
             $arr = $iterator->current();
             if ($this->getEnSonaEklenecekDeger() == null) {
                 $this->dataArr[] = ['id' => $arr[$key], 'name' => trim($arr[$name])];
             } else {
                 $value = trim($arr[$name]);
                 if ($this->getEnSonaEklenecekDeger() == $value) {
                     $sonaEklenecek = ['id' => $arr[$key], 'name' => $value];
                 } else {
                     $this->dataArr[] = ['id' => $arr[$key], 'name' => $value];
                 }
             }
             $iterator->next();
             $this->error = false;
         }
         if (count($sonaEklenecek) != 0) {
             $this->dataArr[] = $sonaEklenecek;
         }
     }
 }
 public function render(FrontendController $frontendController, CmsView $view)
 {
     if (!$this->settingsFound) {
         return $this->renderEditable($frontendController, '<p>no settings found</p>');
     }
     $columnsArr = new \ArrayObject();
     for ($i = 1; $i <= $this->settings->cols; ++$i) {
         $colMods = new \ArrayObject();
         if (isset($this->settings->columns[$i]) === true) {
             foreach ($this->settings->columns[$i] as $mod) {
                 if (isset($this->elements[$mod]) === false) {
                     continue;
                 }
                 /** @var CmsElement $modInstance */
                 $modInstance = $this->elements[$mod];
                 $colMods->append($modInstance->render($frontendController, $view));
             }
         }
         $columnsArr->offsetSet($i, $colMods);
     }
     $this->tplVars->offsetSet('columns', $columnsArr);
     $this->tplVars->offsetSet('column_count', $this->settings->cols);
     $this->tplVars->offsetSet('logged_in', $frontendController->getAuth()->isLoggedIn());
     $html = $view->render($this->identifier . '.html', (array) $this->tplVars);
     return $this->renderEditable($frontendController, $html);
 }
 /**
  * Do translation and workspace overlay
  *
  * @param \ArrayObject $data
  * @return void
  */
 public function languageAndWorkspaceOverlay(\ArrayObject $data)
 {
     $overlayedMetaData = $this->getTsfe()->sys_page->getRecordOverlay('sys_file_metadata', $data->getArrayCopy(), $this->getTsfe()->sys_language_content, $this->getTsfe()->sys_language_contentOL);
     if ($overlayedMetaData !== NULL) {
         $data->exchangeArray($overlayedMetaData);
     }
 }
Example #17
0
File: Event.php Project: visor/nano
 /**
  * @return mixed
  * @param string $name
  * @param mixed $defaultValue
  */
 public function getArgument($name, $defaultValue = null)
 {
     if ($this->arguments->offsetExists($name)) {
         return $this->arguments->offsetGet($name);
     }
     return $defaultValue;
 }
 /**
  * do the magic!
  *
  * @param tx_rnbase_parameters $parameters
  * @param tx_rnbase_configurations $configurations
  * @param ArrayObject $viewData
  *
  * @return string error msg or null
  */
 public function handleRequest(&$parameters, &$configurations, &$viewData)
 {
     $items = $this->getItems();
     $viewData->offsetSet('items', is_array($items) ? array_values($items) : array());
     $viewData->offsetSet('searched', $items !== FALSE);
     return;
 }
Example #19
0
 private function getListAsAnArrayObject($list)
 {
     if ($list instanceof ArrayIterator) {
         $list = new ArrayObject($list->getArrayCopy());
     }
     return $list;
 }
Example #20
0
 public function getSettingsHtml()
 {
     $pluginSettings = craft()->plugins->getPlugin('placid')->getSettings();
     // Get placid requests and send them to the widget settings
     $requests = craft()->placid_requests->findAllRequests();
     $requestsArray = array('' => 'No request selected');
     foreach ($requests as $request) {
         $requestsArray[$request->handle] = $request->name;
     }
     $templatesPath = craft()->path->getSiteTemplatesPath() . $pluginSettings->widgetTemplatesPath;
     $templates = IOHelper::getFolderContents($templatesPath, TRUE);
     $templatesArray = array('' => Craft::t('No template selected'));
     if (!$templates) {
         $templatesArray = array('' => 'Cannot find templates');
         Craft::log('Cannot find templates in path "' . $templatesPath . '"', LogLevel::Error);
     } else {
         // Turn array into ArrayObject
         $templates = new \ArrayObject($templates);
         // Iterate over template list
         // * Remove full path
         // * Remove folders from list
         for ($list = $templates->getIterator(); $list->valid(); $list->next()) {
             $filename = $list->current();
             $filename = str_replace($templatesPath, '', $filename);
             $filenameIncludingSubfolder = $filename;
             $isTemplate = preg_match("/(.html|.twig)\$/u", $filename);
             if ($isTemplate) {
                 $templatesArray[$filenameIncludingSubfolder] = $filename;
             }
         }
     }
     return craft()->templates->render('placid/_widgets/request/settings', array('requests' => $requestsArray, 'templates' => $templatesArray, 'settings' => $this->getSettings()));
 }
Example #21
0
 /**
  * @param string $csv the file pathname
  * @param bool $object if true, returns array object, otherwise a plain array
  * @return ArrayObject
  * @throws Exception
  */
 public static function toArray($csv, $object = true)
 {
     if ($object == false) {
         $array = array();
     } else {
         $array = new ArrayObject();
     }
     if (!file_exists($csv)) {
         throw new Exception('CSV File not found', 404);
     }
     $file = new SplFileObject($csv);
     $file->setFlags(SplFileObject::READ_CSV);
     foreach ($file as $data) {
         $count = count($data);
         if ($object == false) {
             $item = array();
         } else {
             $item = new ArrayObject();
         }
         for ($x = 0; $x < $count; $x++) {
             if ($item instanceof ArrayObject) {
                 $item->append($data[$x]);
             } else {
                 array_push($item, $data[$x]);
             }
         }
         if ($array instanceof ArrayObject) {
             $array->append($item);
         } else {
             array_push($array, $item);
         }
     }
     return $array;
 }
 public function getInputHtml($name, $value)
 {
     // Get site templates path
     $templatesPath = $siteTemplatesPath = craft()->path->getSiteTemplatesPath();
     // Check if the templates path is overriden by configuration
     // TODO: Normalize path
     $limitToSubfolder = craft()->config->get('templateselectSubfolder');
     if ($limitToSubfolder) {
         $templatesPath = $templatesPath . rtrim($limitToSubfolder, '/') . '/';
     }
     // Check if folder exists, or give error
     if (!IOHelper::folderExists($templatesPath)) {
         throw new \InvalidArgumentException('(Template Select) Folder doesn\'t exist: ' . $templatesPath);
     }
     // Get folder contents
     $templates = IOHelper::getFolderContents($templatesPath, TRUE);
     // Add placeholder for when there is no template selected
     $filteredTemplates = array('' => Craft::t('No template selected'));
     // Turn array into ArrayObject
     $templates = new \ArrayObject($templates);
     // Iterate over template list
     // * Remove full path
     // * Remove folders from list
     for ($list = $templates->getIterator(); $list->valid(); $list->next()) {
         $filename = $list->current();
         $filename = str_replace($templatesPath, '', $filename);
         $filenameIncludingSubfolder = $limitToSubfolder ? $limitToSubfolder . $filename : $filename;
         $isTemplate = preg_match("/(.html|.twig)\$/u", $filename);
         if ($isTemplate) {
             $filteredTemplates[$filenameIncludingSubfolder] = $filename;
         }
     }
     // Render field
     return craft()->templates->render('_includes/forms/select', array('name' => $name, 'value' => $value, 'options' => $filteredTemplates));
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Set filters & get data
     $type = $input->getArgument(self::TYPE_ARGUMENT);
     if ($type) {
         $this->productlist->setType($type);
     }
     $active = $input->getOption(self::ACTIVE_OPTION);
     if ($active) {
         $this->productlist->setStatus(1);
     }
     $products = $this->productlist->getProducts();
     // If only count, return it
     if ($input->getOption(self::COUNT_OPTION)) {
         return $output->writeln(sprintf('Count: %d', $products->getTotalCount()));
     }
     // Else prepare data for showing
     $types = $this->productlist->getProductTypesAssoc();
     $rows = new \ArrayObject();
     foreach ($products->getItems() as $id => $product) {
         $rows->append([$product->getId(), $product->getSku(), $product->getName(), $types[$product->getTypeId()]]);
     }
     // Output table layout
     $table = new Table($output);
     $table->setHeaders(['ID', 'SKU', 'Name', 'Type']);
     $table->setRows($rows->getArrayCopy());
     $table->render();
 }
Example #24
0
 function it_proxies_method_calls_to_wrapped_object(\ArrayObject $obj, WrappedObject $wrappedObject)
 {
     $obj->asort()->shouldBeCalled();
     $wrappedObject->isInstantiated()->willReturn(true);
     $wrappedObject->getInstance()->willReturn($obj);
     $this->call('asort');
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new SymfonyStyle($input, $output);
     $io->title('Exporting databases');
     $io->section('Exporting all databases');
     $strategies = $this->collectorDbStrategy->collectDatabasesStrategies();
     $totalStrategies = count($strategies);
     $io->writeln($totalStrategies . ' strategie(s) found.');
     $progressBar = new ProgressBar($output, $totalStrategies);
     $progressBar->setFormat(self::PROGRESS_BAR_FORMAT);
     $progressBar->setMessage('Beginning backuping');
     $this->eventDispatcher->dispatch(Events::BACKUP_BEGINS, new BackupBeginsEvent($output));
     $progressBar->start();
     $reportContent = new \ArrayObject();
     foreach ($strategies as $strategy) {
         $strategyIdentifier = $strategy->getIdentifier();
         $setProgressBarMessage = function ($message) use($progressBar, $strategyIdentifier) {
             $message = "[{$strategyIdentifier}] {$message}";
             $progressBar->setMessage($message);
             $progressBar->display();
         };
         $exportedFiles = $this->processorDatabaseDumper->dump($strategy, $setProgressBarMessage);
         $reportContent->append("Backuping of the database: {$strategyIdentifier}");
         foreach ($exportedFiles as $file) {
             $filename = $file->getPath();
             $reportContent->append("\t→ {$filename}");
         }
         $progressBar->advance();
     }
     $progressBar->finish();
     $io->newLine(2);
     $io->section('Report');
     $io->text($reportContent->getArrayCopy());
     $this->eventDispatcher->dispatch(Events::BACKUP_ENDS, new BackupEndsEvent($output));
 }
Example #26
0
 /**
  * Returns required option value
  *
  * @param string $optionName
  * @return mixed
  */
 public function getOption($optionName)
 {
     if ($this->_options instanceof ArrayObject && $this->_options->offsetExists($optionName)) {
         return $this->_options->offsetGet($optionName);
     }
     return NULL;
 }
Example #27
0
 /**
  * Bootstraps the application.
  *
  * This method is called after all services are registered
  * and should be used for "dynamic" configuration (whenever
  * a service must be requested).
  */
 public function boot(Application $app)
 {
     $src = $app->offsetExists('commands.path') ? $app['commands.path'] : $app['path.src'];
     $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($src));
     $commands = new \ArrayObject();
     /** @var RecursiveDirectoryIterator $dir */
     for ($dir->rewind(); $dir->valid(); $dir->next()) {
         if ($dir->isDot()) {
             continue;
         }
         if ('php' !== $dir->getExtension()) {
             continue;
         }
         $name = $dir->getSubPathname();
         $name = substr($name, 0, -4);
         $className = str_replace(DIRECTORY_SEPARATOR, '\\', $name);
         $r = new ReflectionClass($className);
         if ($r->isAbstract() || false === $r->isSubclassOf("Symfony\\Component\\Console\\Command\\Command")) {
             continue;
         }
         $commands->append(new $className());
     }
     /** @noinspection PhpParamsInspection */
     $app['console'] = $app->share($app->extend('console', function (Console $console) use($commands) {
         foreach ($commands as $command) {
             $console->add($command);
         }
         return $console;
     }));
 }
Example #28
0
 private function parseRawToList($raw)
 {
     $raw = trim($raw);
     if (!empty($raw)) {
         $list = new \ArrayObject();
         $token = explode(PHP_EOL, $raw);
         $a = 1;
         while ($a < count($token)) {
             next($token);
             $attr = new Attribute();
             if (!(current($token) == "!re") && !(current($token) == "!trap")) {
                 $split = explode("=", current($token));
                 $attr->setName($split[1]);
                 if (count($split) == 3) {
                     $attr->setValue($split[2]);
                 } else {
                     $attr->setValue(NULL);
                 }
                 $list->append($attr);
             }
             $a++;
         }
         if ($list->count() != 0) {
             $this->result->add($list);
         }
     }
 }
Example #29
0
 /**
  * Valida o código de barras.
  * @param mixed $value
  * @return boolean
  */
 public function validate($input)
 {
     $input = new StringHelper($input);
     $digitoCean = 0;
     $indiceInicial = 0;
     $digitoCalculo = 0;
     $digitoCalculado = 0;
     $tamCean = $input->length;
     $ceanSemDigito = new StringHelper();
     if (!in_array($tamCean, array(8, 12, 13, 14, 18))) {
         return false;
     }
     $digitoCean = (int) $input->right(1, 1)->getValue();
     $ceanSemDigito->setValue($input->left(0, $input->length - 1)->getValue());
     $indiceInicial = $this->p->count() - $ceanSemDigito->length;
     for ($i = 0; $i < $ceanSemDigito->length; $i++) {
         $digitoCalculo += (int) $ceanSemDigito->substring($i, 1)->getValue() * $this->p->offsetGet($indiceInicial++);
     }
     if ($digitoCalculo % 10 == 0) {
         $digitoCalculado = 0;
     } else {
         $divTemp = (int) ceil($digitoCalculo / 10.0) * 10;
         $digitoCalculado = $divTemp - $digitoCalculo;
     }
     if ($digitoCalculado === $digitoCean) {
         return true;
     }
     return false;
 }
Example #30
0
 /**
  * @param $qid
  * @return SurveyAnswer[]
  */
 public function getAnswers($qid)
 {
     if (array_key_exists($qid, $this->map)) {
         $o = new \ArrayObject($this->map[$qid]);
         return $o->getArrayCopy();
     }
     return null;
 }