public function savedata() { $collection = EDMSQuery::instance("feedback"); $feedbackid = EDMSSequence::nextVal('feedbackid', 1, 'counters'); $newfeedback = array("feedbackid" => intval($feedbackid), "name" => $this->name, "message" => $this->message, "email" => $this->email, "insertdatetime" => new MongoDate()); $result = $collection->insert($newfeedback, array('safe' => true)); }
/** * EDMSQuery::instance() * * @param mixed $collectionName * @return */ public static function instance($collectionName) { if (!isset(self::$_instance)) { self::$_instance = array(); } if (!isset(self::$_instance[$collectionName])) { self::$_instance[$collectionName] = new EDMSQuery($collectionName); } return self::$_instance[$collectionName]; }
public function getCountSearchScripts($search) { if (trim($search) != '') { $collection = EDMSQuery::instance("scripts"); $regex = new MongoRegEx("/{$search}/i"); $criteria = array('$or' => array(array("tags" => $search), array("title" => $regex)), "isprivate" => 0); $select = array(); $count = $collection->findCount($criteria); return $count; } }
public function removeMember($memberid) { $collection = EDMSQuery::instance("members"); $result = $collection->remove(array("memberid" => $memberid), 'true', array('safe' => true)); }
/** * Create an index for the sequence * Call this once if you have a lot of different sequences to handle */ public static function ensureIndex($collectionName = 'edms_sequences', $dbName = null, $connectionId = null) { $query = new EDMSQuery($collectionName, $dbName, $connectionId); $query->ensureIndexes('sequence'); }
public function actionRecover() { $model = new LoginForm(); $status = ""; $oauthproviders = array("google", "yahoo", "facebook", "linkedin"); if (isset($_POST['email'])) { $email = $_POST['email']; $result = $model->checkEmail($email); if ($result) { if (in_array($result, $oauthproviders)) { $status = $result; Yii::app()->user->setFlash("recoverpwd", "This email does not have a ScriptOverflow account."); } else { $token = sha1($email . "AG"); $message = new YiiMailMessage(); $message->view = 'forgotpasswordemailtemplate'; $message->setBody(array('email' => $email, 'token' => $token), 'text/html'); $message->subject = 'Reset your ScriptOverflow password'; $message->addTo($email); $message->setFrom(array(Yii::app()->params['adminEmail'] => 'ScriptOverflow')); Yii::app()->mail->transportOptions = array('host' => Yii::app()->params['smtpserver'], 'port' => Yii::app()->params['smtpport'], 'username' => Yii::app()->params['smtpusername'], 'password' => Yii::app()->params['smtppassword']); Yii::app()->mail->send($message); Yii::app()->user->setFlash("recoverpwd", "Please check your email to reset your password."); $status = 'emailsent'; $collection = EDMSQuery::instance("recoverpwd"); $newentry = array("email" => $email, "token" => $token, "createdatetime" => new MongoDate()); $result = $collection->insert($newentry, array('safe' => true)); } } else { $status = 'emailnotfound'; Yii::app()->user->setFlash("recoverpwd", "Email not found. Please reenter."); } } $this->render('recover', array('status' => $status)); }
public function insertFav($scriptid, $flag) { $collection = EDMSQuery::instance("favs"); $memberid = Yii::app()->user->id; if ($flag) { $criteria = array("memberid" => intval($memberid)); $values = array('$addToSet' => array("scriptid" => intval($scriptid)), '$inc' => array('favcount' => 1)); $result = $collection->upsert($criteria, $values, array('safe' => true)); } else { $criteria = array("memberid" => intval($memberid)); $values = array('$pull' => array("scriptid" => intval($scriptid)), '$inc' => array('favcount' => -1)); $result = $collection->update($criteria, $values, '', array('safe' => true)); } }
/** * Fetches the data from the collection * Uses the assigned cursor * * @return array list of data items */ protected function fetchData() { $data = array(); if (empty($this->_cursor)) { return $data; } if (($sort = $this->getSort()) !== false && is_array($sort) && !empty($sort)) { $this->_cursor->sort($sort); } if (($pagination = $this->getPagination()) !== false) { $pagination->setItemCount($this->getTotalItemCount()); $limit = $pagination->pageSize; $skip = $pagination->currentPage * $limit; $this->_cursor->limit($limit)->skip($skip); } $modelProperties = null; //get the array of public, non static propertyNames of the _objectClassName instance if (isset($this->_objectClassName) && $this->_objectClassName != 'stdClass') { $modelInstance = new $this->_objectClassName(); if (!$modelInstance instanceof CModel) { $reflectionClass = new ReflectionClass($modelInstance); foreach ($reflectionClass->getProperties() as $property) { if ($property->isPublic() && !$property->isStatic()) { $modelProperties[] = $property->getName(); } } } } // fetch data foreach ($this->_cursor as $id => $value) { if (isset($this->_objectClassName)) { if ($this->_objectClassName == 'stdClass') { $data[] = (object) $value; //add as stdClass } else { $data[] = EDMSQuery::arrayToModel($value, $this->_objectClassName, $modelProperties); } } else { $data[] = $value; } } return $data; }
public function getScriptFav($memberid) { $collection = EDMSQuery::instance("favs"); $criteria = array('memberid' => $memberid, "favcount" => array('$gt' => 0)); $select = array("scriptid", "scriptcount"); $result = $collection->findOne($criteria, $select); //print_r($result['scriptid']); if (!empty($result['scriptid'])) { $collection = EDMSQuery::instance("scripts"); $criteria = array('scriptid' => array('$in' => $result['scriptid'])); $select = array(); $sort = array("lastmodifieddate" => -1); $rows = $collection->findArray($criteria, $select, $sort); //print_r($rows); return $rows; } else { return false; } }
public function checkMemberName() { $collection = EDMSQuery::instance("members"); $regex = new MongoRegEx("/^{$this->membername}\$/i"); $criteria = array('membername' => $regex, 'memberid' => array('$ne' => intval($this->memberid)), 'active' => 1); //$criteria = array('membername'=>'ramg','memberid'=>array('$ne'=>28),'active'=>1); $select = array(); $member = $collection->findOne($criteria); if (!empty($member)) { $this->addError('membername', 'Member Name already taken!'); } }