NotificacionController.php 818 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace app\components;
  3. use app\models\Notificacion;
  4. use yii\console\Controller;
  5. use yii\db\Expression;
  6. class NotificacionController extends Controller {
  7. public $debug = true;
  8. public function stdout($texto) {
  9. if ($this->debug) {
  10. parent::stdout($texto);
  11. }
  12. }
  13. public function consultarNotificacion() {
  14. $query = Notificacion::find()
  15. ->orderBy(["envio" => SORT_ASC]);
  16. $enviando = (clone $query)
  17. ->andWhere(["estatus" => Notificacion::ESTATUS_ENVIANDO])
  18. ->one();
  19. if ($enviando !== null) {
  20. $this->stdout("Notificación en poceso: ". $enviando->id ."\n");
  21. return null;
  22. }
  23. return (clone $query)
  24. ->andWhere(["<", "envio", new Expression('now()')])
  25. ->andWhere(["estatus" => Notificacion::ESTATUS_NUEVO])
  26. ->one();
  27. }
  28. }