get() public method

public get ( $key, $default = null )
Esempio n. 1
0
 /**
  * @test Collection::get()
  */
 public function testGet()
 {
     $this->buildEnvironment();
     $result = $this->collection->get('a1');
     $expect = $this->source['a1'];
     $this->assertEquals($expect, $result);
 }
Esempio n. 2
0
 public function testPopPushPutShiftUnshiftInject()
 {
     // pop
     $_3 = $this->collection->pop();
     $this->assertEquals($this->_3, $_3);
     $this->assertEquals($this->_2, $this->collection->last());
     $this->assertEquals(3, $this->collection->count());
     // push
     $this->collection->push($_3);
     $this->assertEquals($this->_3, $this->collection->last());
     // put
     $this->collection->put(2, 'test');
     $this->assertEquals('test', $this->collection->get(2));
     // shift
     $_0 = $this->collection->shift();
     $this->assertEquals($this->_0, $_0);
     $this->assertEquals($this->_1, $this->collection->first());
     $this->assertEquals(3, $this->collection->count());
     // unshift
     $this->collection->unshift($_0);
     $this->assertEquals($this->_0, $this->collection->first());
     // inject
     $this->collection->inject(2, 'test2');
     $this->assertEquals('test2', $this->collection->get(2));
     $this->assertEquals(5, $this->collection->count());
 }
Esempio n. 3
0
 private function appendChildren(Aggregate $entity, CollectionInterface $children) : Aggregate
 {
     $children->each(function (string $name, array $config) use(&$entity) {
         $config = new Collection($config);
         $rel = new ValueObjectRelationship(new ClassName($config->get('class')), new RelationshipType($config->get('type')), $name, $config->get('child')['property'], $config->hasKey('collection') ? (bool) $config->get('collection') : false);
         if ($config->hasKey('properties')) {
             $rel = $this->appendProperties($rel, new Collection($config->get('properties')));
         }
         $config = new Collection($config->get('child'));
         $child = new ValueObject(new ClassName($config->get('class')), $config->get('labels'), $rel);
         if ($config->hasKey('properties')) {
             $child = $this->appendProperties($child, new Collection($config->get('properties')));
         }
         $entity = $entity->withChild($child);
     });
     return $entity;
 }
Esempio n. 4
0
 /**
  * Find image size data
  *
  * @param string $sizeName
  * @return ImageSize
  */
 public function findImageSize($sizeName)
 {
     if ($this->imageSizes->containsKey($sizeName)) {
         return $this->imageSizes->get($sizeName);
     } else {
         return null;
     }
 }
Esempio n. 5
0
 /**
  * /
  * @param  [type] $id [description]
  * @return [type]     [description]
  */
 public function get($id)
 {
     if (!is_string($id)) {
         throw new \Exception("Cookie index must be string", 03);
     }
     $newId = str_replace('.', '_', $id);
     $value = parent::get($newId);
     return new Cookie($value);
 }
Esempio n. 6
0
 public function get($key = '', $defVal = null)
 {
     if (stripos($key, '.') !== false) {
         list($parentKey) = explode('.', $key);
         if (!array_key_exists($parentKey, $this->_loadedFiles)) {
             $this->_loadFile($parentKey);
         }
     }
     return parent::get($key, $defVal);
 }
Esempio n. 7
0
 public function testGetsElementByIndex()
 {
     $list = new Collection(\Cassandra::TYPE_VARINT);
     $list->add(new Varint('1'), new Varint('2'), new Varint('3'), new Varint('4'), new Varint('5'), new Varint('6'), new Varint('7'), new Varint('8'));
     $this->assertEquals(new Varint('1'), $list->get(0));
     $this->assertEquals(new Varint('2'), $list->get(1));
     $this->assertEquals(new Varint('3'), $list->get(2));
     $this->assertEquals(new Varint('4'), $list->get(3));
     $this->assertEquals(new Varint('5'), $list->get(4));
     $this->assertEquals(new Varint('6'), $list->get(5));
     $this->assertEquals(new Varint('7'), $list->get(6));
     $this->assertEquals(new Varint('8'), $list->get(7));
 }
Esempio n. 8
0
 /**
  * Optional method. If exists, allows this class to decide the title for
  * all blockinstances of this type
  */
 public static function get_instance_title(BlockInstance $bi)
 {
     $configdata = $bi->get('configdata');
     if (!empty($configdata['collection'])) {
         require_once 'collection.php';
         $data = get_record_select('collection', 'id = ?', array($configdata['collection']));
         $collection = new Collection($configdata['collection'], (array) $data);
         $title = $collection->get('name');
         return $title;
     }
     return '';
 }
Esempio n. 9
0
 protected function handler_participants(Collection $activities, $fields)
 {
     $res = XDB::iterator('SELECT  id, participant
                             FROM  activities_participants
                            WHERE  id IN {?}', $activities->ids());
     $users = new Collection('User');
     $part = array();
     while ($datas = $res->next()) {
         $part[$datas['id']][] = $users->addget($datas['participant']);
     }
     foreach ($part as $key => $obj) {
         $activities->get($key)->participants($obj);
     }
     $users->select($this->subs['participants']);
 }
Esempio n. 10
0
 public function encode($script)
 {
     $this->search($script);
     $this->words->sort();
     $encoded = new Collection();
     // a dictionary of base62 -> base10
     $size = $this->words->size();
     for ($i = 0; $i < $size; $i++) {
         $encoded->put(Packer::encode62($i), $i);
     }
     $index = 0;
     foreach ($this->words as $word) {
         if ($encoded->has($word)) {
             $word->index = $encoded->get($word);
             $word->clear();
         } else {
             while ($this->words->has(Packer::encode62($index))) {
                 $index++;
             }
             $word->index = $index++;
             if ($word->count == 1) {
                 $word->clear();
             }
         }
         $word->replacement = Packer::encode62($word->index);
         if (strlen($word->replacement) == strlen($word)) {
             $word->clear();
         }
     }
     // sort by encoding
     $this->words->sort(array('Base62', 'sorter'));
     // trim unencoded words
     $this->words = $this->words->slice(0, preg_match_all('/\\|/', $this->getKeyWords(), $matches) + 1);
     $script = preg_replace_callback($this->getPattern(), array(&$this, '_word_replacement'), $script);
     /* build the packed script */
     $p = $this->escape($script);
     $a = '[]';
     $c = max($this->words->size(), 1);
     $k = $this->getKeyWords();
     $e = $this->getEncoder();
     $d = $this->getDecoder();
     // the whole thing
     return $this->format(Base62::$UNPACK, $p, $a, $c, $k, $e, $d);
 }
Esempio n. 11
0
 public function getDoctorsListCount($latitude = 0, $longitude = 0, $query = array())
 {
     $this->data = DB::table('doctors');
     $this->data->leftJoin('doctors_details AS dhospital', 'doctors.id', '=', 'dhospital.doctor_id');
     $this->data->leftJoin('listing_hospitals', 'dhospital.detail_id', '=', 'listing_hospitals.id');
     $this->data->leftJoin('doctors_details AS dhmo', 'doctors.id', '=', 'dhmo.doctor_id');
     $this->data->leftJoin('listing_hmo', 'dhmo.detail_id', '=', 'listing_hmo.id');
     $this->data->leftJoin('doctors_specialization', 'doctors.id', '=', 'doctors_specialization.doctor_id');
     $this->data->leftJoin('location_cities', 'listing_hospitals.city', '=', 'location_cities.id');
     $this->data->leftJoin('location_provinces', 'listing_hospitals.province', '=', 'location_provinces.id');
     $this->data->select(DB::raw("doctors.*, dhospital.detail_id as hospital_id, listing_hospitals.listing_title as hospital_title, listing_hospitals.latitude, listing_hospitals.longitude, listing_hospitals.street, location_cities.city_name, location_provinces.province_name, dhmo.detail_id as hmo_id, listing_hmo.listing_title as hmo_title, doctors_specialization.specialization_id, (6371 * acos (cos ( radians(?) ) * cos( radians( listing_hospitals.latitude ) ) * cos( radians( listing_hospitals.longitude ) - radians(?) ) + sin ( radians(?) ) * sin( radians( listing_hospitals.latitude ) ))) AS distance"))->setBindings([$latitude, $longitude, $latitude]);
     $this->data->where('dhospital.detail_type', '=', 1);
     $this->data->where('dhmo.detail_type', '=', 4);
     if (isset($query['specializations'])) {
         $this->data->whereIn('doctors_specialization.specialization_id', $query['specializations']);
     }
     if (isset($query['locations'])) {
         $this->data->whereIn('listing_hospitals.city', $query['locations']);
     }
     $this->data->groupBy('doctors.id');
     // }
     return $this->data->get();
 }
Esempio n. 12
0
 /**
  * Select a GID which identifies the visibility of a caste-user assocation
  */
 protected function handler_cuvisibility(Collection $users, $fields)
 {
     $_users = array();
     foreach ($users as $u) {
         $_users[$u->id()] = array();
     }
     $viscoll = new Collection('Group');
     $iter = XDB::iterRow('SELECT  uid, cid, visibility
                             FROM  castes_users
                            WHERE  uid IN {?}', $users->ids());
     while (list($uid, $cid, $vis) = $iter->next()) {
         $_users[$uid][$cid] = $vis;
         if ($vis != 0) {
             $viscoll->add($vis);
         }
     }
     $viscoll->select(GroupSelect::base());
     foreach ($users as $u) {
         $cuarray = array_map(function ($gid) use($viscoll) {
             return $gid == 0 ? null : $viscoll->get($gid);
         }, $_users[$u->id()]);
         $u->fillFromArray(array('cuvisibility' => $cuarray));
     }
 }
Esempio n. 13
0
<?php

$collection = new Collection(['a' => 'apple', 'b' => 'banana', 'c' => 'carrot']);
$collection->get('b');
//
// RETURNS:
//
// 'banana'
//
 /**
  * {@inheritdoc}
  */
 public function get($key)
 {
     $this->initialize();
     return $this->coll->get($key);
 }
Esempio n. 15
0
 /**
  * Returns true if the request is a XMLHttpRequest.
  *
  * It works if your JavaScript library set an X-Requested-With HTTP header.
  * It is known to work with Prototype, Mootools, jQuery.
  *
  * @return Boolean true if the request is an XMLHttpRequest, false otherwise
  *
  * @api
  */
 public function isXmlHttpRequest()
 {
     return 'XMLHttpRequest' == $this->headers->get('X_REQUESTED_WITH');
 }
Esempio n. 16
0
 public function testGet()
 {
     $el = $this->collection->get(2);
     $this->assertEquals($this->_2, $el);
 }
Esempio n. 17
0
require_once 'activity.php';
require_once get_config('docroot') . 'artefact/lib.php';
$groupid = param_integer('group');
$returnto = param_variable('returnto', 'view');
$group = get_record_sql('SELECT g.id, g.name, g.grouptype, g.urlid
       FROM {group_member} u
       INNER JOIN {group} g ON (u.group = g.id AND g.deleted = 0)
       WHERE u.member = ?
       AND g.id = ?
       AND g.submittableto = 1', array($USER->get('id'), $groupid));
if (!$group || !group_within_edit_window($group)) {
    throw new AccessDeniedException(get_string('cantsubmittogroup', 'view'));
}
if ($collectionid = param_integer('collection', null)) {
    $collection = new Collection($collectionid);
    if (!$collection || $collection->is_submitted() || $collection->get('owner') !== $USER->get('id')) {
        throw new AccessDeniedException(get_string('cantsubmitcollectiontogroup', 'view'));
    }
    $submissionname = $collection->get('name');
} else {
    $view = new View(param_integer('id'));
    if (!$view || $view->is_submitted() || $view->get('owner') !== $USER->get('id')) {
        throw new AccessDeniedException(get_string('cantsubmitviewtogroup', 'view'));
    }
    $submissionname = $view->get('title');
}
define('TITLE', get_string('submitviewtogroup', 'view', $submissionname, $group->name));
$form = pieform(array('name' => 'submitview', 'renderer' => 'div', 'autofocus' => false, 'method' => 'post', 'elements' => array('submit' => array('type' => 'submitcancel', 'value' => array(get_string('yes'), get_string('no')), 'goto' => get_config('wwwroot') . returnto()))));
$smarty = smarty();
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('message', get_string('submitconfirm', 'view', $submissionname, $group->name));
Esempio n. 18
0
 /**
  */
 public function import_using_strategy(SimpleXMLElement $entry, $strategy, array $otherentries)
 {
     switch ($strategy) {
         case self::STRATEGY_IMPORT_AS_VIEW:
             require_once 'view.php';
             if (!$this->import_entry_as_mahara_view($entry)) {
                 // Not a Mahara view, just do basic import
                 $this->trace('Not a Mahara view, doing basic import', self::LOG_LEVEL_VERBOSE);
                 $viewdata = array('title' => (string) $entry->title, 'description' => (string) $entry->summary, 'type' => 'portfolio', 'layout' => null, 'tags' => self::get_entry_tags($entry), 'numrows' => 1, 'ownerformat' => FORMAT_NAME_DISPLAYNAME, 'owner' => $this->get('usr'));
                 if ($published = strtotime((string) $entry->published)) {
                     $viewdata['ctime'] = $published;
                 }
                 if ($updated = strtotime((string) $entry->updated)) {
                     $viewdata['mtime'] = $updated;
                 }
                 $view = View::create($viewdata, $this->get('usr'));
                 safe_require('blocktype', 'textbox');
                 $bi = new BlockInstance(0, array('blocktype' => 'textbox', 'title' => '', 'row' => 1, 'column' => 1, 'order' => 1, 'configdata' => array('text' => self::get_entry_content($entry, $this))));
                 $view->addblockinstance($bi);
                 $this->viewids[(string) $entry->id] = $view->get('id');
             }
             break;
         case self::STRATEGY_IMPORT_AS_COLLECTION:
             require_once 'collection.php';
             $collectiondata = array('name' => (string) $entry->title, 'description' => (string) $entry->summary, 'tags' => self::get_entry_tags($entry), 'owner' => $this->get('usr'));
             if ($published = strtotime((string) $entry->published)) {
                 $collectiondata['ctime'] = $published;
             }
             if ($updated = strtotime((string) $entry->updated)) {
                 $collectiondata['mtime'] = $updated;
             }
             $collection = new Collection(0, $collectiondata);
             $collection->commit();
             $this->collectionids[(string) $entry->id] = $collection->get('id');
             // Remember entry ids that form part of this entry, and use them later
             // to put views into collections.
             foreach ($entry->link as $link) {
                 if ($this->curie_equals($link['rel'], '', 'has_part') && isset($link['href'])) {
                     $this->collectionviewentries[$collection->get('id')][] = (string) $link['href'];
                 }
             }
             break;
         default:
             throw new ImportException($this, 'TODO: get_string: unknown strategy chosen for importing entry');
     }
 }
Esempio n. 19
0
 /**
  * @param $key
  * @return null
  */
 public function get($key)
 {
     return parent::get(self::normalizeKey($key));
 }
Esempio n. 20
0
 protected function helper_main(Collection $metas, array $cols, array $joins)
 {
     $table = $this->schema->table();
     $as = $this->schema->tableAs();
     $id = $this->schema->id();
     $sql_fields = self::arrayToSqlCols($cols);
     $sql_joins = PlSqlJoin::formatJoins($joins, array());
     $collections = array();
     foreach ($cols as $fields) {
         foreach ($fields as $field) {
             if ($this->schema->isCollection($field)) {
                 // TODO: is this code used ?
                 //$collections[$field] = new Collection($this->schema->collectionType($field));
                 throw new Exception("Oops, there is a main handler for collections now ?");
             } elseif (!empty($this->subs) && array_key_exists($field, $this->subs)) {
                 $collections[$field] = new Collection($this->schema->objectType($field));
             }
         }
     }
     $iter = XDB::iterator("SELECT  {$as}.{$id} AS id, {$sql_fields}\n                                 FROM  {$table} AS {$as}\n                                       {$sql_joins}\n                                WHERE  {$as}.{$id} IN {?}", $metas->ids());
     while ($datas = $iter->next()) {
         foreach ($datas as $key => $value) {
             if ($this->schema->isObject($key)) {
                 $class = $this->schema->objectType($key);
                 $datas[$key] = new $class($value);
             }
             if (array_key_exists($key, $collections) && $value !== null) {
                 $datas[$key] = $collections[$key]->addget($value);
             }
             if ($value === null) {
                 /*
                  * /!\ Null in the DB means false in here.
                  * Therefore Boolean fields must *not* be nullable !
                  */
                 $datas[$key] = false;
             }
         }
         $metas->get($datas['id'])->fillFromArray($datas);
     }
     foreach ($collections as $field => $collection) {
         $collection->select($this->subs[$field]);
     }
 }
Esempio n. 21
0
 public static function load_products()
 {
     if (!Config::$cart_table) {
         return;
     }
     # create a collection for the products table
     $col = new Collection(Config::$cart_table);
     # loop through the products in the cart
     foreach (self::get_cart() as $id => $qty) {
         # select those products by their ids
         # field, value, use_quotes, or
         $col->where('id', $id, true, true);
     }
     # if there is any products in the cart at all
     if ($_SESSION[Config::$sitename]['cart'][Auth::user_id()]) {
         # then load them all into the collection
         $col->get();
     }
     # clear the static products array
     self::$products = [];
     # for each item in the collection
     foreach ($col->items as $product) {
         # add a quantity property to the model
         $product->quantity = $_SESSION[Config::$sitename]['cart'][Auth::user_id()][$product->id];
         # add the product object into the products array
         self::$products[] = $product;
     }
 }
Esempio n. 22
0
 /**
  * @param string $name
  * @param string $def
  * @return string
  */
 public function getOldOnce($name, $def = '')
 {
     if ($this->storage) {
         $old_once = $this->storage->get(OldValue::OLD_ONCE_KEY);
         $old_once = new Collection($old_once);
         if ($old_once->has($name)) {
             $v = $old_once->get($name);
             $old_once->delete($name);
             $this->storage->set(OldValue::OLD_ONCE_KEY, $old_once->get());
             return $v;
         }
     }
     return $def;
 }
Esempio n. 23
0
 /**
  * Delete a collection from the library
  *
  * @param Collection $collection collection object to be deleted
  * @return Zotero_Response
  */
 public function removeCollection($collection)
 {
     $aparams = array('target' => 'collection', 'collectionKey' => $collection->collectionKey);
     $response = $this->request($aparams, 'DELETE', null, array('If-Unmodified-Since-Version' => $collection->get('collectionVersion')));
     return $response;
 }
 /**
  * @param string $perimeterType
  *
  * @return array
  */
 public function getPerimeter($perimeterType)
 {
     return $this->perimeters->get($perimeterType);
 }
Esempio n. 25
0
 /**
  * @param $index
  *
  * @return mixed
  */
 public function pick($index)
 {
     return $this->discounts->get($index);
 }
Esempio n. 26
0
    } else {
        define('MENUITEM', 'myportfolio/collection');
        $owner = $USER->get('id');
        $canedit = true;
        define('SUBTITLE', '');
        define('TITLE', get_string('Collections', 'collection'));
    }
}
$baseurl = get_config('wwwroot') . 'collection/index.php';
if ($urlparams) {
    $baseurl .= '?' . http_build_query($urlparams);
}
$data = Collection::get_mycollections_data($offset, $limit, $owner, $groupid, $institutionname);
foreach ($data->data as $value) {
    $collection = new Collection($value->id);
    $views = $collection->get('views');
    if (!empty($views)) {
        $value->views = $views['views'];
    }
}
$pagination = build_pagination(array('id' => 'collectionslist_pagination', 'class' => 'center', 'url' => $baseurl, 'count' => $data->count, 'limit' => $data->limit, 'offset' => $data->offset, 'firsttext' => '', 'previoustext' => '', 'nexttext' => '', 'lasttext' => '', 'numbersincludefirstlast' => false, 'resultcounttextsingular' => get_string('collection', 'collection'), 'resultcounttextplural' => get_string('collections', 'collection')));
$smarty = smarty(array('paginator'), array(), array(), array('PAGEICON' => $pageIcon));
$urlparamsstr = '';
if ($urlparams) {
    $urlparamsstr = '&' . http_build_query($urlparams);
}
if ($canedit) {
    $smarty->assign('addonelink', get_config('wwwroot') . 'collection/edit.php?new=1' . $urlparamsstr);
}
if (!empty($institutionname) && $institutionname != 'mahara') {
    $smarty->assign('institution', $institutionname);
Esempio n. 27
0
/**
 * Return the title, type and id of the item based on which is more important
 *
 * Takes an array containing ids on either or all of these items with ranking
 * preference in this order:
 * - collection
 * - view
 * and returns the title, type, and id of which ever one is present and is highest ranked
 *
 * @param array  $item An array containing any or all of 'collection', 'view' ids
 * @return array The title/url/type/id information on the most senior one found.
 */
function get_export_contentdata($item)
{
    // first make sure we have an array
    if (is_object($item)) {
        $item = (array) $item;
    }
    $record = new stdClass();
    $record->title = '';
    $record->url = null;
    $record->type = null;
    $record->id = 0;
    if (!empty($item['collection'])) {
        require_once 'collection.php';
        $collection = new Collection($item['collection']);
        $views = $collection->get('views');
        $record->title = $collection->get('name');
        $record->url = $views['views'][0]->fullurl;
        $record->type = 'collection';
        $record->id = $item['collection'];
    } else {
        if (!empty($item['view'])) {
            require_once 'view.php';
            $view = new View($item['view']);
            $record->title = $view->get('title');
            $record->url = get_config('wwwroot') . 'view/view.php?id=' . $item['view'];
            $record->type = 'view';
            $record->id = $item['view'];
        }
    }
    return $record;
}
Esempio n. 28
0
 /**
  * Creates a Collection for the given user, based off a given template and other
  * Collection information supplied.
  *
  * Will set a default name of 'Copy of $collectiontitle' if name is not
  * specified in $collectiondata and $titlefromtemplate == false.
  *
  * @param array $collectiondata Contains information of the old collection, submitted in form
  * @param int $templateid The ID of the Collection to copy
  * @param int $userid     The user who has issued the command to create the
  *                        collection.
  * @param int $checkaccess Whether to check that the user can see the collection before copying it
  * @return array A list consisting of the new collection, the template collection and
  *               information about the copy - i.e. how many blocks and
  *               artefacts were copied
  * @throws SystemException under various circumstances, see the source for
  *                         more information
  */
 public static function create_from_template($collectiondata, $templateid, $userid = null, $checkaccess = true, $titlefromtemplate = false)
 {
     require_once get_config('libroot') . 'view.php';
     global $SESSION;
     if (is_null($userid)) {
         global $USER;
         $userid = $USER->get('id');
     }
     db_begin();
     $colltemplate = new Collection($templateid);
     $data = new StdClass();
     // Set a default name if one wasn't set in $collectiondata
     if ($titlefromtemplate) {
         $data->name = $colltemplate->get('name');
     } else {
         if (!isset($collectiondata['name'])) {
             $desiredname = $colltemplate->get('name');
             if (get_config('renamecopies')) {
                 $desiredname = get_string('Copyof', 'mahara', $desiredname);
             }
             $data->name = self::new_name($desiredname, (object) $collectiondata);
         } else {
             $data->name = $collectiondata['name'];
         }
     }
     $data->description = $colltemplate->get('description');
     $data->tags = $colltemplate->get('tags');
     $data->navigation = $colltemplate->get('navigation');
     if (!empty($collectiondata['group'])) {
         $data->group = $collectiondata['group'];
     } else {
         if (!empty($collectiondata['institution'])) {
             $data->institution = $collectiondata['institution'];
         } else {
             if (!empty($collectiondata['owner'])) {
                 $data->owner = $collectiondata['owner'];
             } else {
                 $data->owner = $userid;
             }
         }
     }
     $collection = self::save($data);
     $numcopied = array('pages' => 0, 'blocks' => 0, 'artefacts' => 0);
     $views = $colltemplate->get('views');
     $copyviews = array();
     foreach ($views['views'] as $v) {
         $values = array('new' => true, 'owner' => isset($data->owner) ? $data->owner : null, 'group' => isset($data->group) ? $data->group : null, 'institution' => isset($data->institution) ? $data->institution : null, 'usetemplate' => $v->view);
         list($view, $template, $copystatus) = View::create_from_template($values, $v->view, $userid, $checkaccess, $titlefromtemplate);
         if (isset($copystatus['quotaexceeded'])) {
             $SESSION->clear('messages');
             return array(null, $colltemplate, array('quotaexceeded' => true));
         }
         $copyviews['view_' . $view->get('id')] = true;
         $numcopied['blocks'] += $copystatus['blocks'];
         $numcopied['artefacts'] += $copystatus['artefacts'];
     }
     $numcopied['pages'] = count($views['views']);
     $collection->add_views($copyviews);
     // Update all the navigation blocks referring to this collection
     if ($viewids = get_column('collection_view', 'view', 'collection', $collection->get('id'))) {
         $navblocks = get_records_select_array('block_instance', 'view IN (' . join(',', array_fill(0, count($viewids), '?')) . ") AND blocktype = 'navigation'", $viewids);
         if ($navblocks) {
             safe_require('blocktype', 'navigation');
             foreach ($navblocks as $b) {
                 $bi = new BlockInstance($b->id, $b);
                 $configdata = $bi->get('configdata');
                 if (isset($configdata['collection']) && $configdata['collection'] == $templateid) {
                     $bi->set('configdata', array('collection' => $collection->get('id')));
                     $bi->commit();
                 }
             }
         }
     }
     db_commit();
     return array($collection, $colltemplate, $numcopied);
 }
Esempio n. 29
0
$copy = param_boolean('copy', 0);
if ($new) {
    // if creating a new collection
    $owner = null;
    $groupid = param_integer('group', 0);
    $institutionname = param_alphanum('institution', false);
    if (empty($groupid) && empty($institutionname)) {
        $owner = $USER->get('id');
    }
    $collection = new Collection(null, array('owner' => $owner, 'group' => $groupid, 'institution' => $institutionname));
    define('SUBTITLE', get_string('edittitleanddesc', 'collection'));
} else {
    // if editing an existing or copied collection
    $id = param_integer('id');
    $collection = new Collection($id);
    $owner = $collection->get('owner');
    $groupid = $collection->get('group');
    $institutionname = $collection->get('institution');
    define('SUBTITLE', $collection->get('name') . ': ' . get_string('edittitleanddesc', 'collection'));
}
if ($collection->is_submitted()) {
    $submitinfo = $collection->submitted_to();
    throw new AccessDeniedException(get_string('canteditsubmitted', 'collection', $submitinfo->name));
}
$urlparams = array();
if (!empty($groupid)) {
    define('MENUITEM', 'groups/collections');
    define('GROUP', $groupid);
    $group = group_current_group();
    define('TITLE', $group->name . ' - ' . get_string('editcollection', 'collection'));
    $urlparams['group'] = $groupid;
Esempio n. 30
0
/**
 * Submits a view or collection for assessment by a remote service
 *
 * @param string $username
 * @param int $id The ID of the view or collection to be submitted
 * @param boolean $iscollection Indicates whether it's a view or a collection
 * @return array An array of data for the web service to consume
 */
function submit_view_for_assessment($username, $id, $iscollection = false)
{
    global $REMOTEWWWROOT;
    list($user, $authinstance) = find_remote_user($username, $REMOTEWWWROOT);
    if (!$user) {
        return false;
    }
    $id = (int) $id;
    if (!$id) {
        return false;
    }
    require_once 'view.php';
    $remotehost = $authinstance->config['wwwroot'];
    $userid = $user->get('id');
    db_begin();
    if ($iscollection) {
        require_once 'collection.php';
        $collection = new Collection($id);
        $title = $collection->get('name');
        $description = $collection->get('description');
        // Check whether the collection is already submitted
        if ($collection->is_submitted()) {
            // If this is already submitted to something else, throw an exception
            if ($collection->get('submittedgroup') || $collection->get('submittedhost') !== $REMOTEWWWROOT) {
                throw new CollectionSubmissionException(get_string('collectionalreadysubmitted', 'view'));
            }
            // It may have been submitted to a different assignment in the same remote
            // site, but there's no way we can tell. So we'll just send the access token
            // back.
            $access = $collection->get_invisible_token();
        } else {
            $collection->submit(null, $remotehost, $userid);
            $access = $collection->new_token(false);
        }
        // If the collection is empty, $access will be false
        if (!$access) {
            throw new CollectionSubmissionException(get_string('cantsubmitemptycollection', 'view'));
        }
    } else {
        $view = new View($id);
        $title = $view->get('title');
        $description = $view->get('description');
        if ($view->is_submitted()) {
            // If this is already submitted to something else, throw an exception
            if ($view->get('submittedgroup') || $view->get('submittedhost') !== $REMOTEWWWROOT) {
                throw new ViewSubmissionException(get_string('viewalreadysubmitted', 'view'));
            }
            // It may have been submitted to a different assignment in the same remote
            // site, but there's no way we can tell. So we'll just send the access token
            // back.
            $access = View::get_invisible_token($id);
        } else {
            View::_db_submit(array($id), null, $remotehost, $userid);
            $access = View::new_token($id, false);
        }
    }
    $data = array('id' => $id, 'title' => $title, 'description' => $description, 'fullurl' => get_config('wwwroot') . 'view/view.php?mt=' . $access->token, 'url' => '/view/view.php?mt=' . $access->token, 'accesskey' => $access->token);
    // Provide each artefact plugin the opportunity to handle the remote submission and
    // provide return data for the webservice caller
    foreach (plugins_installed('artefact') as $plugin) {
        safe_require('artefact', $plugin->name);
        $classname = generate_class_name('artefact', $plugin->name);
        if (is_callable($classname . '::view_submit_external_data')) {
            $data[$plugin->name] = call_static_method($classname, 'view_submit_external_data', $id, $iscollection);
        }
    }
    db_commit();
    return $data;
}