Guest User

Untitled

a guest
Jun 22nd, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. protected function _emailAlreadySubscribed($email)
  2. {
  3. $select = $this->_model->select()->where('email = ?', $email);
  4. $rows = $table->fetchAll($select);
  5. if ($rows->count()) {
  6. return true;
  7. }
  8. return false;
  9. }
  10.  
  11. try {
  12. $model->insert($data);
  13. $added++;
  14. } catch (Zend_Db_Exception $e) {
  15. if(strstr($e->getMessage(), '1062 Duplicate')) {
  16. // duplicate
  17. $duplicates++;
  18. } else {
  19. // general error
  20. $errors++;
  21. }
  22. }
  23.  
  24. protected function _emailAlreadySubscribed($email)
  25. {
  26. $select = $this->_model->select()->where('email = ?', $email);
  27. $rows = $table->fetchAll($select);
  28. if ($rows->count()) {
  29. return true;
  30. }
  31. return false;
  32. }
  33.  
  34. class Project_Validate_DbUnique extends Zend_Validate_Abstract
  35. {
  36. const NOT_UNIQUE = 'dbUniqueNotUnique';
  37.  
  38. protected $_messageTemplates = array(
  39. self::NOT_UNIQUE => "'%column%' '%value' already exists"
  40. );
  41.  
  42. /**
  43. * @var array
  44. */
  45. protected $_messageVariables = array(
  46. 'column' => '_column',
  47. );
  48.  
  49. /**
  50. * The table where to check for unique value in column
  51. *
  52. * @var Zend_Db_Table
  53. */
  54. protected $_dbTable = NULL;
  55.  
  56. /**
  57. * The column name where to check for unique value
  58. *
  59. * @var string
  60. */
  61. protected $_column = '';
  62.  
  63. /**
  64. * The values of the primary key for this row if updating - to exclude the current row from the test
  65. *
  66. * @var array
  67. */
  68. protected $_rowPrimaryKey = NULL;
  69.  
  70. public function __construct(Zend_Db_Table_Abstract $table, $column, $rowPrimaryKey = NULL)
  71. {
  72. $this->_dbTable = $table;
  73. $this->_column = $column;
  74. $this->_rowPrimaryKey = $rowPrimaryKey;
  75. }
  76. public function isValid($value)
  77. {
  78. $this->_setValue($value);
  79.  
  80. $select = $this->_dbTable->select();
  81. $select->where($this->_dbTable->getAdapter()->quoteInto($this->_column . ' = ?', $value));
  82. if (isset($this->_rowPrimaryKey))
  83. {
  84. $rowPrimaryKey = (array) $this->_rowPrimaryKey;
  85. $info = $this->_dbTable->info();
  86.  
  87. foreach ($info['primary'] as $key => $column)
  88. {
  89. $select->where($this->_dbTable->getAdapter()->quoteInto($column . ' != ?', $rowPrimaryKey[$key - 1]));
  90. }
  91. }
  92.  
  93. $row = $this->_dbTable->fetchAll($select);
  94. if ($row->count())
  95. {
  96. $this->_error();
  97. return false;
  98. }
  99.  
  100. return true;
  101. }
  102. }
Add Comment
Please, Sign In to add comment