public function validate() { $result = parent::validate(); if (Catalogue::get()->filter(array('Video_title' => $this->Video_Title))->first()) { $result->error('This media has already been inserted to the catalogue.'); } return $result; }
/** * gets genres as a separate query sorts and removes duplicates * * @return string */ public function getGenres() { $result = Catalogue::get()->sort('Genre')->where('Genre is not null')->column($colName = "Genre"); if ($result != null) { /** clean up keywords from DB **/ $_list = array(parent::__convertAndCleanList($result, '|')); $genreList = ""; foreach ($_list as $list) { foreach ($list as $value) { $genreList .= "<li><span data-path=\"." . str_replace(' ', '', $value) . "\">" . $value . "</span></li>"; } } return $genreList; } }
/** * returns an array of results that contain titles based on keyword metadata * * @return array */ public function seeAlsoTitles() { //check how many keywords //if keywords <= 1 then check trilogy == keyword $trilogy = array($this->video[0]->trilogy); $trilogy = array_map('strtolower', $trilogy); $array = array_diff(array_map('strtolower', $this->keywordsArr), $trilogy); //loop over values so we can create WHERE like clauses $clauses = array(); foreach ($array as $value) { $clauses[] = 'keywords LIKE \'%' . Convert::raw2sql($value) . '%\''; } if ($this->video[0]->trilogy == null && count($this->keywordsArr) > 1) { return Catalogue::get()->where(implode(' OR ', $clauses))->exclude('ID', $this->id); } if (count($this->keywordsArr) <= 1) { return false; //nothing to return so return a false so view doesn't display anything. } else { //keywords are only 1, so we will return back array of keyword results. return Catalogue::get()->where(implode(' OR ', $clauses))->exclude('trilogy', $this->video[0]->trilogy); //get all titles related to wolverine and exclude itself from result. } }
/** * gets distinct all Genres from records * */ public function __getGenres() { $result = Catalogue::get()->sort('Genre')->where('Genre is not null')->column($colName = "Genre"); return $result; }
/** * gets genres as a separate query */ public function getGenres() { $result = Catalogue::get()->sort('Genre')->where('Genre is not null')->column($colName = "Genre"); if ($result != null) { /** clean up keywords from DB **/ $implode = implode("|", $result); //implode array to string, saves foreaching $trim = preg_replace('/\\s+/', '', $implode); //remove white spaces before and after commas $explode = explode("|", $trim); //explode string to array by comma sort($explode); //sort the array alphabetically $_list = array(array_keys(array_flip($explode))); //get only unique elements $genreList = ""; foreach ($_list as $list) { foreach ($list as $value) { $genreList .= "<li><span data-path=\"." . $value . "\">" . $value . "</span></li>"; } } return $genreList; } }