Overview

Packages

  • controladores
  • modelos
  • None
  • PHP

Classes

  • Activity
  • ActivityController
  • AuthController
  • BaseController
  • Course
  • DatabaseSeeder
  • ExampleTest
  • Guardian
  • HomeController
  • Message
  • MessageController
  • OptStudentCriteriaGrade
  • Period
  • Profile
  • SchoolSetup
  • Student
  • StudentCriteriaGrade
  • StudentSubjectSubperiodAverage
  • StudentSubjectSubperiodAverageController
  • SubPeriod
  • TestCase
  • User
  • UserController

Exceptions

  • Exception
  • InvalidArgumentException
  • LogicException

Functions

  • ws_response
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * Mapeo de la tabla usuarios
  5:  * @package modelos
  6:  * @author Fernando Salas <rfsalas@rutatec.com>
  7:  * @since  2016-02-23
  8:  */
  9: class User extends Eloquent {
 10: 
 11:     /**
 12:      * @string variable para mapeo de la tabla representante con el nombre que le corresponde en la base de datos
 13:      */
 14:     protected $table = 'user';
 15: 
 16:     /**
 17:      * @string variable llave primaria utilizada en la tabla user
 18:      */
 19:     protected $primaryKey = 'serial_usr';
 20: 
 21:     /**
 22:      * @string variable tiempo en falso
 23:      */
 24:     public $timestamps = false;
 25: 
 26:     /**
 27:      * @array variable password del usuario
 28:      */
 29:     protected $hidden = array('password_usr');
 30: 
 31:     /**
 32:      * @path foto del usuario
 33:      */
 34:     public $image_path = '/img/users/';
 35: 
 36:     /**
 37:      * @array variable para asociar el usuario a el perfil de estudiante o representante
 38:      */
 39:     public static $allowedProfiles = array('Representante', 'Estudiante');
 40: 
 41:     /**
 42:      * Establece las reglas de logueo del usuario
 43:      *
 44:      * @param   void
 45:      *
 46:      * @return  array
 47:      * @throws  InvalidArgumentException
 48:      * @since   2016-02-23
 49:      * @author  Fernando Salas <rfsalas@rutatec.com>
 50:      *
 51:      * @edit    2016-02-23<br />
 52:      *          Fernando Salas <rfsalas@rutatec.com><br />
 53:      *          documentacion del metodo<br/>
 54:      *          #edit1
 55:      */
 56:     public static function rulesLogin() {
 57:         return array(
 58:             'username' => 'required',
 59:             'password' => 'required',
 60:         );
 61:     }
 62: 
 63:     /**
 64:      * Establece la direccion de la imagen del usuario
 65:      *
 66:      * @param   void
 67:      *
 68:      * @return  path
 69:      * @throws  InvalidArgumentException
 70:      * @since   2016-02-23
 71:      * @author  Fernando Salas <rfsalas@rutatec.com>
 72:      *
 73:      * @edit    2016-02-23<br />
 74:      *          Fernando Salas <rfsalas@rutatec.com><br />
 75:      *          documentacion del metodo<br/>
 76:      *          #edit1
 77:      */
 78:     public function image() {
 79:         if ($this->photo_usr) {
 80:             $path = $this->image_path . $this->photo_usr;
 81: //            if (file_exists($path)) {
 82:             return $path;
 83: //            }
 84:         }
 85:         return $this->image_path . 'noavatar.png';
 86:     }
 87: 
 88:     /**
 89:      * Establece bandeja de entrada de los usuarios
 90:      *
 91:      * @param   string page
 92:      * @param   string status
 93:      * @return  string messages
 94:      * @throws  InvalidArgumentException
 95:      * @since   2016-02-23
 96:      * @author  Fernando Salas <rfsalas@rutatec.com>
 97:      *
 98:      * @edit    2016-02-23<br />
 99:      *          Fernando Salas <rfsalas@rutatec.com><br />
100:      *          documentacion del metodo<br/>
101:      *          #edit1
102:      */
103:     public function messageInbox($page, $status) {
104:         $sql = "";
105:         $limit = 20;
106:         $from = $limit * ($page - 1);
107:         if ($status == 'default') {
108:             $sql = "(SELECT msg.serial_msg, msg.user_from_name_msg, msg.subject_msg, LEFT(msg.message_msg,120) as message_msg, msg.checked_msg, msg.deleted_msg, DATE_FORMAT(msg.send_date_msg, '%d-%m-%Y %H:%i') as send_date_msg
109:                     ,msg.attachment_msg, msg.priority_msg
110:                         FROM message_thread_messages mtm
111:                             JOIN message msg ON msg.serial_msg = mtm.serial_msg 
112:                             AND (msg.checked_msg = 'NO' OR msg.checked_msg = 'YES')
113:                             AND msg.deleted_msg = 'NO' 
114:                             AND msg.removed_permanently_msg = 'NO'
115:                             AND msg.serial_usr_receive =$this->serial_usr
116:                         WHERE  mtm.serial_mth IN
117:                             (
118:                             SELECT ( mtm.serial_mth )
119:                                 FROM message_thread_messages mtm
120:                                 JOIN message msg ON msg.serial_msg = mtm.serial_msg
121:                                 WHERE msg.serial_usr_receive =$this->serial_usr                                            
122:                             GROUP BY mtm.serial_mth
123:                             )
124:                         )
125:                          UNION
126:                             (SELECT msg.serial_msg, msg.user_from_name_msg, msg.subject_msg, msg.message_msg, msg.checked_msg, msg.deleted_msg, DATE_FORMAT(msg.send_date_msg, '%d-%m-%Y %H:%i') as send_date_msg,
127:                             msg.attachment_msg, msg.priority_msg
128:                             FROM message msg
129:                             WHERE msg.serial_usr_receive = $this->serial_usr  
130:                             AND (msg.checked_msg = 'NO' OR msg.checked_msg = 'YES')
131:                             AND msg.removed_permanently_msg = 'NO'
132:                             AND msg.deleted_msg = 'NO' )                
133:                 ORDER BY serial_msg desc
134:                 LIMIT  $from, $limit";
135:         } else if ($status == 'unread') {
136:             $sql = "(SELECT msg.serial_msg, msg.user_from_name_msg, msg.subject_msg, LEFT(msg.message_msg,120) as message_msg, msg.checked_msg, msg.deleted_msg, DATE_FORMAT(msg.send_date_msg, '%d-%m-%Y %H:%i') as send_date_msg
137:                     ,msg.attachment_msg, msg.priority_msg
138:                         FROM message_thread_messages mtm
139:                             JOIN message msg ON msg.serial_msg = mtm.serial_msg 
140:                             AND msg.checked_msg = 'NO' 
141:                             AND msg.deleted_msg = 'NO' 
142:                             AND msg.removed_permanently_msg = 'NO'
143:                             AND msg.serial_usr_receive =$this->serial_usr                          
144:                         WHERE  mtm.serial_mth IN
145:                             (
146:                             SELECT ( mtm.serial_mth )
147:                                 FROM message_thread_messages mtm
148:                                 JOIN message msg ON msg.serial_msg = mtm.serial_msg
149:                                 WHERE msg.serial_usr_receive =$this->serial_usr                                            
150:                             GROUP BY mtm.serial_mth
151:                             )
152:                         )
153:                          UNION
154:                             (SELECT msg.serial_msg, msg.user_from_name_msg, msg.subject_msg, msg.message_msg, msg.checked_msg, msg.deleted_msg, DATE_FORMAT(msg.send_date_msg, '%d-%m-%Y %H:%i') as send_date_msg,
155:                             msg.attachment_msg, msg.priority_msg
156:                             FROM message msg
157:                             WHERE msg.serial_usr_receive = $this->serial_usr  
158:                             AND msg.checked_msg = 'NO' 
159:                             AND msg.removed_permanently_msg = 'NO'
160:                             AND msg.deleted_msg = 'NO' )                
161:                 ORDER BY serial_msg desc
162:                 LIMIT $from, $limit";
163:         } else if ($status == 'delete') {
164:             $sql = "(SELECT msg.serial_msg, msg.user_from_name_msg, msg.subject_msg, LEFT(msg.message_msg,120) as message_msg, msg.checked_msg, msg.deleted_msg, DATE_FORMAT(msg.send_date_msg, '%d-%m-%Y %H:%i') as send_date_msg
165:                     ,msg.attachment_msg, msg.priority_msg
166:                         FROM message_thread_messages mtm
167:                             JOIN message msg ON msg.serial_msg = mtm.serial_msg 
168:                             AND msg.deleted_msg = 'YES' 
169:                             AND msg.removed_permanently_msg = 'NO'
170:                             AND msg.serial_usr_receive =$this->serial_usr                          
171:                         WHERE  mtm.serial_mth IN
172:                             (
173:                             SELECT ( mtm.serial_mth )
174:                                 FROM message_thread_messages mtm
175:                                 JOIN message msg ON msg.serial_msg = mtm.serial_msg
176:                                 WHERE msg.serial_usr_receive =$this->serial_usr                                            
177:                             GROUP BY mtm.serial_mth
178:                             )
179:                         )
180:                          UNION
181:                             (SELECT msg.serial_msg, msg.user_from_name_msg, msg.subject_msg, msg.message_msg, msg.checked_msg, msg.deleted_msg, DATE_FORMAT(msg.send_date_msg, '%d-%m-%Y %H:%i') as send_date_msg,
182:                             msg.attachment_msg, msg.priority_msg
183:                             FROM message msg
184:                             WHERE msg.serial_usr_receive = $this->serial_usr
185:                             AND msg.removed_permanently_msg = 'NO'
186:                             AND msg.deleted_msg = 'YES' )                
187:                 ORDER BY serial_msg desc
188:                 LIMIT  $from, $limit";
189:         }
190:         $messages = DB::select(DB::raw($sql));
191:         return $messages;
192:     }
193: 
194:     /**
195:      * Mensajes no leidos  del usuario
196:      *
197:      * @param   void
198:      * 
199:      * @return  string messages
200:      * @throws  InvalidArgumentException
201:      * @since   2016-02-23
202:      * @author  Fernando Salas <rfsalas@rutatec.com>
203:      *
204:      * @edit    2016-02-23<br />
205:      *          Fernando Salas <rfsalas@rutatec.com><br />
206:      *          documentacion del metodo<br/>
207:      *          #edit1
208:      */
209:     public function unreadMessages() {
210:         $sql = "SELECT COUNT(msg.serial_msg) as messages
211:                                     FROM message msg
212:                                     WHERE serial_usr_receive=$this->serial_usr
213:                                     AND msg.checked_msg='NO'
214:                                     AND msg.removed_permanently_msg!='YES'";
215:         return $messages = DB::select(DB::raw($sql));
216:     }
217: 
218:     /**
219:      * Cambio de estado de los mensajes
220:      *
221:      * @param   void
222:      * 
223:      * @return  string messages
224:      * @throws  InvalidArgumentException
225:      * @since   2016-02-23
226:      * @author  Fernando Salas <rfsalas@rutatec.com>
227:      *
228:      * @edit    2016-02-23<br />
229:      *          Fernando Salas <rfsalas@rutatec.com><br />
230:      *          documentacion del metodo<br/>
231:      *          #edit1
232:      */
233:     public function changeStateMessage($serial_msg, $status) {
234:         $message = Message::find($serial_msg);
235:         if ($status == 'readed') {
236:             $message->checked_msg = 'YES';
237:             $message->save();
238:             return $response = 'Change Succesfull';
239:         } else if ($status == 'deleted') {
240:             if ($message->deleted_msg == 'YES') {
241:                 $message->removed_permanently_msg = 'YES';
242:                 $message->save();
243:             } else {
244:                 $message->deleted_msg = 'YES';
245:                 $message->save();
246:             }
247:             return $response = 'Change Succesfull';
248:         } else {
249:             return $response = 'Fail To Change State';
250:         }
251:     }
252: 
253:     /**
254:      * Detalle de los mensajes de usuario
255:      *
256:      * @param   void
257:      * 
258:      * @return  string messages
259:      * @throws  InvalidArgumentException
260:      * @since   2016-02-23
261:      * @author  Fernando Salas <rfsalas@rutatec.com>
262:      *
263:      * @edit    2016-02-23<br />
264:      *          Fernando Salas <rfsalas@rutatec.com><br />
265:      *          documentacion del metodo<br/>
266:      *          #edit1
267:      */
268:     public function DetailsMessage($serial_msg) {
269:         $message = Message::find($serial_msg);
270:         return $message;
271:     }
272: 
273: }
274: 
learnbox_ws API documentation generated by ApiGen