We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26503
    • 620 Posts
    I'm ehoing that out in a snippet:


     
    echo $modx->getOption('core_path').'components/extendeduser/';
    
    $newUser = $modx->newObject('modUser');
    $newUser->fromArray(array(
        'username' => 'seconduser',
        'password' => 'password',
        'class_key' => 'extUser',
    ));
    
    $newUser->save();
    


    When I check the result:
    /var/www/vhosts/domain.com/httpdocs/core/components/extendeduser/
    



    I can open up the file containing the Sampleclass on the server:
    nano /var/www/vhosts/domain.com/httpdocs/core/components/extendeduser/extendeduser.class.php
    


    everything looks correct path-wise...
      *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

      Sean Kimball CLP, CLS.
      Technical Director / Sr. Developer | BigBlock Studios
      ._______________________________________________.
      Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
      27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
      phone/fax: 905-426-5525
      • 26503
      • 620 Posts
      What is the significance of adding the extension_packages system setting, trying to dig up some info on it, found a bug report..

      Added "serviceName" and "serviceClass" params, which can be used like:
      
      [{"experience":{"path":"++core_pathcomponents/experience/model/","serviceName":"experience","serviceClass":"Experience"}}]
      
      Which would load the "experience" package, and then load the "Experience" class from ++core_pathcomponents/experience/model/experience.class.php. serviceClass is the PHP name of the class, where serviceName relates to the filename that it is found in.
      


      What I placed in the system settings was cut and pasted from the tutorial:

      [{"extendeduser":{"path":"[[++core_path]]components/extendeduser/model/"}}]


      is it correct?
        *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

        Sean Kimball CLP, CLS.
        Technical Director / Sr. Developer | BigBlock Studios
        ._______________________________________________.
        Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
        27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
        phone/fax: 905-426-5525
        • 18373 ☆ A M B ☆
        • 3,141 Posts
        I think you're missing "model" in your getService call.


        extension_packages is for packages that always need to be loaded. What you pasted looks fine, though you're really starting to confuse me with all the different code snippets, classes and what not you're posting everywhere wink
          Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

          Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
          • 26503
          • 620 Posts
          "you're confused" wink haha...

          I had added the model/ to the getService call ... no change. but "hold the phone" I can either load [or try to load] this via the extension_packages OR the get Service in a plugin?

          the tutorial seems to indicate both are needed [which was confusing]

          -sean

          oh - also the extendeduser.class.php exists in both extendeduser/ and extendeduser/model/
            *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

            Sean Kimball CLP, CLS.
            Technical Director / Sr. Developer | BigBlock Studios
            ._______________________________________________.
            Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
            27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
            phone/fax: 905-426-5525
            • 18373 ☆ A M B ☆
            • 3,141 Posts
            I blame it being 4am right now... darn dedication to my job eh? smiley

            Maybe I'll be able to shed some light on this in the morning. For now I salute thy.
              Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

              Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
              • 26503
              • 620 Posts
              after removing the plugin and only going the system setting route - guess whats working? at least not I'm getting a "duplicate entry for key" sql error....

              seems like trying to specify this twice causes issues

              Thanks for your help Mark [it's only 10pm here wink]

              -sean
                *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

                Sean Kimball CLP, CLS.
                Technical Director / Sr. Developer | BigBlock Studios
                ._______________________________________________.
                Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
                27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
                phone/fax: 905-426-5525
                • 26503
                • 620 Posts
                Just in case anyone is following this;
                I did get the initial part working nicely, I decided that I don't actually need to extend modUser at all, if a user gets deleted, I still want the artist bio to be available, also I may need to reassign artist bios to different users.

                schema works nicely, test code adds/removes artists & their related data in other tables, the extension is created and is available - just need to turn the test code into something that actually works [as a formit hook] & figure out the upload to amazon thing.

                I've just been commenting & un-commenting sections in the snippet.test-canadianworldmusic.php as I go ...

                Here are the working files [locations are in the comments]

                The schema:
                <?xml version="1.0" encoding="UTF-8"?>
                
                <!-- server path = /var/www/vhosts/domain.com/httpdocs/devel/canadianworldmusic/_build/schema/canadianworldmusic.mysql.schema.xml -->
                
                <model package="canadianworldmusic" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
                
                	<!-- artist table definition related -->
                	<object class="ArtistAttributes" table="artist_attributes" extends="xPDOSimpleObject">
                		<field key="userkey" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="" />
                		<field key="title" dbtype="varchar" precision="255" phptype="string" null="true" />
                		<field key="banner" dbtype="varchar" precision="255" phptype="string" null="true" />
                		<field key="bio" dbtype="text" phptype="string" null="true" />
                		<field key="manger" dbtype="text" phptype="string" null="true" />
                		<field key="social" dbtype="text" phptype="string" null="true" />
                		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
                			<column key="userkey" collation="A" null="false" />
                		</index>
                		<composite alias="ArtistDiscography" class="ArtistDiscography" local="id" foreign="artistkey" cardinality="many" owner="local" />
                		<composite alias="ArtistGenremap" class="ArtistGenremap" local="id" foreign="artistkey" cardinality="many" owner="local" />
                		<composite alias="ArtistGigs" class="ArtistGigs" local="id" foreign="artistkey" cardinality="many" owner="local" />		
                		<composite alias="ArtistMedia" class="ArtistMedia" local="id" foreign="artistkey" cardinality="many" owner="local" />		
                		<composite alias="ArtistsManagers" class="ArtistsManagers" local="id" foreign="artistkey" cardinality="many" owner="local" />		
                	</object>
                	
                	
                	<!-- an artist may have many albums -->	
                	<object class="ArtistDiscography" table="artist_discography" extends="xPDOSimpleObject">
                		<field key="artistkey" dbtype="int" precision="10" phptype="integer" null="false" default="" />
                		<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
                		<field key="genrekey" dbtype="int" precision="10" phptype="integer" null="true" />
                		<field key="date" dbtype="date" phptype="date" null="false" default="0000-00-00" />
                		<field key="label" dbtype="varchar" precision="255" phptype="string" null="true" />
                		<field key="image" dbtype="text" phptype="string" null="true" />
                		<aggregate alias="ArtistAttributes" class="ArtistAttributes" local="artistkey" foreign="id" cardinality="one" owner="foreign" />
                	</object>
                	
                	
                	<!-- an artist may belong to many genres -->
                	<object class="ArtistGenremap" table="artist_genremap" extends="xPDOSimpleObject">
                		<field key="artistkey" dbtype="int" precision="10" phptype="integer" null="false" default="0" />
                		<field key="genreskey" dbtype="int" precision="10" phptype="integer" null="false" default="0" />
                		<aggregate alias="ArtistAttributes" class="ArtistAttributes" local="artistkey" foreign="id" cardinality="one" owner="foreign" />
                		<aggregate alias="ArtistGenres" class="ArtistGenres" local="genreskey" foreign="id" cardinality="one" owner="foreign" />
                	</object>
                	
                	
                	<!-- list of genre names -->
                	<object class="ArtistGenres" table="artist_genres" extends="xPDOSimpleObject">
                		<field key="genre" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
                		<aggregate alias="ArtistGenremap" class="ArtistGenremap" local="id" foreign="genreskey" cardinality="many" owner="local" />		
                	</object>
                	
                	
                	
                	<!-- artist media an artist may have many media instances -->
                	<object class="ArtistMedia" table="artist_media" extends="xPDOSimpleObject">
                		<field key="artistkey" dbtype="int" precision="10" phptype="integer" null="false" default="0" />
                		<field key="mediatypekey" dbtype="int" precision="10" phptype="integer" null="false" default="0" />
                		<field key="location" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
                		<field key="bytes" dbtype="decimal" precision="10,0" phptype="float" null="true" default="0" />
                		<aggregate alias="ArtistAttributes" class="ArtistAttributes" local="artistkey" foreign="id" cardinality="one" owner="foreign" />
                		<aggregate alias="ArtistMediatypes" class="ArtistMediatypes" local="mediatypekey" foreign="id" cardinality="one" owner="foreign" />
                	</object>
                	
                	
                	<!-- list of media types -->
                	<object class="ArtistMediatypes" table="artist_mediatypes" extends="xPDOSimpleObject">
                		<field key="label" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
                		<field key="mime" dbtype="varchar" precision="50" phptype="string" null="true" />
                		<field key="extension" dbtype="varchar" precision="5" phptype="string" null="true" />
                		<field key="rating" dbtype="enum" precision="'G','PG','A','R','X'" phptype="string" null="true" default="PG" />
                		<aggregate alias="ArtistMedia" class="ArtistMedia" local="id" foreign="artistkey" cardinality="many" owner="local" />
                	</object>
                	
                	
                	<!-- artist gigs - an artist may have many gigs -->
                	<object class="ArtistGigs" table="artist_gigs" extends="xPDOSimpleObject">
                		<field key="artistkey" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="" />
                		<field key="title" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
                		<field key="description" dbtype="text" phptype="string" null="true" />
                		<field key="venue" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
                		<field key="address" dbtype="text" phptype="string" null="true" />
                		<field key="city" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
                		<field key="province" dbtype="varchar" precision="100" phptype="string" null="true" />
                		<field key="country" dbtype="varchar" precision="100" phptype="string" null="true" default="Canada" />
                		<field key="startdate" dbtype="date" phptype="date" null="false" default="0000-00-00" />
                		<field key="enddate" dbtype="date" phptype="date" null="true" />
                		<field key="starttime" dbtype="time" phptype="string" null="true" />
                		<field key="endtime" dbtype="time" phptype="string" null="true" />
                		<aggregate alias="ArtistAttributes" class="ArtistAttributes" local="artistkey" foreign="id" cardinality="one" owner="foreign" />
                	</object>
                	
                	
                	<!-- manager info a manager may belong to many artists -->
                	<object class="ArtistsManagers" table="artists_managers" extends="xPDOSimpleObject">
                		<field key="artistkey" dbtype="int" precision="10" phptype="integer" null="false" default="0" />
                		<field key="salutation" dbtype="varchar" precision="20" phptype="string" null="true" />
                		<field key="title" dbtype="varchar" precision="255" phptype="string" null="true" />
                		<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
                		<field key="company" dbtype="varchar" precision="255" phptype="string" null="true" />
                		<field key="phone" dbtype="varchar" precision="20" phptype="string" null="true" />
                		<field key="extension" dbtype="varchar" precision="20" phptype="string" null="true" />
                		<field key="mobile" dbtype="varchar" precision="20" phptype="string" null="true" />
                		<field key="toll" dbtype="varchar" precision="20" phptype="string" null="true" />
                		<field key="fax" dbtype="varchar" precision="20" phptype="string" null="true" />
                		<field key="email" dbtype="varchar" precision="255" phptype="string" null="true" />
                		<field key="website" dbtype="varchar" precision="255" phptype="string" null="true" />
                		<field key="streetone" dbtype="varchar" precision="255" phptype="string" null="true" />
                		<field key="streettwo" dbtype="varchar" precision="255" phptype="string" null="true" />
                		<field key="city" dbtype="varchar" precision="255" phptype="string" null="true" />
                		<field key="province" dbtype="varchar" precision="255" phptype="string" null="true" />
                		<field key="country" dbtype="varchar" precision="255" phptype="string" null="true" />
                		<field key="postal" dbtype="varchar" precision="255" phptype="string" null="true" />
                		<field key="comments" dbtype="text" phptype="string" null="true" />
                		<field key="notes" dbtype="text" phptype="string" null="true" />
                		<aggregate alias="ArtistAttributes" class="ArtistAttributes" local="id" foreign="artistkey" cardinality="one" owner="foreign" />
                	</object>
                	
                	
                </model>
                


                The build script:
                <?php
                /**
                 * Build Schema script
                 *
                 * server path = /var/www/vhosts/domain.com/httpdocs/devel/canadianworldmusic/_build/build.schema.php
                 *
                **/
                
                // set_time_limit() may be disabled in some php installations [security] 
                // if so just comment out the time stuff, you don't really need it.
                $mtime = microtime();
                $mtime = explode(" ", $mtime);
                $mtime = $mtime[1] + $mtime[0];
                $tstart = $mtime;
                set_time_limit(0);
                
                 
                require_once dirname(__FILE__). '/build.config.php';
                echo dirname(__FILE__). '/build.config.php';
                include_once MODX_CORE_PATH . 'model/modx/modx.class.php';
                
                $modx= new modX();
                $modx->initialize('mgr');
                $modx->loadClass('transport.modPackageBuilder','',false, true);
                $modx->setLogLevel(modX::LOG_LEVEL_INFO);
                $modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');
                 
                
                //$root = dirname(dirname(__FILE__)).'/';
                $root = MODX_BASE_PATH;
                
                $sources = array(
                    'root' => $root,
                    'core' => $root.'core/components/canadianworldmusic/',
                    'model' => $root.'core/components/canadianworldmusic/model/',
                    'assets' => $root.'assets/components/canadianworldmusic/',
                    'schema' => $root.'devel/canadianworldmusic/_build/schema/',
                );
                
                $manager= $modx->getManager();
                $generator= $manager->getGenerator();
                
                $generator->parseSchema($sources['schema'].'canadianworldmusic.mysql.schema.xml', $sources['model']);
                 
                $mtime= microtime();
                $mtime= explode(" ", $mtime);
                $mtime= $mtime[1] + $mtime[0];
                $tend= $mtime;
                $totalTime= ($tend - $tstart);
                $totalTime= sprintf("%2.4f s", $totalTime);
                 
                echo "\nExecution time: {$totalTime}\n";
                 
                exit ();
                


                The build config:
                <?php
                /**
                 * Build config script
                 *
                 * server path = /var/www/vhosts/domain.com/httpdocs/devel/canadianworldmusic/_build/build.config.php
                 *
                 */
                
                define('MODX_BASE_PATH', dirname(dirname(dirname(dirname(__FILE__)))) . '/');
                define('MODX_CORE_PATH', MODX_BASE_PATH . 'core/');
                define('MODX_MANAGER_PATH', MODX_BASE_PATH . 'manager/');
                define('MODX_CONNECTORS_PATH', MODX_BASE_PATH . 'connectors/');
                define('MODX_ASSETS_PATH', MODX_BASE_PATH . 'assets/');
                
                // I find I get errors if I don't set these, though they are not really used. 
                define('MODX_BASE_URL', dirname(dirname(dirname(dirname(__FILE__)))) . '/');
                define('MODX_CORE_URL', MODX_BASE_URL . 'core/');
                define('MODX_MANAGER_URL', MODX_BASE_URL . 'manager/');
                define('MODX_CONNECTORS_URL', MODX_BASE_URL . 'connectors/');
                define('MODX_ASSETS_URL', MODX_BASE_URL . 'assets/');
                


                the test snippet:
                <?php
                /**
                 *
                 * server path = /var/www/vhosts/domain.com/httpdocs/devel/canadianworldmusic/core/components/canadianworldmusic/elements/snippets/snippet.setup-canadianworldmusic.php
                 *
                 *
                 * 
                **/
                 
                 
                 
                 
                 
                // some default[s]
                	$output = ''; 
                
                // install the extension in the manager so we can use it globally
                // will appear in system settings -> filter for -> extension_packages
                //	$modx->removeExtensionPackage('canadianworldmusic',"[[++core_path]]components/canadianworldmusic/model/");
                //	$modx->addExtensionPackage('canadianworldmusic',"[[++core_path]]components/canadianworldmusic/model/");
                
                // set modx to auto create any tables I may use
                	$modx->setOption(xPDO::OPT_AUTO_CREATE_TABLES, true);
                
                /*
                //or do it explicitly
                	$modx->getManager();
                	$modx->manager->createObjectContainer('ArtistsManagers');
                	$modx->manager->createObjectContainer('ArtistMediatypes');
                	$modx->manager->createObjectContainer('ArtistMedia');
                	$modx->manager->createObjectContainer('ArtistGigs');
                	$modx->manager->createObjectContainer('ArtistGenres');
                	$modx->manager->createObjectContainer('ArtistGenremap');
                	$modx->manager->createObjectContainer('ArtistDiscography');
                	$modx->manager->createObjectContainer('ArtistAttributes');
                */
                
                // some house cleaning after we test and fill our database up with junk... 	
                // example get a collection of artists and loop over it deleting as we go
                /*
                	$artists = $modx->getCollection('ArtistAttributes'); 
                	
                	foreach($artists as $artist) {
                	    $thisartist = $artist->get('id');
                	    $aname = $artist->get('title');
                		if($delartist = $modx->getObject('ArtistAttributes',$thisartist)){
                			$delartist->remove();
                			echo 'artist '.$thisartist.' '.$aname.' removed removed<BR />';
                		}else{
                			echo 'An error occurred while trying to remove the artist '.$thisartist.' '.$aname.'!<BR />';
                		}
                	   
                	}
                
                // this is far more efficient, but does not remove related data ... hmmmm 
                	$output .= $modx->removeCollection('ArtistAttributes');
                	$output .= $modx->removeCollection('ArtistsManagers');
                	$output .= $modx->removeCollection('ArtistMediatypes');
                	$output .= $modx->removeCollection('ArtistMediatypes');
                	$output .= $modx->removeCollection('ArtistMedia');
                	$output .= $modx->removeCollection('ArtistGigs');
                	$output .= $modx->removeCollection('ArtistGenres');
                	$output .= $modx->removeCollection('ArtistGenremap');
                	$output .= $modx->removeCollection('ArtistDiscography');
                */
                
                // add media types if MP3 is not found
                
                
                	if(!$modx->getObject('ArtistMediatypes',array('label'=>'MP3'))){
                
                		$mediatypes = array(
                						array('label'=>'MP3','mime'=>'application/mp3','extension'=>'.mp3','bytes'=>0,'rating'=>'G'),
                						array('label'=>'Flash Video','mime'=>'application/flash','extension'=>'.flv','bytes'=>0,'rating'=>'G'),
                						array('label'=>'Image','mime'=>'application/jpg','extension'=>'.jpg','bytes'=>0,'rating'=>'G'),
                						array('label'=>'Zip File','mime'=>'application/zip','extension'=>'.zip','bytes'=>0,'rating'=>'G'),
                						);
                		foreach ($mediatypes as $i => $row) {
                			$newmedia = $modx->newObject('ArtistMediatypes');
                			$newmedia->fromArray(array(
                				'label' => $row['label'],
                				'mime' => $row['mime'],
                				'extension' => $row['extension'],
                				'bytes' => $row['bytes'],
                				'rating' => $row['rating'],
                			));
                			$newmedia->save();
                		}
                	
                	}
                
                // add some generes if 'Bolero' is not found
                
                	if(!$modx->getObject('ArtistGenres',array('genre'=>'Bolero'))){
                		
                		$genres = array('A Capella','Acid','Acoustic','African-American','Afro','Afro Beat','Alternative','Ambient','Americana','Anime','Arabic','Asian','Avant-Garde','Bachata','Baile Funk','Balkan','Bantu','Batucada','Beat','Benga','Bhangra','Big Band','Bluegrass','Blues','Bolero','Bollywood','Bomba','Bossa Nova','Brass','Brazilian','Breakbeat','Burlesque','Cabaret','Cajun','Calypso','Candombe','Celtic','Charanga','Children\'s Music','Chinese','Choral','Classical','Cuban','Cumbia','Dance','Danzon','Descarga','Disco','Downtempo','Drum And Bass','Dub','East European','Egypcian','Electronic','Experimental','Fado','Flamenco','Folk','Forro','Freestyle','Funk','Fusion','Global Beats','Global Fusion','Gospel','Greek','Groove','Guaguanco','Gypsy','Habanera','High Life','Hip Hop','House','Impro','Indian','Indigenous','Industrial','Instrumental','Irish','Japanese','Jazz','Jewish','Jive','Karnatic','Kurdish','Latin','Lounge','Mambo','Mariachi','Mediterranean','Merengue','Motown','Native American','New Age','Nubian','Oriental','Percussion','Persian','Plena','Polka','Polyphony','Pop','Punk','Ragga','Rancheras','Rap','Rapso','Reggae','Reggaeton','Ritual','Rock','Roots','Rumba','Russian','Sacred','Salsa','Samba','Scandinavian','Sega','Sephardic','Ska','Soca','Son','Son Cubano','Son Jarocho','Songwriter','Soukous','Soul','South African','Steel Band','Sufi','Tango','Tarantella','Techno','Throat Singing','Tibetan','Timba','Traditional','Trance','Tribal','Tropicalisimo','Turkish','Urban','Vaudeville','Vocal','World','World Jazz','Yiddish','None of the above');
                		
                		foreach ($genres as $genre) {
                			$addgenre = $modx->newObject('ArtistGenres');
                			$addgenre->fromArray(array(
                				'genre' => $genre,
                			));
                			$addgenre->save();
                		}
                	}
                
                
                
                
                /*
                // test insert an artist
                	$mysocial = array('facebook' => 'http://facebook.com', 'twitter' => 'http://www.twitter.com', 'youtube' => 'http://youtube.com');
                	$mysocial = json_encode($mysocial);
                	$newarst = $modx->newObject('ArtistAttributes');
                	$newarst->fromArray(array(
                		'userkey' => '1',
                		'title' => 'Nashville Pussy',
                		'banner' => 'My Pic',
                		'bio' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu metus vel nunc suscipit vehicula.',
                		'manger' => '2',
                		'social' => $mysocial,
                		'phone' => '+1.000-000-0000',
                		'company' => 'Company Name',
                	));
                	$newarst->save();
                	$artistkey = $newarst->getPrimaryKey() . "";
                
                
                
                
                
                // test add some artists albums
                	$album = array('Album 1','album 2','album 3','album 4','album 5','album 6','album 7');
                	foreach ($album as $record) {
                		$newalbm = $modx->newObject('ArtistDiscography');
                		$newalbm->fromArray(array(
                			'artistkey' => $artistkey,
                			'name' => $record,
                			'genrekey' => '1',
                			'date' => '2010-10-10',
                			'label' => 'Capitol',
                			'image' => 'http://www.mylocaton',
                		));
                		$newalbm->save();
                	}
                
                
                
                
                
                // test add them to genres 
                $genreid = array(22,65,18,5,6,09,34,65,72,121);
                	foreach ($genreid as $gid) {
                		$newgenre = $modx->newObject('ArtistGenremap');
                		$newgenre->fromArray(array(
                			'artistkey' => $artistkey,
                			'genreskey' => $gid,
                		));
                		$newgenre->save();
                	}
                
                
                
                
                // test map some media types 
                	$files = array(
                				array('artistkey'=>$artistkey,'mediatypekey'=>1,'location'=>'http://www.somewhere.com/this/directory/file.zip'),
                				array('artistkey'=>$artistkey,'mediatypekey'=>2,'location'=>'http://www.somewhere.com/this/directory/file.zip'),
                				array('artistkey'=>$artistkey,'mediatypekey'=>3,'location'=>'http://www.somewhere.com/this/directory/file.zip'),
                				array('artistkey'=>$artistkey,'mediatypekey'=>4,'location'=>'http://www.somewhere.com/this/directory/file.zip'),
                				array('artistkey'=>$artistkey,'mediatypekey'=>1,'location'=>'http://www.somewhere.com/this/directory/file.zip'),
                				array('artistkey'=>$artistkey,'mediatypekey'=>2,'location'=>'http://www.somewhere.com/this/directory/file.zip'),
                				);
                	
                	foreach ($files as $i => $row) {
                		$newfile = $modx->newObject('ArtistMedia');
                		$newfile->fromArray(array(
                			'artistkey' => $row['artistkey'],
                			'mediatypekey' => $row['mediatypekey'],
                			'location' => $row['location'],
                		));
                		$newfile->save();
                	}
                
                
                
                
                // test add some gigs types 
                	$gigs = array(
                				array('artistkey'=>$artistkey,'title'=>'Band WarZ','description'=>'This is the description','venue'=>'The Filmore'),
                				array('artistkey'=>$artistkey,'title'=>'Band WarS','description'=>'This is the description','venue'=>'The Tanglewood'),
                				array('artistkey'=>$artistkey,'title'=>'Gig WarZ','description'=>'This is the description','venue'=>'The Spruce Villa'),
                				);
                	
                	foreach ($gigs as $i => $row) {
                		$newgig = $modx->newObject('ArtistGigs');
                		$newgig->fromArray(array(
                			'artistkey' => $row['artistkey'],
                			'title' => $row['title'],
                			'description' => $row['description'],
                			'venue' => $row['venue'],
                		));
                		$newgig->save();
                	}
                
                
                // test adding a manager & updating the artist.
                	$newmanager = $modx->newObject('ArtistsManagers');
                	$newmanager->fromArray(array(
                		'artistkey' => $artistkey,
                		'salutation' => 'Mr.',
                		'name' => 'Stan Lee',
                		'title' => 'Talent Scout',
                		'Company' => 'Marvel',
                	));
                	$newmanager->save();
                
                
                /*
                //example delete artist acton make sure it removes everything but genres and media types
                	if($delarst = $modx->getObject('ArtistAttributes',11)){
                		$delarst->remove();
                		$output .= 'artist removed removed<BR />';
                	}else{
                		$output .= 'An error occurred while trying to remove the artist!<BR />';
                	}
                	
                //example delete genre acton make sure it removes the genres from the genremap
                	if($delgenre = $modx->getObject('ArtistGenres',22)){
                		$delgenre->remove();
                		$output .= 'genre removed removed<BR />';
                	}else{
                		$output .= 'An error occurred while trying to remove the genre!<BR />';
                	}
                	
                //example delete manager acton, make sure it does not delete the artist
                	if($delmanager = $modx->getObject('ArtistsManagers',3)){
                		$delmanager->remove();
                		$output .= 'manager removed removed<BR />';
                	}else{
                		$output .= 'An error occurred while trying to remove the manager!<BR />';
                	}
                */
                
                
                
                // test update an artist 
                	$mysocial = array('facebook' => 'http://facebook.com/myartistname', 'twitter' => 'http://www.twitter.com/myartistname', 'youtube' => 'http://youtube.com/myartistname');
                	$mysocial = json_encode($mysocial);
                	$newarst = $modx->getObject('ArtistAttributes', array('id' => 3));
                	$newarst->fromArray(array(
                		'userkey' => '1',
                		'title' => 'Black Sabbath',
                		'banner' => 'The banner image',
                		'bio' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu metus vel nunc suscipit vehicula.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu metus vel nunc suscipit vehicula.',
                		'manger' => '4',
                		'social' => $mysocial,
                		'phone' => '+1.905-725-8547',
                	));
                	$newarst->save();
                	$artistkey = $newarst->getPrimaryKey() . "";
                	$output .= $artistkey;
                
                
                
                
                // return  some counts
                $output .= '<BR>Artists = '.$modx->getCount('ArtistAttributes').'<BR>';
                $output .= '<BR>Managers = '.$modx->getCount('ArtistsManagers').'<BR>';
                $output .= '<BR>Media Types = '.$modx->getCount('ArtistMediatypes').'<BR>';
                $output .= '<BR>Artist Media = '.$modx->getCount('ArtistMedia').'<BR>';
                $output .= '<BR>Artist Gigs = '.$modx->getCount('ArtistGigs').'<BR>';
                $output .= '<BR>Genres = '.$modx->getCount('ArtistGenres').'<BR>';
                $output .= '<BR>Mapped Genres = '.$modx->getCount('ArtistGenremap').'<BR>';
                $output .= '<BR>Discographys = '.$modx->getCount('ArtistDiscography').'<BR>';
                
                
                
                return $output;
                


                the manager snippet:
                 // set this up in a snippet in modx manager
                  $base_path = $modx->getOption('core_path').'components/canadianworldmusic/elements/snippets/';
                  $o = '';
                  $f = $base_path.'snippet.setup-canadianworldmusic.php';
                  if (file_exists($f)) {
                  	 $o = include $f;
                  } else {
                  	 $modx->setLogTarget('ECHO');
                  	 $modx->log(modX::LOG_LEVEL_ERROR,'snippet.setup-canadianworldmusic.php not found at: '.$f);
                  }
                  return $o;
                
                  *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

                  Sean Kimball CLP, CLS.
                  Technical Director / Sr. Developer | BigBlock Studios
                  ._______________________________________________.
                  Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
                  27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
                  phone/fax: 905-426-5525
                  • 26503
                  • 620 Posts
                  Still testing, trying to update & insert records here:

                  By all I can figure, this should work

                  // test update an artist 
                  	$mysocial = array('facebook' => 'http://facebook.com/myartistname', 'twitter' => 'http://www.twitter.com/myartistname', 'youtube' => 'http://youtube.com/myartistname');
                  	$mysocial = json_encode($mysocial);
                  	
                  	$newartist = $modx->getObject('ArtistAttributes',2);
                  	$newartist->fromArray(array(
                  		'userkey' => '1',
                  		'title' => 'The Asteroids Galaxy Tour',
                  		'banner' => 'The banner image is here',
                  		'bio' => 'Lorem ipsum dolor.',
                  		'manger' => '0',
                  		'social' => $mysocial,
                  		'phone' => '+1.905-725-8547',
                  	));
                  	
                  	$newalbm = $modx->newObject('ArtistDiscography');
                  	$newalbm->set('name','blahblah');
                  	$newalbm->set('genrekey','1');
                  	$newalbm->set('date','2010-10-10');
                  	$newalbm->set('label','Capitol');
                  	$newalbm->set('image','http://www.mylocaton');
                  
                  	$newartist->addOne($newalbm);
                  	
                  	$newartist->save();
                  


                  it WILL update the artist, it will NOT add an album though... this code is correct ~ must be something wrong with my schema?
                    *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

                    Sean Kimball CLP, CLS.
                    Technical Director / Sr. Developer | BigBlock Studios
                    ._______________________________________________.
                    Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
                    27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
                    phone/fax: 905-426-5525
                    • 18373 ☆ A M B ☆
                    • 3,141 Posts
                    Use
                    $newartist->addMany($newalbm)

                    instead of
                    $newartist->addOne($newalbm)


                    The difference between those two is not in the amount of objects you are adding, but the cardinality defined in the schema. If it's a one->one cardinatility you use addOne, if it's a one->many cardinality you use addMany.

                    In this case you're using a one->many relationship, so use addMany.
                      Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                      Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                      • 26503
                      • 620 Posts
                      Thanks again Mark, funny ~ I read the whole xPDO docs section this afternoon & remember seeing that point, just didn't register I guess!

                      Anyway - thanks, this now works perfectly :
                      
                      // test update an artist 
                      	$mysocial = array('facebook' => 'http://facebook.com/myartistname', 'twitter' => 'http://www.twitter.com/myartistname', 'youtube' => 'http://youtube.com/myartistname');
                      	$mysocial = json_encode($mysocial);
                      	
                      	// the artist
                      	$newartist = $modx->getObject('ArtistAttributes',4);
                      	$newartist->fromArray(array(
                      		'userkey' => '1',
                      		'title' => 'The Asteroids Galaxy Tour',
                      		'banner' => 'The banner image is here',
                      		'bio' => 'Lorem ipsum dolor.',
                      		'manger' => '1',
                      		'social' => $mysocial,
                      	));
                      	
                      	// add an album
                      	$newalbm = $modx->newObject('ArtistDiscography');
                      	$newalbm->fromArray(array(
                      		'name' => 'Juice',
                      		'genrekey' => '1',
                      		'date' => '2010-10-10',
                      		'label' => 'Capitol',
                      		'image' => 'http://www.mylocaton',
                      		));
                      	$newartist->addMany($newalbm);
                      	
                      	// add some gigs
                      	$gigs = array(
                      				array('title'=>'Band WarZ','description'=>'This is the description','venue'=>'The Filmore'),
                      				array('title'=>'Band WarS','description'=>'This is the description','venue'=>'The Tanglewood'),
                      				array('title'=>'Gig WarZ','description'=>'This is the description','venue'=>'The Spruce Villa'),
                      				);
                      	foreach ($gigs as $i => $row) {
                      		$newgig = $modx->newObject('ArtistGigs');
                      		$newgig->fromArray(array(
                      			'title' => $row['title'],
                      			'description' => $row['description'],
                      			'venue' => $row['venue'],
                      		));
                      		$newartist->addMany($newgig);
                      	}
                      	
                      	// add a manager
                      	$newmanager = $modx->newObject('ArtistsManagers');
                      	$newmanager->fromArray(array(
                      		'salutation' => 'Mr.',
                      		'name' => 'Stan Lee',
                      		'title' => 'Talent Scout',
                      		'Company' => 'Marvel',
                      	));
                      	$newartist->addMany($newmanager);
                      	
                      	// add some media types
                      	$files = array(
                      				array('mediatypekey'=>1,'location'=>'http://www.somewhere.com/this/directory/file.zip'),
                      				array('mediatypekey'=>2,'location'=>'http://www.somewhere.com/this/directory/file.zip'),
                      				array('mediatypekey'=>3,'location'=>'http://www.somewhere.com/this/directory/file.zip'),
                      				array('mediatypekey'=>4,'location'=>'http://www.somewhere.com/this/directory/file.zip'),
                      				array('mediatypekey'=>1,'location'=>'http://www.somewhere.com/this/directory/file.zip'),
                      				array('mediatypekey'=>2,'location'=>'http://www.somewhere.com/this/directory/file.zip'),
                      				);
                      	
                      	foreach ($files as $i => $row) {
                      		$newfile = $modx->newObject('ArtistMedia');
                      		$newfile->fromArray(array(
                      			'mediatypekey' => $row['mediatypekey'],
                      			'location' => $row['location'],
                      		));
                      		$newartist->addMany($newfile);
                      	}
                      	
                      	
                      	// map some genres 
                      	$genreid = array(22,65,18,5,6,09);
                      	foreach ($genreid as $gid) {
                      		$newgenre = $modx->newObject('ArtistGenremap');
                      		$newgenre->fromArray(array(
                      			'genreskey' => $gid,
                      		));
                      		$newartist->addMany($newgenre);
                      	}
                      	
                      	
                      	// save the artist
                      	$newartist->save();
                      
                      
                        *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

                        Sean Kimball CLP, CLS.
                        Technical Director / Sr. Developer | BigBlock Studios
                        ._______________________________________________.
                        Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
                        27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
                        phone/fax: 905-426-5525