当前位置: 首页>>代码示例>>PHP>>正文


PHP Collection::commit方法代码示例

本文整理汇总了PHP中Collection::commit方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::commit方法的具体用法?PHP Collection::commit怎么用?PHP Collection::commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Collection的用法示例。


在下文中一共展示了Collection::commit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: create_collection

 /**
  * Create a collection of pages
  * @param array $record
  * @throws SystemException if creating failed
  * @return int new collection id
  */
 public function create_collection($record)
 {
     // Validation
     switch ($record['ownertype']) {
         case 'institution':
             if (empty($record['ownername'])) {
                 $record['institution'] = 'mahara';
                 break;
             }
             if ($institutionid = $this->get_institution_id($record['ownername'])) {
                 $record['institution'] = $record['ownername'];
             } else {
                 throw new SystemException("The institution '" . $record['ownername'] . "' does not exist.");
             }
             break;
         case 'group':
             if ($groupid = $this->get_group_id($record['ownername'])) {
                 $record['group'] = $groupid;
             } else {
                 throw new SystemException("The group '" . $record['ownername'] . "' does not exist.");
             }
             break;
         case 'user':
         default:
             if ($ownerid = get_field('usr', 'id', 'username', $record['ownername'])) {
                 $record['owner'] = $ownerid;
             } else {
                 throw new SystemException("The user '" . $record['ownername'] . "' does not exist.");
             }
             break;
     }
     // Check if the given pages exist and belong to the collection's owner
     $addviews = array();
     if (!empty($record['pages'])) {
         $record['pages'] = trim($record['pages']);
         $viewtitles = !empty($record['pages']) ? explode(',', $record['pages']) : false;
         if (!empty($viewtitles)) {
             foreach ($viewtitles as $viewtitle) {
                 if (!empty($viewtitle) && !($view = get_record_sql('
                         SELECT v.id
                         FROM {view} v
                             INNER JOIN {usr} u ON u.id = v.owner
                         WHERE v.title = ?
                             AND u.username = ?', array(trim($viewtitle), $record['ownername'])))) {
                     throw new SystemException("The page '" . $viewtitle . "' does not exist or not belong to the user '" . $record['ownername'] . "'.");
                 }
                 $addviews['view_' . $view->id] = true;
             }
         }
     }
     // Create a new collection
     require_once 'collection.php';
     $data = new StdClass();
     $data->name = $record['title'];
     $data->description = $record['description'];
     if (!empty($record['group'])) {
         $data->group = $record['group'];
     } else {
         if (!empty($record['institution'])) {
             $data->institution = $record['institution'];
         } else {
             if (!empty($record['owner'])) {
                 $data->owner = $record['owner'];
             }
         }
     }
     $collection = new Collection(0, $data);
     $collection->commit();
     // Add views to the collection
     if (!empty($addviews)) {
         $collection->add_views($addviews);
     }
 }
开发者ID:rboyatt,项目名称:mahara,代码行数:79,代码来源:TestingDataGenerator.php

示例2: save

 /**
  * Helper function to create or update a Collection from the supplied data.
  *
  * @param array $data
  * @return collection           The newly created/updated collection
  */
 public static function save($data)
 {
     if (array_key_exists('id', $data)) {
         $id = $data['id'];
     } else {
         $id = 0;
     }
     $collection = new Collection($id, $data);
     $collection->set('mtime', time());
     $collection->commit();
     return $collection;
     // return newly created Collections id
 }
开发者ID:agwells,项目名称:Mahara-1,代码行数:19,代码来源:collection.php

示例3: import_using_strategy

 /**
  */
 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');
     }
 }
开发者ID:agwells,项目名称:Mahara-1,代码行数:48,代码来源:lib.php

示例4: save

 /**
  * Creates a new Collection for the given user.
  *
  * @param array $data
  * @return collection           The newly created Collection
  */
 public static function save($data)
 {
     $collection = new Collection(0, $data);
     $collection->commit();
     return $collection;
     // return newly created Collections id
 }
开发者ID:richardmansfield,项目名称:richardms-mahara,代码行数:13,代码来源:collection.php


注:本文中的Collection::commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。