public function save($relationshipName = NULL)
 {
     if (!empty($relationshipName)) {
         throw new PolymorphicException('Relationship path "' . $relationshipName . '" has no meaning for polymorphic collections');
     }
     return parent::save();
 }
Esempio n. 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $collection = new Collection();
     $collection->name = Input::get('name');
     $collection->save();
     return Redirect::route('collection.index');
 }
 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();
 }
Esempio n. 4
0
 public function testMapWithoutCollection()
 {
     $collection = new Collection();
     $collection->addElementTextsByArray(array('Dublin Core' => array('Title' => array(array('text' => 'Plants', 'html' => false)))));
     $collection->save();
     $row = array('title' => 'Animals', 'description' => 'Foo');
     $map = new CsvImport_ColumnMap_Collection('title');
     $this->assertFalse($map->map($row, array()));
 }
Esempio n. 5
0
function submit(Pieform $form, $values)
{
    global $SESSION, $new;
    $collection = Collection::save($values);
    if (!$new) {
        $SESSION->add_ok_msg(get_string('collectionsaved', 'collection'));
    }
    $collection->post_edit_redirect($new);
}
 public function testMapWithoutCollection()
 {
     $collection = new Collection();
     $collection->addElementTextsByArray(array('Dublin Core' => array('Title' => array(array('text' => 'Plants', 'html' => false)))));
     $collection->save();
     $row = array('title' => 'Animals', 'description' => 'Foo');
     $map = new CsvImport_ColumnMap_Collection('title');
     $this->markTestSkipped(__('Since 2.2-full, collections are checked during import.'));
     $this->assertFalse($map->map($row, array()));
 }
 function test_find()
 {
     //Arrange
     $name = "Hello Kitty";
     $name2 = "Pokemon";
     $test_collection = new Collection($name);
     $test_collection->save();
     $test_collection2 = new Collection($name2);
     $test_collection2->save();
     //Act
     $result = Collection::find($test_collection2->getId());
     //Assert
     $this->assertEquals($test_collection2, $result);
 }
Esempio n. 8
0
 public function setUp()
 {
     parent::setUp();
     // Set the ACL to allow access to collections
     $this->acl = $this->application->getBootstrap()->acl;
     $this->acl->allow(null, 'Collections');
     $this->db = $this->application->getBootstrap()->db;
     $this->user = $this->db->getTable('User')->find(1);
     $this->_authenticateUser($this->user);
     // Create a collection
     $collection = new Collection();
     $collection->public = true;
     $collection->save();
     $this->collection = $collection;
 }
 function test_find()
 {
     //Arrange
     $thing = "Run the World";
     $thing2 = "20 20 Experience";
     $test_collection = new Collection($thing);
     $test_collection->save();
     $test_collection2 = new Collection($thing2);
     $test_collection2->save();
     //Act
     $id = $test_collection->getId();
     $result = Collection::find($id);
     //Assert
     $this->assertEquals($test_collection, $result);
 }
 public function testOwnerIdNotSetWhenUpdatingCollection()
 {
     $user = $this->_getDefaultUser();
     $this->_authenticateUser($user);
     //create collection
     $collection = new Collection();
     $elementTexts = array('Dublin Core' => array('Title' => array(array('text' => 'foobar', 'html' => false)), 'Description' => array(array('text' => 'baz', 'html' => false))));
     $collection->addElementTextsByArray($elementTexts);
     $collection->owner_id = $user->id + 1;
     $collection->save();
     $csrf = new Omeka_Form_Element_SessionCsrfToken('csrf_token');
     $this->request->setPost(array('Elements' => array(), 'csrf_token' => $csrf->getToken()));
     $this->request->setMethod('post');
     $this->dispatch('collections/edit/' . $collection->id);
     $this->assertRedirect();
     $updatedCollection = $this->db->getTable('Collection')->find($collection->id);
     $this->assertNotEquals($user->id, $updatedCollection->owner_id, "The owner_id for the collection should not be that of the user who updated the collection.");
 }
Esempio n. 11
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aCollection !== null) {
             if ($this->aCollection->isModified() || $this->aCollection->isNew()) {
                 $affectedRows += $this->aCollection->save($con);
             }
             $this->setCollection($this->aCollection);
         }
         if ($this->aFile !== null) {
             if ($this->aFile->isModified() || $this->aFile->isNew()) {
                 $affectedRows += $this->aFile->save($con);
             }
             $this->setFile($this->aFile);
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = CollectionFilePeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setNew(false);
             } else {
                 $affectedRows += CollectionFilePeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Esempio n. 12
0
function submit(Pieform $form, $values)
{
    global $SESSION, $new, $copy, $urlparams;
    $values['navigation'] = (int) $values['navigation'];
    $collection = Collection::save($values);
    if (!$new) {
        $SESSION->add_ok_msg(get_string('collectionsaved', 'collection'));
    }
    $collection->post_edit_redirect($new, $copy, $urlparams);
}
 /**
  *Create a new Omeka collection from a Flickr collection
  *
  *@param string $setID A unique identifier for the Flickr collection
  *from which to extract metadata
  *@param string $type The type of Flickr collection
  *@param object $f The phpFlickr interface
  *@param int $collection The ID of the collection to which to add the new item
  *@param string $ownerRole The name of the dublin core field to which to 
  *add the new omeka item or items
  *@param boolean $public Indicates whether the new omeka item should be public
  *@return int $id The collection ID of the newly created Omeka collection
  */
 public static function MakeDuplicateCollection($setID, $type = 'unknown', $f, $ownerRole = 0, $public = 1)
 {
     if ($type == "photoset") {
         $setInfo = $f->photosets_getInfo($setID);
     } else {
         if ($type == "gallery") {
             $response = $f->galleries_getInfo($setID);
             if ($response['stat'] == "ok") {
                 $setInfo = $response['gallery'];
             } else {
                 throw new Exception("Failed to retrieve gallery info from Flickr.");
             }
         } else {
             if ($type == "photostream") {
                 $response = $f->people_getInfo($setID);
                 $setInfo = array('title' => $response['realname'] . " Flickr photostream", 'description' => "<p>The Flickr photostream of " . $response['realname'] . ", who uses the Flickr username " . $response['username'] . "</p><p>" . $response['description'] . "<p>", 'username' => $response['username']);
             }
         }
     }
     $maps = array("Dublin Core" => array('Title' => array($setInfo['title']), 'Description' => array($setInfo['description'])));
     if ($ownerRole > "0") {
         $maps["Dublin Core"][$ownerRole] = array($setInfo['username']);
     }
     $Elements = array();
     $db = get_db();
     $elementTable = $db->getTable('Element');
     foreach ($maps as $elementSet => $elements) {
         foreach ($elements as $elementName => $elementTexts) {
             $element = $elementTable->findByElementSetNameAndElementName($elementSet, $elementName);
             $elementID = $element->id;
             $Elements[$elementID] = array();
             foreach ($elementTexts as $elementText) {
                 if ($elementText != strip_tags($elementText)) {
                     //element text has html tags
                     $text = $elementText;
                     $html = true;
                 } else {
                     //plain text or other non-html object
                     $text = $elementText;
                     $html = false;
                 }
                 $Elements[$elementID][] = array('text' => $text, 'html' => $html);
             }
         }
     }
     $postArray = array('Elements' => $Elements);
     if ($public) {
         $postArray['public'] = "1";
     }
     $record = new Collection();
     $record->setPostData($postArray);
     if ($record->save(false)) {
         // Succeed silently, since we're in the background
     } else {
         error_log($record->getErrors());
     }
     return $record->id;
 }
 function testFind()
 {
     //Arrange
     $collection_name = "Rad stuff";
     $test_collection = new Collection($collection_name);
     $test_collection->save();
     $test_collection_id = $test_collection->getId();
     $name = "Hello Kitty";
     $name2 = "Pokemon";
     $test_item = new Item($name, $test_collection_id);
     $test_item->save();
     $test_item2 = new Item($name2, $test_collection_id);
     $test_item2->save();
     //Act
     $result = Item::find($test_item2->getId());
     //Assert
     $this->assertEquals($test_item2, $result);
 }
Esempio n. 15
0
 function page_admin_collections_create()
 {
     if (isset($_POST['path'])) {
         $success = true;
         $collection = new Collection();
         $collection->path = $_POST['path'];
         if ($collection->validate_path()) {
             if ($collection->save()) {
                 $this->flash_success('Collection added');
             } else {
                 $this->flash_error('Unable to save collection to database.');
             }
         } else {
             $this->smarty->assign('path', $_POST['path']);
             $this->flash_error('Collection could not be added. Check path.');
         }
     }
     $this->content = './tpl/admin/collections/create.tpl';
 }
Esempio n. 16
0
use Symfony\Component\Debug\Debug;
Debug::enable();
$app = new Silex\Application();
// Set Silex debug mode in $app object
$app['debug'] = true;
$server = 'mysql:host=localhost;dbname=inventory';
$username = '******';
$password = '******';
$DB = new PDO($server, $username, $password);
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get('/', function () use($app) {
    return $app['twig']->render('index.html.twig', array('collections' => Collection::getAll(), 'items' => Item::getAll()));
});
$app->post('/collection', function () use($app) {
    $collection = new Collection($_POST['name']);
    $collection->save();
    return $app['twig']->render('index.html.twig', array('collections' => Collection::getAll(), 'items' => Item::getAll()));
});
$app->post('/delete_collections', function () use($app) {
    Collection::deleteAll();
    return $app['twig']->render('index.html.twig', array('collections' => Collection::getAll(), 'items' => Item::getAll()));
});
$app->post('/item', function () use($app) {
    $item = new Item($_POST['name']);
    $item->save();
    return $app['twig']->render('index.html.twig', array('collections' => Collection::getAll(), 'items' => Item::getAll()));
});
$app->post('/delete_items', function () use($app) {
    Item::deleteAll();
    return $app['twig']->render('index.html.twig', array('collections' => Collection::getAll(), 'items' => Item::getAll()));
});
 public function updateCollection()
 {
     if (!Request::ajax()) {
         return App::abort(404);
     }
     if (Input::has('id')) {
         try {
             $collection = Collection::findorFail((int) Input::get('id'));
         } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {
             return App::abort(404);
         }
         $message = 'has been updated successful.';
     } else {
         $collection = new Collection();
         $message = 'has been created successful.';
     }
     if (Input::has('name')) {
         $collection->name = Input::get('name');
         $collection->short_name = Str::slug($collection->name);
     }
     if (Input::has('type_id')) {
         $collection->type_id = Input::get('type_id');
     }
     if (Input::has('on_screen')) {
         $collection->on_screen = (int) Input::get('on_screen');
     }
     $pass = $collection->valid();
     if ($pass->passes()) {
         $collection->save();
         return ['status' => 'ok', 'message' => 'Collection <b>' . $collection->name . '</b> ' . $message, 'data' => $collection];
     }
     $message = '';
     $arrErr = $pass->messages()->all();
     foreach ($arrErr as $value) {
         $message .= "{$value}\n";
     }
     return ['status' => 'error', 'message' => $message];
 }
Esempio n. 18
0
 /**
  * Create a new collection from a simple raw title.
  *
  * @param string $title
  * @return Collection
  */
 private function _createCollectionFromTitle($title)
 {
     $collection = new Collection();
     $collection->save();
     update_collection($collection, array(), array('Dublin Core' => array('Title' => array(array('text' => $title, 'html' => false)))));
     return $collection;
 }
 public function doRestCreate($data)
 {
     $images = $data['images'];
     $imagesResponse = array();
     //returned to client to inform about new related images
     $image_ids = array();
     //used to assign related images
     foreach ($images as $image) {
         $image_ids[] = $image['id'];
         $img = array();
         $img['id'] = $image['id'];
         $img['name'] = $image['text'];
         $imagesResponse[] = $img;
     }
     $model = new Collection();
     $model->attributes = $data;
     if (!empty($images)) {
         $model->images = $image_ids;
     } else {
         $model->images = array();
     }
     //additional afterSave logic in Model file
     if ($model->save()) {
         header('success', true, 200);
         echo json_encode(array('data' => array('success' => true, strtolower(get_class($model)) => $model->attributes, 'images' => $imagesResponse)));
         exit;
     } else {
         header('error', true, 400);
         $errors = $model->getErrors();
         echo json_encode(array('success' => false, 'message' => $errors, 'errorCode' => '400'));
         exit;
     }
 }
<?php

require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/conf.php';
require __DIR__ . '/database.php';
require __DIR__ . '/shopify_functions.php';
require __DIR__ . '/models/Collection.php';
$collections = get_all_collections();
foreach ($collections['collections'] as $collection) {
    $c = new Collection();
    $c->name = $collection['title'];
    $c->shopify_id = $collection['id'];
    $c->save();
    echo 'Collection "' . $collection['title'] . '" has been fetched. <br>';
}