/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Building();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Building'])) {
         $model->attributes = $_POST['Building'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->idno));
         }
     }
     $this->render('create', array('model' => $model));
 }
Пример #2
0
 public function createBuilding()
 {
     $building = new Building();
     $building->name = Input::get('name');
     $building->slug = Input::get('name');
     $building->owner_id = Input::get('user');
     $building->save();
     $user = User::find(Input::get('user'));
     $building->users()->save($user);
     $setting = new Setting();
     $setting->email = $user->email;
     $setting->building_id = $building->id;
     $setting->save();
     return Redirect::to('buildings')->with('message', 'Building created');
 }
 /**
  * Saves buildings. First all will be deleted and then the new or earlier existing ones will
  * be added again. This prevents a need for comparison.
  */
 public function actionBuildingSave($kohteetString, $imageid, $cd, $id, $addTo = false)
 {
     // if we are not adding to the previous values, but instead are replacing
     if (!$addTo) {
         // clearing out all the 'kohteet' for the image
         Building::model()->deleteByPk($imageid);
     }
     // getting rid of spaces in the inputstring
     $kohteetString = str_replace(' ', '', $kohteetString);
     // splits the inputted string into an array, so each building can be handled on it's own
     $kohteetArray = explode(',', $kohteetString);
     // this repeated for the kohteetArray, so that every building is it's own row in the kohteet table
     foreach ($kohteetArray as $kohde) {
         $saari = preg_replace('/[0-9k-z]/', '', $kohde);
         $rakennus = preg_replace('/[^0-9k-z]/', '', $kohde);
         // converting saari letter to uppercase
         $saari = strtolower($saari);
         if (strlen($saari) < 1) {
             continue;
         }
         // if we are adding, checks the database if the building&image combination is already there, will not add a duplicate
         if ($addTo) {
             $duplicateCriteria = new CDbCriteria();
             $duplicateCriteria->condition = 'cdno=:cdno';
             $duplicateCriteria->addCondition('idno=:idno');
             $duplicateCriteria->addCondition('saari=:saari');
             $duplicateCriteria->addCondition('rakennus=:rakennus');
             $duplicateCriteria->params = array(':cdno' => $cd, ':idno' => $id, ':saari' => $saari, ':rakennus' => $rakennus);
             // if a it's already found in the database, will continue; to the the next kohde
             if (Building::model()->find($duplicateCriteria)) {
                 continue;
             }
         }
         $newKohde = new Building();
         $newKohde->cdno = $cd;
         $newKohde->idno = $id;
         $newKohde->saari = $saari;
         $newKohde->rakennus = $rakennus;
         $newKohde->fk = $imageid;
         $newKohde->save();
         unset($newKohde);
     }
 }
Пример #4
0
 public function actionEditMolUser($table, $action, $id, $value)
 {
     switch ($table) {
         case 'po_name':
             switch ($action) {
                 case 'add':
                     $po_name = new po_name();
                     $po_name->po_name = $value;
                     $po_name->po_type_id = $id;
                     if ($po_name->save()) {
                         $result = 'ПО добавлено';
                     }
                     break;
                 case 'delete':
                     $po_name = po_name::findOne($id);
                     if ($po_name->active == '1') {
                         $po_name->active = '0';
                     } else {
                         $po_name->active = '1';
                     }
                     if ($po_name->save()) {
                         $result = 'Статус изменен';
                     }
                     break;
                 case 'edit':
                     if ($value != '') {
                         $po_name = po_name::findOne($id);
                         $po_name->po_name = $value;
                         if ($po_name->save()) {
                             $result = 'ПО переименовано';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
             }
             break;
         case 'po_type':
             switch ($action) {
                 case 'add':
                     $po_type = new po_type();
                     $po_type->po_type = $value;
                     if ($po_type->save()) {
                         $result = 'Тип ПО добавлен';
                     }
                     break;
                 case 'delete':
                     $po_type = po_type::findOne($id);
                     if ($po_type->active == '1') {
                         $po_type->active = '0';
                     } else {
                         $po_type->active = '1';
                     }
                     if ($po_type->save()) {
                         $result = 'Статус изменен';
                     }
                     break;
                 case 'edit':
                     if ($value != '') {
                         $po_type = po_type::findOne($id);
                         $po_type->po_type = $value;
                         if ($po_type->save()) {
                             $result = 'Тип ПО переименован';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
             }
             break;
         case 'mol':
             switch ($action) {
                 case 'add':
                     $mol = new mol();
                     $mol->value = $value;
                     if ($mol->save()) {
                         $result = 'МОЛ добавлено';
                     }
                     break;
                 case 'delete':
                     $mol = mol::findOne($id);
                     if ($mol->active == '1') {
                         $mol->active = '0';
                     } else {
                         $mol->active = '1';
                     }
                     if ($mol->save()) {
                         $result = 'Статус изменен';
                     }
                     break;
                 case 'edit':
                     if ($value != '') {
                         $mol = mol::findOne($id);
                         $mol->value = $value;
                         if ($mol->save()) {
                             $result = 'МОЛ переименовано';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
             }
             break;
         case 'cpu':
             switch ($action) {
                 case 'add':
                     $cpu = new cpu();
                     $cpu->name = $value;
                     if ($cpu->save()) {
                         $result = 'Процессор добавлен';
                     }
                     break;
                 case 'delete':
                     $cpu = cpu::findOne($id);
                     if ($cpu->active == '1') {
                         $cpu->active = '0';
                     } else {
                         $cpu->active = '1';
                     }
                     if ($cpu->save()) {
                         $result = 'Статус изменен';
                     }
                     break;
                 case 'edit':
                     if ($value != '') {
                         $cpu = cpu::findOne($id);
                         $cpu->name = $value;
                         if ($cpu->save()) {
                             $result = 'Процессор переименован';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
             }
             break;
         case 'cartridge_type':
             switch ($action) {
                 case 'add':
                     $type = new CartridgeType();
                     $type->type = $value;
                     if ($type->save()) {
                         $result = 'Тип картриджа добавлен';
                     }
                     break;
                 case 'delete':
                     $type = CartridgeType::find()->where(['type' => $id])->One();
                     if ($type->delete()) {
                         $result = 'Тип картриджа удален';
                     }
                     break;
                 case 'edit':
                     if ($value != '') {
                         $type = CartridgeType::find()->where(['type' => $id])->One();
                         $type->type = $value;
                         if ($type->update()) {
                             $result = 'Картридж переименован';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
             }
             break;
         case 'consignment':
             switch ($action) {
                 case 'add':
                     $consignment = new consignment();
                     $consignment->name = $value;
                     if ($consignment->save()) {
                         $result = 'Партия добавлена';
                     } else {
                         $result = 'Партия НЕ добавлена';
                     }
                     break;
                 case 'delete':
                     // $query_str = 'UPDATE consignment SET active = NOT active WHERE id = "'.$id.'"';
                     //$consignment = consignment::findOne($id);
                     //if ($consignment -> active == '1') $consignment -> active = '0'; else $consignment -> active = '1';
                     //$consignment -> save();
                     //$result = 'Статус изменен';
                     break;
                 case 'edit':
                     if ($value != '') {
                         $consignment = consignment::findOne($id);
                         $consignment->name = $value;
                         if ($consignment->save()) {
                             $result = 'Партия переименована';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
             }
             break;
         case 'type':
             switch ($action) {
                 case 'add':
                     $device_type = new deviceType();
                     $device_type->value = $value;
                     if ($device_type->save()) {
                         $result = 'Тип добавлен';
                     }
                     break;
                 case 'delete':
                     $device_type = deviceType::findOne($id);
                     if ($device_type->active == '1') {
                         $device_type->active = '0';
                     } else {
                         $device_type->active = '1';
                     }
                     if ($device_type->save()) {
                         $result = 'Статус изменен';
                     }
                     break;
                 case 'edit':
                     if ($value != '') {
                         $device_type = deviceType::findOne($id);
                         $device_type->value = $value;
                         if ($device_type->save()) {
                             $result = 'Тип переименован';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
             }
             break;
         case 'mark':
             switch ($action) {
                 case 'add':
                     $mark = new trademarks();
                     $mark->value = $value;
                     if ($mark->save()) {
                         $result = 'Марка добавлена';
                     }
                     break;
                 case 'delete':
                     $mark = mark::findOne($id);
                     if ($mark->active == '1') {
                         $mark->active = '0';
                     } else {
                         $mark->active = '1';
                     }
                     if ($mark->save()) {
                         $result = 'Статус изменен';
                     }
                     break;
                 case 'edit':
                     if ($value != '') {
                         $mark = mark::findOne($id);
                         $mark->value = $value;
                         if ($mark->save()) {
                             $result = 'Марка переименована';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
             }
             break;
         case 'user':
             switch ($action) {
                 case 'add':
                     $user = new user();
                     $user->name = $value;
                     $user->password = sha1('1');
                     if ($user->save()) {
                         $result = 'Сотрудник добавлен';
                     }
                     break;
                 case 'delete':
                     if ($value != '') {
                         $user = user::findOne($id);
                         if ($user->active == '1') {
                             $user->active = '0';
                         } else {
                             $user->active = '1';
                         }
                         if ($user->save()) {
                             $result = 'Статус изменен';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
                 case 'edit':
                     $user = user::findOne($id);
                     $user->name = $value;
                     if ($user->save()) {
                         $result = 'Сотрудник переименован';
                     }
                     break;
             }
             break;
         case 'room':
             switch ($action) {
                 case 'add':
                     $room = new room();
                     $room->value = $value;
                     $room->building_id = $id;
                     if ($room->save()) {
                         $result = 'Кабинет добавлен';
                     } else {
                         $result = print_r($room->getErrors());
                     }
                     break;
                 case 'delete':
                     $room = room::findOne($id);
                     if ($room->active == '1') {
                         $room->active = '0';
                     } else {
                         $room->active = '1';
                     }
                     $room->save();
                     //$result = 'Статус изменен';
                     $result = '';
                     break;
                 case 'edit':
                     if ($value != '') {
                         $room = room::findOne($id);
                         $room->value = $value;
                         if ($room->save()) {
                             $result = 'Кабинет переименован';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
             }
             break;
         case 'device':
             switch ($action) {
                 case 'add':
                     switch (substr($id, 0, 3)) {
                         case 'mrk':
                             $result = 'Марка не добавлена! Выберите тип устройства для добавления!';
                             break;
                         case 'typ':
                             $type_id = intval(substr($id, 4));
                             $trademark = new trademark();
                             $trademark->value = $value;
                             $TypeLinkMark = new TypeLinkMark();
                             $TypeLinkMark->type_id = $type_id;
                             $TypeLinkMark->mark_id = Yii::app()->db->getLastInsertID();
                             if ($TypeLinkMark->save() && $trademark->save()) {
                                 $result = 'Марка добавлена';
                             }
                             break;
                     }
                     break;
                 case 'delete':
                     $device = new device();
                     $device->value = $value;
                     if ($device->save()) {
                         $result = 'Статус изменен';
                     }
                     break;
                 case 'edit':
                     $query_str = 'UPDATE user SET value = "' . $value . '" WHERE id = "' . $id . '"';
                     $result = 'Сотрудник переименован';
                     break;
             }
             break;
         case 'model':
             switch ($action) {
                 case 'add':
                     $model = new model();
                     $model->value = $value;
                     $model->save();
                     $result = 'Модель добавлена';
                     break;
                 case 'delete':
                     $model = model::findOne($id);
                     if ($model->active == '1') {
                         $model->active = '0';
                     } else {
                         $model->active = '1';
                     }
                     $model->save();
                     //$result = 'Статус изменен';
                     $result = '';
                     break;
                 case 'edit':
                     if ($value != '') {
                         $model = model::findOne($id);
                         $model->value = $value;
                         if ($model->save()) {
                             $result = 'Модель переименована';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
             }
             break;
         case 'department':
             switch ($action) {
                 case 'delete':
                     //$result = 'Статус изменен';
                     $department = department::findOne($id);
                     if ($department->active == '1') {
                         $department->active = '0';
                     } else {
                         $department->active = '1';
                     }
                     $department->save();
                     $result = '';
                     break;
                 case 'edit':
                     if ($value != '') {
                         $department = department::findOne($id);
                         $department->value = $value;
                         if ($department->save()) {
                             $result = 'Подразделение переименовано';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
                 case 'add':
                     $department = new Department();
                     $department->value = $value;
                     if ($department->save()) {
                         $result = 'Подразделение добавлено';
                     }
                     break;
             }
             break;
         case 'building':
             switch ($action) {
                 case 'delete':
                     $building = building::findOne($id);
                     if ($building->active == '1') {
                         $building->active = '0';
                     } else {
                         $building->active = '1';
                     }
                     $building->save();
                     //$result = 'Статус изменен';
                     $result = '';
                     break;
                 case 'edit':
                     if ($value != '') {
                         $building = building::findOne($id);
                         $building->value = $value;
                         if ($building->save()) {
                             $result = 'Здание переименовано';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
                 case 'add':
                     $building = new Building();
                     $building->value = $value;
                     $building->department_id = $id;
                     if ($building->save()) {
                         $result = 'Здание добавлено';
                     }
                     break;
             }
             break;
     }
     echo $result;
 }
Пример #5
0
        } else {
            $this->vars[$offset] = $value;
        }
    }

    public function offsetExists($offset) {
        return isset($this->vars[$offset]);
    }

    public function offsetUnset($offset) {
        unset($this->vars[$offset]);
    }

    public function offsetGet($offset) {
        return isset($this->vars[$offset]) ? $this->vars[$offset] : null;
    }

    public function save() {
        var_dump($this->vars);
    }

}

echo 'Возможно, начиная с пятой версии. Подразумевается, что класс Building использует встроенный интерфейс ArrayAccess, которые позволяет обратиться к объекту, как к массиву, тогда как в действительности объект имеет методы, обеспечивающие работу механизма, который и создаёт подобную функциональность.<br>';

$obj = new Building();
$obj['name'] = 'Main tower';
$obj['flats'] = 100;
$obj->save();

echo '<hr>';