public static function WALK_ARRAY($array, $return_data = false, $end = false) { $output = ""; $output .= "<pre>"; if (Validator::HAS_DATA($array)) { if (is_array($array)) { foreach ($array as $key => $data) { if (!is_array($data)) { $output .= $key . ' => ' . $data . '<br/>'; } else { $output .= self::WALK_ARRAY($data, true); } } } } $output .= "</pre>"; if (!$return_data) { echo $output; } else { return $output; } if ($end) { Yii::app()->end(); } }
public static function GET_USER($attribute = null) { if ($attribute != null) { return isset(Yii::app()->user->{$attribute}) ? Yii::app()->user->{$attribute} : null; } else { return Validator::HAS_DATA(Yii::app()->user) ? Yii::app()->user : null; } }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); $usersRol = UserRol::model()->findAll(); if (!Validator::HAS_DATA($usersRol)) { throw new CHttpException('404', Yii::t('app', 'No data available')); } $s2_userRoles = array_merge(array('' => ''), ModelBase::GET_MODEL_ATTRIBUTE_VALUES_TO_ARRAY($usersRol, null, 'name')); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $model->password = null; $this->render('update', array('model' => $model, 's2_userRoles' => $s2_userRoles)); }
public static function toHtmlValueTag($modelData, $tag, $valueAttr = null, $optionContentAttr, $emptyTag = true) { $html = ""; $arrayCount = count($optionContentAttr) - 1; if (Validator::HAS_DATA($modelData)) { foreach ($modelData as $data) { $htmlContent = ""; foreach ($optionContentAttr as $key => $oAttr) { $htmlContent .= $data->{$oAttr}; if ($key < $arrayCount) { $htmlContent .= ' '; } } $htmlValue = $valueAttr != null ? 'value=' . '"' . $data->{$valueAttr} . '"' : ''; $html .= '<' . $tag . ' ' . $htmlValue . '>' . $htmlContent . '</' . $tag . '>'; } } if ($emptyTag) { $html = '<' . $tag . '></' . $tag . '>' . $html; } return $html; }
/** * @param $CActiveRecord $model * @param $string $relation * @param $string $attribute * @return array */ public static function GET_MODEL_ATTRIBUTE_VALUES_TO_ARRAY($model, $relation, $attribute, $appendAttr = NULL, $arrayKeyID = true) { $result = array(); if ($relation != NULL) { if (is_array($model->{$relation})) { foreach ($model->{$relation} as $rel) { $aux = !isset($appendAttr) ? $rel->{$attribute} : $rel->{$attribute} . ',' . $rel->{$appendAttr}; if ($arrayKeyID) { $result[$rel->id] = $aux; } else { $result[] = $aux; } } } else { foreach ($model as $data) { $aux = !isset($appendAttr) ? $data->{$relation}->{$attribute} : $data->{$relation}->{$attribute} . ',' . $data->{$relation}->{$appendAttr}; if ($arrayKeyID) { $result[$data->{$relation}->id] = $aux; } else { $result[] = $aux; } } } } else { foreach ($model as $data) { $aux = !isset($appendAttr) ? $data->{$attribute} : $data->{$attribute} . ',' . $data->{$appendAttr}; if ($arrayKeyID) { $result[$data->id] = $aux; } else { $result[] = $aux; } } } return Validator::HAS_DATA($result) ? $result : false; }
public static function sendMail($model = null, $message, $subject, $address = false, $reply = false) { $testing = Yii::app()->params['testing']; try { $mailer = Yii::createComponent('application.extensions.mailer.EMailer'); if ($model != null) { foreach ($model->attributes as $key => $attribute) { if (Validator::HAS_DATA($attribute) && $key != 'verifyCode') { if ($key != 'file') { $message .= '<div style="position: relative; overflow: hidden;"><p style="float: left;"><b>' . Yii::t('app', $key) . ': </b></p><p style="float: left; margin-left: 10px;max-width: 600px;">' . nl2br($attribute) . '</p></div><div style="clear: both;"></div>'; } else { $mailer->AddAttachment($model->file->tempName, $model->file); } } } } if ($testing) { /*$mailer->IsSendmail(); $mailer->Host = 'smtp.scripsanddeals.com'; $mailer->Port = 25; $mailer->Username = '******'; $mailer->Password = '******'; $mailer->From = '*****@*****.**'; $mailer->FromName = 'Scrips&Deals';*/ $mailer->SMTPAuth = true; $mailer->IsSMTP(); $mailer->Host = 'ssl://smtp.gmail.com'; $mailer->Port = 465; $mailer->Username = '******'; $mailer->Password = '******'; $mailer->From = '*****@*****.**'; $mailer->FromName = 'Scrips&Deals'; $mailer->AddAddress('*****@*****.**'); } else { $mailer->IsSendmail(); $mailer->Host = 'smtp.scripsanddeals.com'; $mailer->Port = 25; $mailer->Username = '******'; $mailer->Password = '******'; $mailer->From = '*****@*****.**'; $mailer->FromName = 'Scrips&Deals'; if ($address) { if (is_array($address)) { foreach ($address as $add) { $mailer->AddAddress($add); } } elseif (is_string($address)) { $address = explode(';', $address); foreach ($address as $add) { $mailer->AddAddress($add); } } } else { //$mailer->AddAddress('*****@*****.**'); } //$mailer->AddAddAddress('*****@*****.**'); } if ($reply) { if (is_array($reply)) { foreach ($reply as $addReply) { $mailer->AddReplyTo($addReply); } } elseif (is_string($reply)) { $reply = explode(';', $address); foreach ($reply as $addReply) { $mailer->AddReplyTo($addReply); } } } $mailer->IsHTML(true); $mailer->CharSet = 'UTF-8'; $mailer->Subject = $subject; $mailer->Body = $message; if (!$mailer->Send()) { error_log($mailer->ErrorInfo, 0); $result = "Hubo un inconveniente al enviar el correo.<br />" . $mailer->ErrorInfo . ". Por favor, inténtalo más tarde."; Yii::app()->user->setFlash('error', $result); } else { Yii::app()->user->setFlash('successMail', Yii::t('app', 'Your mail has been send successfully') . '.'); } } catch (phpmailerException $e) { Yii::app()->user->setFlash('notice', $e->errorMessage()); throw new CHttpException(403, $e->errorMessage()); } catch (Exception $e) { Yii::app()->user->setFlash('notice', $e->getMessage()); throw new CHttpException(403, $e->getMessage()); } }