public function beforeSave() { if ($this->ip) { $this->ip_long = ip2long($this->ip); } return parent::beforeSave(); }
public function beforeDelete() { if ($this->video_file) { $pathVideo = Yii::getPathOfAlias($this->path) . DIRECTORY_SEPARATOR . $this->apartment_id . DIRECTORY_SEPARATOR; deleteFile($pathVideo, $this->video_file); } return parent::beforeDelete(); }
public function beforeSave() { if ($this->isNewRecord) { $maxSorter = Yii::app()->db->createCommand()->select('MAX(sorter) as maxSorter')->from($this->tableName())->queryScalar(); $this->sorter = $maxSorter + 1; } return parent::beforeSave(); }
public function beforeSave() { if ($this->scenario == 'set_default') { $sql = "UPDATE " . $this->tableName() . " SET is_default=0 WHERE id !=" . $this->id; Yii::app()->db->createCommand($sql)->execute(); } return parent::beforeSave(); }
public function afterSave() { $langs = Lang::getActiveLangs(); foreach ($langs as $lang) { Yii::app()->cache->delete(DbMessageSource::CACHE_KEY_PREFIX . '.messages.' . $this->category . '.' . $lang); } return parent::afterSave(); }
public function beforeSave() { $settings = array(); foreach ($this->payModel->attributes as $key => $value) { $settings[$key] = $value; } // Сохраняем аттрибуты зависимой модели (настройки платежки) $this->settings = CJSON::encode($settings); return parent::beforeSave(); }
public function beforeSave() { if ($this->isNewRecord) { $maxSorter = Yii::app()->db->createCommand()->select('MAX(sorter) as maxSorter')->from($this->tableName())->queryScalar(); $this->sorter = $maxSorter + 1; } // $defaultCurrencyCharCode = Currency::getDefaultCurrencyModel()->char_code; // if($defaultCurrencyCharCode != $this->in_currency){ // $this->price = (int) Currency::convert($this->price, $this->in_currency, $defaultCurrencyCharCode); // } return parent::beforeSave(); }
public function beforeDelete() { $sql = 'DELETE FROM {{apartment_reference_values}} WHERE reference_category_id="' . $this->id . '";'; Yii::app()->db->createCommand($sql)->execute(); $sql = 'DELETE FROM {{apartment_reference}} WHERE reference_id="' . $this->id . '"'; Yii::app()->db->createCommand($sql)->execute(); $formDesignerModel = FormDesigner::model()->findByAttributes(array('reference_id' => $this->id)); if ($formDesignerModel) { $formDesignerModel->delete(); } return parent::beforeDelete(); }
public function afterDelete() { if ($this->is_main) { $sql = 'UPDATE {{images}} SET is_main=1 WHERE id_object=:id LIMIT 1'; Yii::app()->db->createCommand($sql)->execute(array(':id' => $this->id_object)); } $names = array('thumb_*x*_' . $this->file_name_modified, 'full_' . $this->file_name_modified); foreach ($names as $name) { $mask = Yii::getPathOfAlias('webroot') . DIRECTORY_SEPARATOR . self::UPLOAD_DIR . DIRECTORY_SEPARATOR . self::OBJECTS_DIR . DIRECTORY_SEPARATOR . $this->id_object . DIRECTORY_SEPARATOR . self::MODIFIED_IMG_DIR . DIRECTORY_SEPARATOR . $name; @array_map("unlink", glob($mask)); } @unlink(Yii::getPathOfAlias('webroot') . DIRECTORY_SEPARATOR . self::UPLOAD_DIR . DIRECTORY_SEPARATOR . self::OBJECTS_DIR . DIRECTORY_SEPARATOR . $this->id_object . DIRECTORY_SEPARATOR . self::ORIGINAL_IMG_DIR . DIRECTORY_SEPARATOR . $this->file_name); return parent::afterDelete(); }
public function beforeDelete() { // удалять тарифы пользователей. деактивировать объявления. $sql = 'SELECT user_id FROM {{users_tariff_plans}} WHERE tariff_id = ' . $this->id; $res = Yii::app()->db->createCommand($sql)->queryColumn(); if ($res) { $usersIds = array(); if (count($res) > 0) { foreach ($res as $userId) { $usersIds[$userId] = $userId; } } if (count($usersIds) > 0) { TariffPlans::deactivateUserAdsByTariffPlan($usersIds); } } $sql = 'UPDATE {{users_tariff_plans}} SET status = ' . UsersTariffPlans::STATUS_NO_ACTIVE . ' WHERE tariff_id = ' . $this->id; Yii::app()->db->createCommand($sql)->execute(); return parent::beforeDelete(); }
public function beforeSave() { Configuration::clearCache(); return parent::beforeSave(); }
public function beforeSave() { $this->status = self::STATUS_NO_ERROR; return parent::beforeSave(); }
public function beforeSave() { if ($this->fileInstance) { $path = Yii::getPathOfAlias($this->path) . DIRECTORY_SEPARATOR . $this->apartment_id; $name = $this->fileInstance->getName(); $ext = $this->fileInstance->getExtensionName(); while (file_exists($path . DIRECTORY_SEPARATOR . $name)) { $name = rand(0, 9) . $name; } $oldUMask = umask(0); if (!is_dir($path)) { @mkdir($path, 0777, true); } umask($oldUMask); if ($this->fileInstance->saveAs($path . DIRECTORY_SEPARATOR . $name)) { $this->name = $name; if ($ext == 'jpg' || $ext == 'png' || $ext == 'gif') { $image = new CImageHandler(); if ($image->load($path . DIRECTORY_SEPARATOR . $name)) { $this->width = $image->getWidth(); $this->height = $image->getHeight(); } else { return false; } } } else { return false; } } return parent::beforeSave(); }
public function afterSave() { if ($this->status == Comment::STATUS_APPROVED) { $this->_calcRating(); // if($this->model_name == 'Apartment'){ // $ad = Apartment::model()->with('user')->findByPk($this->model_id); // if($ad && isset($ad->user)){ // $user = $ad->user; // $notifier = new Notifier(); // $notifier->raiseEvent('onNewComment', $this, array('user' => $user)); // } // } } if ($this->isNewRecord) { if (!Yii::app()->user->isGuest) { $model = HUser::getModel(); $this->user_name = $model->username; $this->user_email = $model->email; } $notifier = new Notifier(); $notifier->raiseEvent('onNewComment', $this); } return parent::afterSave(); }
public function beforeDelete() { return parent::beforeDelete(); }
public static function model($className = __CLASS__) { return parent::model($className); }
public function beforeDelete() { @unlink(Yii::getPathOfAlias($this->path) . DIRECTORY_SEPARATOR . $this->name); $fileName = 'thumb_' . self::FULL_THUMB_WIDTH . 'x' . self::FULL_THUMB_HEIGHT . "_" . $this->name; @unlink(Yii::getPathOfAlias($this->path) . DIRECTORY_SEPARATOR . $fileName); return parent::beforeDelete(); }
public function getAttributeLabel($attribute) { if (issetModule('formeditor')) { $label = FormDesigner::getLabelForm($attribute); return $label ? $label : parent::getAttributeLabel($attribute); } return parent::getAttributeLabel($attribute); }
public function beforeDelete() { $fieldName = $this->field; $sql = "SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_NAME='{{apartment}}' AND COLUMN_NAME='{$fieldName}' AND table_schema = DATABASE()"; $fieldExist = Yii::app()->db->createCommand($sql)->queryScalar(); if ($fieldExist) { Yii::app()->db->createCommand("ALTER TABLE {{apartment}} DROP `{$fieldName}`")->execute(); } Yii::app()->db->createCommand("DELETE FROM {{search_form}} WHERE field=:field")->execute(array(':field' => $fieldName)); Yii::app()->cache->flush(); return parent::beforeDelete(); }
public function beforeDelete() { if (issetModule('seo') && param('genFirendlyUrl')) { $sql = 'DELETE FROM {{seo_friendly_url}} WHERE model_id="' . $this->id . '" AND model_name = "Blog"'; Yii::app()->db->createCommand($sql)->execute(); } if ($this->image) { $this->image->delete(); } $sql = 'DELETE FROM {{comments}} WHERE model_id=:id AND model_name="Blog"'; Yii::app()->db->createCommand($sql)->execute(array(':id' => $this->id)); return parent::beforeDelete(); }
public function afterFind() { // $dateFormat = param('dateFormat', 'd.m.Y H:i:s'); $this->dateCreatedFormat = Yii::app()->dateFormatter->format(Yii::app()->locale->getDateFormat('long'), CDateTimeParser::parse($this->date_created, 'yyyy-MM-dd hh:mm:ss')); parent::afterFind(); }
public function signup() { $firstname = Input::get('firstname'); $lastname = Input::get('lastname'); $username = Input::get('username'); $email = Input::get('email'); $password = Input::get('password'); $cpassword = Input::get('confirmpassword'); $at = Input::get('accounttype'); $parentusername = Input::get('parentusername'); $contact = Input::get('contact'); $picture = ""; if ($password == $cpassword) { $user_check = UserModel::where('username', '=', $username)->first(); if ($user_check == "") { $userid = bin2hex(mcrypt_create_iv(22, MCRYPT_DEV_URANDOM)) . "=" . $username . "+" . $at; if ($at == "Parent") { if (Input::hasFile('file')) { //upload profile picture and set filename to a variale to save to db $file = Input::file('file'); $filename = bin2hex(mcrypt_create_iv(10, MCRYPT_DEV_URANDOM)) . "" . $username . "-" . $file->getClientOriginalName(); $file->move('public/profilepics', $filename); $picture = $filename; } else { //set picture to null $picture = "images/user.png"; } //save as parent account //$pw=Hash::make($password); $pw = md5($password); $user = new UserModel(); $user->userid = $userid; $user->firstname = $firstname; $user->lastname = $lastname; $user->username = $username; $user->password = $pw; $user->email = $email; $user->contact = $contact; $user->accttype = $at; $user->picture = $picture; $user->occupation = 'Please specify'; $user->gender = 'Please specify'; $user->birthday = 'Please specify'; $user->city = 'Please specify'; $user->home = 'Please specify'; $user->save(); $parentid = bin2hex(mcrypt_create_iv(10, MCRYPT_DEV_URANDOM)) . "+" . $userid; $membership = ""; $membership_status = ""; $parent = new ParentModel(); $parent->userid = $userid; $parent->parentid = $parentid; $parent->membership = $membership; $parent->membership_status = $membership_status; $parent->save(); $message = "Parent Registration Successful!"; $response['status'] = "success"; $response['message'] = $message; echo json_encode($response); } elseif ($at == "Child") { $temp_at = ""; //setting $temp_at as null in default. //check if parentusername in database $user = UserModel::where('username', '=', $parentusername)->first(); $temp_at = $user['accttype']; if ($temp_at == "" or $temp_at == "Child") { $return_sets = array('firstname' => $firstname, 'lastname' => $lastname, 'username' => $username, 'email' => $email, 'contact' => $contact); //return Redirect::intended('http://lock-lockitproject.rhcloud.com/#toregister')->with('message', 'Parent Username not found!')->with('sets', $return_sets); $message = "Parent Username not found!"; $response['status'] = "failed"; $response['message'] = $message; echo json_encode($response); } else { if (Input::hasFile('file')) { //upload profile picture and set filename to a variale to save to db $file = Input::file('file'); $filename = bin2hex(mcrypt_create_iv(10, MCRYPT_DEV_URANDOM)) . "" . $username . "-" . $file->getClientOriginalName(); $file->move('public/profilepics', $filename); $picture = $filename; } else { //set picture to null $picture = "images/user.png"; } $pw = md5($password); //For User Database $user = new UserModel(); $user->userid = $userid; $user->firstname = $firstname; $user->lastname = $lastname; $user->username = $username; $user->password = $pw; $user->email = $email; $user->contact = $contact; $user->accttype = $at; $user->picture = $picture; $user->occupation = 'Please specify'; $user->gender = 'Please specify'; $user->birthday = 'Please specify'; $user->city = 'Please specify'; $user->home = 'Please specify'; $user->save(); $childid = bin2hex(mcrypt_create_iv(15, MCRYPT_DEV_URANDOM)) . "+" . $userid; $computerid = bin2hex(mcrypt_create_iv(10, MCRYPT_DEV_URANDOM)) . "computer" . bin2hex(mcrypt_create_iv(10, MCRYPT_DEV_URANDOM)) . "*" . $username; $status = ""; //For Child database $child = new ChildModel(); $child->userid = $userid; $child->childid = $childid; $child->computerid = $computerid; $child->parentusername = $parentusername; $child->status = $status; $child->save(); //For Computer Database $os_username = ""; $domain_name = ""; $sid = ""; $computer = new ComputerModel(); $computer->computerid = $computerid; $computer->username = $os_username; $computer->domainname = $domain_name; $computer->sid = $sid; $computer->save(); //return View::make('content.entry')->with('message',$message)->with('background','#A9F5A9')->with('sets',$this->sets); $message = "Child Registration Successful!"; $response['status'] = "success"; $response['message'] = $message; echo json_encode($response); } } //end of elseif($at=="Child") } elseif ($user_check != "") { $return_sets = array('firstname' => $firstname, 'lastname' => $lastname, 'username' => $username, 'email' => $email, 'contact' => $contact); //return Redirect::intended('http://localhost:8000/#toregister')->with('message', 'Username is already taken!')->with('sets', $return_sets); $message = "Username already taken"; $response['status'] = "failed"; $response['message'] = $message; echo json_encode($response); } } // end of if($password==$cpassword) }
public function beforeDelete() { if (issetModule('seo') && param('genFirendlyUrl')) { $sql = 'DELETE FROM {{seo_friendly_url}} WHERE model_id="' . $this->id . '" AND model_name = "InfoPages"'; Yii::app()->db->createCommand($sql)->execute(); } return parent::beforeDelete(); }
public function afterDelete() { $sql = 'DELETE FROM {{apartment_reference}} WHERE reference_value_id="' . $this->id . '"'; Yii::app()->db->createCommand($sql)->execute(); return parent::afterDelete(); }
public function afterSave() { if (issetModule('seo') && param('genFirendlyUrl')) { SeoFriendlyUrl::getAndCreateForModel($this); } return parent::afterSave(); }
public function view_dashboard() { /* if (Auth::check()) { $user=Session::get('sess_user_arr'); $parent=ParentModel::where('userid','=',$user['userid'])->first(); return View::make('content.dashboard')->with('user',$user)->with('parent',$parent); }*/ $user = Session::get('sess_user_arr'); if ($user != "") { $children = DB::table('user')->leftJoin('child', 'user.userid', '=', 'child.userid')->where('child.parentusername', '=', $user['username'])->get(); $blocklist = DB::table('blacklist')->where('parentusername', '=', $user['username'])->get(); $parent = ParentModel::where('userid', '=', $user['userid'])->first(); return View::make('content.dashboard')->with('user', $user)->with('parent', $parent)->with('children', $children)->with('blocklist', $blocklist); } else { return View::make('content.entry')->with('message', 'Oops, you are not logged in yet!')->with('background', '#F6CECE')->with('sets', $this->sets); } }
public function beforeDelete() { if ($this->name_iso == self::getDefaultLang() || $this->name_iso == self::getAdminMailLang() || $this->model()->count() <= 1) { return false; } $this->deleteLang($this->name_iso); return parent::beforeDelete(); }
public function beforeSave() { // foreach (Lang::getActiveLangs() as $key => $item) { // $additionalInfo = 'additional_info_'.$item; // if (isset($this->$additionalInfo) && !empty($this->$additionalInfo)) { // $this->$additionalInfo = nl2br($this->$additionalInfo); // } // } $this->type = $this->type && in_array($this->type, self::getTypeList('key')) ? $this->type : User::TYPE_PRIVATE_PERSON; return parent::beforeSave(); }
public function afterDelete() { $sql = 'UPDATE {{apartment}} SET window_to="0" WHERE window_to="' . $this->id . '"'; Yii::app()->db->createCommand($sql)->execute(); return parent::afterDelete(); }
public function beforeDelete() { $sql = 'SELECT id, file_path FROM {{messages_files}} WHERE id_message="' . $this->id . '"'; $items = Yii::app()->db->createCommand($sql)->queryAll(); $message = new Messages(); if ($items) { foreach ($items as $item) { if (file_exists($message->uploadPath . '/' . $item['file_path'])) { unlink($message->uploadPath . '/' . $item['file_path']); MessagesFiles::model()->deleteByPk($item['id']); } } } return parent::beforeDelete(); }