/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $zone = new Zone();
     $zone->name = Input::get('name');
     $zone->save();
     return Redirect::to('zone');
 }
示例#2
0
 public function actionCreate()
 {
     $model = new Zone();
     if (isset($_POST['Zone'])) {
         $model->attributes = $_POST['Zone'];
         if ($model->validate() && $model->save()) {
             $this->redirect(array('index'));
         }
     }
     $statusOptions = array(0 => Yii::t('common', 'Disabled'), 1 => Yii::t('common', 'Enabled'));
     $countries = CHtml::listData(Country::model()->findAll(), 'country_id', 'name');
     $this->render('create', array('model' => $model, 'statusOptions' => $statusOptions, 'countries' => $countries));
 }
示例#3
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Zone();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Zone'])) {
         $model->attributes = $_POST['Zone'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
示例#4
0
 public function actionCreate()
 {
     $model = new Zone();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Zone'])) {
         $model->attributes = $_POST['Zone'];
         if ($model->save()) {
             Flashes::addInfoFlash(Yii::t('amo', 'Zone created successfully'));
             $this->redirect(array('view', 'id' => $model->zid));
         } else {
             Flashes::addErrorFlash(Yii::t('amo', 'Could not create the zone.') . '  ' . Yii::t('amo', 'Please, try again later.'));
         }
     }
     $this->render('create', array('model' => $model));
 }
示例#5
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->aZone !== null) {
             if ($this->aZone->isModified() || $this->aZone->isNew()) {
                 $affectedRows += $this->aZone->save($con);
             }
             $this->setZone($this->aZone);
         }
         if ($this->aRoom !== null) {
             if ($this->aRoom->isModified() || $this->aRoom->isNew()) {
                 $affectedRows += $this->aRoom->save($con);
             }
             $this->setRoom($this->aRoom);
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = ZoneHasRoomPeer::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 += ZoneHasRoomPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
示例#6
0
文件: create.php 项目: slijm/e107dkp
require_once e_PLUGIN . "e107dkp/includes/parsers/" . $_POST['parser'] . "/Parser.php";
require_once e_PLUGIN . "e107dkp/includes/models/Member.php";
global $ns;
$parser = new Parser($_POST['raidlog']);
// Report new members created.
$text .= "<h2>Raid Log Parse Report</h2>";
$text .= "<h3>Attendee Parsing Messages</h3><ul style=\"list-style: none;\">";
$attendees = array();
foreach ($parser->getAttendees() as $attendee) {
    $member = Member::loadByName($attendee->name);
    if (!$member) {
        $member = new Member($attendee->name);
        $member->save();
        $text .= "<li>The attendee, " . $member->getName() . ", has not been seen before. A new record has been created.</li>";
        $attendees[] = $member;
    } else {
        $attendees[] = $member;
    }
}
$text .= "</ul>";
$text .= "<h3>Zone Parsing Messages</h3><ul style=\"list-style: none;\">";
$zone = Zone::loadByName($parser->getZone());
if ($zone == false) {
    $zone = new Zone($parser->getZone());
    $zone->save();
    $text .= "<p>The zone, " . $zone->getName() . ", has not been seen before. A new record has been created.</p>";
}
$text .= "</ul>";
$text = "<div style=\"text-align: center;\">" . $text . "</div>";
$ns->tableRender("<a href=\"admin_e107dkp.php\">Main Menu</a> -> <a href=\"" . e_SELF . "\">Raid Management</a> -> Raid Creation Results", $text);
示例#7
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->aZoneRelatedByParentZone !== null) {
             if ($this->aZoneRelatedByParentZone->isModified() || $this->aZoneRelatedByParentZone->isNew()) {
                 $affectedRows += $this->aZoneRelatedByParentZone->save($con);
             }
             $this->setZoneRelatedByParentZone($this->aZoneRelatedByParentZone);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = ZonePeer::ID;
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = ZonePeer::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->setId($pk);
                 //[IMV] update autoincrement primary key
                 $this->setNew(false);
             } else {
                 $affectedRows += ZonePeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         if ($this->collSubscriptions !== null) {
             foreach ($this->collSubscriptions as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->collZonesRelatedByParentZone !== null) {
             foreach ($this->collZonesRelatedByParentZone as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->collZoneHasRooms !== null) {
             foreach ($this->collZoneHasRooms as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 public function getRows($pq)
 {
     $rows = $pq->find("table[bgcolor='#ffccff'] tr[bgcolor='#ccffff']");
     $n = count($rows);
     echo 'Jumlah propinsi: ' . $n . " \n";
     $count = 0;
     foreach ($rows as $value) {
         $count++;
         $row = pq($value);
         $kolom_provinsi = $row->find('td:eq(1) > a');
         $nama_provinsi = $kolom_provinsi->text();
         $link_provinsi = str_replace(' ', '%20', self::NomorNetKodePosBaseUrl . $kolom_provinsi->attr('href')) . '&perhal=1000';
         echo sprintf("Memproses propinsi %d dari %d\n", $count, $n);
         echo sprintf("Propinsi: %s Link: %s\n", $nama_provinsi, $link_provinsi);
         $province = Province::model()->findByAttributes(array('name' => $nama_provinsi));
         if (!$province instanceof Province) {
             $province = new Province();
             $province->name = $nama_provinsi;
             if (!$province->save()) {
                 throw new CException('Cannot save province');
             }
         }
         $countdistrict = 0;
         $pqDist = phpQuery::newDocumentHtml($this->getContents($link_provinsi));
         $rowsDist = $pqDist->find("table[bgcolor='#ffccff'] tr[bgcolor='#ccffff']");
         $nDist = count($rowsDist);
         $countDist = 0;
         foreach ($rowsDist as $valueDist) {
             $countDist++;
             $rowDist = pq($valueDist);
             switch ($rowDist->find('td:eq(2)')->text()) {
                 case 'Kota':
                     $tipeDist = 'kota';
                     break;
                 default:
                 case 'Kab.':
                     $tipeDist = 'kabupaten';
                     break;
             }
             $kolomDist = $rowDist->find('td:eq(3) > a');
             $namaDist = $kolomDist->text();
             $linkDist = str_replace(' ', '%20', self::NomorNetKodePosBaseUrl . $kolomDist->attr('href')) . '&perhal=1000';
             echo sprintf("Memproses distrik " . $province->name . " %d dari %d\n", $countDist, $nDist);
             echo sprintf("Distrik: %s Link: %s\n", $namaDist, $linkDist);
             $distrik = District::model()->findByAttributes(array('name' => $namaDist, 'province_id' => $province->id, 'type' => $tipeDist));
             if (!$distrik instanceof District) {
                 $distrik = new District();
                 $distrik->name = $namaDist;
                 $distrik->type = $tipeDist;
                 $distrik->province_id = $province->id;
                 if (!$distrik->save()) {
                     throw new CException('Cannot save district');
                 }
             }
             $pqZone = phpQuery::newDocumentHtml($this->getContents($linkDist));
             $rowsZone = $pqZone->find("table[bgcolor='#ffccff'] tr[bgcolor='#ccffff']");
             $nZone = count($rowsZone);
             $countZone = 0;
             foreach ($rowsZone as $valueZone) {
                 $countZone++;
                 $rowZone = pq($valueZone);
                 $kolomZone = $rowZone->find('td:eq(4) > a');
                 $namaZone = $kolomZone->text();
                 $linkZone = str_replace(' ', '%20', self::NomorNetKodePosBaseUrl . $kolomZone->attr('href')) . '&perhal=1000';
                 echo sprintf("Memproses zone  %d dari %d\n", $countZone, $nZone);
                 echo sprintf("zone: %s Link: %s\n", $namaZone, $linkZone);
                 $new_zone = false;
                 $zone = Zone::model()->findByAttributes(array('name' => $namaZone, 'district_id' => $distrik->id));
                 if (!$zone instanceof Zone) {
                     $zone = new Zone();
                     $zone->name = $namaZone;
                     $zone->active = 1;
                     $zone->district_id = $distrik->id;
                     if (!$zone->save()) {
                         throw new CException('Cannot save Zone');
                     }
                     $new_zone = true;
                 }
                 echo 'sukses saving zone' . "\n";
                 $countArea = 0;
                 $pqArea = phpQuery::newDocumentHtml($this->getContents($linkZone));
                 $rowsArea = $pqArea->find("table[bgcolor='#ffccff'] tr[bgcolor='#ccffff']");
                 $nArea = count($rowsArea);
                 // Let's speed up things a bit
                 $trans = Yii::app()->db->beginTransaction();
                 foreach ($rowsArea as $valueArea) {
                     $countArea++;
                     $rowArea = pq($valueArea);
                     $kolomArea = $rowArea->find('td:eq(2) > a');
                     $kolomKodePos = $rowArea->find('td:eq(1)');
                     $namaArea = $kolomArea->text();
                     $kodePos = $kolomKodePos->text();
                     $linkKodePos = str_replace(' ', '%20', self::NomorNetKodePosBaseUrl . $kolomArea->attr('href')) . '&perhal=1000';
                     $area = $new_zone ? null : Area::model()->findByAttributes(array('name' => $namaArea, 'zone_id' => $zone->id));
                     if (!$area instanceof Area) {
                         $area = new Area();
                         $area->name = $namaArea;
                         $area->postcode = $kodePos;
                         $area->zone_id = $zone->id;
                         if (!$area->save()) {
                             throw new CException('Cannot save area');
                         }
                     }
                     echo 'Sukses Saving Code Post' . "/n kode pos adalah " . $area->postcode . "\n";
                 }
                 $trans->commit();
             }
         }
     }
 }