Example #1
0
 /**
  *
  * @param array $types
  * @return unknown
  */
 public static function distinctTags($query = array())
 {
     $model = new static();
     $distinct = $model->collection()->distinct("tags", $query);
     $distinct = array_values(array_filter((array) $distinct));
     return $distinct;
 }
Example #2
0
 /**
  *
  * @param array $types
  * @return unknown
  */
 public static function distinctPriorities($query = array())
 {
     $model = new static();
     $distinct = $model->collection()->distinct("priority", $query);
     $distinct = array_values(array_filter($distinct));
     sort($distinct);
     return $distinct;
 }
Example #3
0
 /**
  * Get the Collection from the Repository.
  *
  * @param Repository $repository A specific Repository to get the Collection from.
  *
  * @return Collection The Collection from the Repository.
  */
 public static function collection(Repository $repository = null)
 {
     if (null === $repository) {
         $repository = Tacit::getInstance()->container->get('repository');
     }
     static::$collection = $repository->collection(static::collectionName());
     return static::$collection;
 }
Example #4
0
 public static function fromCode($isocode, $type = 'isocode_2')
 {
     $model = new static();
     if ($doc = $model->collection()->findOne(array($type => $isocode))) {
         $model = $model->bind($doc);
     }
     return $model;
 }
Example #5
0
 /**
  * Provides direct access to the collection of temporaries, if necessary.
  */
 public static function getCollection()
 {
     if (!static::$collection) {
         static::$collection = new Collection();
         register_shutdown_function(function () {
             static::complete();
         });
     }
     return static::$collection;
 }
Example #6
0
 /**
  * Provides direct access to the collection of temporaries, if necessary.
  */
 public static function getCollection()
 {
     if (!static::$collection) {
         static::$collection = \Robo\Robo::getContainer()->get('collection');
         register_shutdown_function(function () {
             static::complete();
         });
     }
     return static::$collection;
 }
Example #7
0
 /**
  * Helper method for creating select list options
  *
  * @param array $query
  * @return multitype:multitype:string NULL
  */
 public static function forSelection(array $query = array(), $id_field = '_id')
 {
     $model = new static();
     $cursor = $model->collection()->find($query, array("last_name" => 1, "first_name" => 1, "email" => 1));
     $cursor->sort(array("last_name" => 1, "first_name" => 1));
     $result = array();
     foreach ($cursor as $doc) {
         $array = array('id' => (string) $doc[$id_field], 'text' => htmlspecialchars(trim($doc['first_name'] . ' ' . $doc['last_name'] . ': ' . $doc['email']), ENT_QUOTES));
         $result[] = $array;
     }
     return $result;
 }
Example #8
0
 /**
  * Helper method for creating select list options
  *
  * @param array $query            
  * @return multitype:multitype:string NULL
  */
 public static function forSelection(array $query = array())
 {
     $model = new static();
     $cursor = $model->collection()->find($query, array($model->__select2_fields['text'] => 1));
     $cursor->sort(array($model->__select2_fields['text'] => 1));
     $result = array();
     foreach ($cursor as $doc) {
         $array = array('id' => (string) $doc[$model->__select2_fields['id']], 'text' => htmlspecialchars($doc[$model->__select2_fields['text']], ENT_QUOTES));
         $result[] = $array;
     }
     return $result;
 }
Example #9
0
 protected function getCollection()
 {
     if (null === static::$collection) {
         // connect
         static::$client = new \MongoClient();
         // select a database
         static::$db = static::$client->ik2;
         // select a collection (analogous to a relational database's table)
         static::$collection = static::$db->cronario_jobsss2;
     }
     return static::$collection;
 }
Example #10
0
 /**
  * Helper method for creating select list options
  *
  * @param array $query            
  * @return multitype:multitype:string NULL
  */
 public static function forSelection(array $query = array())
 {
     $model = new static();
     if (!isset($model->__select2_fields['brackets'])) {
         $model->__select2_fields['brackets'] = '';
     }
     if (empty($model->__select2_fields['brackets'])) {
         $cursor = $model->collection()->find($query, [$model->__select2_fields['text'] => 1, $model->__select2_fields['id'] => 1, $model->__select2_fields['slug'] => 1]);
     } else {
         $cursor = $model->collection()->find($query, [$model->__select2_fields['text'] => 1, $model->__select2_fields['id'] => 1, $model->__select2_fields['slug'] => 1, $model->__select2_fields['brackets'] => 1]);
     }
     $cursor->sort(array($model->__select2_fields['text'] => 1));
     $result = array();
     foreach ($cursor as $doc) {
         $arr = [];
         if (empty($model->__select2_fields['brackets'])) {
             $arr = ['id' => (string) $doc[$model->__select2_fields['id']], 'text' => htmlspecialchars($doc[$model->__select2_fields['text']], ENT_QUOTES)];
         } else {
             $arr = ['id' => (string) $doc[$model->__select2_fields['id']], 'text' => htmlspecialchars($doc[$model->__select2_fields['text']], ENT_QUOTES) . ' (' . htmlspecialchars($doc[$model->__select2_fields['brackets']], ENT_QUOTES) . ')'];
         }
         $result[] = $arr;
     }
     return $result;
 }
Example #11
0
 /**
  * 
  * @param unknown $query
  * @return unknown
  */
 public static function distinctActorTypes($query = array())
 {
     $model = new static();
     $distinct = $model->collection()->distinct("actor_type", $query ? $query : null);
     $distinct = array_values(array_filter($distinct));
     sort($distinct);
     return $distinct;
 }
Example #12
0
 public function __construct($connection = null)
 {
     if ($connection !== null) {
         $this->connection = $connection;
     }
     if (is_string($this->connection)) {
         $this->connection = new Mongo($this->connection);
     }
     if (is_null(self::$collection)) {
         static::$collection = Inflector::lower(get_called_class());
     }
 }
 /**
  * PluginCollection을 지정한다.
  *
  * @param PluginCollection $collection plugin collection
  *
  * @return void
  */
 public static function setCollection($collection)
 {
     static::$collection = $collection;
 }
Example #14
0
 /**
  *
  * @param array $types
  * @return unknown
  */
 public static function distinctStores($query = null)
 {
     $model = new static();
     $distinct = $model->collection()->distinct("storage", $query);
     $distinct = array_values(array_filter($distinct));
     return $distinct;
 }
Example #15
0
 /**
  * Set up class
  *
  * @return void
  */
 public function __construct($collection = null)
 {
     static::$collection = !is_null($collection) ? $collection : new FormatCollection();
 }
Example #16
0
 /**
  * Attempt to get the items in a filtered list that immediately flank a certain one
  * 
  * @param unknown $id
  * @param array $query_params
  * @return multitype:NULL Ambigous <NULL, \Dsc\Mongo\Collection> Ambigous <NULL, \Dsc\Mongo\Collection, unknown>
  */
 public static function surrounding($id, array $query_params = array())
 {
     $return = array('found' => false, 'prev' => null, 'next' => null);
     $model = new static();
     foreach ($query_params as $key => $value) {
         $model->setParam($key, $value);
     }
     $model->__cursor = $model->collection()->find($model->conditions(), $model->fields());
     if ($model->getParam('sort')) {
         $model->__cursor->sort($model->getParam('sort'));
     }
     if ($model->getParam('skip')) {
         $model->__cursor->skip($model->getParam('skip'));
     }
     $found = false;
     $prev = null;
     $next = null;
     foreach ($model->__cursor as $doc) {
         // if the doc is the one we're looking for, get the next one, then break
         if ((string) $doc['_id'] == (string) $id) {
             $found = true;
             if ($nextDoc = $model->__cursor->getNext()) {
                 $next = new static($nextDoc);
             } else {
                 $total = $model->collection()->count($model->conditions());
                 if ($total > $model->getParam('skip') && $model->getParam('limit')) {
                     $skip = $model->getParam('skip') + $model->getParam('limit');
                     $model->__cursor = $model->collection()->find($model->conditions(), $model->fields());
                     if ($model->getParam('sort')) {
                         $model->__cursor->sort($model->getParam('sort'));
                     }
                     $model->__cursor->limit(1);
                     $model->__cursor->skip($skip);
                     if ($model->__cursor->hasNext()) {
                         $query_params['skip'] = $skip;
                         \Dsc\System::instance()->get('session')->trackState(get_class($model), $query_params);
                         $next = new static($model->__cursor->getNext());
                     }
                 }
             }
             // If this is the first doc in the list (if $prev == null),
             if (!empty($next) && empty($prev)) {
                 // and if this is a paginated set, and if we're not on page 1,
                 if ($model->getParam('skip') > $model->getParam('limit')) {
                     // try to load the previous page.  Set the new page as the new state
                     $skip = $model->getParam('skip') - $model->getParam('limit');
                     $model->__cursor = $model->collection()->find($model->conditions(), $model->fields());
                     if ($model->getParam('sort')) {
                         $model->__cursor->sort($model->getParam('sort'));
                     }
                     $model->__cursor->limit(1);
                     $model->__cursor->skip($skip + ($model->getParam('limit') - 1));
                     if ($model->__cursor->hasNext()) {
                         $prev = $model->__cursor->getNext();
                         $query_params['skip'] = $skip;
                         \Dsc\System::instance()->get('session')->trackState(get_class($model), $query_params);
                     }
                 }
             }
             break;
         } else {
             $prev = $doc;
         }
     }
     if ($found) {
         if (!empty($prev)) {
             $prev = new static($prev);
         }
         $return['found'] = $found;
         $return['prev'] = $prev;
         $return['next'] = $next;
     }
     return $return;
 }
Example #17
0
 /**
  *
  * @param array $types
  * @return unknown
  */
 public static function distinctRoutes($query = array())
 {
     $model = new static();
     $distinct = $model->collection()->distinct("assignment.routes.list", $query ? $query : null);
     $distinct = array_values(array_filter($distinct));
     sort($distinct);
     return $distinct;
 }
Example #18
0
 public function __construct($connection = NULL)
 {
     if ($connection !== NULL) {
         $this->connection = $connection;
     }
     if (is_string($this->connection)) {
         $this->connection = new MongoDB($this->connection);
     }
     if (is_null(static::$collection)) {
         static::$collection = strtolower(get_called_class());
     }
 }
Example #19
0
 public function __construct($dbType, $collectionName)
 {
     self::connect($dbType);
     $dbName = self::dbTypeToName($dbType);
     static::$collection = self::getCollection($dbType, $collectionName);
     return static::$collection;
 }
Example #20
0
 /**
  *
  * @param array $types
  * @return unknown
  */
 public static function distinctAdminTags($query = array())
 {
     $model = new static();
     $distinct = $model->collection()->distinct("admin_tags", $query ? $query : null);
     $distinct = array_values(array_filter($distinct));
     return $distinct;
 }
Example #21
0
 public static function setUpBeforeClass()
 {
     static::$collection = new Collection();
     static::$collection->append('part1', ['item1' => 'stuff']);
     static::$collection->freeze('*');
     static::assertTrue(static::$collection->immutable('part1'));
     static::$collection->thaw('*');
     static::assertFalse(static::$collection->immutable('part1'));
 }
Example #22
0
 public static function cleanRepos()
 {
     static::$collection = [];
 }
Example #23
0
 /**
  * Start a collection of routes with common actions
  *
  * @param string
  * @param string|closure
  */
 public static function collection($actions, $definitions)
 {
     // start collection
     static::$collection = $actions;
     // run definitions
     call_user_func($definitions);
     // end of collection
     static::$collection = array();
 }
Example #24
0
 /**
  * Checks Stock Status
  *
  * @return array
  */
 public function stockStatus()
 {
     $status = '';
     if ($this->product_type == 'group') {
         //if any of the sub items are out of stock the group is out of stock
         $items = $this->group_items;
         $ids = array_column($items, 'id');
         array_walk($ids, function (&$id) {
             $id = new \MongoId($id);
         });
         $model = new static();
         $docs = $model->collection()->find(array('_id' => array('$in' => $ids)), array('quantities.manual' => true));
         foreach ($items as $key => $item) {
             foreach ($docs as $doc) {
                 if ($key == (string) $doc['_id']) {
                     if ($item['quantity'] > $doc['quantities']['manual']) {
                         return 'outofstock';
                     }
                 }
             }
         }
         return 'instock';
     } else {
         //varients have stock we are instock
         if ($this->variantsInStock()) {
             $status = 'instock';
         } else {
             //check for open POS
             $pos = false;
             if ($pos) {
                 $status = 'onorder';
             } else {
                 $status = 'outofstock';
             }
         }
     }
     return (string) $status;
 }