public function testAutoloading()
 {
     $kirby = new Kirby(array('debug' => true));
     $kirby->roots->content = TEST_ROOT_ETC . DS . 'content';
     $kirby->roots->site = TEST_ROOT_ETC . DS . 'site';
     // autoload all models
     $kirby->models();
     $site = new Site($kirby);
     $a = $site->find('a');
     $this->assertInstanceOf('Page', $a);
     $this->assertInstanceOf('APage', $a);
     $this->assertEquals('test', $a->customTestMethod());
     $b = $site->find('b');
     $this->assertInstanceOf('Page', $b);
     $this->assertFalse(is_a($b, 'APage'));
     $this->assertFalse('test' == $b->customTestMethod());
 }
 public function update()
 {
     $site = Site::find(Input::get('site_id'));
     $selected_zone = Input::get('selected_zone');
     if ($selected_zone) {
         $site->zone_id = $selected_zone;
         $site->save();
     }
     return Redirect::to('siteZone/' . $site->id);
 }
 public function update()
 {
     $site = Site::find(Input::get('site_id'));
     $users = User::all();
     foreach ($users as $key => $value) {
         $user_access = Input::get('user_access_' . $value->rfid);
         if ($user_access) {
             if ($site->GivesAccessToUser($value->rfid) == 'Denied') {
                 DB::table('site_user')->insert(array('user_id' => $value->rfid, 'site_id' => $site->id));
             } else {
                 DB::table('site_user')->where('user_id', '=', $value->rfid)->where('site_id', '=', $site->id)->delete();
             }
         }
     }
     return Redirect::to('siteUser/' . $site->id);
 }
 public static function save()
 {
     $params = $_POST;
     $v = new Valitron\Validator($params);
     $v->rule('required', 'content');
     $v->rule('lengthMin', 'content', 1);
     $v->rule('required', 'site-id');
     $v->rule('numeric', 'site-id');
     if ($v->validate()) {
         $kommentti = new Kommentti(array('comment_content' => $params['content'], 'site_id' => $params['site-id'], 'kayttaja_id' => $_SESSION['user']));
         $kommentti->save();
         Redirect::to('/site/show_site/' . $params['site-id'], array('message' => 'Kommentti lisätty'));
     } else {
         $site = Site::find($params['site-id']);
         $kommentit = Kommentti::getAllComments($params['site-id']);
         View::make('site/show_site.html', array('site' => $site, 'kommentit' => $kommentit, 'errors' => $v->errors()));
     }
 }
 public function startCreateWebsiteApp()
 {
     $start['User'] = Auth::user();
     //$start['Site'] = new Site();
     $start['Website'] = new Website();
     $start['Template'] = new Template();
     if (!Session::has('siteId')) {
         return response()->json($start);
     }
     if ($site = Site::find(Session::get('siteId'))) {
         $siteInfo = $this->setup->getWebsiteInfoFrom($site->website_type);
         if (isset($site->all_template_id)) {
             $start['Template'] = AllTemplate::find($site->all_template_id);
         }
         if (isset($site->website_id)) {
             $class = $site->website_type;
             $start['Website'] = $siteInfo['website']::find($site->website_id);
         }
     }
     $start['Site'] = $site;
     return Response::json($start);
 }
Exemple #6
0
 public function actionRefresh()
 {
     $request = Yii::app()->getRequest();
     $sid = trim($request->getParam("sid"));
     if ($sid) {
         try {
             //获取url
             $site = new Site();
             $row = $site->find('sid=:sid', array(':sid' => $sid));
             $domain = new Domain();
             $row = $domain->find('id=:id', array(':id' => $row['dmid']));
             $url = 'www.' . $row['name'];
             //获取seo信息
             $seo = new Seotool($url);
             $info['alexa'] = (int) $seo->getAlexaRank();
             $info['google'] = (int) $seo->getIndexedGoogle();
             $info['baidu'] = (int) $seo->getIndexedBaidu();
             $info['pr'] = (int) $seo->getPagerank();
             $info['sid'] = $sid;
             //更新数据
             $res = new Seo();
             $row = $res->find('sid=:sid', array(':sid' => $sid));
             if ($row) {
                 $res = new Seo();
                 $res->_pk = $row['id'];
                 $res->_attributes = $info;
                 $res->setIsNewRecord(false);
                 $res->update();
             } else {
                 $res = new Seo();
                 $res->_attributes = $info;
                 $res->insert();
             }
             $this->redirect(array('list'));
         } catch (CDbException $e) {
             throw CDbException($e);
         }
     }
 }
 /**
  * test HABM operations without clobbering existing records #275
  *
  * @return void
  */
 public function testHABTMKeepExisting()
 {
     $this->loadFixtures('Site', 'Domain', 'DomainsSite');
     $Site = new Site();
     $results = $Site->find('count');
     $expected = 3;
     $this->assertEquals($expected, $results);
     $data = $Site->findById(1);
     // include api.cakephp.org
     $data['Domain'] = array('Domain' => array(1, 2, 3));
     $Site->save($data);
     $Site->id = 1;
     $results = $Site->read();
     $expected = 3;
     // 3 domains belonging to cakephp
     $this->assertEquals($expected, count($results['Domain']));
     $Site->id = 2;
     $results = $Site->read();
     $expected = 2;
     // 2 domains belonging to markstory
     $this->assertEquals($expected, count($results['Domain']));
     $Site->id = 3;
     $results = $Site->read();
     $expected = 2;
     $this->assertEquals($expected, count($results['Domain']));
     $results['Domain'] = array('Domain' => array(7));
     $Site->save($results);
     // remove association from domain 6
     $results = $Site->read();
     $expected = 1;
     // only 1 domain left belonging to rchavik
     $this->assertEquals($expected, count($results['Domain']));
     // add deleted domain back
     $results['Domain'] = array('Domain' => array(6, 7));
     $Site->save($results);
     $results = $Site->read();
     $expected = 2;
     // 2 domains belonging to rchavik
     $this->assertEquals($expected, count($results['Domain']));
     $Site->DomainsSite->id = $results['Domain'][0]['DomainsSite']['id'];
     $Site->DomainsSite->saveField('active', true);
     $results = $Site->Domain->DomainsSite->find('count', array('conditions' => array('DomainsSite.active' => true)));
     $expected = 5;
     $this->assertEquals($expected, $results);
     // activate api.cakephp.org
     $activated = $Site->DomainsSite->findByDomainId(3);
     $activated['DomainsSite']['active'] = true;
     $Site->DomainsSite->save($activated);
     $results = $Site->DomainsSite->find('count', array('conditions' => array('DomainsSite.active' => true)));
     $expected = 6;
     $this->assertEquals($expected, $results);
     // remove 2 previously active domains, and leave $activated alone
     $data = array('Site' => array('id' => 1, 'name' => 'cakephp (modified)'), 'Domain' => array('Domain' => array(3)));
     $Site->create($data);
     $Site->save($data);
     // tests that record is still identical prior to removal
     $Site->id = 1;
     $results = $Site->read();
     unset($results['Domain'][0]['DomainsSite']['updated']);
     unset($activated['DomainsSite']['updated']);
     $this->assertEquals($activated['DomainsSite'], $results['Domain'][0]['DomainsSite']);
 }
 public static function edit($id)
 {
     $site = Site::find($id);
     View::make('site/edit_site.html', array('site' => $site));
 }
 public function updateSiteRelay($site_id, $relay_id, $status)
 {
     $site = Site::find($site_id);
     if (!$site->Zone) {
         $site_relays = $site->Relays;
         if (!$site_relays->count()) {
             for ($i = 0; $i < 6; $i++) {
                 Relay::create(array('site_id' => $site_id, 'relay_id' => $i, 'status' => 'False'));
             }
         }
         $site_relay = Relay::withSiteAndRelay($site_id, $relay_id)->get()->first();
         $relay = Relay::find($site_relay->id);
         if ($status == 0) {
             $statusCommand = 0;
             $statusString = 'Off';
             $status = 'False';
         } else {
             $statusCommand = 1;
             $statusString = 'On';
             $status = 'True';
         }
         $relay->status = $status;
         $relay->save();
         $entry = new Record();
         $entry->site_id = $site_id;
         $entry->site_name = $site->name;
         $entry->switch = $relay->relay_id;
         $entry->status = $statusString;
         $entry->command = $statusCommand;
         $entry->save();
     } else {
         $message = 'This site is zoned. Please update changes to the zone!';
         Session::put('message', $message);
     }
 }
 public function relays($site_id)
 {
     $site = Site::find($site_id);
     $relays = $site->Relays->toJson();
     return $relays;
     // Response::json($relays);
 }
 public function updatePermissions()
 {
     $user = User::find(Input::get('rfid'));
     $sites = Site::all();
     foreach ($sites as $key => $value) {
         $selected_site = Input::get('selected_site_' . $value->id);
         if ($selected_site) {
             $site = Site::find($selected_site);
             if ($site->GivesAccessToUser($user->rfid) == 'Denied') {
                 DB::table('site_user')->insert(array('site_id' => $value->id, 'user_id' => $user->rfid));
             } else {
                 DB::table('site_user')->where('user_id', '=', $user->rfid)->where('site_id', '=', $value->id)->delete();
             }
         }
     }
     $zones = Zone::all();
     foreach ($zones as $key => $value) {
         $selected_zone = Input::get('selected_zone_' . $value->id);
         if ($selected_zone) {
             if ($value->GivesAccessToUser($user->rfid) == 'Denied') {
                 DB::table('user_zone')->insert(array('zone_id' => $value->id, 'user_id' => $user->rfid));
                 foreach ($sites as $site) {
                     if ($value->ContainsSite($site->id)) {
                         DB::table('site_user')->insert(array('site_id' => $site->id, 'user_id' => $user->rfid));
                     }
                 }
             } else {
                 DB::table('user_zone')->where('user_id', '=', $user->rfid)->where('zone_id', '=', $value->id)->delete();
                 foreach ($sites as $site) {
                     if ($value->ContainsSite($site->id)) {
                         DB::table('site_user')->where('user_id', '=', $user->rfid)->where('site_id', '=', $site->id)->delete();
                     }
                 }
             }
         }
     }
     return Redirect::to('user/' . $user->id);
 }
 public function site($siteId)
 {
     $search = Input::get('search', false);
     $timeTypeFilter = Input::get('timeTypeFilter', Webpage::CHANGED_OR_CREATED_FILTER);
     $timeFilter = Input::get('timeFilter', false);
     $typeFilter = Input::get('typeFilter', false);
     $site = Site::find($siteId);
     $webpages = Webpage::makeList($siteId, $search, $timeFilter, $typeFilter, $timeTypeFilter);
     return View::make('site', compact('site', 'webpages', 'search', 'timeFilter', 'typeFilter', 'timeTypeFilter'));
 }