phynx is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. phynx is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . 2007 - 2012, Rainer Furtmeier - Rainer@Furtmeier.de
Пример #1
0
 public static function getStream(User $user)
 {
     $sql = "SELECT id\n\t\t\t\tFROM activities\n\t\t\t\tWHERE user_id = ?\n\t\t\t\tORDER BY id DESC\n\t\t\t";
     $stream = new Collection($sql, array($user->id));
     $stream->bindType('id', 'Activity');
     return $stream;
 }
Пример #2
0
 public function getChildren()
 {
     $sql = "SELECT id\n\t\t    \tFROM s3_files\n\t\t    \tWHERE parent_id = ?\n\t\t    \tORDER BY id DESC";
     $children = new Collection($sql, array($this->id));
     $children->bindType('id', get_class($this));
     return $children;
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function removeActivityPrototype(ActivityPrototypeInterface $activityPrototype)
 {
     if ($this->hasActivityPrototype($activityPrototype)) {
         $this->activityPrototypes->removeElement($activityPrototype);
     }
     return $this;
 }
 public function hookInstall()
 {
     //set up my Collectors table
     $db = get_db();
     $sql = "\n        CREATE TABLE IF NOT EXISTS `{$db->Collector}` (\n          `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n          `collection_id` int(10) unsigned NOT NULL,\n          `name` TEXT NOT NULL,\n          `bio` TEXT NOT NULL,\n          `public` tinyint(1) default '0',\n          PRIMARY KEY (`id`)\n        ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
     $db->query($sql);
     //set up some fake data to work with
     //this is the kind of work that is usually done in a Controller when processing a form
     $collection = new Collection();
     $collection->name = "Fake Collection";
     $collection->owner_id = 1;
     $collection->save();
     $collector = new Collector();
     $collector->name = "Mr. Fake Collector";
     $collector->collection_id = $collection->id;
     $collector->bio = "I collected stuff for the Fake Collection";
     $collector->public = 1;
     $collector->save();
     $collector = new Collector();
     $collector->name = "Mysterious Ghost Collector";
     $collector->collection_id = $collection->id;
     $collector->bio = "I collected stuff for the Fake Collection, but in secret so I don't want the public to know";
     $collector->public = 0;
     $collector->save();
     $collection = new Collection();
     $collection->name = "Pseudo Collection";
     $collection->owner_id = 1;
     $collection->save();
     $collector = new Collector();
     $collector->name = "Mrs. Pseudo Collector";
     $collector->collection_id = $collection->id;
     $collector->bio = "I collected stuff for the Pseudo Collection";
     $collector->public = 1;
     $collector->save();
 }
Пример #5
0
 public function write(Collection $items)
 {
     $path = $this->_getPath();
     $this->items = $items;
     //if (defined('JSON_PRETTY_PRINT')) { //PHP >= 5.4
     //	$json = json_encode($items->convertToArray(), JSON_PRETTY_PRINT); //JSON_PRETTY_PRINT: for debugging issues
     //} else {
     $json = json_encode($items->convertToArray());
     //}
     if ($json === false) {
         throw new \RuntimeException('Cannot encode data to JSON');
     }
     $parentPath = dirname($path);
     if (!is_dir($parentPath)) {
         mkdir($parentPath, 0777, true);
         chmod($parentPath, 0777);
     }
     $alreadyExists = file_exists($path);
     $result = file_put_contents($path, $json);
     if ($result === false) {
         throw new \RuntimeException('Cannot open data file "' . $this->index . '" ("' . $path . '" : error while writing)');
     }
     if (!$alreadyExists) {
         chmod($path, 0777);
     }
 }
Пример #6
0
 public static function seleccComments($tittle)
 {
     $c = new Collection();
     $conn = conexion();
     if ($conn->connect_error) {
         die("Connection failed: " . $conn->connect_error);
     } else {
         $sentencia = $conn->stmt_init();
         if (!$sentencia->prepare("select * from comentarios where (blog_id=?)")) {
             echo "Falló la preparación: (" . $conn->errno . ") " . $conn->error;
         } else {
             mysqli_stmt_bind_param($sentencia, "i", $tittle);
             if (!$sentencia->execute()) {
                 return "0";
             } else {
                 $sentencia->bind_result($Id, $Titulo, $Autor, $Texto, $Blog_id, $Fecha);
                 while ($sentencia->fetch()) {
                     $comment = new Comment(array("autor" => $Autor, "fecha" => $Fecha, "titulo" => $Titulo, "texto" => $Texto, "id" => $Id, "blog_id" => $Blog_id));
                     $c->addItem($comment);
                 }
                 $conn->close();
                 return $c;
             }
         }
     }
 }
Пример #7
0
 /**
  * This method is called in case a primary key was defined using the addPrimaryKey() method.
  * It currently does something only if using SQLite.
  * If a column is an auto-increment key in SQLite, it has to be a primary key and it has to defined
  * when defining the column. Phinx takes care of that so we have to make sure columns defined as autoincrement were
  * not added with the addPrimaryKey method, otherwise, SQL queries will be wrong.
  *
  * @return void
  */
 protected function filterPrimaryKey()
 {
     if ($this->getAdapter()->getAdapterType() !== 'sqlite' || empty($this->options['primary_key'])) {
         return;
     }
     $primaryKey = $this->options['primary_key'];
     if (!is_array($primaryKey)) {
         $primaryKey = [$primaryKey];
     }
     $primaryKey = array_flip($primaryKey);
     $columnsCollection = new Collection($this->columns);
     $primaryKeyColumns = $columnsCollection->filter(function ($columnDef, $key) use($primaryKey) {
         return isset($primaryKey[$columnDef->getName()]);
     })->toArray();
     if (empty($primaryKeyColumns)) {
         return;
     }
     foreach ($primaryKeyColumns as $primaryKeyColumn) {
         if ($primaryKeyColumn->isIdentity()) {
             unset($primaryKey[$primaryKeyColumn->getName()]);
         }
     }
     $primaryKey = array_flip($primaryKey);
     if (!empty($primaryKey)) {
         $this->options['primary_key'] = $primaryKey;
     } else {
         unset($this->options['primary_key']);
     }
 }
    public function renderView()
    {
        $badges_feature = new Collection('badge', $this->context->language->id);
        $badges_feature->where('type', '=', 'feature');
        $badges_feature->orderBy('id_group');
        $badges_feature->orderBy('group_position');
        $badges_achievement = new Collection('badge', $this->context->language->id);
        $badges_achievement->where('type', '=', 'achievement');
        $badges_achievement->orderBy('id_group');
        $badges_achievement->orderBy('group_position');
        $badges_international = new Collection('badge', $this->context->language->id);
        $badges_international->where('type', '=', 'international');
        $badges_international->orderBy('id_group');
        $badges_international->orderBy('group_position');
        $groups = array();
        $query = new DbQuery();
        $query->select('DISTINCT(b.`id_group`), bl.group_name, b.type');
        $query->from('badge', 'b');
        $query->join('
			LEFT JOIN `' . _DB_PREFIX_ . 'badge_lang` bl ON bl.`id_badge` = b.`id_badge`');
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
        foreach ($result as $res) {
            $groups['badges_' . $res['type']][$res['id_group']] = $res['group_name'];
        }
        $badges_type = array('badges_feature' => array('name' => $this->l('Features'), 'badges' => $badges_feature), 'badges_achievement' => array('name' => $this->l('Achievements'), 'badges' => $badges_achievement), 'badges_international' => array('name' => $this->l('International'), 'badges' => $badges_international));
        $levels = array(1 => $this->l('1. Beginner'), 2 => $this->l('2. Pro'), 3 => $this->l('3. Expert'), 4 => $this->l('4. Wizard'), 5 => $this->l('5. Guru'), 6 => $this->l('6. Legend'));
        $this->tpl_view_vars = array('badges_type' => $badges_type, 'current_level_percent' => (int) Configuration::get('GF_CURRENT_LEVEL_PERCENT'), 'current_level' => (int) Configuration::get('GF_CURRENT_LEVEL'), 'groups' => $groups, 'levels' => $levels);
        return parent::renderView();
    }
Пример #9
0
 public static function combine($type, $files, $compress = false)
 {
     $root = panel::instance()->roots()->assets() . DS . $type;
     $cache = new Media($root . DS . 'panel.' . $type);
     $media = new Collection(array_map(function ($file) use($root) {
         return new Media($root . DS . str_replace('/', DS, $file));
     }, $files));
     // get the max modification date
     $modified = max($media->pluck('modified'));
     if (is_writable($root) and (!$cache->exists() or $cache->modified() < $modified)) {
         $cache->remove();
         $content = '';
         foreach ($media as $asset) {
             $content .= $asset->read() . PHP_EOL;
         }
         if ($compress) {
             $content = static::compress($content);
         }
         f::write($root . DS . 'panel.' . $type, $content);
     }
     if ($cache->exists()) {
         return $type(panel()->urls()->{$type}() . '/panel.' . $type . '?v=' . panel()->version());
     }
     return $type(array_map(function ($item) use($type) {
         return 'panel/assets/' . $type . '/' . $item;
     }, $files));
 }
Пример #10
0
 public static function getValidatedByIdTab($id_tab)
 {
     $advices = new Collection('advice', Context::getContext()->language->id);
     $advices->where('validated', '=', 1);
     $advices->where('id_tab', '=', (int) $id_tab);
     return $advices;
 }
 /**
  * Return a list of available configuration options.
  *
  * @param Collection $availableTypes Collection of Injector\InjectorInterface::TYPE_*
  *     constants indicating valid package types that could be injected.
  * @param string $projectRoot Path to the project root; assumes PWD by
  *     default.
  * @return Collection Collection of ConfigOption instances.
  */
 public function getAvailableConfigOptions(Collection $availableTypes, $projectRoot = '')
 {
     // Create an initial collection to which we'll append.
     // This approach is used to ensure indexes are sane.
     $discovered = new Collection([new ConfigOption('Do not inject', new Injector\NoopInjector())]);
     Collection::create($this->discovery)->map(function ($discoveryClass) use($projectRoot) {
         if (is_array($discoveryClass)) {
             return new ConfigDiscovery\DiscoveryChain($discoveryClass, $projectRoot);
         }
         return new $discoveryClass($projectRoot);
     })->filter(function ($discovery) {
         return $discovery->locate();
     })->map(function ($discovery, $file) use($projectRoot, $availableTypes) {
         // Look up the injector based on the file type
         $injectorClass = $this->injectors[$file];
         if (is_array($injectorClass)) {
             return new Injector\ConfigInjectorChain($injectorClass, $discovery, $availableTypes, $projectRoot);
         }
         return new $injectorClass($projectRoot);
     })->filter(function ($injector) use($availableTypes) {
         return $availableTypes->reduce(function ($flag, $type) use($injector) {
             return $flag || $injector->registersType($type);
         }, false);
     })->each(function ($injector, $file) use($discovered) {
         $discovered[] = new ConfigOption($file, $injector);
     });
     return 1 === $discovered->count() ? new Collection([]) : $discovered;
 }
Пример #12
0
 public function getActiveBots()
 {
     $sql = "SELECT id\n\t\t\t\tFROM bots\n\t\t\t\tWHERE oauth_token_id = ?\n\t\t\t\tAND status != 'retired'\n\t\t\t\tORDER BY name";
     $bots = new Collection($sql, array($this->id));
     $bots->bindType('id', 'Bot');
     return $bots;
 }
Пример #13
0
 public function addBeneficiary(BeneficiaryUser $beneficiary)
 {
     if (!$this->beneficiaries->contains($beneficiary)) {
         $this->beneficiaries->add($beneficiary);
     }
     return $this;
 }
Пример #14
0
 /**
  * Scrape URL and collect output
  * @param string $url
  * @param OutputInterface $output
  */
 public function scrape($url, OutputInterface $output)
 {
     $this->collection->exchangeArray([]);
     try {
         $initialPage = $this->client->get($url)->send();
     } catch (BadResponseException $e) {
         $output->writeln('<error>' . $e->getMessage() . '</error>');
         throw new \RuntimeException('Unable to load initial page');
     }
     $xml = $this->getSimpleXml($initialPage->getBody());
     $items = $xml->xpath($this->config['collection']);
     foreach ($items as $item) {
         $title = $item->xpath($this->config['title']);
         $unitPrice = $item->xpath($this->config['unitPrice']);
         $itemUrl = $item->xpath($this->config['itemUrl']);
         $itemSize = 0;
         $itemDesc = null;
         if (isset($itemUrl[0]->attributes()['href'])) {
             try {
                 $itemPage = $this->client->get((string) $itemUrl[0]->attributes()['href'])->send();
                 $itemPageBody = $this->getSimpleXml($itemPage->getBody());
                 $itemSize = $itemPage->getContentLength();
                 $itemDesc = $itemPageBody->xpath($this->config['desc']);
             } catch (BadResponseException $e) {
                 $output->writeln('<error>' . $e->getMessage() . '</error>');
             }
         }
         if ($title && $unitPrice) {
             $parsedPrice = (double) \trim(\str_replace('&pound', null, $unitPrice[0]));
             $this->collection->append(['title' => \trim($title[0]), 'unit_price' => $parsedPrice, 'description' => \trim($itemDesc[0]), 'size' => \round($itemSize / 1024) . 'kb']);
         }
     }
     return $this->collection;
 }
 public function getIncompleteProductLoads($user_id)
 {
     //get user and in progress product requests / ideas
     $user = $this->eloquent->with(['ideas' => function ($query) {
         $query->where('is_fulfilled', '=', 0);
     }])->with(['productRequests' => function ($query) {
         $query->whereNull('product_id');
     }])->find($user_id);
     if (empty($user)) {
         return [];
     }
     $user = $user->toArray();
     $product_requests = $user['product_requests'];
     $ideas = $user['ideas'];
     //compile inprogress items
     $inprogress_items = new \Collection();
     foreach ($product_requests as $product_request) {
         $inprogress_items->add(['type' => 'id load', 'human_time_diff' => \Carbon::createFromFormat('Y-m-d H:i:s', $product_request['created_at'])->diffForHumans(), 'created_at' => $product_request['created_at'], 'updated_at' => $product_request['updated_at'], 'id' => $product_request['id'], 'description' => $product_request['vendor'] . ' ' . $product_request['vendor_id'], 'query' => ['vendor' => $product_request['vendor'], 'vendor_id' => $product_request['vendor_id']]]);
     }
     foreach ($ideas as $idea) {
         $inprogress_items->add(['type' => 'idea load', 'human_time_diff' => \Carbon::createFromFormat('Y-m-d H:i:s', $idea['created_at'])->diffForHumans(), 'created_at' => $idea['created_at'], 'updated_at' => $idea['updated_at'], 'id' => $idea['id'], 'description' => $idea['description'], 'query' => ['idea_description' => $idea['description']]]);
     }
     $inprogress_items->sortBy('created_at');
     return $inprogress_items->toArray();
 }
Пример #16
0
 public function getSliceJobs()
 {
     $sql = "SELECT id\n        \t\tFROM slice_jobs\n        \t\tWHERE slice_config_id = ?\n        \t\tORDER BY id DESC";
     $sliceJobs = new Collection($sql, array($this->id));
     $sliceJobs->bindType('id', 'SliceJob');
     return $sliceJobs;
 }
Пример #17
0
 public static function buildCollection($filters, $order = null)
 {
     // filters must be field=>value
     $collection = new Collection();
     $sql = $params = array();
     foreach ($filters as $key => $filter) {
         if (!is_array($filter)) {
             $params[":{$key}"] = $filter;
             $sql[] = "`{$key}` = :{$key}";
         } else {
             $params[":{$key}"] = $filter['value'];
             $sql[] = "`{$key}` {$filter['operator']} :{$key}";
         }
     }
     if ($sql) {
         $sql = "WHERE " . implode(' AND ', $sql);
     } else {
         $sql = '';
     }
     $sql = "SELECT * FROM `" . static::TABLE_NAME . "` {$sql}";
     $stmt = static::getConnection()->prepAndExecute(new \ArtfulRobot\PDO_Query("Fetch records from " . static::TABLE_NAME, $sql, $params));
     if ($stmt->errorCode() != '00000') {
         throw new Exception("PDO error: " . print_r($stmt->errorInfo(), 1));
     }
     while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         // create an object of the class
         $obj = new static();
         $obj->loadFromArray($row, false, self::CAST_DB);
         // these lines differ from main code
         $id = implode("\\A", $obj->getPK());
         $collection->append($obj, $id);
         unset($obj);
     }
     return $collection;
 }
Пример #18
0
 function search($query)
 {
     $collection = new Collection(\OCP\User::getUser());
     $l = \OC_L10N::get('media');
     $app_name = (string) $l->t('Music');
     $artists = $collection->getArtists($query);
     $albums = $collection->getAlbums(0, $query);
     $songs = $collection->getSongs(0, 0, $query);
     $results = array();
     foreach ($artists as $artist) {
         $results[] = new \OC_Search_Result($artist['artist_name'], '', \OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist['artist_name']), $app_name);
     }
     foreach ($albums as $album) {
         $artist = $collection->getArtistName($album['album_artist']);
         $results[] = new \OC_Search_Result($album['album_name'], 'by ' . $artist, \OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist) . '&album=' . urlencode($album['album_name']), $app_name);
     }
     foreach ($songs as $song) {
         $minutes = floor($song['song_length'] / 60);
         $seconds = $song['song_length'] % 60;
         $artist = $collection->getArtistName($song['song_artist']);
         $album = $collection->getalbumName($song['song_album']);
         $results[] = new \OC_Search_Result($song['song_name'], "by {$artist}, in {$album} {$minutes}:{$seconds}", \OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist) . '&album=' . urlencode($album) . '&song=' . urlencode($song['song_name']), $app_name);
     }
     return $results;
 }
Пример #19
0
 public static function newMerged(array $decks)
 {
     $merged = new Collection();
     foreach ($decks as $deck) {
         $merged->merge($deck);
     }
     return new static($merged);
 }
Пример #20
0
 public function testRand()
 {
     $collection = new Collection([1, 2, 3]);
     $result = $collection->rand();
     $this->assertCount(1, $result);
     $result = $collection->rand(2);
     $this->assertCount(2, $result);
 }
Пример #21
0
 public function testCollection()
 {
     $data = array(new Record(), new Record());
     $collection = new Collection($data);
     $recordInfo = $collection->getRecordInfo();
     $this->assertInstanceOf('PSX\\Data\\RecordInfo', $recordInfo);
     $this->assertEquals(array('entry' => $data), $recordInfo->getData());
 }
Пример #22
0
 /**
  * Get list of shop urls
  *
  * @param bool $id_shop
  * @return Collection
  */
 public static function getShopUrls($id_shop = false)
 {
     $urls = new Collection('ShopUrl');
     if ($id_shop) {
         $urls->where('id_shop', '=', $id_shop);
     }
     return $urls;
 }
Пример #23
0
 /**
  * Returns the current element
  * 
  * @return array|object
  */
 public function current()
 {
     $values = parent::current();
     if (isset($values) && isset($this->collection) && $this->collection->getDocumentClass()) {
         $values = $this->collection->asDocument($values, $this->lazy);
     }
     return $values;
 }
Пример #24
0
 public static function fromCollection(Collection $initialData)
 {
     $tree = new self();
     foreach ($initialData->toArray() as $element) {
         $tree->insert($element);
     }
     return $tree;
 }
Пример #25
0
 private function addCollectableToCollection($task, Collection $collection, $taskName = Collection::UNNAMEDTASK, TaskInterface $rollbackTask = null)
 {
     $collection->add($taskName, $task);
     if ($rollbackTask) {
         $collection->rollback($rollbackTask);
     }
     return $this;
 }
 public function testShuffleReindexed()
 {
     $collection = new Collection(['first' => new Bar('a'), 'second' => new Bar('b'), 'third' => new Bar('c'), 'fourth' => new Bar('c')]);
     $result = $collection->shuffle(false);
     $this->assertArrayHasKey(0, $result);
     $this->assertArrayHasKey(1, $result);
     $this->assertArrayHasKey(2, $result);
     $this->assertArrayHasKey(3, $result);
 }
Пример #27
0
 public function testDispatch()
 {
     $eventMock = $this->getMock('Magento\\Framework\\Event', [], [], '', false);
     $observer1 = $this->getObserverMock('test_observer1', $eventMock);
     $observer2 = $this->getObserverMock('test_observer2', $eventMock);
     $this->observerCollection->addObserver($observer1);
     $this->observerCollection->addObserver($observer2);
     $this->observerCollection->dispatch($eventMock);
 }
Пример #28
0
 public static function getShopGroups($active = true)
 {
     $groups = new Collection('ShopGroup');
     $groups->where('deleted', '=', false);
     if ($active) {
         $groups->where('active', '=', true);
     }
     return $groups;
 }
Пример #29
0
 function test_Collection_addComponents()
 {
     $coll = new Collection();
     $coll->addComponents(null);
     $this->assertTrue($coll instanceof collection);
     $coll->addComponents(new Point(0, 0));
     $coll->addComponents(new Point(10, 10));
     $this->asserttrue(count($coll->components), 2);
 }
Пример #30
0
 public static function getStream(User $user)
 {
     $sql = "SELECT activity, action_date\n\t\t\t\tFROM activities\n\t\t\t\tWHERE user_id = ?\n\t\t\t\tORDER BY id DESC\n\t\t\t";
     $stream = new Collection($sql, array($user->id));
     $stream->bindValue('activity');
     $stream->bindType('action_date', 'DateTime');
     $stream->bindData('user_link', $user->getLink());
     return $stream;
 }