Exemple #1
0
    if (libxml_get_errors()) {
        echo "Errors in {$abbr}-schools.xml, skipping.\n";
        continue;
    }
    foreach ($schools->school as $school) {
        if ($obj = SchoolQuery::create()->filterBySlug($school->Slug)->findOne()) {
            if ($bookstoreType != $obj->getBookstoreType()) {
                echo "Tried to add a school for a slug that already exists, skipping: {$school->Slug}\n";
                continue;
            } else {
                $obj->setTouched(true)->save();
            }
        }
        $query = SchoolQuery::create()->filterByBookstoreType($bookstoreType);
        $obj = $query->filterBySlug($school->Slug)->findOne();
        if (!$obj) {
            $obj = new School();
            $obj->setSlug($school->Slug)->setBookstoreType($bookstoreType);
            echo "Adding new school: {$school->Slug}\n";
        }
        $obj->setName(html_entity_decode($school->Name))->setShortName(html_entity_decode($school->ShortName))->setSlug($school->Slug)->setState($school->State)->setZip($school->Zip)->setLocalTax($school->LocalTax)->setAmazonTag($school->AmazonTag ?: 'txtbks-20')->setSubdomain($school->Subdomain)->setBId($school->BId)->setTouched(1)->setEnabled(1)->save();
    }
}
$untouchedSchools = SchoolQuery::create()->filterByTouched(false)->find();
foreach ($untouchedSchools as $school) {
    if ($school->getEnabled()) {
        echo "Disabling " . $school->getSlug() . "\n";
        $school->setEnabled(0)->save();
    }
}
require_once __DIR__ . '/json.php';
class School extends BaseMongoRecord
{
  protected $has_many=array('Student');
  /** 
       Can add more targets with-> $has_many=array('ClsA','ClsB',...)
       below methods are genereated automaticlly:
       $this->getStudents();//return MongoRecordIterator
       $this->setStudents($stuarray);//parm is array of students,return $this
       $this->createStudent();//new student and return it,return student
       $this->addStudent($stu);//parm is student instante,return $this
       $this->removeStudent($stu);//parm is student instant,return $this
    */
}
$school=new School();
$school->setName('fooschool');

$school->createStudent()->setName("foostu1")->save();
$school->createStudent()->setName("foostu2")->save();
$school->save();

$students=$school->getStudents();//=>MongoRecordIterator
var_dump($students->count());//=>2
foreach($students as $student)
  {
    var_dump($student);
  }

$student=new Student();
$student->setName('foostu3')->save();
$school->addStudent($student);