/** * @return Logger */ public function getLogger() { if (!isset($this->_logger)) { $this->_logger = \Yii::getLogger(); } return $this->_logger; }
public function init() { parent::init(); if (!$this->items) { throw new InvalidConfigException(\Yii::t('front', 'No required parameter given') . ' - items'); } }
public static function getUrlUploadMultiImages($obj, $user_id) { $url_arr = array(); $min_size = 1024 * 1000 * 700; $max_size = 1024 * 1000 * 1000 * 3.5; foreach ($obj["tmp_name"] as $key => $tmp_name) { $ext_arr = array('png', 'jpg', 'jpeg', 'bmp'); $name = StringHelper::filterString($obj['name'][$key]); $storeFolder = Yii::getPathOfAlias('webroot') . '/images/' . date('Y-m-d', time()) . '/' . $user_id . '/'; $pathUrl = 'images/' . date('Y-m-d', time()) . '/' . $user_id . '/' . time() . $name; if (!file_exists($storeFolder)) { mkdir($storeFolder, 0777, true); } $tempFile = $obj['tmp_name'][$key]; $targetFile = $storeFolder . time() . $name; $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION)); $size = $obj['name']['size']; if (in_array($ext, $ext_arr)) { if ($size >= $min_size && $size <= $max_size) { if (move_uploaded_file($tempFile, $targetFile)) { array_push($url_arr, $pathUrl); } else { return NULL; } } else { return NULL; } } else { return NULL; } } return $url_arr; }
public function run($action, $to, $id) { $to = CActiveRecord::model($this->getController()->CQtreeGreedView['modelClassName'])->findByPk((int) $to); $moved = CActiveRecord::model($this->getController()->CQtreeGreedView['modelClassName'])->findByPk((int) $id); if (!is_null($to) && !is_null($moved)) { try { switch ($action) { case 'child': $moved->moveAsLast($to); break; case 'before': if ($to->isRoot()) { $moved->moveAsRoot(); } else { $moved->moveBefore($to); } break; case 'after': if ($to->isRoot()) { $moved->moveAsRoot(); } else { $moved->moveAfter($to); } break; } } catch (Exception $e) { Yii::app()->user->setFlash('CQTeeGridView', $e->getMessage()); } } $this->getController()->redirect(array($this->getController()->CQtreeGreedView['adminAction'])); }
/** * Run this widget. * This method registers necessary javascript and renders the needed HTML code. */ public function run() { list($name, $id) = $this->resolveNameID(); if (isset($this->htmlOptions['id'])) { $id = $this->htmlOptions['id']; } else { $this->htmlOptions['id'] = $id; } if (isset($this->htmlOptions['name'])) { $name = $this->htmlOptions['name']; } else { $this->htmlOptions['name'] = $name; } if ($this->hasModel()) { echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions); } else { echo CHtml::textField($name, $this->value, $this->htmlOptions); } $options = CJavaScript::encode($this->options); $js = "jQuery('#{$id}').datepicker({$options});"; if (isset($this->language)) { $this->registerScriptFile($this->i18nScriptFile); $js = "jQuery('#{$id}').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['{$this->language}'], {$options}));"; } $cs = Yii::app()->getClientScript(); $cs->registerScript(__CLASS__, $this->defaultOptions ? 'jQuery.datepicker.setDefaults(' . CJavaScript::encode($this->defaultOptions) . ');' : ''); $cs->registerScript(__CLASS__ . '#' . $id, $js); }
/** * Renders the content of the widget. * @throws CException */ public function run() { // Hide empty breadcrumbs. if (empty($this->links)) { return; } $links = array(); if (!isset($this->homeLink)) { $content = CHtml::link(Yii::t('zii', 'Inicio'), Yii::app()->homeUrl); $links[] = $this->renderItem($content); } else { if ($this->homeLink !== false) { $links[] = $this->renderItem($this->homeLink); } } foreach ($this->links as $label => $url) { if (is_string($label) || is_array($url)) { $content = CHtml::link($this->encodeLabel ? CHtml::encode($label) : $label, $url); $links[] = $this->renderItem($content); } else { $links[] = $this->renderItem($this->encodeLabel ? CHtml::encode($url) : $url, true); } } echo CHtml::tag('ul', $this->htmlOptions, implode('', $links)); }
/** * Magic getter. Returns this widget's packages. */ public function getPackages() { if (!isset($this->_packages)) { $this->_packages = array_merge(parent::getPackages(), array('TwoColumnSortableWidgetManagerJS' => array('baseUrl' => Yii::app()->request->baseUrl, 'js' => array('js/sortableWidgets/TwoColumnSortableWidgetManager.js'), 'depends' => array('SortableWidgetManagerJS')))); } return $this->_packages; }
/** * @param string $url * @param string $method * @param string $body * * @return FhirResponse */ public function request($url, $method = 'GET', $body = null) { $server_name = null; foreach ($this->servers as $name => $server) { if (substr($url, 0, strlen($server['base_url']))) { $server_name = $name; break; } } $this->applyServerConfig($server_name ? $this->servers[$server_name] : array()); $this->http_client->setUri($url); $this->http_client->setMethod($method); if ($body) { $this->http_client->setRawData($body, 'application/xml+fhir; charset=utf-8'); } $response = $this->http_client->request(); $this->http_client->resetParameters(); if ($body = $response->getBody()) { $use_errors = libxml_use_internal_errors(true); $value = Yii::app()->fhirMarshal->parseXml($body); $errors = libxml_get_errors(); libxml_use_internal_errors($use_errors); if ($errors) { throw new Exception("Error parsing XML response from {$method} to {$url}: " . print_r($errors, true)); } } else { $value = null; } return new FhirResponse($response->getStatus(), $value); }
public function init() { // register class paths for extension captcha extended Yii::$classMap = array_merge(Yii::$classMap, array('CaptchaExtendedAction' => Yii::getPathOfAlias('ext.captchaExtended') . DIRECTORY_SEPARATOR . 'CaptchaExtendedAction.php', 'CaptchaExtendedValidator' => Yii::getPathOfAlias('ext.captchaExtended') . DIRECTORY_SEPARATOR . 'CaptchaExtendedValidator.php')); $this->search = new Search(); $this->link = new Linksite(); }
public function init() { $this->name = \Yii::t('skeeks/shop/app', 'Delivery services'); $this->modelShowAttribute = "name"; $this->modelClassName = ShopDelivery::className(); parent::init(); }
/** * Позволяет тонко сконфигурировать грид перед самой отрисовкой * * @param BeforeGridEvent $event */ public function onBeforeGrid(BeforeGridEvent $event) { if (isset(Yii::app()->controller->buttons)) { foreach (Yii::app()->controller->buttons as $key => $buttonConfig) { if (isset($buttonConfig['code']) && $buttonConfig['code'] == 'create') { // Модули - типы создаваемого экземпляра $addButtonData = null; $phpScripts = PhpScript::model()->findAllByAttributes(array('id_php_script_interface' => PhpScript::ID_PHP_SCRIPT_INTERFACE_MODULE)); if (count($phpScripts) > 0) { $addButtonData = '<button class="btn navbar-btn btn-success dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>'; $addButtonData .= '<ul class="dropdown-menu">' . "\n"; foreach ($phpScripts as $phpScript) { /** * @var $phpScript PhpScript */ $linkModule = ObjectUrlRule::createUrlFromCurrent(BackendModule::ROUTE_INSTANCE_LIST, array(ObjectUrlRule::PARAM_OBJECT_INSTANCE => -1, ObjectUrlRule::PARAM_SYSTEM_MODULE => $phpScript->id_php_script_type)); $addButtonData .= "<li><a href='" . $linkModule . "'>" . $phpScript->description . "</a></li>"; } $addButtonData .= '</ul>' . "\n"; } $buttonConfig['addButtonData'] = $addButtonData; Yii::app()->controller->buttons[$key] = $buttonConfig; break; } } } }
protected function performAjaxValidation($model) { if (isset($_POST['ajax']) && $_POST['ajax'] === 'create-category-form') { echo CActiveForm::validate($model); Yii::app()->end(); } }
public function afterSave() { parent::afterSave(); $sql = "UPDATE p_nfy_subscription_categories " . "set category = 'role_{$this->role_name}.' " . "where category = 'role_{$this->oldName}.';"; Yii::app()->db->createCommand($sql)->execute(); return true; }
public function checkAccess() { // Save users last action on this space $membership = $this->space->getMembership(Yii::app()->user->id); if ($membership != null) { $membership->updateLastVisit(); } else { // Super Admin can always enter if (!Yii::app()->user->isAdmin()) { // Space invisible? if ($this->space->visibility == Space::VISIBILITY_NONE) { // Not Space Member throw new CHttpException(404, Yii::t('SpaceModule.behaviors_SpaceControllerBehavior', 'Space is invisible!')); } } } // Delete all pending notifications for this space $notifications = Notification::model()->findAllByAttributes(array('space_id' => $this->space->id, 'user_id' => Yii::app()->user->id), 'seen != 1'); foreach ($notifications as $n) { // Ignore Approval Notifications if ($n->class == "SpaceApprovalRequestNotification" || $n->class == "SpaceInviteNotification") { continue; } $n->seen = 1; $n->save(); } }
public function loadModel($id) { if (($model = DictionaryGroup::model()->findByPk($id)) === null) { throw new CHttpException(404, Yii::t('DictionaryModule.dictionary', 'Requested page was not found')); } return $model; }
public function actionUpdate($fid = 0, $gid = 0, $sort = '') { $timer = new CountTimer(); $cacheToken = 'cache-update'; Yii::beginProfile($cacheToken); ob_start(); // 生成版块列表缓存 $this->forward('forum/forumlist', false); // 生成帖子列表缓存 $sortArr = array('', 'new', 'marrow', 'top'); $fids = $this->_getFids($fid); $uids = $this->_getUidsByGid($gid); foreach ($sortArr as $sort) { foreach ($fids as $fid) { foreach ($uids as $uid) { $_GET = array_merge($_GET, array('hacker_uid' => $uid, 'boardId' => $fid, 'page' => 1, 'pageSize' => 10, 'sortby' => $sort)); $res = $this->forward('forum/topiclist', false); ob_clean(); } } } ob_end_clean(); var_dump($timer->stop()); Yii::endProfile($cacheToken); }
/** * Creates account for new users */ public function actionRegister() { if (!Yii::app()->user->isGuest) { Yii::app()->request->redirect('/'); } $user = new User('register'); $profile = new UserProfile(); if (Yii::app()->request->isPostRequest && isset($_POST['User'], $_POST['UserProfile'])) { $user->attributes = $_POST['User']; $profile->attributes = $_POST['UserProfile']; $valid = $user->validate(); $valid = $profile->validate() && $valid; if ($valid) { $user->save(); $profile->save(); $profile->setUser($user); // Add user to authenticated group Yii::app()->authManager->assign('Authenticated', $user->id); $this->addFlashMessage(Yii::t('UsersModule.core', 'Спасибо за регистрацию на нашем сайте.')); // Authenticate user $identity = new UserIdentity($user->username, $_POST['User']['password']); if ($identity->authenticate()) { Yii::app()->user->login($identity, Yii::app()->user->rememberTime); Yii::app()->request->redirect($this->createUrl('/users/profile/index')); } } } $this->render('register', array('user' => $user, 'profile' => $profile)); }
/** * $controller::$configuration['statusKey'] = 'status' by default * $controller::$configuration['statusError'] = 'error' by default * $controller::$configuration['resourceKey'] = 'resource' by default * $controller::$configuration['errorDescriptionKey'] = 'errorDescription' by default * @param string $errorCode is a key of Response::$errorDictionary array. * @param array $errorresource null by default. Can be added to specify error body (resource) of response * @return array prepeared to be JSON encoded */ public static function error($errorCode, $errorresource = null) { $controller = Yii::app()->controller; $errorDescription = self::errorDescription($errorCode); self::$response = array($controller::$configuration['statusKey'] => $controller::$configuration['statusError'], $controller::$configuration['statusError'] => array($controller::$configuration['errorCodeKey'] => $errorCode, $controller::$configuration['errorDescriptionKey'] => $errorDescription, $controller::$configuration['resourceKey'] => $errorresource)); return self::get(); }
public function actionView() { $radioId = Yii::app()->request->getParam("id", 0); $radioName = WapRadioModel::model()->findByPk($radioId)->name; $albumId = WapRadioModel::model()->getAlbumByRadio($radioId, "c2.id"); $radioAvatar = RadioModel::model()->getAvatarUrl($radioId, 's1'); $album = WapAlbumModel::model()->published()->findByPk($albumId); if (!$album) { $this->forward("/site/error", true); } $songsOfAlbum = WapSongModel::model()->getSongsOfAlbum($albumId); $artists = AlbumArtistModel::model()->getArtistsByAlbum($albumId); $phone = yii::app()->user->getState('msisdn'); $errorCode = 'success'; $errorDescription = ''; $registerText = WapAlbumModel::model()->getCustomMetaData('REG_TEXT'); ///meta tag $AlbumDetail = AlbumModel::model()->findByPk($albumId); $artistId = !empty($artists) ? $artists[0]->artist_id : $AlbumDetail->artist_id; $ArtistInfo = ArtistModel::model()->findByPk($artistId); $this->itemName = $AlbumDetail->name; $this->artist = $ArtistInfo->name; $this->thumb = AlbumModel::model()->getAvatarUrl($albumId, 's1'); $this->url = URLHelper::buildFriendlyURL("album", $albumId, Common::makeFriendlyUrl($ArtistInfo->name)); $this->description = strip_tags($AlbumDetail->description); //get other radio $parent_id = Yii::app()->params['horoscope']['parent_id']; $radioListOther = WapRadioModel::model()->getHoroscopes($parent_id); $this->render('detail', array('album' => $album, 'songsOfAlbum' => $songsOfAlbum, 'errorCode' => $errorCode, 'errorDescription' => $errorDescription, 'registerText' => $registerText, 'radioListOther' => $radioListOther, 'radioAvatar' => $radioAvatar)); }
public function redirect($url, $terminate = true, $statusCode = 302) { $this->setHeader('Location', $url); if ($terminate) { Yii::app()->end(0, false); } }
/** * Create the links for resources in the resource root * @return array the links, name => config */ protected function createLinks() { $app = \Yii::app(); /* @var \Restyii\Web\Application $app */ $controller = $this->getController(); $module = $controller->getModule(); if (!$module) { $module = $app; } $controllers = $app->getSchema()->getControllerInstances($module); /* @var \Restyii\Controller\Base[]|\CController[] $controllers */ $links = array('self' => array('title' => $module->name, 'href' => trim($app->getBaseUrl(), '/') . '/')); foreach ($controllers as $id => $controller) { if ($id === $module->defaultController) { continue; } $links[$id] = array('title' => method_exists($controller, 'classLabel') ? $controller->classLabel(true) : String::pluralize(String::humanize(substr(get_class($controller), 0, -10))), 'href' => $controller->createUrl('search')); if (method_exists($controller, 'classDescription')) { $links[$id]['description'] = $controller->classDescription(); } if (isset($controller->modelClass)) { $links[$id]['profile'] = array($controller->modelClass); } } return $links; }
/** * Authenticates the password. * This is the 'authenticate' validator as declared in rules(). */ public function authenticate($attribute, $params) { if (!$this->hasErrors()) { $identity = new UserIdentity($this->username, $this->password); $identity->authenticate(); switch ($identity->errorCode) { case UserIdentity::ERROR_NONE: $duration = $this->rememberMe ? 3600 * 24 * 30 : 0; // 30 days Yii::app()->user->login($identity, $duration); break; case UserIdentity::ERROR_USERNAME_INVALID: $this->addError('username', Yii::t('lan', 'Username is incorrect.')); break; case UserIdentity::ERROR_BANNED: $this->addError('username', Yii::t('lan', 'User is banned.')); break; case UserIdentity::ERROR_CONFIRMREGISTRATION: $this->addError('username', Yii::t('lan', 'Confirm user email.')); break; default: $this->addError('password', Yii::t('lan', 'Password is incorrect.')); break; } } }
/** * Initializes this application component. * This method is required by the {@link IApplicationComponent} interface. * It checks the availability of eAccelerator. * @throws CException if eAccelerator extension is not loaded, is disabled or the cache functions are not compiled in. */ public function init() { parent::init(); if (!function_exists('eaccelerator_get')) { throw new CException(Yii::t('yii', 'CEAcceleratorCache requires PHP eAccelerator extension to be loaded, enabled or compiled with the "--with-eaccelerator-shared-memory" option.')); } }
/** * {@inheritdoc} * * @param array $fixtures fixtures to be loaded. The array keys are fixture * names, and the array values are either AR class names or table names. If * table names, they must begin with a colon character (e.g. 'Post' means * an AR class, while ':Post' means a table name). * * @return void * @since 0.1.0 */ public function load($fixtures) { //$schema = $this->getDbConnection()->getSchema(); //$schema->checkIntegrity(false); $this->_rows = array(); $this->_records = array(); foreach ($fixtures as $fixtureName => $tableName) { if ($tableName[0] === ':') { $tableName = substr($tableName, 1); unset($modelClass); } else { $modelClass = \Yii::import($tableName, true); $tableName = CActiveRecord::model($modelClass)->tableName(); } if (($prefix = $this->getDbConnection()->tablePrefix) !== null) { $tableName = preg_replace('/{{(.*?)}}/', $prefix . '\\1', $tableName); } $this->resetTable($tableName); $rows = $this->loadFixture($tableName); if (is_array($rows) && is_string($fixtureName)) { $this->_rows[$fixtureName] = $rows; if (isset($modelClass)) { foreach (array_keys($rows) as $alias) { $this->_records[$fixtureName][$alias] = $modelClass; } } } } //$schema->checkIntegrity(true); }
protected function showGeneralForm() { $model = new SettingGeneralForm(); settings()->deleteCache(); //Set Value for the Settings $model->site_name = Yii::app()->settings->get('general', 'site_name'); $model->site_title = Yii::app()->settings->get('general', 'site_title'); $model->site_description = Yii::app()->settings->get('general', 'site_description'); $model->slogan = Yii::app()->settings->get('general', 'slogan'); $model->homepage = Yii::app()->settings->get('general', 'homepage'); // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'settings-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if (isset($_POST['SettingGeneralForm'])) { $model->attributes = $_POST['SettingGeneralForm']; if ($model->validate()) { settings()->deleteCache(); foreach ($model->attributes as $key => $value) { Yii::app()->settings->set('general', $key, $value); } user()->setFlash('success', t('General Settings Updated Successfully!')); } } $this->render('cmswidgets.views.settings.settings_general_widget', array('model' => $model)); }
public function run() { // Незачем выполнять последующие действия // для авторизованного пользователя: if (Yii::app()->user->isAuthenticated()) { $this->controller->redirect(Yii::app()->getUser()->getReturnUrl()); } $module = Yii::app()->getModule('user'); // Если восстановление отключено - ошбочка ;) if ($module->recoveryDisabled) { throw new CHttpException(404, Yii::t('UserModule.user', 'requested page was not found!')); } // Новая форма восстановления пароля: $form = new RecoveryForm(); if (($data = Yii::app()->getRequest()->getPost('RecoveryForm')) !== null) { $form->setAttributes($data); if ($form->validate() && Yii::app()->userManager->passwordRecovery($form->email)) { Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'Letter with password recovery instructions was sent on email which you choose during register')); $this->controller->redirect(array('/user/account/backendlogin')); } else { Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('UserModule.user', 'Password recovery error.')); } } $this->controller->render('recovery', array('model' => $form)); }
/** * @param Order $order */ public function sendOrderChangesNotify(Order $order) { $theme = Yii::t('OrderModule.order', 'Order #{n} in {site} store is changed', ['{n}' => $order->id, '{site}' => Yii::app()->getModule('yupe')->siteName]); $from = $this->module->notifyEmailFrom ?: Yii::app()->getModule('yupe')->email; $body = $this->view->renderPartial('/order/email/orderChangeStatus', ['order' => $order], true); $this->mail->send($from, $order->email, $theme, $body); }
/** * Render a test button. This link calls a modal * popup. * @return The element's content as a string. */ protected function renderTestButton() { $content = '<span>'; $content .= ZurmoHtml::ajaxLink(ZurmoHtml::tag('span', array('class' => 'z-label'), Zurmo::t('ZurmoModule', 'Test Connection')), Yii::app()->createUrl('zurmo/ldap/testConnection/', array()), static::resolveAjaxOptionsForTestLdapConnection($this->form->getId()), array('id' => 'TestLdapConnectionButton', 'class' => 'LdapTestingButton z-button')); $content .= '</span>'; return $content; }
/** * Runs the widget. */ public function run() { $id = $this->id; echo '</div>'; /** @var CClientScript $cs */ $cs = Yii::app()->getClientScript(); $options = CJavaScript::encode($this->options); $cs->registerScript(__CLASS__ . '#' . $id, "jQuery('#{$id}').modal({$options});"); // Register the "show" event-handler. if (isset($this->events['show'])) { $fn = CJavaScript::encode($this->events['show']); $cs->registerScript(__CLASS__ . '#' . $id . '.show', "jQuery('#{$id}').on('show', {$fn});"); } // Register the "shown" event-handler. if (isset($this->events['shown'])) { $fn = CJavaScript::encode($this->events['shown']); $cs->registerScript(__CLASS__ . '#' . $id . '.shown', "jQuery('#{$id}').on('shown', {$fn});"); } // Register the "hide" event-handler. if (isset($this->events['hide'])) { $fn = CJavaScript::encode($this->events['hide']); $cs->registerScript(__CLASS__ . '#' . $id . '.hide', "jQuery('#{$id}').on('hide', {$fn});"); } // Register the "hidden" event-handler. if (isset($this->events['hidden'])) { $fn = CJavaScript::encode($this->events['hidden']); $cs->registerScript(__CLASS__ . '#' . $id . '.hidden', "jQuery('#{$id}').on('hidden', {$fn});"); } }
/** * Initializes this application component. * This method is required by the {@link IApplicationComponent} interface. * It checks the availability of Zend Data Cache. * @throws CException if Zend Data Cache extension is not loaded. */ public function init() { parent::init(); if (!function_exists('zend_shm_cache_store')) { throw new CException(Yii::t('yii', 'CZendDataCache requires PHP Zend Data Cache extension to be loaded.')); } }